function i_length(str)         //返回str长度---中文2位。
{  
  var ret=0;
  for(var i=0;i<str.length;i++)
    ret+=(str.charCodeAt(i)>255?2:1);
  return(ret);
}

function b_nospaceorquote(str)       //检查是否有空格和单引号
{ 
  var index=0;
  var cur_char;
  while(index<str.length)
  {
     cur_char=str.charAt(index);
     if(cur_char==' '||cur_char=="'")
        return (false);
     index=index+1;
  }
  return(true);
}

function b_alldigit(str)                  //检查是否为数字
{ 
  var index=0;
  var cur_char;
  while(index<str.length)
  {
     cur_char=str.charAt(index);
     if(cur_char>'9'||cur_char<'0')
        return (false);
     index=index+1;
  }
  return(true);
}

 function b_isnull(str)            //检查表单项是否为空
{  
           var index=0;
           str_get='';
           while(index<str.length)
           {
             if(str.charAt(index)!=' ')
                str_get=str_get+str.charAt(index);
             else
                str_get=str_get+'';
             index=index+1;
           }
          if(str_get=='')
            return (true);
          else
            return (false);
}

function b_length_ok(str)         //检查身份证长度是否在15-18之间
{ 
   if ((str.length !=15)&&(str.length !=18)) {
             return 0;
         }
   return (true);//else

}

function email_isok(str)        //检查填写的email是否合法
{
    reg = new         
	RegExp("^([_a-z0-9]+([\._a-z0-9-]+)*)@([a-z0-9]{2,}(\.[a-z0-9-]{2,})*\.[a-z]{2,3})$") ;
    if (!reg.test(str))
	{
        alert('email地址不合法！');
        return (false);
    }
    return(true);
}


function chkdate(strYear,strMonth,strDay)      //检查日期是否合法
{
    var intday;
    var intMonth;
    var intYear;

    //get stryear,strmonth,strday;
    intday = parseInt(strDay, 10);
    intMonth = parseInt(strMonth, 10);
    intYear = parseInt(strYear, 10);
    //document.write(intYear);
    if(isNaN(intYear))
    {
         alert('年份应是数字');
         return false;
     }
     if(intYear<1900 || intYear>2003)
     {
         alert('您的出生年对吗？');
         return false;
      }
      if (intMonth>12 || intMonth<1)
	  {
           return false;
      }
      if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1))
      {
           //not possible
           err = 6;
           return false;
       }
       if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1))
       {
            alert('本月只有30天');
            return false;
        }
		if (intMonth == 2)
		{
		   if (intday < 1)
		   {
		   	  err = 8;
			  return false;
			}
			if (LeapYear(intYear) == true)
			{
			   if (intday > 29)
			   {
  			   	  alert('本月只有29天');
				  return false;
				}
			}//if leap
			else
			{
			 	if (intday > 28)
				{
  				   alert('本月只有28天');
				   return false;
				 } //if28
			 }       //else leap
   		}//       if m=2
		return true;
	}

function LeapYear(intYear)
{
    if (intYear % 100 == 0)
	{
        if (intYear % 400 == 0) { return true; }
    }
    else
	{
        if ((intYear % 4) == 0) { return true; }
    }
    return false;
}
//date end




function write_isok()        //检查写留言表单的正确性
{
          
          if(b_isnull(document.write.name.value))
            {
               alert('“姓名”字段不能为空!');
                document.write.name.focus();
                return (false);
             }
          if(b_isnull(document.write.content.value))
          {
               alert('不能发表0字节留言；');
                document.write.content.focus();
                return (false);
          }
	   if(document.write.content.value.length>1000)
         {
               alert('“留言”长度不能大于1000个字符！');
               document.write.content.focus();
               return (false);
          }
                      return (email_isok(document.write.email.value));

}

function MM_goToURL()       //下拉菜单页码跳转
{ 
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function checklength(theform)   //检查输入文字的长度
{
       // if (1) { message = "\n\n所允许的最大长度为 200 个字符."; }
       // else { message = ""; }
        alert("你输入的文字为 "+theform.value.length+" 个字符！");
}

function textCounter(field, countfield, maxlimit)   //限制输入文本框的字符长度
{
  if (field.value.length > maxlimit)
      {field.value = field.value.substring(0, maxlimit);}
  else
      {countfield.value = maxlimit - field.value.length;}
}
