// Validation functions

//function that checks if field contains only spaces, tabs, newlines, etc...
function WV_isBlank(val){
	if(val==null){
		return true;
		}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){
			return false;
			}
		}
	return true;
	}

//function that checks if the character entered is a digit 
function WV_isDigit(num) {
	if (num.length>1){
		return false;
		}
	var string="1234567890";
	if (string.indexOf(num)!=-1){
		return true;
		}
	return false;
	}

//function that checks if the entered value is a integer
//this function uses the WV_isBlank and WV_isDigit functions	
function WV_isInteger(val){
	if (WV_isBlank(val)){
		return false;
		}
	for(var i=0;i<val.length;i++){
		if(!WV_isDigit(val.charAt(i))){
			return false;
			}
		}
	return true;
	}

//function that checks if the value entered is numeric.
function WV_isNumeric(val){
	return(parseFloat(val,10)==(val*1));
	}

//function that rounds a float to the given number of decimals
function WV_Round(x,d) {
	var dec = 1;
	var i;	
	for(i=1;i<=d;i++) {
		dec = dec * 10;
		}	
	return(Math.round(x*dec)/(dec));
	}

//function that replaces the comma in the entered value to a point for conversion to float
function WV_ReplaceComma(input) {
	var i;
	if (input.length>0) {
		for(i=0;i<input.length;i++) {
			if(input.charAt(i)==',') {
				input = input.substring(0,i) + '.' + input.substring(i+1,input.length);
				}
			}
		}
	return input;
	}

//function that replaces the point in a string to a comma for display on the web
function WV_ReplacePoint(input) {
	var i;
	if (input.length>0) {
		for(i=0;i<input.length;i++) {
			if(input.charAt(i)=='.') {
				input = input.substring(0,i) + ',' + input.substring(i+1,input.length);
				}
			}
		}
	return input;
	}

//function that checks entered e-mailaddress	
function WV_isEmail(entered){
	apos=entered.indexOf("@"); 
	dotpos=entered.lastIndexOf(".");
	lastpos=entered.length-1;
	if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) {
			return false;
		}
	else {
		return true;
		}
	}

//function that opens a new window	
function WV_Popup(url,targetwin,winwidth,winheight,winleft,wintop,winscroll,winresize,wintoolbar,winstatus,winmenu,winlocation) {
	var wv_popup;
	
	wv_popup = window.open(url,targetwin,'width=' + winwidth + ',height=' + winheight + ',top=' + wintop + ',left=' + winleft + ',scrollbars=' + winscroll + ',status=' + winstatus + ',toolbar=' + wintoolbar + ',location=' + winlocation + ',menubar=' + winmenu + ',resizable=' + winresize);
	}

//function that checks if the input is a date of the format dd/mm/jjjj for a date entered in a textbox. Second parameter is the type of seperator	
function WV_isDateText(mydate,seperator) {
	var arrDate = mydate.split(seperator);
	var myDate = new Date(arrDate[2],arrDate[1]-1,arrDate[0]);
	
	if(myDate.getDate()==arrDate[0]&&myDate.getMonth()==arrDate[1]-1&&myDate.getFullYear()==arrDate[2]) {
		return true;
		}
	return false;
	}
	
//function that checks if the input is a date of the format dd/mm/jjjj for a date chosen by 3 combobox's
function WV_isDateCombo(d,m,y) {
	var myDate = new Date(y,m-1,d);
	
	if(myDate.getDate()==d&&myDate.getMonth()==m-1&&myDate.getFullYear()==y) {
		return true;
		}
	return false;
	}
	