﻿onload = function () {
  ro();
}

function ro() {
  var d = document;
  if(d.images){
    if(!d.MM_p) d.MM_p=new Array();
    var anchorFields = d.getElementsByTagName('A');
    for ( var i =0; i <anchorFields.length ; i++  ) {
      var anchor = anchorFields[i];
      if ( !anchor.firstChild ) continue;
      if ( !anchor.firstChild.src ) continue;
      if ( new String(anchor.firstChild.src).match(/-out-/) ) {
        var src_on  = new String(anchor.firstChild.src).replace(/-out-/,'-on-') ;
        anchor.onmouseover = function () {this.firstChild.src = this.firstChild.src.replace(/-out-/,'-on-')};
        anchor.onmouseout  = function () {this.firstChild.src = this.firstChild.src.replace(/-on-/,'-out-')};
        d.MM_p[i] = new Image;
        d.MM_p[i].src = src_on;
      }
    }
  }
}

/* news
---------------------------------------------------------------------------*/
function checkInput_news()
{		
	if(InetChk_IsNull("n_title","标题不允许为空！")){
		return false;
	}
	if(InetChk_IsNull("n_info","内容不允许为空！")){
		return false;
	}
	return true;
}

function checkForm_news()
{
	if(checkInput_news()){
		  document.news_new.action="action.php?item=news";
		  document.news_new.submit();
	}
}


/* event
---------------------------------------------------------------------------*/
function checkInput_event()
{		
	if(InetChk_IsNull("e_title","标题不允许为空！")){
		return false;
	}
	if(InetChk_IsNull("e_info","内容不允许为空！")){
		return false;
	}
	return true;
}

function checkForm_event()
{
	if(checkInput_event()){
		  document.event_new.action="action.php?item=event";
		  document.event_new.submit();
	}
}


/* companion
---------------------------------------------------------------------------*/
function checkInput_com()
{		
	if(InetChk_IsNull("c_name","姓名不允许为空！")){
		return false;
	}	
	if(InetChk_IsNull("c_height","身高不允许为空！")){
		return false;
	}	
	if(InetChk_IsNull("c_bust","三围不允许为空！")){
		return false;
	}	
	if(InetChk_IsNull("c_waist","三围不允许为空！")){
		return false;
	}
	if(InetChk_IsNull("c_hips","三围不允许为空！")){
		return false;
	}
	return true;
}

function checkForm_com()
{
	if(checkInput_com()){
		  document.com_new.action="action.php?item=com";
		  document.com_new.submit();
	}
}


/* companion
---------------------------------------------------------------------------*/
function checkInput_compic()
{		
	if(InetChk_IsNull("cp_path","姓名不允许为空！")){
		return false;
	}
	return true;
}

function checkForm_compic()
{
	if(checkInput_compic()){
		  document.com_pic_new.action="action.php?item=com_pic";
		  document.com_pic_new.submit();
	}
}


/* system
---------------------------------------------------------------------------*/
/* schedule
---------------------------------------------------------------------------*/
function checkInput_sche()
{		
	if(InetChk_IsNull("s_name","姓名不允许为空！")){
		return false;
	}
	return true;
}

function checkForm_sche()
{
	if(checkInput_sche()){
		  document.sche_new.action="action.php?item=sche";
		  document.sche_new.submit();
	}
}


/* picture
---------------------------------------------------------------------------*/
function checkInput_pic()
{		
	if(InetChk_IsNull("p_path","图片路径不允许为空！")){
		return false;
	}
	return true;
}

function checkForm_pic()
{
	if(checkInput_pic()){
		  document.pic_new.action="action.php?item=pic";
		  document.pic_new.submit();
	}
}


/* link
---------------------------------------------------------------------------*/
function checkInput_link()
{				
	if(InetChk_IsNull("l_title","标题不允许为空！")){
		return false;
	}
	if(InetChk_IsNull("l_path","图片路径不允许为空！")){
		return false;
	}
	return true;
}

