function checkForm() {
	if (!document.forms[0].geslacht[0].checked && !document.forms[0].geslacht[1].checked) {
		alert("Kies voor De Heer of Mevrouw")
		return false
	} else if (document.forms[0].voornaam.value == "") {
		alert("Vul uw voornaam in")
		document.forms[0].voornaam.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 (!checkEmail(document.forms[0].mail.value)) {
        alert("Vul een geldig e-mailadres in.")
        document.forms[0].mail.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
		document.forms[0].submit()
}

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
    }
}

function checkPostcode(strPostcode, n) {
    var intCharCodeMin = 65
    var intCharCodeMax = 122
    var intCharCodeMinInside = 90
    var intCharCodeMaxInside = 97

    strPostcode = String(strPostcode)

    if (strPostcode.length < 6)
        return false

    if(strPostcode.length > 7)
        return false

    strPostcode = strPostcode.replace(" ", "")

    if (strPostcode.length == 7)
        return false

    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
}

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
}
