Array.prototype.contains = function (element) {
	for (var i = 0; i < this.length; i++) {
		if (this[i] == element) {
			return true;
		}
	}
	return false;
};




function setOtherFunction() {
	// afh. van keuze 'otherfunction' legen
	objSelect = document.getElementById('functie');
	var objOpt = objSelect.options[objSelect.selectedIndex];
	if (objOpt.value != 0) {
		document.frmContact1.otherfunction.value = "";
	}
}
			
			
			
			
function Validate_String(string, return_invalid_chars) {
	valid_chars = '1234567890-_.^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	invalid_chars = '';
	
	if(string == null || string == '')
		return(true);
	
	// voor elk karakter van de string
	for (index = 0; index < string.length; index++) {
		char = string.substr(index, 1);
		
		// is het een valid karakter?
		if(valid_chars.indexOf(char) == -1) {
			// if not, is it already on the list of invalid characters?
			if(invalid_chars.indexOf(char) == -1) {
				// if it's not, add it
				if(invalid_chars == '')
					invalid_chars += char;
				else
					invalid_chars += ', ' + char;
			}
		}
	}
	
	// if the string does not contain invalid characters, the function will return true.
	// if it does, it will either return false or a list of the invalid characters used
	// in the string, depending on the value of the second parameter.
	if(return_invalid_chars == true && invalid_chars != '') {
		last_comma = invalid_chars.lastIndexOf(',');
		
		if(last_comma != -1)
			invalid_chars = invalid_chars.substr(0, $last_comma) + 
			' and ' + invalid_chars.substr(last_comma + 1, invalid_chars.length);
		
		return(invalid_chars);
	}
	else
		return(invalid_chars == '');
}




function isNumberKey(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;
	
	return true;
}


submitOK = true;

function doAjaxSubmit(){
	validateContact1();
	if (submitOK === true){
		var $_elements = document.getElementById('contactformpje').elements;
		var $_poststring = "";
		for (var n = 0;n<$_elements.length;n++){
			if ($_elements[n].type == 'checkbox'){
				if ($_elements[n].checked){
					$_poststring += '&' + $_elements[n].name + '=' + encodeURI($_elements[n].value);
				}
			}else{
				$_poststring += '&' + $_elements[n].name + '=' + encodeURI($_elements[n].value);
			}	
		}

		$jah.setParams($_poststring);
		document.getElementById('contactform01').style.display = 'none';
		document.getElementById('fancy_functie').style.display = 'none';
		document.getElementById('contactform02').style.display = 'none';
		document.getElementById('contactform03').style.display = 'block';
		document.getElementById('contactform03').innerHTML = 'Sending your request...'
		$jah.setHtmlObj('contactform03');				
		$jah.doRequest('/obj/submitform.ajax.php', 'POST');
	}
}

function doAjaxSubmit2(){
	validateContact1();
	validateContact2();
	if (submitOK === true){
		var $_elements = document.getElementById('contactformpje').elements;
		var $_poststring = "";
		for (var n = 0;n<$_elements.length;n++){
			if ($_elements[n].type == 'checkbox'){
				if ($_elements[n].checked){
					$_poststring += '&' + $_elements[n].name + '=' + encodeURI($_elements[n].value);
				}
			}else{
				$_poststring += '&' + $_elements[n].name + '=' + encodeURI($_elements[n].value);
			}	
		}

		$jah.setParams($_poststring);
		document.getElementById('contactform01').style.display = 'none';
		document.getElementById('fancy_functie').style.display = 'none';
		document.getElementById('contactform02').style.display = 'none';
		document.getElementById('contactform03').style.display = 'block';
		document.getElementById('contactform03').innerHTML = 'Sending your request...'
		$jah.setHtmlObj('contactform03');				
		$jah.doRequest('/obj/submitform.ajax2.php', 'POST');
	}
}

