// function to delete blanks from the left and right side.
function deleteBlanks(entry)
{
	var len = entry.length ;
	var foundBlank = 1;
	while(foundBlank == 1 && len > 0) 
	{
		var indx = entry.indexOf(" ");
		if(indx == -1) 
			foundBlank = 0 ;
		else
			entry = entry.substring(0,indx) + entry.substring(indx+1,len);
		len = entry.length;
	}
	return entry;
}
	
// function to check empty controls in the form
function isEmpty(val,valName) {
	retVal = true;
if (!deleteBlanks(val.value)) {
	alert(valName + " is required");
	val.select();
	val.focus();
	retVal = false;	
	}
	return retVal;
}
	
/*Function To Check Entered Data is number or not */
function isNumber(val) {
	retVal = true;
	count=0;
	str = val.toString();
	for (i=0;i<str.length;i++) {
		ch = str.substr(i, 1);
		if (ch<"0" || ch>"9") {
			retVal = false;
		}
	}
	 return retVal;
}
	
// function to check the emailid is valid or not<br>
function isEmail(val) {
	retVal = true; 
	tmp = val.value;
	if (isEmpty(val,"Email Address")) {
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,7})+$/.test(tmp)){
			retVal = true;	
		}
		else{
			alert("Email Address is invalid")
			val.focus();
			val.select();
			retVal = false;	
		}
	}
	else {
		retVal = false;
	}	
	return retVal;
}
	
// function to validate the length of zip code
function isLength(zipVal){

	var str = zipVal.toString();
	var strLength = str.length;
	var retVal = false;
	while(1) {
		if (strLength>5) {
		return retVal;
			break;
		}
		retVal = true;
		break;
	}
	return retVal;
}

// function to check valid telephone number
function isTel(val1,val2,val3,valName) {
	inv=0;
	v=val1.value+val2.value+val3.value;
	if (v!="") {
		if (v.length<10)
			inv=1;
		for (var i=0;i<v.length && inv==0;i++) {
			if ( v.charAt(i)<"0" || v.charAt(i)>"9")
				inv=1;
		}
		if (inv==1) {
			alert (valName + " is invalid")
			val1.focus();
			val1.select();
			return false;
		}
	}
	return true;
}
	//alows only A-Z, 0-9 and spaces
function isValidText(frmElement, fieldName) {
	myRegExp = new RegExp("[^a-z,0-9,\\s]", "i"); 
	if(myRegExp.test(frmElement.value)) {
		alert("Special characters not allowed in " + fieldName);
		frmElement.focus();
		frmElement.select();
		retVal = false;
	}
	else {
		retVal = true;
		}
	return retVal;
}

	//alows only A-Z and spaces
function isValidChar(frmElement, fieldName) {
	myRegExp = new RegExp("[^a-z,\\s]", "i"); 
	if(myRegExp.test(frmElement.value)) {
		alert("Only characters allowed in " + fieldName);
		frmElement.focus();
		frmElement.select();
		retVal = false;
	}
	else {
		retVal = true;
		}
	return retVal;
}
// function to check empty textarea in the form	
function isTextAreaEmpty(val,valName){
	var val1 = val.value;
	var len = val1.length;  
	v= "\r\n";
	for(i=0; i < (len/2); i++){
		v= v++;
	}	
	if (val1== v || deleteBlanks(val1)=='' || val1==' ') {
		alert('Please enter '+valName);
		return false;
	}
	else {
		return true;
	}
}