function checkForm_link()
{
	if(checkInput_link()){
		  document.link_new.action="action.php?item=link";
		  document.link_new.submit();
	}
}


/* QA
---------------------------------------------------------------------------*/
function checkInput_qa()
{		
	if(InetChk_IsNull("q_question","标题不允许为空！")){
		return false;
	}
	if(InetChk_IsNull("q_answer","内容不允许为空！")){
		return false;
	}
	return true;
}

function checkForm_qa()
{
	if(checkInput_qa()){
		  document.qa_new.action="action.php?item=qa";
		  document.qa_new.submit();
	}
}




/* user
---------------------------------------------------------------------------*/
function checkInput_user()
{		
	if(InetChk_IsNull("u_name","登录名不允许为空！")){
		return false;
	}
	if(InetChk_IsNull("pwd","密码不允许为空！")){
		return false;
	}	
	if(InetChk_IsNull("re_pwd","确认密码不允许为空！")){
		return false;
	}
	if(document.user_new.pwd.value != document.user_new.re_pwd.value){
		alert("两次输入的密码不相同！");
		document.user_new.pwd.value="";
		document.user_new.re_pwd.value="";
		document.user_new.pwd.focus();
		return false;
	}
	return true;
}

function checkForm_user()
{
	if(checkInput_user()){
		  document.user_new.action="action.php?item=user";
		  document.user_new.submit();
	}
}


/* password
---------------------------------------------------------------------------*/
function checkInput_pwd()
{	
	if(InetChk_IsNull("pwd","密码不允许为空！")){
		return false;
	}	
	if(InetChk_IsNull("re_pwd","确认密码不允许为空！")){
		return false;
	}
	if(document.pwd_new.pwd.value != document.pwd_new.re_pwd.value){
		alert("两次输入的密码不相同！");
		document.pwd_new.pwd.value="";
		document.pwd_new.re_pwd.value="";
		document.pwd_new.pwd.focus();
		return false;
	}
	return true;
}

function checkForm_pwd()
{
	if(checkInput_pwd()){
		  document.pwd_new.action="action.php?item=person";
		  document.pwd_new.submit();
	}
}


/* information
---------------------------------------------------------------------------*/
function checkInput_info()
{	
	if(InetChk_IsNull("i_name","姓名不允许为空！")){
		return false;
	}	
	if(InetChk_IsNull("i_email","E-mail不允许为空！")){
		return false;
	}	
	if(InetChk_IsNull("ii_email","确认E-mail不允许为空！")){
		return false;
	}
	if(!strIsNull(document.info_new.i_email.value)){
		if(mailaddrChk("i_email")){
			return false;
		}
	}
	if(!strIsNull(document.info_new.ii_email.value)){
		if(mailaddrChk("ii_email")){
			return false;
		}
	}
	if(document.info_new.i_email.value != document.info_new.ii_email.value){
		alert("两次输入的E-mail不相同！");
		document.info_new.i_email.value="";
		document.info_new.ii_email.value="";
		document.info_new.ii_email.focus();
		return false;
	}	
	if(InetChk_IsNull("i_info","内容不允许为空！")){
		return false;
	}
	if(InetChk_IsNull("checkNum","验证码不允许为空！")){
		return false;
	}
	if(document.info_new.code.value != document.info_new.checkNum.value.toUpperCase()){
		alert("验证码错误！");
		document.info_new.checkNum.value="";
		document.info_new.checkNum.focus();
		return false;
	}
	return true;
}

function checkForm_info()
{
	if(checkInput_info()){
		 // document.info_new.action="action.php?item=info";
		  document.info_new.submit();
	}
}


