<!--
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Description: This javaScript is to check for max number.
// Programmer: hat
// Function(s): chkMaxNum(this,20[,true]);	//required two variables, third var for errMsg
// Tested on: IE6.0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var debug = false;
/* Sample calls
	<script src="/includes/scripts/chkMaxNum.js"></script>
	<input name="field1" value="0" onKeyUp="return chkMaxNum(this,20);"> or;
	<input name="field2" value="0" onKeyUp="return chkMaxNum(this,20,true);">
*/
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Call this function to check for max number
// Ex:	chkMaxNum(this,20); or chkMaxNum(document.fromName.field1,20,true);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	function chkMaxNum(objField,errMsg){
		window.onerror = getChkMaxNumEH;
if (debug) alert("Input: "+ objField +" maxNumber: "+ maxNum +"errorMsg:"+ errMsg);
		if (errMsg == "" || typeof(errMsg) == 'undefined'){
			errMsg = false;
		}

		if(!chkBSpace(objField)){
           if(errMsg) alert("This field is required!");
		    {
			objField.focus();
			 return false;			
			}
		}


		var txtSpace = " ";
		if(objField.value.indexOf(txtSpace) > -1) {
			if(errMsg) alert("Please enter numeric number!");
			objField.focus();
			return false;
		} else {
			var val = "";
			var oval = objField.value;
			
			if (oval.substr(0,1) == "$")
			   oval = oval.substr(1);
			   
			
			var found = false;
			
			for (i = 0; i < oval.length; i++ )
			  {
				
			   if (oval.substr(i,1) == ".")
			      found = true;
			   
			   if ((found) || (oval.substr(i,1) != ","))
			       val = val + oval.substr(i,1);
			   
			  }
			
			
		    if(isNaN(val)){
			  if(errMsg) alert("Please enter numeric number ONLY!");
			  {
  			    objField.focus();
			    return false;
			  }
		      } 
		}
		
		objField.value = formatCurrency(val);
		return true;
	}
	function getChkMaxNumEH() {
if (debug) alert("Error: getChkMaxNum Javascript");
		return true;
	}
	
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') +  num + '.' + cents);
}
	
//-->