// Checks for Contact
function sendContact(){
	var msg = "";
	String(document.forms['contact'].name.value)=="" ? msg += "- Name\n" : "";
	String(document.forms['contact'].email.value)=="" ? msg += "- Email-address\n" : "";
	String(document.forms['contact'].recipient.value)=="" ? msg += "- Recipient\n" : "";
	String(document.forms['contact'].message.value)=="" ? msg += "- Message\n" : "";
	if (msg != ""){
		msg = "Please fill out the following required fields:\n\n" + msg + "\nand then try again.";
		alert (msg);
	}else{
		document.forms['contact'].submit();
	}
}

// Checks for Chat
function chatlogin(){
	if(navigator.product == 'Gecko') {
		document.loginform["interface"].value = 'mozilla';
	}else if(navigator.appName == 'Microsoft Internet Explorer' && window["ietest"] && window["ietest"].innerHTML) {
		document.loginform["interface"].value = 'ie';
	}else if(window.opera) {
		document.loginform["interface"].value = 'opera';
	}

	var msg = "";
	String(document.forms['loginform'].Nickname.value)=="" ? msg += "- Nickname\n" : "";
	if (msg != ""){
		msg = "Please fill out the following required fields:\n\n" + msg + "\nand then try again.";
		alert (msg);
	}
	else{
		document.forms['loginform'].submit();
	}
}

// Checks for Newsletter
function newsletter(){
	var msg = "";
	String(document.forms['newsletter'].email.value)=="" ? msg += "- Email-address\n" : "";
	String(document.forms['newsletter'].pw.value)=="" ? msg += "- Password\n" : "";
	String(document.forms['newsletter'].pw-conf.value)=="" ? msg += "- Password\n" : "";
	if (msg != ""){
		msg = "Please fill out the following required fields:\n\n" + msg + "\nand then try again.";
		alert (msg);
	}
	else{
		document.forms['newsletter'].submit();
	}
}

function editnewsletter(){
	var msg = "";
	String(document.forms['editnewsletter'].email.value)=="" ? msg += "- Email-address\n" : "";
	if (msg != ""){
		msg = "Please fill out the following required fields:\n\n" + msg + "\nand then try again.";
		alert (msg);
	}
	else{
		document.forms['editnewsletter'].submit();
	}
}


// General functions
function checkPassword(theForm, user_password1, user_password2){
	if (theForm.user_password1.value != theForm.user_password2.value){
		alert("The passwords do not match!");
		theForm.user_password2.value = "";
 		return (false);
	}
}

function checkEmailaddress(ea){
	// assume address is valid
	valid = true;
	ea = ea.toLowerCase();

	// check email address syntax
	if(ea == null) valid = false;
	else if(ea.indexOf("@") < 2) valid = false;
	else if(ea.indexOf("@") != ea.lastIndexOf("@")) valid = false;
	else if(ea.length - ea.lastIndexOf(".") < 3) valid = false;
	else if(ea.substr(ea.indexOf("@")+1,ea.length-1).indexOf(".") < 2) valid = false;

	// make sure the last set set of chars only contain alpha chars
	s = ea.substr(ea.lastIndexOf(".")+1,ea.length-1);
	for(i = 0 ; i < s.length ; i++){
		if(s.charCodeAt(i) < 97 || s.charCodeAt(i) > 122) valid = false;
	}

	// make sure the chars before the @ are valid (charCodes 33-57,65-90,95,97-122)
	s = ea.substr(0,ea.indexOf("@"));
	for(i = 0 ; i < s.length ; i++){
		c = s.charCodeAt(i);
		if(c == 95 || (c >= 33 && c <= 57) || (c >= 65 && c <= 90) || (c >= 97 && c <= 122)) ;
		else {
			valid = false;
			break;
		}
	} 
	if (valid == false){
	msg = "Please fill out a valid email-address!";
		alert (msg);
	}
}

function checkURL(url,target){
	if (String(url).substring(0,7)=="http://"){
		target.value = String(url).substring(7,String(url).length);
	}
}

