function isNull( field , fieldName) 
{  
   if ( trim(field.value) == "" )
    {
      if ( isNull.arguments.length  == 1 ) 
         alert( "This value can not be null" );  
      else  
         alert( fieldName + " can not be null!" );
     field.focus();
     return false;  
   }  
    return true;
}

function isEmail(field)
{
 if (field.value != "")
  {
   if (field.value.indexOf("@")>0 && field.value.indexOf("@")<field.value.length-1)
     return true;
   else
    {
      alert("Please correct your email!");
      field.focus();
      return false;
    }
  }
 return true;
}

function isLegality(field)
{
 if (field.value != "")
  {
   if (field.value.indexOf("<")>=0 || field.value.indexOf(">")>=0)
    { 
      alert("Some character can't be inputed£¡");
      field.focus();
      return false;
    }
  }
 return true;
}

function equalString(field1,field2,fieldName)
{
  if (field1.value != field2.value)
   {
      if ( equalString.arguments.length  < 3 ) 
         alert( "The two value must be equal£¡" );  
      else  
         alert( fieldName + "must be equal" );
     field1.focus();
     return false;  
   }
  return true;
}    

function isInt(theElement, theElementName)
{
  s = theElement.value;
  //alert(s.indexOf("."));
  if(s.indexOf(".")>=0){
     alert(theElementName+ " must be a number! ");
     theElement.focus();
     return false;
     }
  
  if (isNaN(Math.abs(theElement.value)) && (s.charAt(0) != '#'))
  {
      if (( isInt.arguments.length  == 1 ) )
         alert( "must be a number£¡" );
      else  
         alert( theElementName +  "  must be a number! " );
    theElement.focus(); 
    return false;
  }
  return true;
}



function isNumber_Max(theElement, theElementName,max)
     {
       s = theElement.value;
       
       if(s.indexOf(".")>=0){
         alert(theElementName+ " must be a integer! ");
         theElement.focus();
         return false;
        }
       if (isNaN(Math.abs(theElement.value)) && (s.charAt(0) != '#'))
         {
           if (( isNumber_Max.arguments.length  == 1 ) )
              alert( "must be a number! " );
           else  
              alert( theElementName + " must be a number! " );
          
           theElement.focus(); 
           return false;
         }
        if (s<0 || s>max)
         {
              alert (theElementName + " must between 0 and " +max + "! ");
              theElement.focus();
              return false;
         }
       return true;
     }
     
function trim(str)
{
   i=0;
   j=str.length-1;
  temp="";
   while(i<str.length)
   {
      if(str.charAt(i)==' ')
      {
          i++;
      }
      else if(str.charAt(i)=='\r')
      {
       i++;
       i++;
      }
      else
      {
        break;
      }
   }
   while(j>=0)
   {
      if(str.charAt(j)==' ')
      {
          j--;
      }
      else if(str.charAt(j)=='\n')
      {
       j--;
       j--;
      }
      else
      {
        break;
      }
   }
   for(t=i;t<=j;t++)
   {
    temp=temp+str.charAt(t);
   }
   return temp;   
}


