﻿function getHttpObject() 
{ 
    var _http;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer") 
    {
        //如果用户使用IE，就返回XMLHTTP的ActiveX对象
        _http = new ActiveXObject("MSXML2.XMLHTTP.3.0"); 
    }
    else//非IE
    {
        //否则返回一个XMLHttpRequest对象
        _http = new XMLHttpRequest(); 
    }
    return _http;
}
//获取全局的HTTP请求对象
var http = getHttpObject();//也可以在顶端声明
//处理请求状态变化
function getHello() 
{ 
    //4表示请求已完成
    if (http.readyState == 4) //这里的http是全局变量
    {
        //获取服务段的响应文本
        var helloStr = http.responseText; 
        
        //alert(helloStr);
        if(helloStr=="1")//表示本地和平台都不存在
            {
            document.getElementById("txtusercode").value="1";   
            }
        if(helloStr=="0")  //表示没有验证
            {
           document.getElementById("txtusercode").value="0";    
            }
           if(helloStr=="2") //表示中心平台已经注册
            {
           document.getElementById("txtusercode").value="2";    
            } 
            if(helloStr=="3") //表示本地已经注册
            {
           document.getElementById("txtusercode").value="3";    
            }  
    }
}
function CheckUserName()
{
    var sfnum1 = document.getElementById("sfnum");
    if(sfnum1.value!="")
    {
        var url = "http://guahao.zjol.com.cn/ajax/yzuser.ashx?type=2&str="+sfnum1.value;

        //指定服务端的地址
        http.open("GET", url, true); 
        //请求状态变化时的处理函数
        http.onreadystatechange = getHello; 
        //发送请求
        http.send(null); 
    }
//    else
//    {
//         alert("请输入身份证号");
//         return;
//    }
}
/////////////////////////////////////////////////////////////////////////////////////////

function  locking(){   
      document.all.ly.style.display="block";   
      document.all.ly.style.width=document.body.clientWidth;   
      document.all.ly.style.height=document.body.clientHeight;      

     self.parent.topFrame.lockingtop();

      document.all.Layer2.style.display='block';   
      }   
      
function   Lock_CheckForm(theForm){   
      document.all.ly.style.display='none';document.all.Layer2.style.display='none'; 
      self.parent.topFrame.Lock_CheckFormtop();
      return   false;     
      }  
      
function isChinaIDCard(num) 
{ 
var factorArr = new Array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1); 
var error; 
var varArray = new Array();
var intValue;
var lngProduct = 0; 
var intCheckDigit;
var intStrLen = num.length; 
var idNumber = num; 
// initialize 
if ((intStrLen != 15) && (intStrLen != 18)) { 
//error = "输入身份证号码长度不对！"; 
//alert(error); 
//frmAddUser.txtIDCard.focus();
return false; 
} 
// check and set value 
for(i=0;i<intStrLen;i++) {
varArray[i] = idNumber.charAt(i);
if ((varArray[i] < '0' || varArray[i] > '9') && (i != 17)) { 
//error = "错误的身份证号码！."; 
//alert(error);
//frmAddUser.txtIDCard.focus(); 
return false; 
} else if (i < 17) {
varArray[i] = varArray[i]*factorArr[i]; 
} 
}
if (intStrLen == 18) {
//check date
var date8 = idNumber.substring(6,14); 
if (checkDate(date8) == false) {
//error = "身份证中日期信息不正确！."; 
//alert(error); 
return false;
} 
// calculate the sum of the products 
for(i=0;i<17;i++) { 
lngProduct = lngProduct + varArray[i]; 
}
// calculate the check digit
intCheckDigit = 12 - lngProduct % 11; 
switch (intCheckDigit) { 
case 10: 
intCheckDigit = 'X'; 
break; 
case 11: 
intCheckDigit = 0; 
break; 
case 12: 
intCheckDigit = 1; 
break; 
} 
// check last digit 
if (varArray[17].toUpperCase() != intCheckDigit) { 
//error = "身份证效验位错误!...正确为： " + intCheckDigit + "."; 
//alert(error); 
return false; 
} 
} 
else{ //length is 15 
//check date 
var date6 = idNumber.substring(6,12); 
if (checkDate(date6) == false) { 
//alert("身份证日期信息有误！."); 
return false; 
} 
} 
//alert ("Correct."); 
return true; 
} 
function checkDate(date) 
{ 
return true; 
}     
    
  function   IDUpdate(StrNo){   
    
  if   (!isChinaIDCard(StrNo))   {return   false}   
  if   (StrNo.length==15)   
  {   
            var   a,b,c   
            StrNo=StrNo.substr(0,6)+"19"+StrNo.substr(6,9)   
            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;
    
            switch(b)   
            {   
            case   0:   {StrNo=StrNo+"1";}break;
            case   1:   {StrNo=StrNo+"0";}break;
            case   2:   {StrNo=StrNo+"X";}break;   
            case   3:   {StrNo=StrNo+"9";}break;
            case   4:   {StrNo=StrNo+"8";}break;
            case   5:   {StrNo=StrNo+"7";}break;   
            case   6:   {StrNo=StrNo+"6";}break;   
            case   7:   {StrNo=StrNo+"5";}break;
            case   8:   {StrNo=StrNo+"4";}break;   
            case   9:   {StrNo=StrNo+"3";}break;
            case   10:   {StrNo=StrNo+"3";}
            }   
            }   
            return   StrNo;   
  }
 
