﻿// 检测添加机构窗体

//检测用户名是否存在，格式是否正确
function checkLoingUser(form)
{   
    if((form.txtUserName.value.length == 0)||(form.txtUserName.value.length>20))
    {        
        alert("登录名不能为空并且不超过２０字符!");        
    }
    else
    {     
        var oServerXmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
        oServerXmlHttp.open("post","../Share/checkLoginUserName.ashx?UserName="+form.txtUserName.value,"false");
        oServerXmlHttp.send();
        var strErr = oServerXmlHttp.responseText;          
        switch (strErr)
        {
            case "01":
                alert("含有非法字符!");
            case "02":
                alert("用户名只能用字母、数字、下划线!");
                break;
            case "03":
                alert("已存在该用户名，请用其它用户");
                break;
            case "04":
                alert("恭喜您:\"" + form.txtUserName.value + "\" 已检测通过!");
                break;
            case "05":
                alert("数据库错误，请稍后访问!");
                break;
            default:
                alert("strErr")
        }      
    }
}
//重新验证是否是信息系统教师
function CheckIsTeacherMis(studentId)
{
    var oServerXmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
    oServerXmlHttp.open("post","ReStudentIsTeacherMis.ashx?StudentId="+studentId,"false");
    oServerXmlHttp.send();
    var strErr = oServerXmlHttp.responseText;  
    window.LabTS.innerHTML=strErr;
    alert(strErr);
    return false;
}
//检测窗体里的数据是否添加正确
function CheckAddStForm(form)
{
    //返回变量
    var bRturn =  false;
    var strMessage="";
    
    //登录名
    if((form.txtUserName.value.length == 0)||(form.txtUserName.value.length>20))
    {
        bRturn = true;
        strMessage += "\r登录名不能为空并且不超过２０字符!"; 
        form.txtUserName.style.backgroundColor="#ffffcc";
    }
    else
    {  
        form.txtUserName.style.backgroundColor="#ccccff";     
    }
    
    //密码
    if((form.txtUserPwd.value.length == 0)||(form.txtUserPwd.value.length>20))
    {
        bRturn = true;
        strMessage += "\r密码不能为空并且不超过16字符!"; 
        form.txtUserPwd.style.backgroundColor="#ffffcc";
    }
    else
    {  
        form.txtUserPwd.style.backgroundColor="#ccccff";     
    }
    //班级号
    var classNoReg = /^\d{13}$/;
    
    if((form.txtClassNo.value.length != 13)||(!classNoReg.test(form.txtClassNo.value)))
    {
        bRturn = true;        
        strMessage += "\r班级号不正确!只能是数字";
        form.txtClassNo.style.backgroundColor = "#ffffcc";
    }
    else
    {
        var convet="strFclassNo="+form.txtClassNo.value;
        var oServerXmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
        oServerXmlHttp.open("post","../webservices/WebService.asmx/CheckClassIsTrue","false");
        oServerXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        oServerXmlHttp.send(convet);
        var xmlDOC = new ActiveXObject("MSXML2.DOMDocument")  
        xmlDOC=oServerXmlHttp.ResponseXML;
        var result = xmlDOC.selectSingleNode("//string").text;
        if(result != "True")
        {
            bRturn = true;        
            strMessage += "\r班级号不存在!";
            form.txtClassNo.style.backgroundColor = "#ffffcc";
        }
        else
        {
            form.txtClassNo.style.backgroundColor = "#ccccff";
        }
    }
    //姓名
    if(form.txtName.value.length==0)
    {
        bRturn = true;
        strMessage += "\r姓名不能为空"
        form.txtName.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.txtName.style.backgroundColor = "#ccccff";
    }
    //生日
    if(!checkDate(form.txtBrithday.value))
    {
        bRturn = true;
        strMessage += "\r生日格式错误!"
        form.txtBrithday.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.txtBrithday.style.backgroundColor = "#ffffff";
    }
    //邮编
 
    
    //所属单位
    if((form.txtCompany.value.length == 0)||(form.txtCompany.value.length > 30))
    {
        bRturn = true;
        strMessage += "\r所属单位名为空或太长!"
        form.txtCompany.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.txtCompany.style.backgroundColor = "#ccccff";
     }
    
    //联系电话
    if(form.txtIdCard.value.length != 15&&form.txtIdCard.value.length!=18)
    {
        bRturn = true;
        strMessage += "\r身份证为15位或者18位!"
        form.txtIdCard.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.txtIdCard.style.backgroundColor = "#ffffff";
     }
    //手机
 
  if(form.drpTitle.value.length==0)
    {
        bRturn = true;
        strMessage += "\r职称必须选择"
        form.drpTitle.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.drpTitle.style.backgroundColor = "#ccccff";
    }
    if(form.drpLeval.value.length==0)
    {
        bRturn = true;
        strMessage += "\r学科层次必须选择"
        form.drpLeval.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.drpLeval.style.backgroundColor = "#ccccff";
    }
    if(form.drpRjxk.value.length==0)
    {
        bRturn = true;
        strMessage += "\r任教学科必须选择"
        form.drpRjxk.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.drpRjxk.style.backgroundColor = "#ccccff";
    }
    if(form.drpStudy.value.length==0)
    {
        bRturn = true;
        strMessage += "\r学历必须选择"
        form.drpStudy.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.drpStudy.style.backgroundColor = "#ccccff";
    }
    if(bRturn)
    {
        alert(strMessage);
        return false;
    }
    else
    {
        return true;
    }   
    
}

