﻿function voorlettersOnChange(content) {
    //document.getElementById("voorlettersTxt").value = autoCapitalize(document.getElementById("voorlettersTxt").value);

    var voorlettersTxt = document.getElementById("voorlettersTxt")
    voorlettersTxt.value = upperCaseFirst(voorlettersTxt);
}

function achternaamOnChange(content) {
    document.getElementById("achternaamTxt").value = titleCase(document.getElementById("achternaamTxt").value);

    //var achternaamTxt = document.getElementById("achternaamTxt")
    //achternaamTxt.value = upperCaseFirst(achternaamTxt);
}

function emailOnChange(content) {
    
    //var emailTxt = document.getElementById("emailTxt")
    //emailTxt.value =  functioName(emailTxt);
}

function emailherhaalOnChange(content) {

    //var emailherhaalTxt = document.getElementById("emailherhaalTxt")
    //emailherhaalTxt.value =  functioName(emailherhaalTxt);
}

function straatnaamOnChange(content) {
    document.getElementById("straatnaamTxt").value = titleCase(document.getElementById("straatnaamTxt").value);

    //var straatnaamTxt = document.getElementById("straatnaamTxt")
    //straatnaamTxt.value =  functioName(straatnaamTxt);
}

function huisnummerOnChange(content) {

    //var huisnummerTxt = document.getElementById("huisnummerTxt")
    //huisnummerTxt.value =  functioName(huisnummerTxt);
}

function postcodeOnChange(content) {
    
    document.getElementById("postcodeTxt").value = autoFormatZip(document.getElementById("postcodeTxt").value);

    //var postcodeTxt = document.getElementById("postcodeTxt")
    //postcodeTxt.value =  functioName(postcodeTxt);
}

function woonplaatsOnChange(content) {
    document.getElementById("woonplaatsTxt").value = titleCase(document.getElementById("woonplaatsTxt").value);

    //var woonplaatsTxt = document.getElementById("woonplaatsTxt")
    //woonplaatsTxt.value =  functioName(woonplaatsTxt);
}

function telefoon1OnChange(content) {
    
    //var telefoon1Txt = document.getElementById("telefoon1Txt")
    //telefoon1Txt.value =  functioName(telefoon1Txt);
}

function telefoon2OnChange(content) {

    //var telefoon2Txt = document.getElementById("telefoon2Txt")
    //telefoon2Txt.value =  functioName(telefoon2Txt);
}

function provincieOnChange(content) {

    //var provincieTxt = document.getElementById("provincieTxt")
    //provincieTxt.value =  functioName(provincieTxt);
}

function extra1OnChange(content) {

    //var extra1Txt = document.getElementById("extra1Txt")
    //extra1Txt.value =  functioName(extra1Txt);
}

function extra2OnChange(content) {

    //var extra2Txt = document.getElementById("extra2Txt")
    //extra2Txt.value =  functioName(extra2Txt);
}

function extra3OnChange(content) {

    //var extra3Txt = document.getElementById("extra3Txt")
    //extra3Txt.value =  functioName(extra3Txt);
}

function extra4OnChange(content) {

    //var extra4Txt = document.getElementById("extra4Txt")
    //extra4Txt.value =  functioName(extra4Txt);
}

function organisatieOnChange(content) {

    //var organisatieTxt = document.getElementById("organisatieTxt")
    //organisatieTxt.value =  functioName(organisatieTxt);
}


// PUT HERE THE REPLACE FUNCTIONS

function autoCapitalize(value) {

    // Automatically capitalize the initials
    var objVoorletters = document.getElementById("voorlettersTxt")
    var voorletters = objVoorletters.value;
    var result = '';

    // 1. remove anything that's not a letter
    re = /[^a-z]/gi;
    voorletters = voorletters.replace(re, '');

    // 2. capitalize everything
    voorletters = voorletters.toUpperCase();

    // 3. add spaces after each letter
    for (var i = 0; i < voorletters.length; i++) {
        result += voorletters.substr(i, 1);
        if (i < voorletters.length - 1) {
            result += ' ';
        }
    }
    return result;
}

