function disableForm(theform) {
	if (document.all || document.getElementById) {
		for (i = 0; i < theform.length; i++) {
			var tempobj = theform.elements[i];
			if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset") {
				tempobj.disabled = true;
			}
		}
//	var dateObj = new Date();
//	var creationDate = dateObj.getMonth()+1 + "/" + dateObj.getDate() + "/" + dateObj.getFullYear();
//	theform.creation_date.value = creationDate;
//	theform.purchase_date.value = theform.purchase_month.options[theform.purchase_month.selectedIndex].value + "/" + theform.purchase_day.options[theform.purchase_day.selectedIndex].value + "/" + theform.purchase_year.options[theform.purchase_year.selectedIndex].value;
	
//	theform.birthdate.value = theform.birthdate_month.options[theform.birthdate_month.selectedIndex].value + "/" + theform.birthdate_day.options[theform.birthdate_day.selectedIndex].value + "/" + theform.birthdate_year.options[theform.birthdate_year.selectedIndex].value;
//	theform.email_to.value = theform.email.value;
//	theform.email_from.value = theform.email.value;
	return true;
	}
}

function CheckForm(formObj) {
	if (formObj.aanhef.value.length=="") {
		alert("Vul uw aanhef in.");
		formObj.aanhef.focus();return false
	}
	if (formObj.voornaam.value.length=="") {
		alert("Vul uw voornaam in.");
		formObj.voornaam.focus();return false
	}
	if (formObj.achternaam.value.length=="") {
		alert("Vul uw achternaam in.");
		formObj.achternaam.focus();return false
	}
	if (formObj.straat.value.length=="") {
		alert("Vul uw straat in.");
		formObj.straat.focus();return false
	}
	if (formObj.huisnummer.value.length=="") {
		alert("Vul uw huisnummer in.");
		formObj.huisnummer.focus();return false
	}
	if (formObj.plaats.value.length=="") {
		alert("Vul uw plaats in.");
		formObj.plaats.focus();return false
	}
	if (formObj.land.selectedIndex == 0) {
		alert("Kies een land.");
		formObj.land.focus();return false
  }

	if (formObj.email.value.length > 0) {
		if(validateEmail(formObj.email.value) == false) {
			alert("Please check your email address.");
			formObj.email.focus();
			return false;
		}
	}

	if (formObj.optin.checked == false) {
		alert("Om u in te schrijven voor de nieuwsbrief dient u het het vinkje onderaan het formulier aan te klikken.");
		return false;
	}
	
}

function validateEmail(incoming) {
	var emailstring = incoming;
	var ampIndex = emailstring.indexOf("@");
	var afterAmp = emailstring.substring((ampIndex + 1), emailstring.length);
		// find a dot in the portion of the string after the ampersand only
	var dotIndex = afterAmp.indexOf(".");
		// determine dot position in entire string (not just after amp portion)
	dotIndex = dotIndex + ampIndex + 1;
		// afterAmp will be portion of string from ampersand to dot
	afterAmp = emailstring.substring((ampIndex + 1), dotIndex);
		// afterDot will be portion of string from dot to end of string
	var afterDot = emailstring.substring((dotIndex + 1), emailstring.length);
	var beforeAmp = emailstring.substring(0,(ampIndex));
	var email_regex = /^(([^<>;()[\]\\.,;:@"]+(\.[^<>()[\]\\.,;:@"]+)*)|(".+"))@((([a-z0-9]([-a-z0-9]*[a-z0-9])?)|(#[0-9]+)|(\[((([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\.){3}(([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\]))\.)*(([a-z]([-a-z0-9]*[a-z0-9])?)|(#[0-9]+)|(\[((([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\.){3}(([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\]))$/;
		// index of -1 means "not found"
	if ((emailstring.indexOf("@") != "-1") &&
		(emailstring.length > 5) &&
		(afterAmp.length > 0) &&
		(beforeAmp.length > 1) &&
		(afterDot.length > 1) &&
		(email_regex.test(emailstring)) ) {
		  return true;
	} else {
			return false;
	}
}
