function writeDate() {
	var now = new Date();
	var yr = now.getYear();
	if (navigator.appName.indexOf("Internet Explorer")==-1) {
		yr = yr + 1900;
	}
	var mName = now.getMonth() + 1;
	var dName = now.getDay() + 1;
	var dayNr = ((now.getDate()<10) ? "0" : "")+ now.getDate();
	if(dName==1) Day = "Sonntag";
	if(dName==2) Day = "Montag";
	if(dName==3) Day = "Dienstag";
	if(dName==4) Day = "Mittwoch";
	if(dName==5) Day = "Donnerstag";
	if(dName==6) Day = "Freitag";
	if(dName==7) Day = "Samstag";
	if(mName==1) Month="Januar";
	if(mName==2) Month="Februar";
	if(mName==3) Month="März";
	if(mName==4) Month="April";
	if(mName==5) Month="Mai";
	if(mName==6) Month="Juni";
	if(mName==7) Month="Juli";
	if(mName==8) Month="August";
	if(mName==9) Month="September";
	if(mName==10) Month="Oktober";
	if(mName==11) Month="November";
	if(mName==12) Month="Dezember";
	// String to display current date.
	   var todaysDate =(" "
		   + Day
		   + ", "
		   + dayNr
		   + ". "
		   + Month
		   + " "
		   + yr);
	// Write date to page.
	document.open();
	document.write("<FONT class=\"date\">"+todaysDate+"</FONT>");
}

function getHeight() {
	if ((window.innerHeight < screen.availHeight*0.8) || (window.innerWidth < screen.availWidth)) {
		window.moveTo(0,0);
		window.resizeTo(screen.availWidth, screen.availHeight);
	}
	var newHeight = window.innerHeight - 15;
	document.open();
	document.write("<div id=\"outerDiv\" style=\"height:" + newHeight + "px; margin-top:0px\">");
}

function checkForm() {
	if (document.form1.name.value == '') {
		alert('Bitte geben Sie einen Namen ein!');
		return false;
	} else {
		document.form1.name.value = document.form1.name.value.replace("ü","&uuml;").replace("ä","&auml;").replace("ö","&ouml;").replace("Ü","&Uuml;").replace("Ä","&Auml;").replace("Ö","&Ouml;").replace("ß","&szlig;");
	}
	if (document.form1.text.value == '') {
		alert('Bitte geben Sie einen Kommentar in das Textfeld ein!');
		return false;
	} else {
		document.form1.text.value = document.form1.text.value.replace("ü","&uuml;").replace("ä","&auml;").replace("ö","&ouml;").replace("Ü","&Uuml;").replace("Ä","&Auml;").replace("Ö","&Ouml;").replace("ß","&szlig;");
	}
	if (document.form1.homepage.value != '') {
		if ((document.form1.homepage.value.indexOf('http://') == -1) && (document.form1.homepage.value.indexOf('https://') == -1)) {
			alert('Dies ist keine gültige Internetadresse! Diese muss mit http:// oder https:// beginnen!');
			return false;
		}
	}
	if (document.form1.email.value != '') {
		if (!checkEmailAdr(document.form1.email.value)) {
			alert('Dies ist keine gültige E-Mail Adresse!');
			return false;
		}
	}
	if (document.form1.control.value.toUpperCase() != 'H6C43') {
		alert('Bitte geben Sie den Kontrollcode ein! Er steht direkt neben dem Feld und muss nur in das Feld übertragen werden.');
		return false;
	}
	setTimeout("openFile('artmedic_guestbook/')", 2000);
	return true;
}

function checkEmailAdr(address) {
	var status = true;
	var username = "";
	var hostname = "";
	
	if ( address.length < 8 )
		return false;
	
	var seperate = address.lastIndexOf("@");
	if ( seperate == -1 )
		return false;
	
	username = address.substring(0, seperate );
	if ( ! checkUsername( username, "<>()[],;:@\" " ) )
		return false;
	
	hostname = address.substring(seperate+1, address.length );
	if ( ! checkHostname( hostname ) )
		return false;
	
	return true;
}

function checkHostname( hostname ) {
	if ( hostname.charAt(0) == '[' ) {
		if ( hostname.charAt(hostname.length-1) != ']' )
			return false;
		var ipnr = hostname.substring( 1, hostname.length -1 );
		return checkIpnr( ipnr );
	}
	if ( hostname.charAt(0) == '#' ) {
		var nr = hostname.substring( 1, hostname.length );
		return checkNr( nr );
	}
	return checkFqdn( hostname );
}