/*注册验证开始*/ 
//共有函数
function setorrer(obj)
{
    obj.style.border="solid 1px #eee"; 
    obj.style.background="#ffff99 url(../images/exclamation.png) no-repeat right center;";
}
		
function setsucess(obj)
{
    obj.style.border="solid 1px #008000";
    obj.style.background="url(../images/accept.png) no-repeat right center;"; 
}

//验证身份证格式
function jcsf(obj)
{
    var sfnum1 = document.getElementById("sfnum");
    if(sfnum1.value!=""&&sfnum1.value!=null)
    {
        $.ajax({
        type: "POST",//用POST方式传输
        url:'ajax/yzuser.ashx',//目标地址
        data:{type:2,str:sfnum1.value},
        beforeSend:function(){$("#divload").show();},//发送数据之前
        complete:function(){$("#divload").hide();},//接收数据完毕
        success:function(msg) {
       
      if(msg==1)  
      {
           //alert("服务器连接失败,请稍后重试");
           document.getElementById("txtusercode").value=3;  
           return false;  
      }
      if(msg==2)
      {
            document.getElementById("txtusercode").value=1;
           return false;  
      }
      if(msg==3)
      {
          document.getElementById("txtusercode").value=3; 
          //alert("证件号码已经被注册过,请用其它身份注册"); 
          //sfnum1. focus(); 
          return false; 
      }
      if(msg==4)
      {
          document.getElementById("txtusercode").value=3;  
          alert("证件号码已经被注册过,请用其它身份注册"); 
          //sfnum1. focus(); 
          return false; 
      }
      }});
 } 
}
/* 注册验证结束*/

 //首页综合搜索
    function chgprovince(ID){
        document.theForm.selecthospital.length=0;
        document.theForm.selecthospital.options[0]=new Option("请选择","-1");
        document.theForm.selectdep.length=0;
        document.theForm.selectdep.options[0]=new Option("请选择","-1");
        for(i=0;i<city.length;i++){
            if(city[i][0]==ID){
                document.theForm.selecthospital.options[document.theForm.selecthospital.length]=new Option(city[i][2],city[i][1]);
            }
        }    
    }
    
    //医院联动科室
    function chgcity(ID){
        document.theForm.selectdep.length=0;
        document.theForm.selectdep.options[0]=new Option("请选择","-1");
        for(i=0;i<area.length;i++){
            if(area[i][0]==ID){
                document.theForm.selectdep.options[document.theForm.selectdep.length]=new Option(area[i][2],area[i][1]);
            }
        }    
    }
    
    //头部搜索
    function chgprovincehead(ID){
        document.headform.selectdep.length=0;
        document.headform.selectdep.options[0]=new Option("请选择","-1");
        for(i=0;i<area.length;i++){
            if(area[i][0]==ID){
                document.headform.selectdep.options[document.headform.selectdep.length]=new Option(area[i][2],area[i][1]);
            }
        }    
    }
    
    function nTabs(thisObj,Num){
if(thisObj.className == "active")return;
var tabObj = thisObj.parentNode.id;
var tabList = document.getElementById(tabObj).getElementsByTagName("li");
for(i=0; i <tabList.length; i++)
{
if (i == Num)
{
   thisObj.className = "active"; 
      document.getElementById(tabObj+"_Content"+i).style.display = "block";
}else{
   tabList[i].className = "normal"; 
   document.getElementById(tabObj+"_Content"+i).style.display = "none";
}
} 
}

