/*********************************************************************************/
/*-------------------CLIENT VALIDATION LIBRARY----------------------------------
/* 	Created by Nilesh Rana . 7-May-2003
/**********************************************************************************/
var beforeEventValue =""
var flgKeyUpOver = true;

function fnCheckNumKey(eventObj, intSize,intPrecision, intSigned) {
	var whichKey;
	var returnValue = false;
	whichKey = (document.all)?event.keyCode:eventObj.which;
	beforeEventValue = (document.all)?event.srcElement.value:eventObj.target.value;
	var intDotPosition = beforeEventValue.indexOf('.');
	var intSignPosition = beforeEventValue.indexOf('+');
	
	if (intSignPosition < 0)
		intSignPosition = beforeEventValue.indexOf('-');
		
	if (whichKey < 48 || whichKey > 57)  // if not between 0 to 9
	{	
		if (intSigned == 1 && (whichKey == 45 || whichKey == 43 || whichKey == 46)) {  
			if (intDotPosition >= 0 && whichKey == 46)
				returnValue = false;
			else if (intPrecision != 0 && whichKey == 46)
				returnValue = true; 
			else if (intPrecision == 0 && intSize == 0 && whichKey == 46)
				returnValue = true; 
			else if (whichKey == 45 || whichKey == 43) {
				if (intSignPosition >= 0) 
					returnValue = false;
				else 
					returnValue = true;
			} else 
				returnValue = false;
			
			
		} else if (intSigned == 0 && whichKey == 46) { 
			if (intDotPosition >= 0 && whichKey == 46)
				returnValue = false;
			else if (intPrecision != 0 && whichKey == 46)
				returnValue = true; 
			else if (intPrecision == 0 && intSize == 0 && whichKey == 46)
				returnValue = true; 
			else 
				returnValue = false; 
				
		} else 
			returnValue = false;
	} else 	
		returnValue = true;
	if (!returnValue) beforeEventValue = "";
	
	flgKeyUpOver = false;	
	
	return returnValue;
}

function disableKeyDown()
{
	return flgKeyUpOver;
}

function fnResetToValidNum(Obj, intSize,intPrecision, intSigned) {
	if (beforeEventValue == "") {
		flgKeyUpOver = true;	
		return false;
	}
	intSize = intPrecision > 0? intSize-intPrecision: intSize;
	afterEventValue = Obj.value;
	returnValue = false;
	var reSignedNumber = new RegExp("^[\\+\\-]?\\d*(\\.\\d*)?$");
	var reSignedInteger = new RegExp("^[\\+\\-]?\\d{0," + intSize + "}$");
	var reSignedFloat = new RegExp("^[\\+\\-]?\\d{0," + intSize + "}(\\.\\d{0," + intPrecision + "})?$");
	var reUnSignedNumber = new RegExp("^\\d*(\\.\\d*)?$");
	var reUnSignedInteger = new RegExp("^\\d{0," + intSize + "}$");
	var reUnSignedFloat = new RegExp("^\\d{0," + intSize + "}(\\.\\d{0," + intPrecision + "})?$");
	
	if (intSigned == 1) {
		if (intPrecision!=0) 
			returnValue = reSignedFloat.test(afterEventValue);
		else if (intSize != 0 & intPrecision==0) 
			returnValue = reSignedInteger.test(afterEventValue);
		else if (intSize == 0 & intPrecision==0) 
			returnValue = reSignedNumber.test(afterEventValue);
		else 
			returnValue = false;
	}
	else if (intSigned == 0) {
		if (intPrecision!=0) 
			returnValue = reUnSignedFloat.test(afterEventValue);
		else if (intSize != 0 & intPrecision==0) 
			returnValue = reUnSignedInteger.test(afterEventValue);
		else if (intSize == 0 & intPrecision==0) 
			returnValue = reUnSignedNumber.test(afterEventValue);
		else 
			returnValue = false;
	}
	else 
		returnValue = false;
	if (!returnValue)
		Obj.value = beforeEventValue;
	flgKeyUpOver = true;	
	return returnValue;
}


