function isLengthRight(length,inStr)
{
	var str=Trim(inStr);
	var	i = 0 
	for (dd=0;dd<str.length; dd++) {
		if (str.charCodeAt(dd) > 255 ) {
			i = i+2;
		} else {
		 	i = i+1;
		}
	}

	//比较长度
	var j=parseInt(length);
	if(i==j)
	{
		return 1;
	}
	else
	{
		return i>j?-1:0;
	}
}

function isDigit(inStr)
{
	var Digits = "0123456789";
	var temp;
	
	if(isEmpty(inStr)==1)
		return 1;

	for(var i=0;i<inStr.length;i++)
	{
		temp=inStr.substring(i,i+1);
		if (Digits.indexOf(temp)==-1)
		{
			return 0;
		}
	}
	return 1;	
}

function isEmpty(inStr)
{
	
	for(var i=0;i<inStr.length;i++)
		if(inStr.substring(i,i+1)!=" ")
			return 0;
	return 1;
}

function Trim(inStr)
{
	if(isEmpty(inStr)==1)
		return "";
	var temp=inStr
	while(temp.indexOf(' ')==0)
		temp=temp.substring(1,temp.length);
	while(temp.lastIndexOf(' ')==temp.length-1)
		temp=temp.substring(0,temp.length-1);
	return temp;
}

function isDate(inStr)
{
	if(inStr=="")return 1;
	var Year;
	var Month;
	var Day;
	strDate=Trim(inStr);
	if(strDate.length!=8)
	{
		return 0;
	}
	Year=strDate.substring(0,4);
	Month=strDate.substring(4,6);
	Day=strDate.substring(6,8);
	if( ( isDigit(Year)!=1 )||( isDigit(Month)!=1 )||( isDigit(Day)!=1 )||( Year<"1900" )||( Year>"2100" ) )
	{
		return 0;
	}
	switch(Month)
	{
		case '01':
		case '03':
		case '05':
		case '07':
		case '08':
		case '10':
		case '12':
		if(Day<'01'||Day>'31')
		return 0;
		break;
		case '04':
		case '06':
		case '09':
		case '11':
		if(Day<'01'||Day>'30')
		return 0;
		break;
		case '02':
		if(( parseInt(Year)%4==0 && parseInt(Year)%100!=0 )|| parseInt(Year)%400==0)
		{
			if(Day<'01'||Day>'29')
			return 0;
		}
		else
		{
			if(Day<'01'||Day>'28')
			return 0;
		}					
		break;
		default:
		return 0;
	}
	return 1;
}

function isWord(inStr)
{
	var validLetters = "abcdefghijkmlnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var temp;
	var strWord=Trim(inStr)	  
	for(var i=0;i<strWord.length;i++)
	{
		temp=strWord.substring(i,i+1);
		if (validLetters.indexOf(temp)==-1)
		{
			return 0;
		}
		if (i>20)
		{
			return -1;
		}	
	}
	return 1;	
}

/*
   检查输入的年份
*/
function isYear(inStr)
{
	var Year;
	
	Year=Trim(inStr);
	if(Year.length==0)
		return 1;
	
	if(Year.length!=4)
	//判断长度是否正确
	{
		return 0;
	}
	
	
	if( ( isDigit(Year)!=1 )||( Year<"1900" )||( Year>"2100" ) )
	//年非数值或者年份过小过大认为不是日期
	{
		return 0;
	}
	return 1;
}

/*
   检查输入的手机号
*/
function checkMobile(mobile)
{
	if (isEmpty(mobile)!=1)
	{   
		if ((isLengthRight(11,mobile)!=1)&&
		(isLengthRight(12,mobile)!=1)|| 
		(isDigit(mobile)!=1))
		{ 
			return 0;
		} 
	}
	return 1;
}

function isEmailFormat(inStr){
	if(inStr.length==0) return 1;
	var AtSym    = inStr.indexOf('@');
	var Period   = inStr.lastIndexOf('.');
	var Space    = inStr.indexOf(' ');
	var Length   = inStr.length - 1;   
	if ((AtSym < 1) ||               
    	(Period <= AtSym+1) ||       
    	(Period == Length ) ||       
    	(Space  != -1)){  
				return 0;
	}
        return 1;
}

function checkUserName(userName){
	
	var LETTERS="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ._-";
	var DIGITS="0123456789";
	var exceptExistCharOnly="0123456789.";
	userName=userName.toUpperCase();
	if(userName.substring(0,2)=="FS"){
		alert("用户名不能以fs或FS开头");
		return 0;
	}
	if(userName.length<3)
		return 0;
	if(isEmpty(userName)!=1){
		var flag=0;
		
		if (exceptExistCharOnly_Fun(exceptExistCharOnly,userName)) return 0;
		
		for(var i=0;i<userName.length;i++){
			var temp=userName.substring(i,i+1);
			
			if(LETTERS.indexOf(temp)==-1){
				if(DIGITS.indexOf(temp)==-1){
					return 0;
				}
			}else{
				flag=1
			}
		}
		if(flag==0) return 0;
	}
	return 1;
}

function exceptExistCharOnly_Fun(exceptExistCharOnly,userName){
	var isExcept=true;
	for (var i=0;i<userName.length;i++){
		var temp=userName.substring(i,i+1);
		
		if (exceptExistCharOnly.indexOf(temp)==-1){
			isExcept=false;
			break;
		}
	}
	return isExcept;
}