function doAjaxSubmit3(){
	validateContact3();
	if (submitOK === true){
		var $_elements = document.getElementById('contactformpje').elements;
		var $_poststring = "";
		for (var n = 0;n<$_elements.length;n++){
			if ($_elements[n].type == 'checkbox'){
				if ($_elements[n].checked){
					$_poststring += '&' + $_elements[n].name + '=' + encodeURI($_elements[n].value);
				}
			}else{
				$_poststring += '&' + $_elements[n].name + '=' + encodeURI($_elements[n].value);
			}	
		}
		$jah.setParams($_poststring);
		document.getElementById('contactform01').style.display = 'none';
		document.getElementById('contactform03').style.display = 'block';
		document.getElementById('contactform03').innerHTML = 'Sending your request...'
		$jah.setHtmlObj('contactform03');				
		$jah.doRequest('/obj/submitform.ajax3.php', 'POST');
	}
}

function validateContact1() {
	// 1. settings
	x = document.frmContact1;
	errormessage = "Complete this form with your ";
	emailmessage = "";
	submitOK = true;
	
	
	// 2. values
	name = x.name.value;
	name = name.replace(/\s+$|^\s*/gi, "");
	firstname = x.firstname.value;
	firstname = firstname.replace(/\s+$|^\s*/gi, "");
	functie = x.functie.value;
	otherfunction = x.otherfunction.value;
	otherfunction = otherfunction.replace(/\s+$|^\s*/gi, "");
	company = x.company.value;
	company = company.replace(/\s+$|^\s*/gi, "");
	address = x.address.value;
	address = address.replace(/\s+$|^\s*/gi, "");
	zip = x.zip.value;
	zip = zip.replace(/\s+$|^\s*/gi, "");
	city = x.city.value;
	city = city.replace(/\s+$|^\s*/gi, "");
	country = x.country.value;
	country = country.replace(/\s+$|^\s*/gi, "");
	phone = x.phone.value;
	phone = phone.replace(/\s+$|^\s*/gi, "");
	fax = x.fax.value;
	fax = fax.replace(/\s+$|^\s*/gi, "");
	email = x.email.value;
	email = email.replace(/\s+$|^\s*/gi, "");
	url = x.url.value;
	url = url.replace(/\s+$|^\s*/gi, "");
	
	
	// 3. set stripped values in textfields
	x.name.value = name;
	x.firstname.value = firstname;
	x.otherfunction.value = otherfunction;
	x.company.value = company;
	x.address.value = address;
	x.zip.value = zip;
	x.city.value = city;
	x.country.value = country;
	x.phone.value = phone;
	x.fax.value = fax;
	x.email.value = email;
	x.url.value = url;
	
	
	// 4. control content
		// 4.1. name
		if (name.length == 0) {
			errormessage += "name"
			submitOK = "False";
		}
		// 4.2. function
		if (functie == 0 && otherfunction.length == 0) {
			if (errormessage != "Complete this form with your ")
				errormessage += ", "
			errormessage += "function (or other function)"
			submitOK = "False";
		}
		// 4.3. address
		if (address.length == 0) {
			if (errormessage != "Complete this form with your ")
				errormessage += ", "
			errormessage += "address"
			submitOK = "False";
		}
		// 4.4. zip
		if (zip.length == 0) {
			if (errormessage != "Complete this form with your ")
				errormessage += ", "
			errormessage += "zip code"
			submitOK = "False";
		}
		// 4.5. city
		if (city.length == 0) {
			if (errormessage != "Complete this form with your ")
				errormessage += ", "
			errormessage += "city"
			submitOK = "False";
		}
		// 4.6. country
		if (country.length == 0) {
			if (errormessage != "Complete this form with your ")
				errormessage += ", "
			errormessage += "country"
			submitOK = "False";
		}
		// 4.7. phone
		if (phone.length == 0) {
			if (errormessage != "Complete this form with your ")
				errormessage += ", "
			errormessage += "phone"
			submitOK = "False";
		}
		// 4.8. email
		if (email.length == 0) {
			if (errormessage != "Complete this form with your ")
				errormessage += ", "
			errormessage += "email"
			submitOK = "False";
		} else {
			// er van uitgaan dat emailadres van type: user_name@domain.tld
			at = email.indexOf('@');
			dot = email.lastIndexOf('.');
			
			if(at == -1 || dot == -1 || dot <= at + 1 || dot == 0 || dot == email.length - 1) {
				emailmessage += "\Use a correct e-mail address please."
				submitOK = "False";
			}
            
            user_name = email.substr(0, at);
			domain_name = email.substr(at + 1, email.length);
			
			if(Validate_String(user_name) === false || Validate_String(domain_name) === false) {
				emailmessage += "\Use a correct e-mail address please."
				submitOK = "False";
			}
		}
	
	
	// 5. evaluate submitOK
	if(submitOK === true) {
		//window.alert('juplahoi')
		document.getElementById('contactform01').style.display = 'none';
		document.getElementById('fancy_functie').style.display = 'none';
		document.getElementById('contactform02').style.display = 'block';
	}else{
		if (emailmessage != "") {
			if (errormessage != "Complete this form with your ") {
				errormessage += " please."
				alert(errormessage + "\n(* are required fields)" + emailmessage);
			} else {
				alert(emailmessage);
			}
		} else {
			errormessage += " please."
			alert(errormessage + "\n(* are required fields)");
		}
		return false;
	}
}