/* kaiin
---------------------------------------------------------------------------*/
function checkInput_kaiin()
{	
	if(InetChk_IsNull("k_name","お名前不允许为空！")){
		return false;
	}	
	if(InetChk_IsNull("k_phone","電話不允许为空！")){
		return false;
	}
	if(InetChk_IsNull("k_email","メール不允许为空！")){
		return false;
	}
	if(InetChk_IsNull("checkNum","验证码不允许为空！")){
		return false;
	}
	if(document.kaiin.code.value != document.kaiin.checkNum.value.toUpperCase()){
		alert("验证码错误！");
		document.kaiin.checkNum.value="";
		document.kaiin.checkNum.focus();
		return false;
	}
	if(!strIsNull(document.kaiin.k_email.value)){
		if(mailaddrChk("k_email")){
			return false;
		}
	}
	return true;
}

function checkForm_kaiin()
{
	if(checkInput_kaiin()){
		  document.kaiin.action="index.php?item=kaiin&mo=val";
		  document.kaiin.submit();
	}
}




/* 清空按钮
----------------------------------------------------------------------------*/
function resetBtn(fm){
	fm.reset();
    return false;
}



/*  校验类
--------------------------------------------------------------------------------------*/

//空校验（判断字符串是否为空，包括全是空格的情况）
//返回值：
//		空返回true，非空返回false
function strIsNull(str1) {
    var strTemp1,strTemp2
    strTemp1 = new String(str1);
    if((strTemp1=="")||(strTemp1==null)) {
        return true;
    }
    strTemp2 = new String();
    for(t=0;t<strTemp1.length;t++) {
        strTemp2=strTemp2 + " ";
    }
    if(strTemp1==strTemp2) {
		return true;
	}
    else {
		return false;
	}
}

//空校验（包括全是空格的情况）
//参数说明：
//		ctlID：输入域的ID，不要使用Name
//		strMsg：错误提示的内容，格式为“xxx不允许为空！”
//返回值：
//		通过检查返回true，否则返回false
function InetChk_IsNull(ctlID,strMsg)
{
	if (strIsNull(document.getElementById(ctlID).value))
	{
		document.getElementById(ctlID).focus();
		alert(strMsg);
		return true;
	}
	else
	{
		return false;
	}
}

//函数返回字符串的长度
function StrLength(str1) {
    strTALen = new String(str1);
    return(strTALen.length);
}

//最大长度校验（忽略汉字和普通字符的区别）
//参数说明：
//		ctlID：输入域的ID，不要使用Name
//		strMsg：错误提示的内容，格式为“xxx允许的最大长度为N个字符！”
//		intMaxLen：输入域允许的最大字符串长度
//返回值：
//		通过检查返回true，否则返回false
function InetChk_StrMaxLen(ctlID,strMsg,intMaxLen)
{
	if (StrLength(document.getElementById(ctlID).value) > intMaxLen)
	{
		document.getElementById(ctlID).focus();
		alert(strMsg);
		return true;
	}
	else
	{
		return false;
	}
}

//最小长度校验（忽略汉字和普通字符的区别）
//参数说明：
//		ctlID：输入域的ID，不要使用Name
//		strMsg：错误提示的内容，格式为“xxx允许的最小长度为N个字符！”
//		intMaxLen：输入域允许的最大字符串长度
//返回值：
//		通过检查返回true，否则返回false
function InetChk_StrMinLen(ctlID,strMsg,intMinLen)
{
	if (StrLength(document.getElementById(ctlID).value) < intMinLen)
	{
		document.getElementById(ctlID).focus();
		alert(strMsg);
		return true;
	}
	else
	{
		return false;
	}
}

//下面函数用于判断日期型函数，输入格式YYYY-MM-DD
function NKChkChar(strVariable) {
    k = 0;
    k1 = 0;
    s1 = "";
    var s = new Array(0,0,0);
    length1 = strVariable.length;
    for(i=0;i<length1;i++) {
        a = strVariable.charAt(i);
        if(a=="-") {
            n = i+1;
            k = n;
            break;
        }
    }
    for(i=0;i<length1;i++) {
        a = strVariable.charAt(i);
        if(a=="-") {
            j = i+1;
            k1 = j;
            s1 = s1+a;
        }
    }
    s[2] = s1.length;
    s[0] = k;
    s[1] = k1;
    return s;
}

