/* 
 Uitleg over gebruik
 ------------------------------------------------------------------------------------
 Lokatie:                        http://www.dminterface.nl/scripts/validaties2.js
 Invoer in de body van HTML:     <script language="javascript" type="text/javascript" src="http://messagent.dminterface.nl/scripts/validaties2.js"></script>
 ------------------------------------------------------------------------------------
 *Alles kleine letter:            onblur="this.value=this.value.toLowerCase();"
 *Alles hoofdletter:              onblur="this.value=this.value.toUpperCase();"
 *Eerste letter een hoofdletter:  onkeypress="return Invoer(this,achternaam);"
 *Alleen nummers invoeren:        onkeypress="return Invoer(this,nummers);"
 *Alleen letters invoeren:        onkeypress="return Invoer(this,letters);"
 *Alleen telefoonnummer invoeren: onkeypress="return Invoer(this,telefoon);"
 *Alleen woonplaats invoeren:     onkeypress="return Invoer(this,woonplaats);" onblur="this.value=this.value.toUpperCase();"
 *Alleen e-mailadres invoeren:    onkeypress="return Invoer(this,email);"
 *Punt-na-letter:                 onkeypress="return Invoer(this,voorletters);" onblur="this.value=this.value.toUpperCase() + '.';"
 *Automatisch naar volgend veld:  onkeyup="return VolgendVeld(this, 4, event);"
 *Postcode opzoeken:              onblur="ZoekPostcode();"
 ------------------------------------------------------------------------------------
 
 -->> Uitleg postcode opzoeken: <<--
 Maak drie velden aan:
 Eerste postcodeveld: <input type='text' id='pc1' size='4' onkeyup="return VolgendVeld(this, 4, event);" onkeypress="return Invoer(this,nummers);"/>
 Tweede postcodeveld: <input type='text' id='pc2' size='2' onkeyup="return VolgendVeld(this, 2, event);" onkeypress="return Invoer(this,letters);"/>
 Huisnummerveld:      <input type='text' id='hnr' onblur="ZoekPostcode()" onkeypress="return Invoer(this,nummers);" size=4/>
 -----------------------------------                       

*/
var isNN = (navigator.appName.indexOf("Netscape") !=-1);

//Controleer Invoer
  var achternaam = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'- ";
  var telefoon = "0123456789+";
  var nummers = "0123456789";
  var aantal = "123456789";
  var letters = "abcdeéëfghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ";
  var voorletters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  var woonplaats = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'-. ";
  var email = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-.@_1234567890";


function Invoer(thestr,controle) {
	var key;
  var keychar;
   
   if (window.event) key = window.event.keyCode;
   else if (e)
    key = e.which;
   else
    return true;
   keychar = String.fromCharCode(key);

   if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==18) || (key==27) || (key==27) || (key==224) || (key==225) || (key==226) || (key==228) || (key==232) || (key==233) || (key==234) || (key==235) || (key==239) || (key==242) || (key==243) || (key==244) || (key==246) || (key==249) || (key==250) || (key==251) || (key==252) || (key==253) || (key==255))
      return true;  
	 else if(((controle).indexOf(keychar) > -1)) {
    if (controle == "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") { //voorletters
     if (thestr.value.substr(1,1)=='' || thestr.value.substr(1,1)=='.') { if (thestr.value.substr(0,1) == "." || thestr.value == "") {	thestr.value = ""; } }
     if (thestr.value.substr(0,1) == "." || thestr.value == "") {	thestr.value = thestr.value.substr(1).toUpperCase(); 
     } else {
		  thestr.value = thestr.value.toUpperCase() + ".";
		 }
		}
    if (controle == "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'-. ") { //woonplaats
		 thestr.value = thestr.value.toUpperCase();
		}
    if (controle == "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'- ") { //achternaam
		 thestr.value = thestr.value.substr(0, 1).toUpperCase() + thestr.value.substr(1).toLowerCase();
		}
    if (controle == "0123456789+") { //telefoon
     if (thestr.value.substr(0,3) == "000") { thestr.value = thestr.value.substr(0, 1); }
      if (thestr.value.substr(0,2) == "00") { if (thestr.value.length > 12) { thestr.value = thestr.value.substr(0, 12); } 
      } else {
       if (thestr.value.substr(0,1) == "+") { if (thestr.value.length > 11) { thestr.value = thestr.value.substr(0, 11); }
       } else {
		    if (thestr.value.substr(0,1) == "0") { if (thestr.value.length > 9) { thestr.value = thestr.value.substr(0, 9); }
        } else {
        thestr.value = "";
        }
       }
      }
     }		
    return true;		
	 } else {
    return false;
   } 	
}


