// JavaScript Document

    var boxes = ["PersTel", "FirmTel", "PersFax", "FirmFax", "PersGsm"];
    var fields = ["tel", "telfirma", "fax", "faxfirma", "telmobiel"];
    function fCheckPhone() {
        var i, box, zoneBox, tel, field, pretel, artel;
        
        for (i = 0; i < boxes.length; i++) {
            box = document.getElementById(boxes[i]);
            field = document.getElementById(fields[i]);
            zoneBox = document.getElementById(boxes[i] + "Zone");
            zoneBox.value = zoneBox.value.replace(/\D/g,"");
            tel = box.value;
            pretel = "";
            if (zoneBox.value != "0032") {
                //rest
				
                tel = zoneBox.value + "/" + tel.replace(/(^[0\D]*0*)|\D/g,""); //filter out leading zeros and non-nr chars

            } else {
                //Belgie
                artel = tel.split("/");
				
                if (artel.length != 2) {
                    artel = tel.split("-");
                }
                if (artel.length != 2) {
                    tel = tel.replace(/(^[0\D]*0*)|\D/g,"");
                } else {
                    pretel = artel[0].replace(/(^[0\D]*0*)|\D/g,"");
                    tel = artel[1].replace(/(^[0\D]*0*)|\D/g,"");
                }
                
                if (tel.length == 6 && pretel != "") {
                    //xx.xx.xx
                    tel = tel.substring(0, 2) + "." + tel.substring(2, 4) + "." + tel.substring(4);
                } else if (tel.length == 7 && pretel != "") {
                    //xxx.xx.xx
                    tel = tel.substring(0, 3) + "." + tel.substring(3, 5) + "." + tel.substring(5);
                } else if (tel.length == 8) { //ambiguous
                    //live and let live
                } else if (tel.length == 9 && pretel == "") { //9 with zone = gsm
                    //xxx-xx.xx.xx
                    tel = tel.substring(0, 3) + "/" + tel.substring(3, 5) + "." + tel.substring(5, 7) + "." + tel.substring(7);
                }
                if (pretel !== "") {
                    pretel += "/";
                }
                tel = "0" + pretel + tel;
            }
         /*   if (tel.substring(0,1) == "/")
			{
				
				tel = tel.substring(1,tel.length-1);	
				alert(tel)
			}*/
			
            if (tel !== "/" && tel !== "0/" && tel !== "0" && tel !== zoneBox.value + "/") {
                field.value = tel;
            } else {
                field.value = "";
            }

            //box.value = tel;
        }
    }
    
    function fSetCountryCode(id) {
        var xmlHttp, i;
        try {
            // Firefox, Opera 8.0+, Safari
            xmlHttp=new XMLHttpRequest();
        } catch (e) {
            // Internet Explorer
            try {
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {
                    //alert("Your browser does not support AJAX!");
                    return false;
                }
            }
        }

        xmlHttp.open("GET", "ajax/GetTelCode.asp?id=" + id);
        xmlHttp.send(null);
        xmlHttp.onreadystatechange = function () {
            if (xmlHttp.readyState == 4) {
                if (xmlHttp.responseText != "32" || 1 == 1) {//Belgie check //disabled
                    if (xmlHttp.responseText == "0") {//empty check
                        for (i = 0; i < boxes.length; i++) {
                            document.getElementById(boxes[i] + "Zone").value = "";
                        }
                    } else {
                        for (i = 0; i < boxes.length; i++) {
                            document.getElementById(boxes[i] + "Zone").value = "00" + xmlHttp.responseText + "";
                        }
                    }
                    for (i = 0; i < boxes.length; i++) {
                        document.getElementById(boxes[i] + "Zone").disabled = "disabled";
                    }
                } else {
                    for (i = 0; i < boxes.length; i++) {
                        document.getElementById(boxes[i] + "Zone").disabled = "";
                        document.getElementById(boxes[i] + "Zone").value = "";
                    }
                }
            }
        }
    }
