//******************************************************
/*
	AUTHOR	:	Rajdeep Kwatra
	DATE	:	09 Nov. 2005
	PURPOSE	:	Provides validations/masking for various types: Phone, Alphabetic, Numeric with/without decimal
*/
//******************************************************
//browser detection
var strUserAgent = navigator.userAgent.toLowerCase(); 
var isIE = strUserAgent.indexOf("msie") > -1; 
var isNS6 = strUserAgent.indexOf("netscape6") > -1; 
var isNS4 = !isIE && !isNS6  && parseFloat(navigator.appVersion) < 5; 

var DecExists=-1;
//mask function: Allows only Numeric input. Set allowDecimal=1 to allow entering one period(.)
//Syntax(with decimal):onkeypress="return maskKeyNumeric(event,this.value,1)"
//Syntax(without decimal):onkeypress="return maskKeyNumeric(event,this.value,0)"
function maskKeyNumeric(objEvent,num,allowDecimal) {
	var iKeyCode, strKey;  				
	if (isIE) {
		iKeyCode = objEvent.keyCode;
	} else {
		iKeyCode = objEvent.which;
	}
	
	strKey = String.fromCharCode(iKeyCode);
	
	if(allowDecimal==0)
	{
		DecExists=0;
	}
	else	
	{
		DecExists=num.indexOf('.');
	}
	
	if(iKeyCode!=8 && iKeyCode!=9)//Backspace & Tab
	{
    	if((iKeyCode>=48 && iKeyCode<=57) || (iKeyCode==46 && DecExists==-1))
    	{
        	//Valid Characters;Do nothing
    	}
    	else
    	{
    		return false;
    	}
	}
}

//mask function: Allows only Numeric input with hyphen symbol.
//Syntax(with decimal):onkeypress="return maskKeyPhone(event)"
function maskKeyPhone(objEvent) {
	var iKeyCode, strKey;  				
	if (isIE) {
		iKeyCode = objEvent.keyCode;
	} else {
		iKeyCode = objEvent.which;
	}
	strKey = String.fromCharCode(iKeyCode);
			
	if(iKeyCode!=8 && iKeyCode!=9)//Backspace & Tab
	{
    	if((iKeyCode>=48 && iKeyCode<=57) || (iKeyCode==45))
    	{
        	//Valid Characters;Do nothing
    	}
    	else
    	{    		
    		return false;
    	}
	}
}


//mask function: Allows only Numeric input with , symbol.
//Syntax(with decimal):onkeypress="return maskKeyMoney(event)"
function maskKeyMoney(objEvent) {
	var iKeyCode, strKey;  				
	if (isIE) {
		iKeyCode = objEvent.keyCode;
	} else {
		iKeyCode = objEvent.which;
	}
	strKey = String.fromCharCode(iKeyCode);
			
	if(iKeyCode!=8 && iKeyCode!=9)//Backspace & Tab
	{
    	if((iKeyCode>=48 && iKeyCode<=57) || (iKeyCode==44))
    	{
        	//Valid Characters;Do nothing
    	}
    	else
    	{    		
    		return false;
    	}
	}
}

//mask function: Allows only Alphabetic input. No special symbols allowed
//Syntax(with decimal):onkeypress="return maskKeyAlpha(event)"
function maskKeyAlpha(objEvent) {
	var iKeyCode, strKey;  				
	if (isIE) {
		iKeyCode = objEvent.keyCode;
	} else {
		iKeyCode = objEvent.which;
	}
	
	strKey = String.fromCharCode(iKeyCode);
			
	//alert(iKeyCode);		
	if(iKeyCode!=8 && iKeyCode!=9)//Backspace & Tab
	{
    	if((iKeyCode>=65 && iKeyCode<=90) || (iKeyCode>=97 && iKeyCode<=122) || iKeyCode == 32)
    	{
			//Valid Characters;Do nothing        	
    	}
    	else
    	{
    		return false;
    		
    	}
	}
}