	var Alphabet = /^\b[a-z\s\.]*$/i         
	var Address = /./ 						
	var AlphaNumeric = 	/^[a-z_0-9\s]*$/i	
	var Phone = /^[1-9][0-9]{3}\-\[1-9][0-9]{3}\-\[1-9][0-9]{4}$/;	
	var ZipCode1 = /^[1-9][0-9]{4}$/;  
	var ZipCode2 =  /^[1-9][0-9]{3}$/;
	var Email = /^[a-z][a-z_0-9\.\-]+@[a-z_0-9\.\-]+\.[a-z]{2,3}$/i 

///////////////////////    K E Y   T R A P    ////////////////////////////////////
var isIE = ((navigator.appName.indexOf("Microsoft") != -1) ? true : false);
//following function is to be called for both ONKEYPRESS and ONKEYUP events of the control
function keyTrap(objControl,checkType,eventType)
{
	if((isIE) && (eventType=='up')) return
	if((isIE) && ((event.keyCode==9) || (event.keyCode==16))) return //tab and shift+tab
	if(checkType=='Real')
	{
		if((isIE) && ((event.keyCode <48 || event.keyCode >57) && (event.keyCode!=46)))
			event.keyCode =0
		objControl.value = objControl.value.replace(/[^0-9\.]/g,'')	
	}
	else if(checkType=='Integer')
	{
		if((isIE) && (event.keyCode <48 || event.keyCode >57 ))
			event.keyCode =0
		objControl.value = objControl.value.replace(/[^0-9]/g,'')		
	}	
	else if(checkType=='Phone')
	{
		if((isIE) && ((event.keyCode <48 || event.keyCode >57) && (event.keyCode !=40) && (event.keyCode !=41) && (event.keyCode !=45) && (event.keyCode !=32)))
			event.keyCode =0
		objControl.value = objControl.value.replace(/[^0-9\-\s\(\)]/g,'')		
	}
	else if(checkType=='SSN')
	{
		if((isIE) && ((event.keyCode <48 || event.keyCode >57) && (event.keyCode !=45) && (event.keyCode !=32)))
			event.keyCode =0
		objControl.value = objControl.value.replace(/[^0-9\-\s]/g,'')		
	}
	else if(checkType=='Currency')
	{
		if((isIE) && ((event.keyCode <48 || event.keyCode >57) && (event.keyCode !=36) && (event.keyCode !=44) && (event.keyCode !=46)))
			event.keyCode =0
		objControl.value = objControl.value.replace(/[^0-9\.\$\,]/g,'')		
	}				
		
}

//###########################   U N F O R M A T I N G   ###########################################
function unFormat(formattedStr)
	{
	return formattedStr.replace(/[\(\)\-\s\,\$]*/g,"");
	}

//##################################   F O R M A T I N G  ##########################################
function format(strControlValue, strFormatType, strFormatParam)
{
	if(strControlValue=="")
		return "";
	//unformatting the given value before formating
	strControlValue = unFormat(strControlValue)
	if(strFormatType == 'Phone')
	{
		if(strControlValue.length==10 && strFormatParam=="(XXX) XXX-XXXX")
			return "("+strControlValue.substring(0,3) + ") " + strControlValue.substring(3,6) + "-" + strControlValue.substring(6);
		else if(strControlValue.length==10 && strFormatParam=="XXX-XXX-XXXX")
			return strControlValue.substring(0,3) + "-" + strControlValue.substring(3,6) + "-" + strControlValue.substring(6);
		else if(strControlValue.length==7)
			return strControlValue.substring(0,3) + "-" + strControlValue.substring(3);
		else
			return strControlValue //alert for not entering proper value in phone field 
	}
	else if(strFormatType == 'SSN')
	{
		if(strControlValue.length==9)
			return strControlValue.substring(0,3) + "-" + strControlValue.substring(3,5) + "-" + strControlValue.substring(5);
		else
			return strControlValue //alert for not entering proper value in phone field
	}
	else if((strFormatType == 'Currency') || (strFormatType == 'Currency$'))
	{
		var strAmt = "", cents = "", whole = "", decPovar = 0
		whole = "" + Math.round(parseFloat(strControlValue) * Math.pow(10, strFormatParam))
		if(whole.length >2)
			decPovar = whole.length - strFormatParam
		if(decPovar > 0)
		{
			strAmt = whole.substring(0, decPovar)
			cents = whole.substring(decPovar,whole.length)
		}
		else
			strAmt = whole

		for (i = 0; i < Math.floor((strAmt.length - (1+i))/3); i++)
			strAmt = strAmt.substring(0,strAmt.length -(4*i+3))+ "," + strAmt.substring(strAmt.length -(4*i+3));

		if(strAmt.length > 0)
		{
			if (cents.length == 0)
				cents = "00"
			else if(cents.length == 1)
				cents = cents + "0"
			strAmt = strAmt + "." + cents
		}
		if(strFormatType == 'Currency$')
			return '$' + strAmt;
		else
			return strAmt;
	}
	else if(strFormatType == 'Percentage')
	{
		var percentStr="", decimalStr="", i=0, j=0;
		var decCnt = strControlValue.indexOf('.');
		if(decCnt!=-1)
		{
			decimalStr = strControlValue.substring(decCnt);
			if(decimalStr.length != strFormatParam + 1)
			{
				var ctr = strFormatParam + 1 - decimalStr.length;
				for(i = 0; i < ctr; i++)
					decimalStr += "0";
				
				if(ctr<0)
					decimalStr = decimalStr.substring(0,strFormatParam+1);
			}
			strControlValue = strControlValue.substring(0,strControlValue.indexOf('.'));
		}
		else
		{
			decimalStr = ".";
			for(i=0; i < strFormatParam; i++)
				decimalStr += "0";
		}
		return strControlValue + decimalStr ;
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////
function trim(strControlValue)
	{
	return  strControlValue.replace(/\s{1,}$/,"").replace(/^\s*/,"") 
	}
/////////////////////////////////////////////////////////////////////////////////////////////
function check(objControl,strTestPattern,strControlName,blnCanBeNull,blnFocusToControl)
	{   
	var ControlValue = trim(objControl.value) 
	if(ControlValue =='')
		{
		if(blnCanBeNull) 
			return true
		else
			{
				alert(strControlName+ " is a required field.\nPlease enter proper value in "+strControlName)
				if(blnFocusToControl) objControl.focus();
				return false
			}
		}
	if (strTestPattern.test(ControlValue))
		return true
	else
		{
		alert("Invalid " +strControlName+ ".\nPlease enter proper value in "+strControlName)
		if(blnFocusToControl) objControl.focus();
		return false
		}
						
	}  