// Controleer contactformulier
function checkMailform() {
	var blnOk = true;
	if (blnOk) {
		if (document.forms[0].bedrijf.value=="")
			{
			alert("Vul een bedrijfsnaam in");
			blnOk = false;
			document.forms[0].bedrijf.focus();
			event.returnValue = false ;
			}
	}
	
	if (blnOk) {
		if (document.forms[0].functie.value=="")
			{
			alert("Vul uw functie in");
			blnOk = false;
			document.forms[0].functie.focus();
			event.returnValue = false ;
			}
	}
	
	if (blnOk) {
		if (document.forms[0].voornaam.value=="")
			{
			alert("Vul uw voornaam in");
			blnOk = false;
			document.forms[0].voornaam.focus();
			event.returnValue = false ;
			}
	}

	if (blnOk) {
		if (document.forms[0].adres.value=="")
			{
			alert("Vul het afleveradres in");
			blnOk = false;
			document.forms[0].adres.focus();
			event.returnValue = false ;
			}
	}
	
	if (blnOk) {
		if (document.forms[0].postcode.value=="")
			{
			alert("Vul postcode in");
			blnOk = false;
			document.forms[0].postcode.focus();
			event.returnValue = false ;
			} else {
				if (!checkPostcode(document.forms[0].postcode.value))
				{
				alert("U heeft een ongeldige postcode ingevuld");
				blnOk = false;
				document.forms[0].postcode.focus();
				document.forms[0].postcode.value = '';
				event.returnValue = false;}
			}
	}
	
	if (blnOk) {
		if (document.forms[0].plaats.value=="")
			{
			alert("Vul uw plaats in");
			blnOk = false;
			document.forms[0].plaats.focus();
			event.returnValue = false ;
			}
	}
	
		if (blnOk) {
		if (document.forms[0].telefoon.value=="")
			{
			alert("Vul uw telefoonnummer in");
			blnOk = false;
			document.forms[0].telefoon.focus();
			event.returnValue = false ;
			} else {
				if (!isTelNummer(document.forms[0].telefoon.value))
				{
				alert("Het door u ingevulde telefoonummer is onjuist");
				blnOk = false;
				document.forms[0].telefoon.focus();
				document.forms[0].telefoon.value = '';
				event.returnValue = false;}
			}
	}


if (blnOk) {
		document.forms[0].submit();
	}
}


// Postcodecheck
  function checkPostcode(strPostcode, n)
  {
    var intCharCodeMin = 65;
    var intCharCodeMax = 122;
    var intCharCodeMinInside = 90;
    var intCharCodeMaxInside = 97;
    
    //convert postcode
    strPostcode = String(strPostcode);
      
    //check length min 6
    if (strPostcode.length < 6)
    {
      return false;
    }
    
    //check length max 7 
    if(strPostcode.length > 7)
    {
      return false;
    }

    //replace space;
    strPostcode = strPostcode.replace(" ","");

    //check 7 characters with space
    if (strPostcode.length == 7)
    {
      return false;
    }
      
    //Check if first four digits are numbers    
    if (String(parseInt(strPostcode.substr(0,4))).length != 4)
    {
      return false;
    }
          
    for (i=4;i<6;i++)
    { 
		if ( strPostcode.charCodeAt(i)< intCharCodeMin || strPostcode.charCodeAt(i)> intCharCodeMax || (strPostcode.charCodeAt(i) > intCharCodeMinInside && strPostcode.charCodeAt(i) < intCharCodeMaxInside  ))
		{
		  return false;
		}
    }
    return true;
  }

 // Telefoonnummercheck
function isTelNummer(str) {
  if(!str) return false;
  for(var i=0; i<str.length; i++){
    var ch=str.charAt(i);
    if ("0123456789-() +".indexOf(ch) ==-1) return false;
  }
  return true;
}