function theFormsubmit()
{
   if(!checkForms(document.theForm.txtdocname1))
   {
        alert("专家姓名不能输入非法字符");
        document.theForm.txtdocname.value="";
        return;
   }
   
   if(document.theForm.selectarea.value=="-1")
   {
        alert("请选择医院所在区域");
        return;
   }
   
   if(document.theForm.selecthospital1.value=="-1")
   {
        alert("请选择医院");
        return;
   }

    document.theForm.target="_tank";
    document.theForm.submit();
}
function theForm2submit()
{
    if(!checkForms(document.theForm2.txtzc))
    {
        alert("专家特长不能输入非法字符");
        document.theForm2.txtzc.value="";
        return;
    }
     if(!checkForms(document.theForm2.txtname2))
    {
        alert("专家姓名不能输入非法字符");
        document.theForm2.txtname2.value="";
        return;
    }
    
    document.theForm2.target="_tank";
    document.theForm2.submit();
}
function theForm3submit()
{
    if(!checkForms(document.theForm3.txthosname))
    {
        alert("医院名称不能输入非法字符");
        document.theForm3.txthosname.value="";
        return;
    }
    document.theForm3.target="_tank";
    document.theForm3.submit();
}

function theheadFormsubmit()
{
   if(document.headform.selecthospital.value=="-1")
   {
       alert("请选择医院");
       return;
   }
   if(!checkForms(document.headform.txtdocname))
   {
        alert("专家姓名不能输入非法字符");
        document.headform.txtdocname.value="";
        return;
   }

    document.headform.target="_top";
    document.headform.submit();
}

   
 function checkForms(s)
{
   var iu, iuu, regArray=new Array("◎","■","●","№","↑","→","↓","'",";","{","}"+
   "!","@","#","$","%","^","&","*","(",")","_","-","+","=","|","","[","]","？","~","`","!"+
   "select","update","delete","drop","js","script",">","<","table","td","tr","style","class","for","table","where","order"+
   "!","<",">","‰","→","←","↑","↓","¤","§","＃","＆","＆","＼","≡","≠"+
   "≈","∈","∪","∏","∑","∧","∨","⊥","‖","‖","∠","⊙","≌","≌","√","∝","∞","∮"+
   "∫","≯","≮","＞","≥","≤","≠","±","＋","÷","×","/","Ⅱ","Ⅰ","Ⅲ","Ⅳ","Ⅴ","Ⅵ","Ⅶ","Ⅷ","Ⅹ","Ⅻ","一","二"+
   "╄","╅","╇","┻","┻","┇","┭","┷","┦","┣","┝","┤","┷","┷","┹","╉","╇","【","】"+
   "三","四","五","六","七","八","九","十","①","②","③","④","⑤","⑥","⑦","⑧","⑨","⑩","┌","├","┬","┼","┍","┕","┗","┏","┅","—"+
   "〖","〗","←","〓","☆","§","□","‰","◇","＾","＠","△","▲","＃","℃","※",".","≈","￠");

   iuu=regArray.length;
   var obj=s;
   for(iu=1;iu<=iuu;iu++)
   {   
      if(regArray[iu] !="")
       {
          if (obj.value.indexOf(regArray[iu])!=-1)
           { 
             s.focus(); 
             return false;
          }
        }
   }
   return true; 
}

function islogin()
{
$.ajax({
       type: "POST",//用POST方式传输
       url:'ajax/login.ashx',//目标地址
       data:{type:0},
       beforeSend:function(){},//发送数据之前
       complete:function(){},//接收数据完毕
       success:function(msg) {
       if(msg==1||msg==2)
       {
      $("#login").hide();
      $("#loginin").show(); 
       }
       else
       {
       $("#login").show();
       $("#loginin").hide(); 
       }
       }});
}

//首页登录
function login()
{
    var name = document.getElementById("txtusername").value;
    var pwd = document.getElementById("txtpassword").value;
    if(name==""||pwd=="")
    {
        alert("身份证号码或密码不能为空");
        return;
    }
    else
    {
        $.ajax({
               type: "POST",//用POST方式传输
               url:'ajax/login.ashx',//目标地址
               data:{type:1,name:name,pwd:pwd},
               beforeSend:function(){},//发送数据之前
               complete:function(){},//接收数据完毕
               success:function(msg) {
               if(msg==1||msg==2)
               {
                   islogin();
                   if(msg==2)
                   {
                      alert("您的密码存在安全隐患，请及时修改密码，以免给您带来不必要的麻烦");
                   }  
               }
               else
               {
                   alert(msg);
                   document.getElementById("txtpassword").value="";
               }
               }});
    }
}