function validateContact2() {
	// 1. settings
	x = document.frmContact1;
	errormessage = "Complete this form with your ";
	emailmessage = "";
	submitOK = true;
	
	
	// 2. values
	login = x.login.value;
	login = login.replace(/\s+$|^\s*/gi, "");
	password = x.password.value;
	password = password.replace(/\s+$|^\s*/gi, "");
	verify = x.verify.value;
	verify = verify.replace(/\s+$|^\s*/gi, "");
	
	
	// 3. set stripped values in textfields
	x.login.value = login;
	x.password.value = password;
	x.verify.value = verify;
	
	
	// 4. control content
		// 4.1. name
		if (login.length == 0) {
			errormessage += "login"
			submitOK = "False";
		}
		// 4.2. function
		if (password.length == 0) {
			if (errormessage != "Complete this form with your ")
				errormessage += ", "
			errormessage += "password"
			submitOK = "False";
		}
		// 4.3. address
		if (verify.length == 0) {
			if (errormessage != "Complete this form with your ")
				errormessage += ", "
			errormessage += "verify"
			submitOK = "False";
		}
		if (verify != password) {
			if (errormessage != "Complete this form with your ")
				errormessage += ", "
			errormessage += "password & verify (password and verify must be the same)"
			submitOK = "False";
		}
	
	
	// 5. evaluate submitOK
	if(submitOK === true) {
		//window.alert('juplahoi')
		document.getElementById('contactform01').style.display = 'none';
		document.getElementById('fancy_functie').style.display = 'none';
		document.getElementById('contactform02').style.display = 'block';
	}else{
		errormessage += " please."
		alert(errormessage + "\n(* are required fields)");
		return false;
	}
}

function validateContact3() {
	// 1. settings
	x = document.frmContact1;
	errormessage = "Complete this form with your ";
	emailmessage = "";
	submitOK = true;
	
	
	// 2. values
	email = x.email.value;
	email = email.replace(/\s+$|^\s*/gi, "");
	
	
	// 3. set stripped values in textfields
	x.email.value = email;
	
	
	// 4. control content
		// 4.1. email
		if (email.length == 0) {
			if (errormessage != "Complete this form with your ")
				errormessage += ", "
			errormessage += "email"
			submitOK = "False";
		} else {
			// er van uitgaan dat emailadres van type: user_name@domain.tld
			at = email.indexOf('@');
			dot = email.lastIndexOf('.');
			
			if(at == -1 || dot == -1 || dot <= at + 1 || dot == 0 || dot == email.length - 1) {
				emailmessage += "\Use a correct e-mail address please."
				submitOK = "False";
			}
            
            user_name = email.substr(0, at);
			domain_name = email.substr(at + 1, email.length);
			
			if(Validate_String(user_name) === false || Validate_String(domain_name) === false) {
				emailmessage += "\Use a correct e-mail address please."
				submitOK = "False";
			}
		}
	
	
	// 5. evaluate submitOK
	if(submitOK === true) {
		//window.alert('juplahoi')
		document.getElementById('contactform01').style.display = 'none';
		document.getElementById('contactform03').style.display = 'block';
	}else{
		if (emailmessage != "") {
			if (errormessage != "Complete this form with your ") {
				errormessage += " please."
				alert(errormessage + "\n(* are required fields)" + emailmessage);
			} else {
				alert(emailmessage);
			}
		} else {
			errormessage += " please."
			alert(errormessage + "\n(* are required fields)");
		}
		return false;
	}
}