function isNull( field , fieldName) 
{  
   if ( trim(field.value) == "" )
    {
      if ( isNull.arguments.length  == 1 ) 
         alert( "This value can not be null" );  
      else  
         alert( fieldName + " 不能为空！" );
     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("请输入正确的 email 账号！");
      field.focus();
      return false;
    }
  }
 return true;
}

function isLegality(field)
{
 if (field.value != "")
  {
   if (field.value.indexOf("<")>=0 || field.value.indexOf(">")>=0 )
    { 
      alert("某些特殊字符不能作为输入！");
      field.focus();
      return false;
    }
  }
 return true;
}


function equalString(field1,field2,fieldName)
{
  if (field1.value != field2.value)
   {
      if ( equalString.arguments.length  < 3 ) 
         alert( "两次输入值必须相同！" );  
      else  
         alert( fieldName + "必须相同！" );
     field1.focus();
     return false;  
   }
  return true;
}    

function isInt(theElement, theElementName)
{
  s = theElement.value;
  //alert(s.indexOf("."));
  if(s.indexOf(".")>=0){
     alert(theElementName+ " 必须是数值！");
     theElement.focus();
     return false;
     }
  
  if (isNaN(Math.abs(theElement.value)) && (s.charAt(0) != '#'))
  {
      if (( isInt.arguments.length  == 1 ) )
         alert( "必须是数值！" );
      else  
         alert( theElementName +  "  必须是数值！" );
    theElement.focus(); 
    return false;
  }
  return true;
}



function isNumber_Max(theElement, theElementName,max)
     {
       s = theElement.value;
       
       if(s.indexOf(".")>=0){
         alert(theElementName+ " 必须是整数！");
         theElement.focus();
         return false;
        }
       if (isNaN(Math.abs(theElement.value)) && (s.charAt(0) != '#'))
         {
           if (( isNumber_Max.arguments.length  == 1 ) )
              alert( "必须是个数值！" );
           else  
              alert( theElementName + " 必须是个数值！" );
          
           theElement.focus(); 
           return false;
         }
        if (s<0 || s>max)
         {
              alert (theElementName + " 必须在0和 " +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;   
}

function isDate(year,month,day,maxYear)
{
  yearValue = year.value;
  monthValue = month.value;
  dayValue = day.value;

if (yearValue!="" || monthValue!="" || dayValue!="")
{
  maxYear=2100	 
  if (isNaN(yearValue) || yearValue<1900 || yearValue>parseInt(maxYear))
  {
     alert("Please check the year");
     year.focus();
     return false;
  }
  if (isNaN(monthValue) || monthValue<1 || monthValue>12)
  { 
     alert("Please check the month");
     month.focus();
     return false;
  }
  if (isNaN(dayValue) || dayValue<1 || dayValue>31)
  {
     alert("Please check the day");
     day.focus();
     return false;
  }
  if (((monthValue==4 || monthValue==6 || monthValue==9 || monthValue==11)&& dayValue>30) 
|| (monthValue==2 && dayValue>29) 
|| ((monthValue==2 && dayValue>28 && !((yearValue%4==0&&yearValue%100!=0)||(yearValue%400==0)))))
  {
    alert("Please check the day");
    day.focus();
    return false;
  }
}

return true;
  
}