function DateString(DateString) {
    var str = new Array(0,0,0);
    var k;
    leng = DateString.length;
    str = NKChkChar(DateString);

    m = str[0];
    n = str[1];
    len = str[2];

    yy = DateString.substring(0,m-1);
    mm = DateString.substring(m,n-1);
    dd = DateString.substring(n,10);

    l1 = yy.length;
    l2 = mm.length;
    l3 = dd.length;

    y = parseInt(yy);
    m = parseInt(mm);
    d = parseInt(dd);

    r = yy-y;
    s = mm-m;
    t = dd-d;

    //输入长度越界时;
    if(leng>10)  k = "输入日期长度越界！";
    //输入串输入多个"-"时;
    //else if((DateString!="")&&(len!=2))    k = "";
	//update by zy ，因为老的民政bs用到这个函数，当格式不对时，无提示
    else if((DateString!="")&&(len!=2))    k = "日期格式不正确";
    //输入年月日的位数越界时;
    else if((DateString!="")&&(l1!=4||l2<0||l2>2||l3<0||l3>2))  k = "请检查年-月-日的位数！";
    //年月日为非数据时;
    else if((DateString!="")&&(isNaN(yy)||isNaN(mm)||isNaN(dd)))  k = "请输入整形数据！";
    //判断年月日范围
    else if((DateString!="")&&(yy<=0))    k = "年的计数应大于0！";
    else if((DateString!="")&&(mm<1||mm>12))      k = "月的范围为[1,12]！";
    else if((DateString!="")&&(dd<1||dd>31))      k = "日的范围为[1,31]！";
    else if((DateString!="")&&(mm=="04"||mm=="06"||mm=="09"||mm=="11"||mm=="4"||mm=="6"||mm=="9"||mm=="11")&&(dd>30||dd<1))  k = "日的范围为[0,30]！";
    else if((DateString!="")&&(mm=="01"||mm=="03"||mm=="05"||mm=="07"||mm=="08"||mm=="10"||mm=="12"||mm=="1"||mm=="3"||mm=="5"||mm=="7"||mm=="8")&&(dd>31||dd<1))  k = "日的范围为[0,31]！";
    else if((DateString!="")&&(mm=="02"&&parseInt(dd)>28&&(isLeapYear(yy)==0)||mm=="2")&&parseInt(dd)>28&&(isLeapYear(yy)==0))    k = "日的范围为[0,28]！";
    else if((DateString!="")&&(mm=="02"&&parseInt(dd)>29&&(isLeapYear(yy)==1)||mm=="2")&&parseInt(dd)>29&&(isLeapYear(yy)==1))    k = "日的范围为[0,29]！";
    else k = 1;
    return k;
}

//日期格式校验（yyyy-MM-dd）
//额外说明：月份、日期输入两位或者一位都可以
//参数说明：
//		ctlID：输入域的ID，不要使用Name
//		strMsg：错误提示的内容，格式为“xxxx输入的日期格式不正确！＋不正确的原因＋\n\n正确的日期格式为：【yyyy-MM-dd】”
//返回值：
//		通过检查返回true，否则返回false
function InetChk_DateFormat(ctlID,strMsg)
{
	var strErr = DateString(document.getElementById(ctlID).value);
	if (strErr != 1)
	{
		document.getElementById(ctlID).focus();
		alert(strMsg + strErr + "\n\n正确的日期格式为：【yyyy-MM-dd】");
		return true;
	}
	else
	{
		//document.getElementById(ctlID).value=formatDate(document.getElementById(ctlID).value);
		return false;
	}
}

