//This function stops non decimal values to be entered in Text box

function AllowDecimal(e, sText) { 

	var key;

	var keychar;

	var Char;

	var i;

	var ValidChars;

	var ValidChars1;

	ValidChars  = ".";

	ValidChars1  = "-";

	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==48) || (key==49) || (key==50) ||(key==51) || (key==52) || (key==53) || (key==54) || (key==55) ||(key==56) || (key==57)  || (key==2) || (key==46) || (key==45)) {

		if(keychar == ".") {

			for (i = 0; i < l.length; i++) { 

				Char = l.charAt(i);

				if (ValidChars.indexOf(Char) != -1) 

					return false;

			}

		}

		if(keychar == "-") {

			return false;

		}

		return true;

	}

	else if (key==22)

		return false;

	else

		return false;

}           



//This function stops wildcards to be entered in Text box

function disallowWildCard(e, sText)	{ 

	var key, keychar, Char, i;

	l = sText;

	if (window.event)

		key = window.event.keyCode;

	else if (e)

		key = e.which;

	else

		return true;

	keychar = String.fromCharCode(key);

	if(keychar == "%")

		return false;

	else

		return true;

}



//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+$/, ''); };





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.type == "textarea") {

			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;

			}

			if(pointer.value.trim().length > fldArr[2]) {

				alert("Please fill correct '" + fldArr[1] + "' to continue. Maximum Length for this field is " + fldArr[2] + ".");

				pointer.value.trim().substr(0, fldArr[2]);

				pointer.focus();

				return false;

			}

		}

		else {

			if(pointer.value.trim() == "") {

				alert("Please fill '" + fldArr[1] + "' to continue.");

				pointer.focus();

				return false;

			}

		}

	}

	return true;

}



//gets size of the page

function ___getPageSize() {

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {	

		xScroll = window.innerWidth + window.scrollMaxX;

		yScroll = window.innerHeight + window.scrollMaxY;

	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac

		xScroll = document.body.scrollWidth;

		yScroll = document.body.scrollHeight;

	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari

		xScroll = document.body.offsetWidth;

		yScroll = document.body.offsetHeight;

	}

	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer

		if(document.documentElement.clientWidth){

			windowWidth = document.documentElement.clientWidth; 

		} else {

			windowWidth = self.innerWidth;

		}

		windowHeight = self.innerHeight;

	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode

		windowWidth = document.documentElement.clientWidth;

		windowHeight = document.documentElement.clientHeight;

	} else if (document.body) { // other Explorers

		windowWidth = document.body.clientWidth;

		windowHeight = document.body.clientHeight;

	}	

	// for small pages with total height less then height of the viewport

	if(yScroll < windowHeight){

		pageHeight = windowHeight;

	} else { 

		pageHeight = yScroll;

	}

	// for small pages with total width less then width of the viewport

	if(xScroll < windowWidth){	

		pageWidth = xScroll;		

	} else {

		pageWidth = windowWidth;

	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);

	return arrayPageSize;

}

// email code

function chkmail(usernm){

   //var email=document.frm.emailer.value;

    var email=usernm;

        //var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;  //short form

    var emailExp = /^[a-z_A-Z0-9\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;

    if(email.match(emailExp))

    {

       return true;

    }

    else

    {

     // alert("Invalid Email");

     // document.frm.emailer.focus();

      return false;

    }   



}
