function ValidationGetInt(value, defaultValue)
{
   try
   {
      value = parseInt(value);
      if (isNaN(value)) value = defaultValue;
   }
   catch (ex) { value = defaultValue; }
   return value;
}

if( pageValidator.Masks["NumberMask"] == null )
pageValidator.Masks["NumberMask"] = function( event )
{
   if( !event ) event = window.event;

   var iKeyCode = String(event.keyCode ? event.keyCode : event.which);
   var oSrcElement = event.srcElement ? event.srcElement : event.currentTarget;
   var sValue = new String(oSrcElement.value);

   var rawPrecision = oSrcElement.getAttribute('ieprecision');
   var m_Precision = (rawPrecision == undefined ? new Array() : new String(rawPrecision).split(','));
   
   var iDecimalPlaces = ValidationGetInt(m_Precision[0], 6);
   var iDecimalPrecision = ValidationGetInt(m_Precision[1], 0);

   var iLength = sValue.length;
   var iCommaIndex = sValue.indexOf('.')

   if( event.type == 'keydown' )
   {
      //sCommaKeyCodes = keyboardHandling.KeyDown["COMMA"] + ',' + keyboardHandling.KeyDown["NUM_COMMA"];
      sCommaKeyCodes = keyboardHandling.KeyDown["PERIOD"] + ',' + keyboardHandling.KeyDown["NUM_PERIOD"];
      sHyphenKeyCodes = keyboardHandling.KeyDown["HYPHEN"] + ',' + keyboardHandling.KeyDown["NUM_SUBTRACT"];
   }
   else if( event.type == 'keypress' )
   {
      //sCommaKeyCodes = keyboardHandling.KeyPress["COMMA"];
      sCommaKeyCodes = keyboardHandling.KeyPress["PERIOD"];
      sHyphenKeyCodes = keyboardHandling.KeyPress["HYPHEN"];
   }

   if( iKeyCode.IsIn(sCommaKeyCodes) )
   {
      if( iDecimalPrecision == 0 )
      {
           //w3c stop default behavior   
           if( event.cancelable ) event.preventDefault();
           //ie stop default behavior
          event.returnValue = false;
          //DOM level 0 stop default behavior
          return false; 
      }
      else
      {
         if( sValue == '' )
         {
            oSrcElement.value = '0.';
               //w3c stop default behavior   
               if( event.cancelable ) event.preventDefault();
               //ie stop default behavior
              event.returnValue = false;
              //DOM level 0 stop default behavior
              return false; 
         }
         else if( sValue == '-' )
         {
            oSrcElement.value = '-0.';
               //w3c stop default behavior   
               if( event.cancelable ) event.preventDefault();
               //ie stop default behavior
              event.returnValue = false;
              //DOM level 0 stop default behavior
              return false; 
         }
         else if( iCommaIndex != -1 )
         {
               //w3c stop default behavior   
               if( event.cancelable ) event.preventDefault();
               //ie stop default behavior
              event.returnValue = false;
              //DOM level 0 stop default behavior
              return false; 
         }
      }   
   }
   else if ( iKeyCode.IsIn(sHyphenKeyCodes) )
   {
      if( sValue != '' )
      {
            //w3c stop default behavior   
            if( event.cancelable ) event.preventDefault();
            //ie stop default behavior
           event.returnValue = false;
           //DOM level 0 stop default behavior
           return false; 
      }
   }
   else
   {
      if( !keyboardHandling.IsNumericKey(event) && !keyboardHandling.IsNavigationKey(event) )
      {          
            //w3c stop default behavior   
            if( event.cancelable ) event.preventDefault();
            //ie stop default behavior
           event.returnValue = false;
           //DOM level 0 stop default behavior
           return false; 
      }
   }
   
   if( !keyboardHandling.IsNavigationKey(event) && !iKeyCode.IsIn(sCommaKeyCodes) && !iKeyCode.IsIn(sHyphenKeyCodes) )
   {
      if( iCommaIndex != -1 && iLength > 1 )
      {
         numParteInt = sValue.replace("-","").substr(0,iCommaIndex);
         numParteDec = sValue.replace("-","").substr(iCommaIndex+1,iLength);

         if( numParteDec.length == iDecimalPrecision )
         {
                //w3c stop default behavior   
                if( event.cancelable ) event.preventDefault();
                //ie stop default behavior
               event.returnValue = false;
               //DOM level 0 stop default behavior
               return false; 
         }
      }
      else
      {
         numParteInt = sValue.replace("-","");

         if( numParteInt.length == iDecimalPlaces )
         {
            if( iDecimalPrecision > 0 )
            {
               oSrcElement.value = sValue + '.';
            }
            else
            {
                    //w3c stop default behavior   
                    if( event.cancelable ) event.preventDefault();
                    //ie stop default behavior
                   event.returnValue = false;
                   //DOM level 0 stop default behavior
                   return false; 
            }
         }
      }
   }
}

if( pageValidator.PostValidationMethods["IsValidNumberRange"] == null )
pageValidator.PostValidationMethods["IsValidNumberRange"] = function( pSrcElement, dMinValue, dMaxValue )
{
   var oSrcElement = pSrcElement;
   var dValue = parseFloat(oSrcElement.value);

   if( isNaN(dValue) || isNaN(dMinValue) || isNaN(dMaxValue) )
      return false;
      
   if( dMaxValue != null ) dMaxValue = parseFloat(dMaxValue);
   if( dMinValue != null ) dMinValue = parseFloat(dMinValue);

   if( dMaxValue != null && dMinValue != null )
   {
      if( dMinValue <= dMaxValue )
      {
         if( dValue >= dMinValue && dValue <= dMaxValue )
            return true;
      }
   }
   else if( dMinValue != null )
   {
      if( dValue >= dMinValue )
         return true;
   }
   else if( dMaxValue != null )
   {
      if( dValue <= dMaxValue )
         return true;
   }
   else
   {
      return true;
   }
   
   return false;
}