//日期范围校验，用于检查输入的日期在指定的范围内
//额外说明：被校验的日期首先需要通过日期格式校验
//参数说明：
//		ctlID：输入域的ID，不要使用Name
//		strMsg：输入域的字段名称
//		dtFrom：起始的日期范围
//		dtEnd：截至的日期范围
//返回值：
//		通过检查返回true，否则返回false
function InetChk_DateScope(ctlID,strMsg,dtFrom,dtEnd)
{
	var dtInput = document.getElementById(ctlID).value;
	if (Date1VsDate2(dtEnd,dtInput) == 1 || Date1VsDate2(dtInput,dtFrom) == 1)
	{
		alert(strMsg + "输入的日期超出了限定的范围！\n\n日期范围应该在" + formatDate(dtFrom) + "至" + formatDate(dtEnd) + "之间。");
		document.getElementById(ctlID).focus();
		return true;
	}
	else
	{
		return false;
	}
}

//整数数值和范围校验，用于检查输入的字符串是一个整数，并且在指定的范围内
//参数说明：
//		ctlID：输入域的ID，不要使用Name
//		strMsg：输入域的字段名称
//		intFrom：起始的整数范围
//		intEnd：截至的整数范围
//返回值：
//		通过检查返回true，否则返回false
function InetChk_Int(ctlID,strMsg,intFrom,intEnd)
{
	var strErr = "";
	var strInput = document.getElementById(ctlID).value;
	//judgeIntLen函数第二个参数用于判断整数的长度，不能正常进行范围界定，因此先判断是否为整数即可。
	//目前相关项目中的数值范围使用9位整数即可（含负号是8位）
	var isInt = judgeIntLen(strInput,9);
	if (isInt != 1)
	{
		strErr = isInt;
	}
	else
	{
		if (parseInt(strInput) < intFrom || parseInt(strInput) > intEnd)
		{
			strErr = strErr + "输入的整数超出了限定的范围！\n\n整数范围应该在" + intFrom + "至" + intEnd + "之间。"
		}
	}

	if (strErr != "")
	{
		alert(strMsg + strErr);
		document.getElementById(ctlID).focus();
		return true;
	}
	else
	{
		return false;
	}
}

//校验身份证号码：数字（0-9）和X，位数为15或18位.
//正确返回 true ， 错误返回 false
function CheckCardId(CarId){
   var carId = CarId;
   if((StrLength(carId)!=0) && (StrLength(carId)!=15 && StrLength(carId)!=18)){
               alert("身份证号码应为15位或18位！");
               return false;
    }
   for(var i=0;i<carId.length;i++) {
        var ch = carId.substring(i,i+1);
        if(((ch>="0")&&(ch<="9"))||(ch=="x")||(ch=="X")) {
        }else{
            alert("身份证号码中只能包含数字（0-9）或'x','X'！");
            return false;
        }
    }
    return true;

}

//校验身份证号码：数字（0-9）和X，位数为15或18位.
//正确返回 出生日期 ， 错误返回 false ；
function CheckCardId_DB(CarId){
   var carId = CarId;
   if((StrLenght(carId)!=0) && (StrLenght(carId)!=15 && StrLenght(carId)!=18)){
               alert("身份证号应为15位或18位！");
               return false;
    }
   for(var i=0;i<carId.length;i++) {
        var ch = carId.substring(i,i+1);
        if(((ch>="0")&&(ch<="9"))||(ch=="x")||(ch=="X")) {
        }else{
            alert("身份证号中只能包含数字（0-9）或'x','X'！");
            return false;
        }
    }
    var strcsrq = "";
    if(StrLenght(carId)==15){
    	strcsrq = "19"+carId.substring(6,12);
    }else if(StrLenght(carId)==18){
    	strcsrq = carId.substring(6,14);
    }
    var csrq = "";
    csrq = strcsrq.substring(0,4)+"-"+strcsrq.substring(4,6)+"-"+strcsrq.substr(6);
    var k = "";
    k=DateString(csrq);
    if(k!=1){
    	alert("证件号码不能为空！");
	return false;
    }
    //alert(csrq);
    return csrq;
}

