//This function stops non numeric values to be entered in Text box
function AllowNumeric(e, sText)	{ 
	var key, keychar, Char, i, ValidChars;
	ValidChars = "-";
	l = sText;
	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==27) || (key==48) || (key==49) || (key==50) ||(key==51) || (key==52) || (key==53) || (key==54) || (key==55) ||(key==56) || (key==57) || (key==45)  ) {
		if(keychar == "-") {
			return false;
		}
		return true;
	}
	else
		return false;
}


//This function email format to be entered in Text box
function isemail(obj) {
	var str = obj.value;
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail ID");
	   obj.focus();
	   return false;
	}
	
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID");
	   obj.focus();
	   return false;
	}
	
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid E-mail ID");
		obj.focus();
		return false;
	}
	
	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid E-mail ID");
		obj.focus();
		return false;
	 }
	
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid E-mail ID");
		obj.focus();
		return false;
	 }
	
	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid E-mail ID");
		obj.focus();
		return false;
	 }
	
	 if (str.indexOf(" ")!=-1){
		alert("Invalid E-mail ID");
		obj.focus();
		return false;
	 }	
	 return true;					
}


//Trim Function
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };


//if (!(doNotAllow1InPhone(ptr.phone))) { return false; }
function doNotAllow1InPhone(obj) {
	Arr = obj.value.trim().split("");
	if(Arr[0] == "1") {
		alert("Country Codes are not allowed in Phone/Fax. Please remove to continue.");
		obj.focus();
		return false;
	}
	return true;
}


function checkNumeric(fld, minlen, chkAllSame) { 
	if(isNaN(fld.value)) {
		alert("Please fill numeric value to continue.");
		fld.focus();
		return false;
	}
	if(fld.value.trim().length < minlen)
	{
		alert('Field Value has to be atleast ' + minlen + ' digits');
		fld.focus();
		return false;
	}
	
	if(chkAllSame == 1) {
		Arr = fld.value.trim().split("");
		fine = 0;
		for(i=0; i<Arr.length; i++) {
			if(Arr[0] != Arr[i]) {
				fine = 1;
			}
		}
		if(fine == 0) {
			alert('Invalid ' + fld.name + '!');
			fld.focus();
			return false;
		}
	}
	return true;
}


//Validate Form for blank values
function verifyForm(ptr, fldList) {
	fldListArr = fldList.split(",");
	for(i=0; i<fldListArr.length; i++)
	{
		fldArr = fldListArr[i].split("|");
		pointer = eval("ptr." + fldArr[0]);

		if(pointer.type == "checkbox") {
			if(!pointer.checked) {
				alert("Please fill '" + fldArr[1] + "' to continue.");
				pointer.focus();
				return false;
			}
		}
		else if(pointer.type == "radio") {
			if(!pointer.checked) {
				alert("Please fill '" + fldArr[1] + "' to continue.");
				pointer.focus();
				return false;
			}
		}
		else if(pointer.type == "text") {
			if(pointer.value.trim() == "") {
				alert("Please fill '" + fldArr[1] + "' to continue.");
				pointer.focus();
				return false;
			}
			if(pointer.value.trim().length < 2) {
				alert("Please fill correct '" + fldArr[1] + "' to continue.");
				pointer.focus();
				return false;
			}
		}
		else {
			if(pointer.value.trim() == "") {
				alert("Please fill '" + fldArr[1] + "' to continue.");
				pointer.focus();
				return false;
			}
		}
	}
	return true;
}