//检测窗体里的数据是否添加正确
function CheckAddThForm(form)
{
    //返回变量
    var bRturn =  false;
    var strMessage="";
    
    //登录名
    if((form.txtUserName.value.length == 0)||(form.txtUserName.value.length>20))
    {
        bRturn = true;
        strMessage += "\r登录名不能为空并且不超过２０字符!"; 
        form.txtUserName.style.backgroundColor="#ffffcc";
    }
    else
    {  
        form.txtUserName.style.backgroundColor="#ccccff";     
    }
    
    //密码
    if((form.txtUserPwd.value.length == 0)||(form.txtUserPwd.value.length>20))
    {
        bRturn = true;
        strMessage += "\r密码不能为空并且不超过16字符!"; 
        form.txtUserPwd.style.backgroundColor="#ffffcc";
    }
    else
    {  
        form.txtUserPwd.style.backgroundColor="#ccccff";     
    }
    //班级号
    //姓名
    if(form.txtName.value.length==0)
    {
        bRturn = true;
        strMessage += "\r姓名不能为空"
        form.txtName.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.txtName.style.backgroundColor = "#ccccff";
    }
      //所属机构
    if(form.TxtJgNo.value.length==0)
    {
        bRturn = true;
        strMessage += "\r请选择所属机构"
        form.txtJg.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.txtJg.style.backgroundColor = "#ccccff";
    }
    
    //所属单位
    if((form.txtCompany.value.length == 0)||(form.txtCompany.value.length > 30))
    {
        bRturn = true;
        strMessage += "\r所属单位名为空或太长!"
        form.txtCompany.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.txtCompany.style.backgroundColor = "#ccccff";
     }
    
    //联系电话
    if(form.txtIdCard.value.length != 15&&form.txtIdCard.value.length!=18)
    {
        bRturn = true;
        strMessage += "\r身份证为15位或者18位!"
        form.txtIdCard.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.txtIdCard.style.backgroundColor = "#ffffff";
     }
    //手机
    
    if(form.drpTitle.value.length==0)
    {
        bRturn = true;
        strMessage += "\r职称必须选择"
        form.drpTitle.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.drpTitle.style.backgroundColor = "#ccccff";
    }
    if(form.drpLeval.value.length==0)
    {
        bRturn = true;
        strMessage += "\r学科层次必须选择"
        form.drpLeval.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.drpLeval.style.backgroundColor = "#ccccff";
    }
    if(form.drpRjxk.value.length==0)
    {
        bRturn = true;
        strMessage += "\r任教学科必须选择"
        form.drpRjxk.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.drpRjxk.style.backgroundColor = "#ccccff";
    }
    if(form.drpStudy.value.length==0)
    {
        bRturn = true;
        strMessage += "\r学历必须选择"
        form.drpStudy.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.drpStudy.style.backgroundColor = "#ccccff";
    }
    if(bRturn)
    {
        alert(strMessage);
        return false;
    }
    else
    {
        return true;
    }   
    
}