//身份证校验
//额外说明：只校验15位或18位、使用数字和“x”或“X”
//参数说明：
//		ctlID：输入域的ID，不要使用Name
//返回值：
//		通过检查返回true，否则返回false
function InetChk_CardID(ctlID)
{
	var strErr = CheckCardId(document.getElementById(ctlID).value);
	if (strErr == false)
	{
		document.getElementById(ctlID).focus();
		return true;
	}
	else
	{
		return false;
	}
}

//包含校验
//参数说明：
//		ctlID：输入域的ID，不要使用Name
//		strMsg：错误提示内容
//		strRule：包含的字符，检查输入字符必须在strRule中
//返回值：
//		通过检查返回true，否则返回false
function InetChk_StrInRule(ctlID,strMsg,strRule)
{
	var strErr = CheckInputIn(strRule,document.getElementById(ctlID).value);
	if (!strErr)
	{
		document.getElementById(ctlID).focus();
		alert(strMsg + "\n\n输入内容必须包含以下字符：\n" + strRule);
		return true;
	}
	else
	{
		return false;
	}
}

//非包含校验
//参数说明：
//		ctlID：输入域的ID，不要使用Name
//		strMsg：错误提示内容
//		strRule：非包含的字符，检查输入字符不能使用strRule中的字符
//返回值：
//		通过检查返回true，否则返回false
function InetChk_StrNotInRule(ctlID,strMsg,strRule)
{
	var strErr = CheckInputOut(strRule,document.getElementById(ctlID).value);
	if (!strErr)
	{
		document.getElementById(ctlID).focus();
		alert(strMsg + "\n\n输入内容不能使用以下字符：\n" + strRule);
		return true;
	}
	else
	{
		return false;
	}
}

//中文汉字的判断，如果字符串包含汉字返回1，否则返回0
function checkChinese(str) {
    var strTemp = str;
    var retValue = 0;
    for(i=0;i<strTemp.length;i++) {
        if(strTemp.charAt(i)>'　') {
            retValue = 1;
            break;
        }
    }
    return retValue;
}

//检查email地址的格式是否正确
//格式正确返回false
function mailaddrChk(ctlID) {
    if(document.getElementById(ctlID).value.indexOf("@")<=0) {
        alert("请输入正确的Email地址！");
		document.getElementById(ctlID).focus();
        return true;
    } else if(document.getElementById(ctlID).value.lastIndexOf("@")==(document.getElementById(ctlID).value.length-1)) {
        alert("请输入正确的Email地址！");
		document.getElementById(ctlID).focus();
        return true;
    } else if(document.getElementById(ctlID).value.indexOf(".")<=0) {
        alert("请输入正确的Email地址！");
		document.getElementById(ctlID).focus();
        return true;
    } else if(document.getElementById(ctlID).value.lastIndexOf(".")==(document.getElementById(ctlID).value.length-1)) {
        alert("请输入正确的Email地址！");
		document.getElementById(ctlID).focus();
        return true;
    } else if(checkChinese(document.getElementById(ctlID).value)==1) {
        alert("email地址不能包含中文！");
		document.getElementById(ctlID).focus();
        return true;
    } else {
		return false;
    }
}

//电话号码的输入正确性判断
function judgeTel(ctlID) {
    if(document.getElementById(ctlID).indexOf('-')==0) {
        return false;
    } else if(document.getElementById(ctlID).lastIndexOf('-')==document.getElementById(ctlID).length-1) {
        return false;
    }
    for(var i=0;i<document.getElementById(ctlID).length;i++) {
        var ch = document.getElementById(ctlID).substring(i,i+1);
        if((ch>="0"&&ch<="9")||ch=="-"||ch==" "||ch=="("||ch==")") {
        } else {
            return false;
        }
    }
    return true;
}