/*
   检查输入的身份证号码
*/
function checkIDCard(ctrl){	       
	if(isEmpty(ctrl)!=1){
		if((isLengthRight(15,ctrl)!=1)&&(isLengthRight(18,ctrl)!=1)){
			return 0;
		}else if(isLengthRight(15,ctrl)==1){
			if(isDigit(ctrl)!=1){        
				return 0;
			}	
			birthday="19"+(ctrl).substring(6,12);
			if(isDate(birthday)!=1){          
				return 0;
			}
		}else if(isLengthRight(18,ctrl)==1){
			if(isDigit((ctrl).substring(0,17))!=1){        
        		return 0;
      		}      
      		if((isDigit((ctrl).substring(17,18))!=1)&&(isWord((ctrl).substring(17,18))!=1)){        
        		return 0;
      		}      
      		birthday=(ctrl).substring(6,14);      
      		if(isDate(birthday)!=1){
        		return 0;            
			}    	
		}
		return 1;    	
	}
	else{
		return 0;
	}  
}

function checkSecurityCode(idCard){
	var DIGITS="0123456789";
	if(idCard.length<6)
		return 0;
	if(isEmpty(idCard)!=1){
		var flag=0;
		for(var i=0;i<idCard.length;i++){
			var temp=idCard.substring(i,i+1);
			if(DIGITS.indexOf(temp)==-1)	
				return 0;
		}
	}
	return 1;
}

 function   isChinaIDCard(StrNo){   
 //var StrNo = document.form1.usr_regnum1.value
  //StrNo   =   StrNo.toString()   
  if   (StrNo.length==18)   
  {   
            var   a,b,c   
            if   (!isInteger(StrNo.substr(0,17)))   {return   false}   
            a=parseInt(StrNo.substr(0,1))*7+parseInt(StrNo.substr(1,1))*9+parseInt(StrNo.substr(2,1))*10;   
            a=a+parseInt(StrNo.substr(3,1))*5+parseInt(StrNo.substr(4,1))*8+parseInt(StrNo.substr(5,1))*4;   
            a=a+parseInt(StrNo.substr(6,1))*2+parseInt(StrNo.substr(7,1))*1+parseInt(StrNo.substr(8,1))*6;     
            a=a+parseInt(StrNo.substr(9,1))*3+parseInt(StrNo.substr(10,1))*7+parseInt(StrNo.substr(11,1))*9;     
            a=a+parseInt(StrNo.substr(12,1))*10+parseInt(StrNo.substr(13,1))*5+parseInt(StrNo.substr(14,1))*8;     
            a=a+parseInt(StrNo.substr(15,1))*4+parseInt(StrNo.substr(16,1))*2;   
            b=a%11;   
    
            if   (b==2)   //最后一位为校验位   
            {   
            c=StrNo.substr(17,1).toUpperCase();   //转为大写X   
            }   
            else   
            {   
            c=parseInt(StrNo.substr(17,1));   
            }   
    
            switch(b)   
            {   
	            case   0:   if   (   c!=1   )   {
		            //alert("身份证好号码校验位错:最后一位应该为:1");
		            return   false;
	            }
	            break;   
            	case   1:   if   (   c!=0   )   {
		            //alert("身份证好号码校验位错:最后一位应该为:0");
		            return   false;
            	}
            	break;   
            case   2:   if   (   c!="X")   {
            	//alert("身份证好号码校验位错:最后一位应该为:X");
            	return   false;
            }break;   
            case   3:   if   (   c!=9   )   {//alert("身份证好号码校验位错:最后一位应该为:9");
            return   false;}break;   
            case   4:   if   (   c!=8   )   {//alert("身份证好号码校验位错:最后一位应该为:8");
            return   false;}break;   
            case   5:   if   (   c!=7   )   {//alert("身份证好号码校验位错:最后一位应该为:7");
            return   false;}break;   
            case   6:   if   (   c!=6   )   {//alert("身份证好号码校验位错:最后一位应该为:6");
            return   false;}break;   
            case   7:   if   (   c!=5   )   {//alert("身份证好号码校验位错:最后一位应该为:5");
            return   false;}break;   
            case   8:   if   (   c!=4   )   {//alert("身份证好号码校验位错:最后一位应该为:4");
            return   false;}break;   
            case   9:   if   (   c!=3   )   {//alert("身份证好号码校验位错:最后一位应该为:3");
            return   false;}break;   
            case   10:   if   (   c!=2   ){//alert("身份证好号码校验位错:最后一位应该为:2");
            return   false}   
            }   
            }   
  else   //15位身份证号   
            {   
            if   (!isInteger(StrNo))   {//alert("身份证号码错误,前15位不能含有英文字母！");
            return   false}     
            }   
    
  switch(StrNo.length){   
  case   15:     
                  if   (isValidDate("19"+StrNo.substr(6,2),StrNo.substr(8,2),StrNo.substr(10,2)))   
                          {return   true;}   
                  else   
                          {return   false;}   
  case   18:     
                  if   (isValidDate(StrNo.substr(6,4),StrNo.substr(10,2),StrNo.substr(12,2)))   
                          {return   true;}   
                  else   
                          {return   false;}   
  }   
  //alert("输入的身份证号码必须为15位或者18位！");   
  return   false   
  }   
    
  function   isValidDate(iY,   iM,   iD)   {     
          var   a=new   Date(iY,iM-1,iD);   
          var   y=a.getFullYear();   
          var   m=a.getMonth()+1;   
          var   d=a.getDate();   
          if   (y!=iY   ||   m!=iM   ||   d!=iD)   
          {   
                  //window.alert   ('身份证号码内日期错误！');   
                  return   false;   
          }   
  return   true   
  }   
    
  function   isInteger(str)   {   
  if   (/[^\d]+$/.test(str)){   
  return   false;   
  }   
  return   true;   
  }