//检测窗体里的数据是否添加正确
function CheckAddJgForm(form)
{
    //返回变量
    var bRturn =  false;
    var strMessage="";
    
    //登录名
    if((form.txtUserName.value.length == 0)||(form.txtUserName.value.length>20))
    {
        bRturn = true;
        strMessage += "\r登录名不能为空并且不超过２０字符!"; 
        form.txtUserName.style.backgroundColor="#ffffcc";
    }
    else
    {  
        form.txtUserName.style.backgroundColor="#ccccff";     
    }
    
    //密码
    if((form.txtUserPwd.value.length == 0)||(form.txtUserPwd.value.length>20))
    {
        bRturn = true;
        strMessage += "\r密码不能为空并且不超过16字符!"; 
        form.txtUserPwd.style.backgroundColor="#ffffcc";
    }
    else
    {  
        form.txtUserPwd.style.backgroundColor="#ccccff";     
    }
    //机构名称
    if((form.txtJgName.value.length == 0)||(form.txtJgName.value.lenght >50))
    {
        bRturn = true;
        strMessage += "\r机构名称不能为空并且不能超过50个字符!";
        form.txtJgName.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.txtJgName.style.backgroundColor = "#ccccff";
    }
    //所属机构
    if(form.TxtJgNo.value.length==0)
    {
        bRturn = true;
        strMessage += "\r请选择所属机构"
        form.txtJg.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.txtJg.style.backgroundColor = "#ccccff";
    }
    //地址
    if(form.txtJgAdd.value.length > 100)
    {
        bRturn = true;
        strMessage += "\r地址不能超过１００个字符!"
        form.txtJgAdd.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.txtJgAdd.style.backgroundColor = "#ffffff";
    }
    //邮编
    if(form.txtJgPostCode.value.length > 12)
    {
        bRturn = true;
        strMessage += "\r邮编不正确!"
        form.txtJgPostCode.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.txtJgPostCode.style.backgroundColor = "#ffffff";
    }
    
    //负责人
    if((form.txtJgUserName.value.length == 0)||(form.txtJgUserName.value.length > 30))
    {
        bRturn = true;
        strMessage += "\r负责人姓名为空或太长!"
        form.txtJgUserName.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.txtJgUserName.style.backgroundColor = "#ccccff";
     }
    
    //联系电话
    if(form.txtJgPhone.value.length > 15)
    {
        bRturn = true;
        strMessage += "\r电话号码太长!"
        form.txtJgPhone.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.txtJgPhone.style.backgroundColor = "#ffffff";
     }
    //手机
    if(form.txtJgMoveTel.value.length > 18)
    {
        bRturn = true;
        strMessage += "\r手机号码有错!"
        form.txtJgMoveTel.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.txtJgMoveTel.style.backgroundColor = "#ffffff";
     }
    //Email
    if(form.txtEmail.value.length >0)
    {
        if(!checkmail(form.txtEmail.value) || (form.txtEmail.value.lenght >30))
        {
            bRturn = true;
            strMessage += "\rEmail不正确!"
            form.txtEmail.style.backgroundColor = "#ffffcc";
        }
        else
        {
            form.txtEmail.style.backgroundColor = "#ffffff";
        }
    }
    else
    {
        form.txtEmail.style.backgroundColor = "#ffffff";
    }
    
    
    if(bRturn)
    {
        alert(strMessage);
        return false;
    }
    else
    {
        return true;
    }   
    
}
function CheckModJgForm(form)
{
    //返回变量
    var bRturn =  false;
    var strMessage="";
    
    //登录名
    if((form.txtUserName.value.length == 0)||(form.txtUserName.value.length>20))
    {
        bRturn = true;
        strMessage += "\r登录名不能为空并且不超过２０字符!"; 
        form.txtUserName.style.backgroundColor="#ffffcc";
    }
    else
    {  
        form.txtUserName.style.backgroundColor="#ccccff";     
    }
    
    //密码
    if((form.txtUserPwd.value.length == 0)||(form.txtUserPwd.value.length>20))
    {
        bRturn = true;
        strMessage += "\r密码不能为空并且不超过16字符!"; 
        form.txtUserPwd.style.backgroundColor="#ffffcc";
    }
    else
    {  
        form.txtUserPwd.style.backgroundColor="#ccccff";     
    }
    //机构名称
    if((form.txtJgName.value.length == 0)||(form.txtJgName.value.lenght >50))
    {
        bRturn = true;
        strMessage += "\r机构名称不能为空并且不能超过50个字符!";
        form.txtJgName.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.txtJgName.style.backgroundColor = "#ccccff";
    }
    //地址
    if(form.txtJgAdd.value.length > 100)
    {
        bRturn = true;
        strMessage += "\r地址不能超过１００个字符!"
        form.txtJgAdd.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.txtJgAdd.style.backgroundColor = "#ffffff";
    }
    //邮编
    if(form.txtJgPostCode.value.length > 12)
    {
        bRturn = true;
        strMessage += "\r邮编不正确!"
        form.txtJgPostCode.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.txtJgPostCode.style.backgroundColor = "#ffffff";
    }
    
    //负责人
    if((form.txtJgUserName.value.length == 0)||(form.txtJgUserName.value.length > 30))
    {
        bRturn = true;
        strMessage += "\r负责人姓名为空或太长!"
        form.txtJgUserName.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.txtJgUserName.style.backgroundColor = "#ccccff";
     }
    
    //联系电话
    if(form.txtJgPhone.value.length > 15)
    {
        bRturn = true;
        strMessage += "\r电话号码太长!"
        form.txtJgPhone.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.txtJgPhone.style.backgroundColor = "#ffffff";
     }
    //手机
    if(form.txtJgMoveTel.value.length > 18)
    {
        bRturn = true;
        strMessage += "\r手机号码有错!"
        form.txtJgMoveTel.style.backgroundColor = "#ffffcc";
    }
    else
    {
        form.txtJgMoveTel.style.backgroundColor = "#ffffff";
     }
    //Email
    if(form.txtEmail.value.length >0)
    {
        if(!checkmail(form.txtEmail.value) || (form.txtEmail.value.lenght >30))
        {
            bRturn = true;
            strMessage += "\rEmail不正确!"
            form.txtEmail.style.backgroundColor = "#ffffcc";
        }
        else
        {
            form.txtEmail.style.backgroundColor = "#ffffff";
        }
    }
    else
    {
        form.txtEmail.style.backgroundColor = "#ffffff";
    }
    
    
    if(bRturn)
    {
        alert(strMessage);
        return false;
    }
    else
    {
        return true;
    }   
    
}

