function checkNameCharacter(strname){
 /* var checkStr = strname.replace(/\//g,"");
  var n = 0;
  var m = 0;
  for(i=0; i<checkStr.length; i++) {
    chcode = checkStr.charCodeAt(i);
    if (chcode >=0  && chcode <= 255) {
      n++;
    } else {
      m++;
    }
  }
  if(n==0||m==0){
    return true;
  }else
    return false;
  */
  return true;  
}
//全英文必须有分割/ 中英文不需要分割/
function ck_name(namecheck) {
	var isValid = false;
	var r1 = new RegExp("^[A-Za-z](.+)$");
	if(r1.test(namecheck)){
		var r2 = new RegExp("^[A-Za-z][A-Za-z\\s]+/[A-Za-z\\s]{2,}$");
		if(r2.test(namecheck)){
			isValid = true;		
		}
	}else{	
		if(namecheck.indexOf("/") ==-1 ) isValid = true;
	}
	return isValid;
}

function ck_name1(namecheck) {
//alert(namecheck);u4E00-\u9FA5
//u2121H-\u777EH
  if(/[^\u4E00-\u9FA5]/gi.test(namecheck)){
              //alert(namecheck.indexOf("/"));
      if (namecheck.indexOf("/")>1){
          var substr = namecheck.substring(namecheck.indexOf("/")+1,namecheck.length);
          if(substr.length>=1){
            return true
          }else
            return false;
      	}else{
      	  return false
      	}
	  return false;
  }else{
  return true;
//    if(/[^\u2121H-\u777EH]/gi.test(namecheck)){
//    return true;
//    }else{
//      alert("中文名字中含有生僻字,请致电客服!");
//      return false;
//    }
  }
}
// 计算出生日期离今天相差几年
function datediffyearTest(str){
  var strnowtime = DateToString(new Date());
  //alert(strnowtime);
  //alert(str);
  var time = StrToDate(strnowtime);
  var dateobj = new Date(str.replace(/-/g, "\/"));
  var revalue = Math.abs(time - dateobj) / 1000 / 60 / 60 / 24 / 365;
  //salert(Math.ceil(revalue));
  return Math.ceil(revalue);
}
// 计算出生日期离今天相差几年
function datediffyear(str){
  var time  = new Date();
  var tmpy1 = time.getFullYear();
  var tmpm1 = time.getMonth() + 1;
  var tmpd1 = time.getDate();

  var dateobj1 = StrToDate(str);
  var dateobj  = new Date(dateobj1);
  var tmpy = dateobj.getFullYear();
  var tmpm = dateobj.getMonth() + 1;
  var tmpd = dateobj.getDate();
  var num = Math.abs(tmpy1 - tmpy);
  if(tmpm1>tmpm){
  	 num++;
  }
  if(tmpm1==tmpm){
    if(tmpd1>tmpd){
      num++;
    }
    if(tmpd1<tmpd){
      num--;
    }
  }
  if(tmpm1 < tmpm){
    num--;
  }
  //alert("Num:"+num);
  return num;
}
//dep格式为200509081710
function datediffyearNew(str,dep){
  var strnowtime = dep.substring(0,4)+"-"+dep.substring(4,6)+"-"+dep.substring(6,8);
  //alert(strnowtime);
  //alert(str);
  var time1 = StrToDate(strnowtime);
  var time  = new Date(time1);
  var tmpy1 = time.getFullYear();
  var tmpm1 = time.getMonth() + 1;
  var tmpd1 = time.getDate();

  var dateobj1 = StrToDate(str);
  var dateobj  = new Date(dateobj1);
  var tmpy = dateobj.getFullYear();
  var tmpm = dateobj.getMonth() + 1;
  var tmpd = dateobj.getDate();
  if(tmpy1 < tmpy)
  return -1;
  var num = Math.abs(tmpy1 - tmpy);
  if(num == 12 || num == 2){
	  if(tmpm1>tmpm){
	  	 num++;
	  }
	  if(tmpm1==tmpm){
	    if(tmpd1>tmpd){
	      num++;
	    }
	    if(tmpd1<tmpd){
	      num--;
	    }
	  }
	  if(tmpm1 < tmpm){
	    num--;
	  }
  }  
  return num;
}
// 通过生日检测是否是婴儿
function checkbirthdayisBabyNew(birthday,dep){
  if (datediffyearNew(birthday,dep) < 3){
    return true;
  }else{
    return false;
  }
}
// 通过生日检测是否是儿童
function checkbirthdayisChildrenNew(birthday,dep){
  if ((datediffyearNew(birthday,dep) <= 12)&&(datediffyearNew(birthday,dep) >= 2)){
    return true;
  }else{
    return false;
  }
}
// 通过生日检测是否是婴儿
function checkbirthdayisBaby(birthday){
  if (datediffyear(birthday) < 3){
    return true;
  }else{
    return false;
  }
}
// 通过生日检测是否是儿童
function checkbirthdayisChildren(birthday){
  //alert(datediffyear(birthday));
  if(datediffyear(birthday) <= 12 && datediffyear(birthday) >= 2 ){
    return true;
  }else{
    return false;
  }
}
//判断输入的日期是不是在当前日期之前
function isAfterToday(str){
    var time = DateToString(new Date());
    if(str >= time){
      return true;
    }else{
      return false;
    }
}
//判断是否相差3个小时
//dep格式为20050908171000,serverdate为200609081710
function checkDateBeforeThreeHours(dep,serdate){
  var time  = new Date(dep.substring(0,4),dep.substring(4,6)-1,dep.substring(6,8),dep.substring(8,10),dep.substring(10,12),dep.substring(12,14));
  var serv = new Date(serdate.substring(0,4),serdate.substring(4,6)-1,serdate.substring(6,8),serdate.substring(8,10),serdate.substring(10,12),serdate.substring(12,14));
  var nimitime = time.getTime();
  var servtime = serv.getTime();
  var revalue = (nimitime - servtime)/( 1000 * 60 * 60);
  num = Math.ceil(revalue);
//  alert("Num:"+num);
  return num;
}
//返回前一天的日期
function getDayBefore(str){
  var date = StrToDate(str);
  var yest = new Date(date - 1000*60*60*24);//减去1天
  var strdate = DateToString(yest);
  return strdate;
}
//返回后一天的日期
function getDayAfter(str){
  var date = StrToDate(str);
  var tom = new Date(date + 1000*60*60*24);//加上1天
  var strdate = DateToString(tom);
  return strdate;
}
function isIdCardNo(num)
{
  //alert(num);
  //if (isNaN(num)) {alert("输入的不是数字"); return false;}
  var len = num.length, re;
  if (len == 15){
    if (isNaN(num)) {
      alert("15的身份证号码必须全部是数字！");
      return false;
    }else
      re = new RegExp(/^(\d{6})()?(\d{2})(\d{2})(\d{2})(\d{3})$/);
  }else
  if (len == 18){
    var senth = num.substring(0,17);
    var last = num.substring(17,18);
    //alert(senth+'|'+last);
    if (isNaN(senth)) {alert("18的身份证号码前17位必须全部是数字！"); return false;}
    //alert(isNaN(last) +"|"+(last!="X"));
    if (isNaN(last)&&(last!="X")&&(last!="x")) {
      alert("18的身份证号码最后一位必须为数字或者'X'");
      return false;
    }else
      re = new RegExp(/^(\d{6})()?(\d{4})(\d{2})(\d{2})(\d{4})$/);
  } else {
      alert("身份证号码位数不对！");
      return false;
  }
  var a = num.match(re);
  if (a != null)
  {
    if (len==15)
    {
      var D = new Date("19"+a[3]+"/"+a[4]+"/"+a[5]);
      var B = D.getYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];
    }else{
      var D = new Date(a[3]+"/"+a[4]+"/"+a[5]);
      var B = D.getFullYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];
    }
    if (!B) {
        alert("输入的身份证号 "+ a[0] +" 里出生日期不对！");
        return false;
    }
  }
  return true;
}