// VolgendVeld
var x,y,a,b;

function VolgendVeld(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode;
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !BevatElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(GetIndex(input)+1) % input.form.length].focus();
	};

	function BevatElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length) {
			if(arr[index] == ele) {
				found = true;	
			} else {
				index++;
			};
		};
		return found;
	};

	function GetIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1) {
			if (input.form[i] == input) {
				index = i;
			} else {
				i++;
			};
		};
		return index;
	};

return true;
};



//ZoekPostcode
function ZoekPostcode(){
document.write('<link rel="stylesheet" type="text/css" href="http://www.dminterface.nl/scripts/preloader/skin.css">\n');
document.write('<script type="text/javascript" src="http://www.dminterface.nl/scripts/preloader/utilities.js"></script>\n');
document.write('<script type="text/javascript" src="http://www.dminterface.nl/scripts/preloader/container-min.js"></script>\n');
document.write('<script type="text/javascript" src="http://www.dminterface.nl/scripts/preloader/loadingpanel.js"></script>\n');	
  var loadingPanel = new yuiLoadingPanel();
	var ajaxRequest;
	try{
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				return false;
			}
		}
	}
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState != 4){
		 loadingPanel.show();
     loadingPanel.show("Processing...");
		}		
		if(ajaxRequest.readyState == 4){
		 document.getElementById("wpl").value = ajaxRequest.responseText;
		 loadingPanel.hide();
		}
	}
	var pc1 = document.getElementById('pc1').value;
	var pc2 = document.getElementById('pc2').value;
	var hnr = document.getElementById('hnr').value;
	var queryString = "?pc1=" + pc1 + "&pc2=" + pc2 + "&hnr=" + hnr;
       ajaxRequest.open("GET", "http://www.dminterface.nl/scripts/plaats.php" + queryString, true);
	     ajaxRequest.send(null);
	ZoekStraat();
}
function ZoekStraat(){
  var loadingPanel = new yuiLoadingPanel();	
	var ajaxRequest;
	try{
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				return false;
			}
		}
	}
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState != 4){
		 loadingPanel.show();
     loadingPanel.show("Processing...");
		}				
		if(ajaxRequest.readyState == 4){
		 document.getElementById("str").value = ajaxRequest.responseText;
 		 loadingPanel.hide();
		}
	}
	var pc1 = document.getElementById('pc1').value;
	var pc2 = document.getElementById('pc2').value;
	var hnr = document.getElementById('hnr').value;
	var queryString = "?pc1=" + pc1 + "&pc2=" + pc2 + "&hnr=" + hnr;
	     ajaxRequest.open("GET", "http://www.dminterface.nl/scripts/straat.php" + queryString, true);
	     ajaxRequest.send(null);
}



// Opgemaakte foutmeldingen (met bullet) en rode velden (voor CBA)
document.write('<link rel="stylesheet" type="text/css" href="http://messagent.dminterface.nl/images/scripts/validaties.css">\n');
function ZoekRij(elementName) {
	var x = document.getElementById(elementName);
	if(!x)
		return;
	while(x.tagName.toUpperCase()!="TR" && x.tagName.toUpperCase()!="BODY")
		x = x.parentNode;
	return x;
}
function VerwerkFout(strError) {
	var sluittabel = "<TR><TD>&nbsp;</TD></TR></TABLE>";
	var melding = "Deze velden zijn verplicht.<BR><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 ALIGN=left>";
	var errStr = "";
	if(strError!="") {
		strError = strError.replace("'","&acute;");
		var names = strError.split("<BR>");
		for(i=0;i<names.length-1;i++)	{
			if(names[i]!="") {
				var x = ZoekRij(names[i]);
				if(x) {
					x.className="error";
					var el = document.getElementById(names[i]);
				}	else {
					if(names[i].indexOf("|")>0)	{
						var arr = names[i].split("|");
						for(j=0;j<arr.length-1;j++)	{
							el = ZoekRij(arr[j]);
							if(el) {
								var field = document.getElementById(arr[j]);
								field.err = arr[arr.length-1];
								el.err = arr[arr.length-1];
								el.className="error";
							}
						}
						errStr += "<TR><TD class=validaties ALIGN=left><FONT COLOR=red>"+arr[arr.length-1]+"</FONT></TD></TR>";
					}
				}
			}
		}
		if(errStr!="" && (document.getElementById("FoutWeergeven")))
				document.getElementById("FoutWeergeven").innerHTML = ""+melding+""+errStr+""+sluittabel+"";
	}
}