//检测Emil true:正确 false:错误
function checkmail(mail)
{
  var strr;
  re=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
  if(re.test(mail))
  {
    return true;
  }
  else
  {
    return false;
  } 
}
//检测日期的格试 true:正确 false:错误
function checkDate(val)
{
    var dateReg = /^(19|20)\d\d\-\d{1,2}\-\d{1,2}$/;
    if(dateReg.test(val))
    {
        if(datecheck(val))
            return true;
        else					
            return false;			
    }
    else
    {
        return false;
    }
}

function datecheck(val)
		{
			var mydate = val.split("-");
			var year = mydate[0];//取得是否为润年
			var month = mydate[1];//取得日期中的月份
			var day = mydate[2];//取得日期中的日
			if(month>12 || month == 0 || day == 0)  
			{
				return  false;
			}  
			if(month==4||month==6||month==9||month==11)
			{  
				if(day>30)  
					return  false;  
				else  
					return  true;  
			}  
			else  if(month==2)
			{  
				if(((year % 400 == 0)||((year % 4 == 0)&&(year % 100 != 0)))&&day>29)  //润月天数
					return  false;  
				else  if(!(((year % 400 == 0)||((year % 4 == 0)&&(year % 100 != 0))))&&day>28)  
					return  false;  
				else  
					return  true;  
			}  
			else
			{  
				if(day>31)  
					return  false;  
				else  
					return  true;  
			}  
		}