//判断两个日期之间的天数(beforeDay '2006-03-05',affterDay '2006-03-09')
function getDaysBetweenTwoDay(beforeDay,affterDay){
//alert(beforeDay+'|'+affterDay);
   var be =  StrToDate(beforeDay);
   var af =  StrToDate(affterDay);
   //alert(be+"|"+af);
   var revalue = (af - be)/( 1000 * 60 * 60 * 24);
   return revalue;
}

//根据正确的身份证号获得生日
function getBirthdayByCardNo(val){
	var birthdayValue = "";
	if(15==val.length){
		//15位身份证号码
		birthdayValue = val.charAt(6)+val.charAt(7);
		if(parseInt(birthdayValue)<10){
			birthdayValue = '20'+birthdayValue;
		}else{
			birthdayValue = '19'+birthdayValue;
		}
		birthdayValue=birthdayValue+'-'+val.charAt(8)+val.charAt(9)+'-'+val.charAt(10)+val.charAt(11);
	}
	if(18==val.length){ 
		//18位身份证号码
		birthdayValue=val.charAt(6)+val.charAt(7)+val.charAt(8)+val.charAt(9)+'-'+val.charAt(10)+val.charAt(11)   +'-'+val.charAt(12)+val.charAt(13);
	}
	return birthdayValue;
}
