
function validate() 
{ 
var result1; 
result1 = trim(document.theForm.tur_initialen.value); if (result1.length < 1) { alert('Initialen is een verplicht veld'); theForm.tur_initialen.focus(); return false; }
result1 = trim(document.theForm.tur_achternaam.value); if (result1.length < 3) { alert('Achternaam is een verplicht veld'); theForm.tur_achternaam.focus(); return false; }
result1 = trim(document.theForm.tur_straat.value); if (result1.length < 3) { alert('Straat is een verplicht veld'); theForm.tur_straat.focus(); return false; }
result1 = trim(document.theForm.tur_huisnummer.value); if (result1.length < 1) { alert('Huisnummer is een verplicht veld'); theForm.tur_huisnummer.focus(); return false; }

if (document.theForm.tur_postcode.value.length<6) { alert('Postcode is een verplicht veld'); theForm.tur_postcode.focus(); return false; }

result1 = trim(document.theForm.tur_plaats.value); if (result1.length < 3) { alert('Plaats is een verplicht veld'); theForm.tur_plaats.focus(); return false; }
if (!isValidPhone(document.theForm.tur_telefoon.value)) { alert('Telefoon is een verplicht veld'); theForm.tur_telefoon.focus(); return false; }
if (!isValidEmail(document.theForm.tur_email.value)) { alert('E-mail is een verplicht veld'); theForm.tur_email.focus(); return false; }
result1 = trim(document.theForm.tur_password.value); if (result1.length < 4) { alert('Wachtwoord is een verplicht veld en dient minimaal 4 karakters te bevatten'); theForm.tur_password.focus(); return false; }

result1 = trim(document.theForm.tur_akkoordvoorwaarden.checked==false); ;if (result1) { alert('U dient akkoord te gaan met de algemene voorwaarden'); theForm.tur_akkoordvoorwaarden.focus(); return false; }
}   

function validateSterkte() 
{ 
var result1; 
result1 = trim(document.theForm.kbr_sferischR.value); if (result1=='') { alert('Sterkte rechts is een verplicht veld'); theForm.kbr_sferischR.focus(); return false; }
result1 = trim(document.theForm.kbr_sferischL.value); if (result1=='') { alert('Sterkte links is een verplicht veld'); theForm.kbr_sferischL.focus(); return false; }

if(document.theForm.kbr_cylinderR.value!=''&&document.theForm.kbr_asR.value=='') { alert('Bij een cylinder dient tevens een as-richting te worden ingevoerd'); theForm.kbr_asR.focus(); return false; }
if(document.theForm.kbr_cylinderL.value!=''&&document.theForm.kbr_asL.value=='') { alert('Bij een cylinder dient tevens een as-richting te worden ingevoerd'); theForm.kbr_asL.focus(); return false; }

if(document.theForm.kbr_pd.value=='') { alert('PD is een verplicht veld'); theForm.kbr_pd.focus(); return false; }

if(document.theForm.kbr_addR.value=='') { alert('Additie is een verplicht veld'); theForm.kbr_addR.focus(); return false; }

}   


function isValidEmail(emailAddress) {
var re = /^(([^<>()[\]\\.,;:\s@\""]+(\.[^<>()[\]\\.,;:\s@\""]+)*)|(\"".+\""))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
return re.test(emailAddress);
}

function isValidPhone(phonenumber) {
var re = /^(\+)?(\d|-| ){10,20}/;
return re.test(phonenumber);
}

function trim(inputString) {
// Removes leading and trailing spaces from the passed string. Also removes
// consecutive spaces and replaces it with one space. If something besides
// a string is passed in (null, custom object, etc.) then return the input.
if (typeof inputString != 'string') { return inputString; }
var retValue = inputString;
var ch = retValue.substring(0, 1);
while (ch == ' ') { // Check for spaces at the beginning of the string
 retValue = retValue.substring(1, retValue.length);
ch = retValue.substring(0, 1);
}
ch = retValue.substring(retValue.length-1, retValue.length);
while (ch == ' ') { // Check for spaces at the end of the string
retValue = retValue.substring(0, retValue.length-1);
ch = retValue.substring(retValue.length-1, retValue.length);
}
   while (retValue.indexOf('  ') != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
retValue = retValue.substring(0, retValue.indexOf('  ')) + retValue.substring(retValue.indexOf('  ')+1, retValue.length); // Again, there are two spaces in each of the strings
}
return retValue; // Return the trimmed string back to the user
} // Ends the 'trim' function

function isValidBankReknr(banknr) {
var tot=0;
var deel=0;
var rest =0;
	if (banknr.length==0){
	    return true;
  	} 
	if (banknr.length > 9){
	  return false;
	} 
	else{
	  if (banknr.length < 4){
	    return false;
  	  } 
	  if (banknr.length < 8){
	    return true;
  	  } 
	  if (banknr.length==8){
	    return false;
  	  } 
	for (i=0;i<banknr.length;i++){
	getal=banknr.substr(i,1);
	tot +=getal * (9 - i);
	} 
	deel =tot/11;
	rest=tot%11;
	if (rest!=0)
	{
	  return false;
	}
	else {
	  return true;
	}
 } 
}