function checkIpnr( ipnr ) {
	var iL=0;
	var iC=0;
	var i=0;
	var sNr = "";	
	for( ; i< ipnr.length; i++ ) {
		if ( ipnr.charAt(i) == '.' ) {
			if ( !iL || (iL> 3) || parseInt( sNr,10 ) > 255 )
				return false;
			iC++;
			iL = 0;
			sNr = "";
			continue;
		}
		if ( isDigit ( ipnr.charAt(i) ) ) {
			iL++;
			sNr = sNr + ipnr.charAt(i);
			continue;
		}
		return false;
	}
	if ( parseInt( sNr,10 ) > 255 )
		return false;
	if ( ( (iC==3) && (iL>=1) && (iL<=3) ) || ( (iC==4) && (!iL) )  )
		return true;
	else
		return false;
}

function isDigit( ch ) {
	if ( (ch >= '0') && (ch <= '9') )
		return true;
	else
		return false;
}


function isAlpha( ch ) {
	if ( ((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z')) )
		return true;
	else
		return false;
}


function isAlnum( ch ) {
	if ( isAlpha( ch ) || isDigit( ch ) )
		return true;
	else
		return false;
}

function checkFqdn( fqdn ) {
	var iL=0;
	var iC=0;
	var i=fqdn.length-1;
	if ( (fqdn.charAt(0) == '.') || (fqdn.charAt(0) == '-') )
		return false;
	if ( fqdn.charAt(i) == '.' )
		i=i-1;
	for( ; i>=0; i-- )	{
		if ( fqdn.charAt(i) == '.' ) {
			if ( iL < 2 && iC < 2 )
				return false;
			if ( fqdn.charAt(i-1) == '-' )
				return false;
			iC++;
			iL = 0;
			continue;
		}
		if ( isAlnum ( fqdn.charAt(i) ) ) {
			iL++;
			continue;
		}
		if ( fqdn.charAt(i) == '-' ) {
			if ( !iL )
				return false;
			iL++;
			continue;
		}
		return false;
	}
	if ( !iC || ( iL == 1 && iC < 2 ) || ( !iL && iC==1 ) ) {
		return false;
	}
	return true;
}
  
function notIn( str1, str2 ) {
	var i = 0;
	var j = str2.length;
	for( ; i<j; i++ ) {
		var str3 =  str2.charAt(i);
		if( str1.indexOf( str3 ) != -1 )
			return false;
	}
	return true;
}

function checkNr ( nr ) {
	var i=0;
	var j=nr.length;
	if( j < 1 )
		return false;
	for( ; i<j; i++ )
		if( ( nr.charAt(i) < '0' ) || ( nr.charAt(i) > '9' ) )
			return false;
	return true;
}

function checkUsername( username, mustBeQuoted ) {
	var i = 0;
	var j = username.length;
	if ( username.charAt(0) != '"' ) {
		if ( (username.charAt(0) <  ' ') || (username.charAt(0) >  '~') || !notIn( mustBeQuoted, username.charAt(0) ) )
			return false;
		for( i=1; i<j; i++ ) {
			if ( ( (username.charAt(i) < ' ') || (username.charAt(i) >  '~') || !notIn ( mustBeQuoted, username.charAt(i) ) ) && ( username.charAt(i-1) != '\\' ) )
				return false;
		}
	} else {
		if ( username.charAt( j-1 ) != '"' )
			return false;
		for( i=1; i<j-1; i++ ) {
			if ( ( (username.charAt(i) == '\n') || (username.charAt(i) == '\r')	|| (username.charAt(i) == '\"') ) && (username.charAt(i-1) != '\\') )
				return false;
		}
	}
	return true;
}

function openFile(file) {
	if (document.getElementById) {
		var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	}
	if (x) {
		x.onreadystatechange = function() {
			if (x.readyState == 4 && x.status == 200) {
				var el = document.getElementById("main");
				//alert (x.responseText);
				el.innerHTML = x.responseText;
			} //if
		} //funcction
		x.open("GET", file, true);
		x.send(null);
		return true;
	}//if
	return false;
};

function openOffer(file) {
	if (document.getElementById) {
		var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	}
	if (x) {
		x.onreadystatechange = function() {
			if (x.readyState == 4 && x.status == 200) {
				var el = document.getElementById("offerBottom");
				//alert (x.responseText);
				el.innerHTML = x.responseText;
			} //if
		} //funcction
		x.open("GET", file, true);
		x.send(null);
	}//if
};

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
var newwindow = ''

function popitup(url) {
	var popUpImg = new Image();
	popUpImg.src = url;
	var image = waitUntilLoaded(popUpImg);
	if (newwindow.location && !newwindow.closed) {
		newwindow.location.href = url; newwindow.focus();
	} else {
		newwindow=window.open(url,'htmlname','width=' + image.width + ',height=' + image.height + ',resizable=1') ;
	}
}

function waitUntilLoaded(popUpImg) {
	if (popUpImg.complete) {
		return popUpImg;
	} else {
		setTimeout(popUpImg, 100);
	}
}

function tidy() {
	if (newwindow.location && !newwindow.closed) { 
		newwindow.close();
	} 
}

