// Controleer contactformulier
function checkForm() {
	var blnOk = true;
	if (blnOk) {
		if (document.forms[0].naam.value=="")
			{
			alert("Geben Sie Ihren Namen ein");
			blnOk = false;
			document.forms[0].naam.focus();
			event.returnValue = false ;
			}
	}
	
	if (blnOk) {
		if (document.forms[0].plaats.value=="")
			{
			alert("Geben Sie Ihren Wohnort ein");
			blnOk = false;
			document.forms[0].plaats.focus();
			event.returnValue = false ;
			}
	}
	
	if (blnOk) {
		if (document.forms[0].mail.value=="")
			{
			alert("Geben Sie Ihre E-Mail-Adresse ein");
			blnOk = false;
			document.forms[0].mail.focus();
			event.returnValue = false ;
			} else {
				if (!checkEmail(document.forms[0].mail.value))
				{
				alert("Ihre E-Mail-Adresse ist nicht korrekt");
				blnOk = false;
				document.forms[0].mail.focus();
				document.forms[0].mail.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;
}

 function checkEmail(strEmail)
{
	strtmpEmail = String(strEmail);
	
	// Er moet een @ en een . voorkomen in een emailadres
	if (strtmpEmail.indexOf("@")== -1 || strtmpEmail.indexOf(".")== -1)
	{
		return false;
	}
	nAt = strtmpEmail.indexOf("@")
	if (nAt > 0) {
		strCheck = strtmpEmail.slice(nAt + 1)
		// De @ komt voor de .  xxx.ppibv@nl, maar tim@ppibv.nl moet ook kunnen
		// Indien de . direct na de @ komt is dat ook fout  tim@.nl
		if (strCheck.indexOf(".") <= 0 )
		{
			return false;
		}
		else {
			// Na de punt minimaal 2 tekens tim@ppibv.n
			return ((parseInt(strCheck.length) -1) - parseInt(strCheck.indexOf("."))  > 1 );
		}	
	}
	else {
		return false;
	}
}