function Mequery()
{
var Mar = document.getElementById("Marquee"); 
var child_div=Mar.getElementsByTagName("div") 
var picH = 310;//移动高度 
var scrollstep=2;//移动步幅,越大越快 
var scrolltime=20;//移动频度(毫秒)越大越慢 
var stoptime=3000;//间断时间(毫秒) 
var tmpH = 0; 
Mar.innerHTML += Mar.innerHTML; 
function start(){ 
if(tmpH < picH){ 
tmpH += scrollstep; 
if(tmpH > picH )tmpH = picH ; 
Mar.scrollTop = tmpH; 
setTimeout(start,scrolltime); 
}else{ 
tmpH = 0; 
Mar.appendChild(child_div[0]); 
Mar.scrollTop = 0; 
setTimeout(start,stoptime); 
} 
} 
onload=function(){setTimeout(start,stoptime)}; 
}

function check2()
{

var tpphone = document.getElementById("phonenum");

if(tpphone.value=="")
{
alert("手机号码必须填写");
tpphone.focus();
return false;
}
}

function GetBrithday(s){
  if(s.length==15) s = "19" + s.substr(6, 6);
  else s = s.substr(6,8);
  var y = s.substr(0,4);
  var m = s.substr(4,2);
  var d = s.substr(6,2);
  return y + "-" + m + "-" + d;  
}


function check()
{    
        //验证身份证
    var sftype = document.getElementById("sftype");
    var sfnum1 = document.getElementById("sfnum");
    if(sfnum1.value=="")
    {
        alert("身份证号码不能为空"); 
        sfnum1.focus(); 
        return false; 
    }

    if(!isChinaIDCard(sfnum1.value))
    {
        alert("身份证号码输入有误");
        sfnum1.focus(); 
        return false; 
    }
    
    //CheckUserName();
   /* 
    var txtusercode = document.getElementById("txtusercode").value
    if(txtusercode=="0")
    {
        alert("身份证号码正在验证中，请稍后");
        sfnum1.focus(); 
        return false;
    }
    if(txtusercode=="2")
     {
        alert("身份证号码已经在医院注册，请直接登录，默认密码为身份证后8位，如有疑问，请联系我们");
        sfnum1.focus(); 
        return false;
    }
    if(txtusercode=="3")
     {
        alert("身份证号码已经被注册");
        sfnum1.focus(); 
        return false;
    }
    */
    
    //验证密码开始
    var password = document.getElementById("password"); 
    var passwordre = document.getElementById("passwordre"); 
    var strRegex1=".{6,12}";
    var re1=new RegExp(strRegex1); 
    if (!re1.test(password.value))
    {
        alert("密码格式不正确，请重新填写");
        password.value="";
        passwordre.value="";
        password.focus();
        return false;
    }

    if(password.value!=passwordre.value)
    {
        alert("两次密码输入不一致，请重新填写");
        password.value="";
        passwordre.value="";
        password.focus();
        return false;
    }
    //验证密码结束
    
    //验证真实姓名
    var realname = document.getElementById("realname"); 
    var strRegex2="^[\u4e00-\u9fa5]{2,5}$";
    var re2=new RegExp(strRegex2); 
    if (!re2.test(realname.value))
    {
        alert("真实姓名为空或格式不正确，请重新填写");
        realname.value="";
        realname.focus();
        return false;
    }
    //验证真实姓名  
    
   
 //验证邮件
    var email = document.getElementById("email1");
    if(email.value!=null&&email.value!="")
    {
        var strRegex4="^[ _a-z0-9- ]+(\.[a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$";
        var re4=new RegExp(strRegex4); 
        if (!re4.test(email.value))
        {
            alert("电子邮件填写有误，请重新填写");
            email.value=""; 
            email.focus(); 
            return false;
        }  
    }
    //验证邮件
 
    //验证手机
    var tpphone = document.getElementById("phonenum");
    if(tpphone.value=="")
    {
        alert("手机号码必须填写");
        tpphone.focus();
        return false;
    }
    else
    {
        var a=/^1[3|4|5|8][0-9]\d{4,8}$/ ; 
        if (!tpphone.value.match(a) ){
            alert("移动电话格式不正确! "); 
            tpphone.focus();
            return false;
        } 
    }
    //验证手机 
   
}

////////////

