/* ***   FUNCTION THAT ALLOWS ONLY NUMBERS (WHOLE) INSIDE A TEXTBOX   *** */
/* To be called in onkeypress event */ 
function NumKeys()
{
		// Variable to store the "KeyCode".
	var KCode = window.event.keyCode;

	// Check what is the value of "KeyCode". If its valid
	// allow the value to be displayed, otherwise prompt.
	if(KCode >= 48 && KCode < 58)
	{
		window.event.keyCode = KCode;	
	}	
	else
	{	
		window.status = "Invalid Character. Only Numbers Are Allowed.";
		window.event.keyCode = 0;
	}
} // END FUNCTION 

/*---------------------------------------------------------------------------------------------------------------------*/
/* ***   FUNCTION THAT restricts comma "," */
function txtkeys1(obj)
{
	var KCode = window.event.keyCode;
	if(KCode == 44)
	{
		window.status = "Invalid Character. comma " + "," + "  is restricted.";
		window.event.keyCode = 0;
	}		
}
/*---------------------------------------------------------------------------------------------------------------------*/
/* ***   FUNCTION THAT allows only Alpahabets,Numbers and some special charactes 
			like ".", "_", "-", "/", "\", "(", ")", "&", " "(Space).  *** */
function TxtKeys(obj)
{
	/* This is to be called in the "KeyPress" event of a Text control */
	// Variable to store the value of "KeyCode".
	KCode = window.event.keyCode;

	// Check if the "KeyCode" is from "A" to "Z".
	if(KCode > 64 && KCode < 91)
	{
		window.status ="";
		window.event.keyCode = KCode; 
	}
	// Check if the "KeyCode" is from "a" to "z".
	else if(KCode > 96 && KCode < 123)
	{
//		window.status = "";
		window.event.keyCode = KCode; 
	}
	// Check if the "KeyCode" is from "0" to "9".
	else if(KCode > 47 && KCode < 58)
	{
		window.status ="";
		window.event.keyCode = KCode; 
	}
	// Check if the "KeyCode" is anyother character, mentioned above.
	else 
	{
		switch(KCode)
		{
			case 48:
			case 57:
			case 46:			
			case 95:
			case 45:
			case 47:
			case 92:
			case 32:
			case 40:
			case 41:
			case 38:
			case 42:
						
//				window.status = "";
				window.event.keyCode = KCode ;
				break;
			default:
				window.status = "Invalid Character."
				window.event.keyCode = 0; 
		}
	}
}// END FUNCTION
/*---------------------------------------------------------------------------------------------------------------------*/
/* ***   FUNCTION THAT CHECKS DECIMAL NUMBERS INSIDE A TEXTBOX   *** */

/* To be called in onkeypress event */ 
function DeciKeys()
{
		// Variable to store the "KeyCode".
	var KCode = window.event.keyCode;

	// Check what is the value of "KeyCode". If its valid
	// allow the value to be displayed, otherwise prompt.
	if(KCode >= 48 && KCode < 58)
	{
		window.event.keyCode = KCode;	
	}
	else if(KCode == 46)	
	{
		window.event.keyCode = KCode;	
	}
	else
	{	
		window.status = "Invalid Character. Only Numbers Are Allowed.";
		window.event.keyCode = 0;
	}
} // END FUNCTION  

/* To be called in onblur event */
function deckeys(obj,decimals) 
{
  var strNumber = obj.value;
  //var strNumber = new String(pnumber);
  var arrParts = strNumber.split('.');
  var intWholePart = parseInt(arrParts[0],10);
  var strResult = '';
  if (isNaN(intWholePart))
    intWholePart = '0';
  if(arrParts.length > 1)
  {
    var decDecimalPart = new String(arrParts[1]);
    var i = 0;
    var intZeroCount = 0;
     while ( i < String(arrParts[1]).length )
     {
       if( parseInt(String(arrParts[1]).charAt(i),10) == 0 )
       {
         intZeroCount += 1;
         i += 1;
       }
       else
         break;
    }     
    decDecimalPart = parseInt(decDecimalPart.substring(0,decimals));
   
    var stringOfZeros = new String('');
    i=0;
    if( decDecimalPart > 0 )
    {
      while( i < intZeroCount)
      {
        stringOfZeros += '0';
        i += 1;
      }
    }
    decDecimalPart = String(intWholePart) + "." + stringOfZeros + String(decDecimalPart); 
    var dot = decDecimalPart.indexOf('.');
    if(dot == -1)
    {
      decDecimalPart += '.'; 
      dot = decDecimalPart.indexOf('.'); 
    } 
    var l=parseInt(dot)+parseInt(decimals); 
    while(decDecimalPart.length <= l) 
    {
      decDecimalPart += '0'; 
    }
    strResult = decDecimalPart;
  }
  else
  {
    var dot; 
    var decDecimalPart = new String(intWholePart); 

    decDecimalPart += '.'; 
    dot = decDecimalPart.indexOf('.'); 
    var l=parseInt(dot)+parseInt(decimals); 
    while(decDecimalPart.length <= l) 
    {
      decDecimalPart += '0'; 
    }
    strResult = decDecimalPart;
  }
   
  obj.value = strResult;
} // END FUNCTION
/*---------------------------------------------------------------------------------------------------------------------*/
 
 
 function CartNumKeys()
{
		// Variable to store the "KeyCode".
	var KCode = window.event.keyCode;

	// Check what is the value of "KeyCode". If its valid
	// allow the value to be displayed, otherwise prompt.
	if(KCode >= 48 && KCode < 58  )
	{
		window.event.keyCode = KCode;	
	}	
	else
	{	
		window.status = "Invalid Character. Only Numbers Are Allowed.";
		window.event.keyCode = 0;
	}
} // END FUNCTION 
  
