function checkMailform() {
	if (document.forms[0].voorletter.value == "") {
		alert("Vul uw voorletter(s) in.")
		document.forms[0].voorletter.focus()
		return false
	} else if (document.forms[0].achternaam.value == "") {
		alert("Vul uw achternaam in.")
		document.forms[0].achternaam.focus()
		return false
	} else if (document.forms[0].adres.value == "") {
		alert("Vul uw adres in.")
		document.forms[0].adres.focus()
		return false
	} else if (document.forms[0].postcode.value == "") {
		alert("Vul uw postcode in.")
		document.forms[0].postcode.focus()
		return false
	} else if (!checkPostcode(document.forms[0].postcode.value)) {
		alert("U heeft een ongeldige postcode ingevuld.")
		document.forms[0].postcode.focus()
		document.forms[0].postcode.value = ''
		return false
	} else if (document.forms[0].plaats.value == "") {
		alert("Vul uw plaats in.")
		document.forms[0].plaats.focus()
		return false
	} else if (document.forms[0].telefoon.value == "") {
		alert("Vul uw telefoonnummer in.")
		document.forms[0].telefoon.focus()
		return false
	} else if (!isTelNummer(document.forms[0].telefoon.value)) {
		alert("Het door u ingevulde telefoonummer is onjuist.")
		document.forms[0].telefoon.focus()
		document.forms[0].telefoon.value = ''
		return false
	} else if (document.forms[0].email.value == "") {
		alert("Vul uw e-mailadres in.")
		document.forms[0].email.focus()
		return false
	} else if (!checkEmail(document.forms[0].email.value)) {
		alert("Het door u ingevulde e-mailadres is niet juist")
		document.forms[0].email.focus()
		document.forms[0].email.value = ''
		return false
	} else
		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
}

// Controleer of e-mailadres valid is
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  xxx@.nl
		if (strCheck.indexOf(".") <= 0) {
			return false
		} else {
			// Na de punt minimaal 2 tekens xxx@ppibv.nl
			return ((parseInt(strCheck.length) -1) - parseInt(strCheck.indexOf("."))  > 1 )
		}
	} else {
		return false
	}
}