// Checks for Contact Form

function sendContactForm(){
	var msg = "";
	String(document.forms['contact'].voornaam.value)=="" ? msg += "voornaam, " : "";
	String(document.forms['contact'].achternaam.value)=="" ? msg += "achternaam, " : "";

	if(controleGeselecteerd(document.forms['contact'].geslacht) == false){	
		msg +="geslacht, ";	
	}
	
	String(document.forms['contact'].telefoonnummer.value)=="" ? msg += "telefoonnummer, " : "";
	String(document.forms['contact'].postcode.value)=="" ? msg += "postcode, " : "";		
	String(document.forms['contact'].woonplaats.value)=="" ? msg += "woonplaats, " : "";			
	controleEmail(document.forms['contact'].email)==false ? msg += "e-mail adres, " : "";	

	strLen = msg.length;
	msg = msg.substring(0,msg.length-2);
	if (msg != ""){
		document.getElementById('error-msg').innerHTML = '<span><strong>Let op:</strong> U heeft de volgende velden onjuist ingevoerd:</span><br />'+msg; 
		document.getElementById('error-msg').style.display = 'block';		
	}
	else{
		//document.getElementById('error-msg').style.display = 'none;';		
		document.forms['contact'].submit();
	}
}

function controleEmail(objectInputText){
	
	if(objectInputText.value == ''){
		return false;
	}else if(objectInputText.value.indexOf('@') == -1){
		return false;
	}else{
		return true;
	}
}

function controleGeselecteerd(objectRadio)
{	
	found = 0;
	for(i=0;i<objectRadio.length && found==0;i++)
	{
		if(objectRadio[i].checked)
		{
			found = 1;
		}
	}

	return found;
}

function gaNaarAncher($naam){
	window.location.hash=$naam;
}

function sendRelatiecounselingForm(){
	var msg = "";
	var formulier = document.forms['informatie'];
	
	// verplicht:
	// Geslacht geslachtZ/geslachtP
	if(controleGeselecteerd(formulier.geslachtZ) == false){
		msg += "uw geslacht, ";
	}
	
	if(controleGeselecteerd(formulier.geslachtP) == false){
		msg += "geslacht partner, ";
	}
	
	// Achternaam achternaamZ/achternaamP
	String(formulier.achternaamZ.value)=="" ? msg += "uw achternaam, " : "";
	String(formulier.achternaamP.value)=="" ? msg += "achternaam partner, " : "";
	
	// Postcode, woonplaats postcodeZ/postcodeP
	String(formulier.postcodeZ.value)=="" ? msg += "uw postcode, " : "";
	String(formulier.postcodeP.value)=="" ? msg += "postcode partner, " : "";
	
	//E-mail adres emailZ/emailP
	String(formulier.emailZ.value)=="" ? msg += "uw e-mailadres, " : "";
	String(formulier.emailP.value)=="" ? msg += "e-mailadres partner, " : "";
	
	strLen = msg.length;
	msg = msg.substring(0,msg.length-2);
	if (msg != ""){
		document.getElementById('error-msg').innerHTML = '<span><strong>Let op:</strong> U heeft de volgende velden onjuist ingevoerd:</span><br />'+msg; 
		document.getElementById('error-msg').style.display = 'block';	
		gaNaarAncher("error-msg");
	}else{
		//alert("alles ok");
		//document.getElementById('error-msg').style.display = 'none;';		
		formulier.submit();
	}
}

function sendInformatieForm(){
	var msg = "";
	String(document.forms['informatie'].voornaam.value)=="" ? msg += "voornaam, " : "";
	String(document.forms['informatie'].naam.value)=="" ? msg += "naam, " : "";
	
	if(controleGeselecteerd(document.forms['informatie'].geslacht) == false){
		msg += "geslacht,";
	}
	
	String(document.forms['informatie'].postcode.value)=="" ? msg += "postcode, " : "";
	String(document.forms['informatie'].telefoonnummer.value)=="" ? msg += "telefoonnummer, " : "";
	controleEmail(document.forms['informatie'].email)==false ? msg += "e-mail adres, " : "";
	
	strLen = msg.length;
	msg = msg.substring(0,msg.length-2);
	if (msg != ""){
		document.getElementById('error-msg').innerHTML = '<span><strong>Let op:</strong> U heeft de volgende velden onjuist ingevoerd:</span><br />'+msg; 
		document.getElementById('error-msg').style.display = 'block';		
	}else{
		document.forms['informatie'].submit();
	}
}

function sendInformatieFormVivid(){	
	var msg = "";
	String(document.forms['informatie'].voornaam.value)=="" ? msg += "voornaam, " : "";
	String(document.forms['informatie'].naam.value)=="" ? msg += "naam, " : "";
	
	if(controleGeselecteerd(document.forms['informatie'].geslacht) == false){
		msg += "geslacht,";
	}

	// burg
	if(document.forms['informatie'].burgelijke_staat.selectedIndex == 0){
		msg += "burgerlijke staat,";
	}
	
	// adres
	String(document.forms['informatie'].adres.value)=="" ? msg += "adres, " : "";
	
	String(document.forms['informatie'].huisnummer.value)=="" ? msg += "huisnummer, " : "";
	
	String(document.forms['informatie'].postcode.value)=="" ? msg += "postcode, " : "";
	
	// woonplaats
	String(document.forms['informatie'].woonplaats.value)=="" ? msg += "woonplaats, " : "";
	
	// land
	if(controleGeselecteerd(document.forms['informatie'].land) == false){
		msg += "land,";
	}
	
	String(document.forms['informatie'].telefoonnummer.value)=="" ? msg += "telefoonnummer, " : "";
	controleEmail(document.forms['informatie'].email)==false ? msg += "e-mail adres, " : "";
	
	strLen = msg.length;
	msg = msg.substring(0,msg.length-2);
	if (msg != ""){
		document.getElementById('error-msg').innerHTML = '<span><strong>Let op:</strong> U heeft de volgende velden onjuist ingevoerd:</span><br />'+msg; 
		document.getElementById('error-msg').style.display = 'block';		
	}else{
		//alert("alles ok");
		//document.getElementById('error-msg').style.display = 'none;';		
		document.forms['informatie'].submit();
	}
}

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 = "het e-mail adres dat u heeft ingevoerd is onjuist";
	document.getElementById('error-msg').innerHTML = '<span><strong>Let op:</strong> U heeft de volgende velden onjuist ingevoerd:</span><br />'+msg; 
	document.getElementById('error-msg').style.display = 'block';
	} else {
		document.getElementById('error-msg').style.display = 'none;';
	}
}
