
function checkNumeric(obj) {
	if (Trim(obj.value) != "") {
		test = obj.value.replace(",",".");
		if (isNaN(test)) {
			window.alert("Ongeldige nummerieke waarde");
			obj.focus();
		}
	}	
}

function checkTime(obj) {
	if (Trim(obj.value) != "") {
		if (obj.value.search(/:/g) == -1) {
			obj.value = obj.value + ":00";
		}
		if (!Date.isValid(obj.value,"H:m")) {
			window.alert("Ongeldige tijd");
			obj.focus();
		}
	}
}

function checkDate(obj) {
	if (Trim(obj.value) != "") {
		if (Date.isValid(obj.value,"d-M-y")) {
			return;
		}
		var d = new Date();
		jaar = "" + d.format('yyyy');
		maand = "" + d.format('M');
		if (obj.value.search(/-/g) == -1) {
			obj.value = obj.value + "-" + maand + "-" + jaar ;
		} else if (obj.value.search(/-\d-/g) == -1 || obj.value.search(/-\d\d-/g) == -1) {
			obj.value = obj.value + "-" + jaar;					
		}
		if (!Date.isValid(obj.value,"d-M-y")) {
			//window.alert("Ongeldige datum");
			obj.focus();
		}
	}	
}

function timeDifference(obj,obj1,obj2) {
	var t1 = document.getElementById(obj1);
	var t2 = document.getElementById(obj2);
	if (Trim(t1.value)!="" && Trim(t2.value) != "") {
		
		var d1 = Date.parseString(t1.value,"H:m");
		var d2 = Date.parseString(t2.value,"H:m");
		if (d1 != null && d2 != null) {
			var i1 = (d1.getHours() * 60) + d1.getMinutes();
			var i2 = (d2.getHours() * 60) + d2.getMinutes();
			obj.value = (i2-i1)/60;
		}
	}
	
}

	/*
	Vangt de tab af speciaal voor autocomplete input element
	Anders moeten gebruikers twee keer op de tab drukken.
	*/
	function mkeydown(obj,e) {
		if(window.event) // IE
		{
			keynum = e.keyCode
		}
		else if(e.which) // Netscape/Firefox/Opera
		{
			keynum = e.which
		}	
		if (keynum == 9) {  //tab
			obj.focus();
		}		
	}


function addDropDownAtuoComplete(params) {
		/*Params kan de volgende parameters bevatten:
			{ Server : het php script dat de databse teruggeeft = verplicht
				Callback : De callback functie om iets te doen met de geselecteerde data  = verplicht
				typeAhead :  = optioneel
				forceSelecton : = optioneel,
				Container : de drop down container   = verplicht
				Input : het input element   = verplicht
				scriptQueryAppend : = optioneel,
				}			
		*/		
	
		var myServer = params.Server;		
		var mySchema = ["\n", "\t"];
		var DataSource = new YAHOO.widget.DS_XHR(myServer, mySchema);
		DataSource.responseType = YAHOO.widget.DS_XHR.TYPE_FLAT;
	    DataSource.maxCacheEntries = 60;
	    DataSource.queryMatchSubset = true;		    
	    
	    if ('scriptQueryAppend' in params) {
	    	DataSource.scriptQueryAppend = params.scriptQueryAppend;
	    }
	    if (params.Input == null) {
	    	window.alert("Input param = null");
	    	return;
	    }
	    if (params.Container == null) {
	    	window.alert("Input Container = null");
	    	return;
	    }
	    params.Input.setAttribute("onkeydown","mkeydown(this,event)");
		var AutoComp = new YAHOO.widget.AutoComplete(params.Input,params.Container, DataSource);
	    AutoComp.queryDelay = 0;
	    AutoComp.maxResultsDisplayed = 10
	    AutoComp.itemSelectEvent.subscribe(params.Callback);
	    AutoComp.useShadow = true; 
	    AutoComp.animVert = false;
	    AutoComp.animHoriz = false;
	    AutoComp.useIFrame = true;
	    
	    if ('typeAhead' in params) {
		    AutoComp.typeAhead = params.typeAhead; 
	    } else {
	    	AutoComp.typeAhead = false;
	    }
	    if ('forceSelecton' in params) {
	    	AutoComp.forceSelection = params.forceSelecton; 	    
	    } else {
	    	AutoComp.forceSelection = false; 	    
	    }
	    AutoComp.formatResult = function(oResultItem, sQuery) {
	            try {
		            var sKey = oResultItem[0];
		            var nID = oResultItem[1];
	                var sKeyQuery = sKey.substr(0, sQuery.length);
	                var sKeyRemainder = sKey.substr(sQuery.length);
	                var extra = '';
				    if ('idfield' in params) {
						extra += " idfield=\"" + params.idfield + "\" ";
				    } 				    	
				    if ('nextElement' in params) {
						extra += " nextElement=\"" + params.nextElement + "\" ";
				    } 				    	
		            var aMarkup = ["<div id=\"ysearchresult\" class=\"mysearschresult\" " + extra + " ><div class='ysearchquery'>",
		                null,
		                "</div><span style=\"font-weight:bold;color:red\">",
		                sKeyQuery,
		                "</span>",
		                sKeyRemainder,
		                "</div>"];
	            } catch(e) {
	            	window.alert(e);		            	
	            }
	            return (aMarkup.join(""));
	        };
	    return AutoComp;
	}	

	