function numbersonly(myfield, e, dec) {
    var key;
    var keychar;

    if (window.event)
        key = window.event.keyCode;
    else if (e)
        key = e.which;
    else
        return true;

    keychar = String.fromCharCode(key);

    // control keys
    if ((key == null) || (key == 0) || (key == 8) ||
		(key == 9) || (key == 13) || (key == 27))
        return true;

    // numbers
    else if ((("0123456789").indexOf(keychar) > -1))
        return true;

    // decimal point jump
    else if (dec && (keychar == ".")) {
        myfield.form.elements[dec].focus();
        return false;
    }
    else
        return false;
}

function altijdNul(myfield) {
    //alert(this)
    if (myfield.value.length == 0) {
        myfield.value = "0";
    }
}

function upperCaseFirst(valueContent) {    
    return valueContent.value.charAt(0).toUpperCase() + valueContent.value.substr(1, valueContent.value.length);
}

/*************************************************/
	/* Nieuwe invoermaskers, PD, 20090727 */
 
	function autoCapitalize(val) {
	    var result = '';
 
	    // 1. remove anything that's not a letter
	    re = /[^a-z]/gi;
	    val = val.replace(re, '');
 
	    // 2. capitalize everything
	    val = val.toUpperCase();
 
	    // 3. add spaces after each letter
	    for (var i = 0; i < val.length; i++) {
	        result += val.substr(i, 1);
	        //if(i<voorletters.length-1)
	        {
	            result += '.';
	        }
	    }
 
	    return result;
	}
 
 
	function titleCase(str) {
	    str = alltrim(str);
	    var newStr = str.toLowerCase().replace(/\b\w+\b/g, cnvrt);
	    return checkReplaceParm(newStr, "cnvrt");
 
	    function cnvrt() {
	        /*Branch which should be capitalized */
	        //if (arguments[arguments.length -2] == 0)
	        // First word capitalize if first char is letter*/
	        //return arguments[0].replace(/^[a-z]/, cnvrt2);
	        /*else*/if (/^(aan|bij|de|den|der|d|en|het|la|in|onder|op|over|s|t|te|ten|ter|tot|uit|van|ver|voor)$/.test(arguments[0]))
	        /* List of words to skip */
	            return arguments[0];
	        else
	        /* All other capitalize if first character is letter */
	            return arguments[0].replace(/^[a-z]/, cnvrt2);
	    }
 
	    function cnvrt2() {
	        /* Capitalize letter */
	        return arguments[0].toUpperCase();
	    }
	}
 
	function alltrim(str) {
	    return str.replace(/^\s+|\s+$/g, '');
	}
	function checkReplaceParm(str) {
	    /* Check browser supports functions in replace */
	    if (/^\s*function\s+alpha2number/.test(str)) {
	        alert("This browser does not support using a function as a parameter for replace.");
	        return "";
	    }
	    else {
	        return str;
	    }
	}
	function autoFormatZip(zipcode) {
	    if (zipcode != '') {
	        zipcode = zipcode.toUpperCase().replace(/\ /g, '')
	        if (zipcode.length == 6) {
	            zipcode = zipcode.substring(0, 4) + ' ' + zipcode.substr(4, 2)
	        }
	    }
	    return zipcode;
	}
	function numbersOnly(myfield, e, dec) {
	    var key;
	    var keychar;
 
	    if (window.event)
	        key = window.event.keyCode;
	    else if (e)
	        key = e.which;
	    else
	        return true;
 
	    keychar = String.fromCharCode(key);
 
	    // control keys
	    if ((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27))
	        return true;
 
	    // numbers
	    else if ((("0123456789").indexOf(keychar) > -1))
	        return true;
 
	    // decimal point jump
	    else if (dec && (keychar == ".")) {
	        myfield.form.elements[dec].focus();
	        return false;
	    }
	    else
	        return false;
	}
	function elfproef(veld) {
	    var input = veld.value;
	    var tot = 0;
	    var deel = 0;
	    var rest = 0;
 
	    veld.className = "correct";
 
	    if (input.length > 10 || input.length == 8 || input.length == 0) {
	        veld.className = "incorrect";
	    }
	    else {
	        if (input.length > 8) {
	            if (input.length == 9) {
	                input = "0" + input
	            }
	            for (i = 0; i < input.length; i++) {
	                getal = input.substr(i, 1);
	                tot += getal * (10 - i);
	            }
	            deel = tot / 11;
 
	            rest = tot % 11;
	            if (rest != 0) {
	                veld.className = "incorrect";
	            }
	        }
	    }
	    return (veld.className == "correct");
	}

 

