function fixNumber(input, e)  //Only numbers allowed
{ 
  var keycode
     
  if (e.which)
    keycode = e.which;
  else if (e.keyCode)
    keycode = e.keyCode;
  
  if (IsFunctionKey(keycode))
     return true;
        
  if (String.fromCharCode(keycode).match(/\d/)) 
     return true;
  
  return false;
}

function fixName(input, e) //Weird symbols and numbers not allowed
{
  var keycode
     
  if (e.which)
    keycode = e.which;
  else if (e.keyCode)
    keycode = e.keyCode;
    
  if (IsFunctionKey(keycode))
     return true;
  
  //if (String.fromCharCode(keycode).test("^([a-zA-Zà-ú '-]+\)$") 
  //   return true;
          
  if (String.fromCharCode(keycode).match(/\d|_|:|\*|&|\^|%|\$|#|@|!|\?|~|\+|=|;|<|>|\[|\]/)) 
     return false;
  return true;
}

function fixGenericPhone(input, e) 
{  
  var keycode
     
  if (e.which)
    keycode = e.which;
  else if (e.keyCode)
    keycode = e.keyCode;
  
  if (IsFunctionKey(keycode))
     return true;
     
  if (String.fromCharCode(keycode).match(/\d|\+|\\|\/|-|x|X/))
     return true;
  return false;   
}
  
function fixIsraeliPhone(input, e) 
{  
  var keycode
     
  if (e.which)
    keycode = e.which;
  else if (e.keyCode)
    keycode = e.keyCode;
  
  if (IsFunctionKey(keycode))
     return true;
     
  var inputChar = String.fromCharCode(keycode)
  
  switch (input.value.length)
  {  
      case 10:
          return false;
      case 0:
          if (inputChar == "0")
            return true;
          return false;            
      case 1:          
          if (inputChar.match(/2|3|4|7|8|9/))
           return true;    
          return false;          
      case 2:  
         if (inputChar == "-")
            return true; 
         if (inputChar.match(/\d/) )
         {
           input.value += "-";
           return true;
         }        
         return false;        
      default:
         if ( inputChar.match(/\d/) )
            return true;           
         return false;
  } 
}

function fixIsraeliCellular(input, e) 
{  
  var keycode
     
  if (e.which)
    keycode = e.which;
  else if (e.keyCode)
    keycode = e.keyCode;
  
  if (IsFunctionKey(keycode))
     return true;
     
  var inputChar = String.fromCharCode(keycode)
  
  switch (input.value.length)
  {  
      case 11:
          return false;
      case 0:
          if (inputChar == "0")
            return true;
          return false;            
      case 1:          
          if (inputChar == "5")
            return true;
          return false;           
      case 2:  
         if ( inputChar.match(/0|2|4|7/) ) 
           return true;
         return false; 
      case 3:
         if (inputChar == "-")
            return true;  
         if (inputChar.match(/\d/) )
         {
           input.value += "-";
           return true;
         }        
         return false;                 
      default:
         if ( inputChar.match(/\d|-/) )
            return true;           
         return false;
  } 
}


function fixDate(input, e)
{
  var keycode
 
  if (e.which)
    keycode = e.which;
  else if (e.keyCode)
    keycode = e.keyCode;
  
  if (IsFunctionKey(keycode))
      return true; 
  
  var inputChar = String.fromCharCode(keycode) 
        
  switch (input.value.length)
  {
    case 10:   
       return false;
    case 0:  //first digit of day
       if (inputChar.match(/0|1|2|3/))
           return true;
       if (inputChar.match(/\d/))
           {
             input.value += "0";
             return true;   
           }    
       return false; 
    case 1:  //second digit of day
        if (input.value == "3")
        {
          if (inputChar.match(/0|1/))
             return true;
          return false;
        }    
        else      
          if (inputChar.match(/\d/))
            return true;
          return false; 
    case 2: //first digit of month
        if (inputChar.match(/0|1/))
        {
           input.value += "/";
           return true;
        }
        else
           if (inputChar.match(/\d/))
           {
             input.value += "/0";
             return true;   
           }
           else
           if (inputChar == "/")
              return true;
        return false;  
    case 3: //first digit of month  
        if (inputChar.match(/0|1|2/))
           return true     
        else
           if (inputChar.match(/\d/))
           {
             input.value += "0";
             return true;   
           }          
        return false;  
    case 4: //second digit of month  
        if (inputChar.match(/\d/))
           return true            
        return false;                
    case 5: //first digit of year        
       //if (inputChar.match(/1|2/))
        if (inputChar.match(/\d/))
        {
           input.value += "/";
           return true;        
        }
        if (inputChar == "/")
              return true;
        return false;   
    case 6: //first digit of year        
        //if (inputChar.match(/1|2/))
        if (inputChar.match(/\d/))                
           return true;        
        return false;         
    default : //year digits
       if (inputChar.match(/\d/))
            return true;
       return false;         
  }
}


function IsFunctionKey(key)
{
 if ( (key == 46) || //del key
      (key == 45) || //insert key
      (key == 8)  || //backspace key
      (key == 9)  || //tab key
      (key == 13) || //enter key 
      (key == 27) || //escape key
      (key > 32 && key < 41) //pg. up, pg. down, arrows, home, end
     )              
      return true;
 return false;
}