function showWindow(location,width,height)     {
	var screenY = window.screen.availHeight;
	var screenX = window.screen.availWidth;
	var left=(screenX-width)/2;
	var top=(screenY-height) / 2;
  	test = window.open(location
  		,"_blank","scrollbars=yes,location=no,height="+ height + ",width="+ width + ",top=" + top + ",left=" + left + ",menubar=no,status=no,titlebar=no,resizable=yes");
	  if (test == null) {
	  		popupFail(location);
	  		return false;
	  } else {
	  	return test;
	  }
   	
}

function sizeWindowTo(width,height) {
	window.resizeTo(width,height);	
	var screenY = window.screen.availHeight;
	var screenX = window.screen.availWidth;
	var left=(screenX-width)/2;
	var top=(screenY-height) / 2;
	window.moveTo(left,top);
}
	
function popupFail(link) {
	window.alert("U heeft waarschijnlijk het gebruik van popup vensters gebolkeerd\nVoor het goed functioneren van deze site is het gebruik van popups noodzakelijk!")
}
	
	
function checkEmailAddress(Adress) {

    // Note: The next expression must be all on one line...
    //       allow no spaces, linefeeds, or carriage returns!
    var goodEmail = Adress.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\..{2,2}))$)\b/gi);

    if (goodEmail){
       return true
    } else {
       return false
       }
    }

    
function CheckBank(val)
    {
        var total=0;
        var re = new RegExp ('[\D\.\ ]', 'gi') ;
        r=val.replace(re,'');


        if(r.length==9)
        {
            for(var c=0;c<r.length;c++) {
                total = total + parseInt((r.substring(c,c+1) * (9-c)));
            }
            if(((total/11)+'').indexOf('.')>0) {
                return false;
            } else {
              return true;
            }
                
        }
        if(!(r.length==6 || r.length ==7) || isNaN(r) )
        {
            return false;
        }
        return true;
    }

	function checkPC(testValue) {
		var size = testValue.length;
		size=testValue.length;
		data = "";
		for (i = 0;i<size;i++) {
			if  (testValue.substring(i,i+1) != " ") {
				data +=testValue.substring(i,i+1);
			}			
		}
		testValue = data;
		
		data = testValue.split(" ");
		size = data[0].length
		if (size < 6 ){
			cijfers = data[0];
			if (data.length > 1) {
				letters = data[1];
			} else {
				letters = ''
			}
		} else {
			if (size > 6) {
				return false;
			}
			cijfers = data[0].substring(0,4);
			letters = data[0].substring(4,6);
		}
		if (cijfers.length != 4 || isNaN(cijfers) || !(isNaN(letters)) || letters.length != 2 ) {
			return false;
		}
		return true;
	}

	
function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
		return "";
	}
	else{
		return TRIM_VALUE;
	}
} //End Function

function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;
	
	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
		
	} //End While
	return strTemp;
	
} //End Function

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";
	
	var iTemp = 0;
	
	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function

