﻿Close();
var obj = null;
function CreateAjax()
{
 
  if(window.XMLHttpRequest)//ff
  {
    xmlobj=new XMLHttpRequest();
    return xmlobj;
  }
  else if(window.ActiveXObject)//ie
  {
     var objs=["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];
     for(var i=0;i<objs.length;i++)
     {
       try
       {
         var o=new ActiveXObject(objs[i]);
         return o;
       }
       catch(e)
       {       
         

       }
     }
  }
}

function Close()
{
  obj=CreateAjax();
  if(obj)
  {
     var str="../EHomeWeb/Wsession.aspx";
   
    
     var url=str;

     obj.onreadystatechange = function() 
     {
         if (obj != null) 
         {
             if (obj.readyState == 4) {

                 if (obj.status == 200) {
                     if (obj.responseText == "type") {

                         Exit();
                     }

                 }
                 else {
                     Exit();
                     //              window.location.href="../index.html";
                     return;
                 }
             }
         }
     }
     obj.open("POST",url,true);
     obj.send(null);
  }
  else
  {   Exit();
//     window.location.href="../index.html";
  }
   
}
function show(id,usernbame)
{   
      if(id=="")
     {
       // alert("账号不能为空");
        document.getElementById('popmessage').innerHTML="账号不能为空!"; 
        show_div("win_otherMessage");        
        return;
     }
     if(usernbame.length==0)
     {
      
    //   alert("密码不能为空");
       document.getElementById('popmessage').innerHTML="密码不能为空!"; 
       show_div("win_otherMessage");
       return;
     }
     if(usernbame.length>16)
     {
       alert("密码长度不能超过16位");
       return;
     }
 
  obj=CreateAjax();
  if(obj)
  {

     var regMe = document.getElementById('ckbRegMe').checked;
     if(isNaN(id))
     {
        var str="./EHomeweb/LoginChecking.aspx?id="+ encMe(id,prikey)+"&d=0&pwd="+ encMe(usernbame,prikey)+"&type=0&RegMe = " + regMe
     //    var str="../EHomeWeb/LoginChecking.aspx?id="+ id+" && pwd="+ usernbame+" && type=0 &&RegMe = " + regMe;
     }else
     {
      var str="./EHomeweb/LoginChecking.aspx?id="+encMe(id,prikey)+"&d=0&pwd="+encMe(usernbame,prikey)+"&type=1&RegMe = " + regMe;
       //  var str="../EHomeWeb/LoginChecking.aspx?id="+ id+" && pwd="+ usernbame+" && type=1 &&RegMe = " + regMe;
     }
     
     if(regMe)
         SetMyCookie("regme","true",60);
     else
         SetMyCookie("regme","false",60);        
    
     var url=str;
     obj.onreadystatechange = function() {
         if (obj.readyState == 4) {

             if (obj.status == 200) {

                 if (obj.responseText != "") {

                     if (obj.responseText == id) {

                         //document.cookie="username="+id;
                         SetMyCookie("username", id, 60);                         
	                        index(); 
                     }
                     else if(obj.responseText=="ipnotallow")
                     {
                      document.getElementById('popmessage').innerHTML="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;您的帐号不在设定IP范围内登陆!\n如果疑问;请联系客户热线:400-662-889;或企业QQ:4006628899"; 
                            show_div("win_otherMessage");
                     }
                     else if(obj.responseText.indexOf("surpassdate")>0) {
                      show_div("win_surpassdate");
                     }
                     else {
                         if (obj.responseText == "密码错误" || obj.responseText == "用户名不存在" || obj.responseText == "手机号不正确" || obj.responseText == "数据库连接失败!请检查数据库连接方式是否正确") {
                           if(obj.responseText == "用户名不存在")
                            document.getElementById('popmessage').innerHTML="帐户还未注册!";
                           else
                           document.getElementById('popmessage').innerHTML=obj.responseText+"!"; 
                            show_div("win_otherMessage");
                             return;

                         }
                         else {
                          SetMyCookie("surpassdate", "false", 60);                        
                             SetMyCookie("username", obj.responseText, 60);
                             index();
                         }
                     }
                 }

             }
             else {
                 window.location.href = "../index.html";
                 return;
             }
         }
        
     }
     obj.open("POST",url,true);
     obj.send(null);
     
  }
  else
  {
     window.location.href="../index.html";
  }
  
}


//function setCookie(name)
//   {
//     alert(name);
//     document.cookie="username="+name;
//   // document.cookie="cookiePassword="+document.myForm.myPassword.value; ;
//   // window.alert("cookie文件中的内容为："+document.cookie+"\n"+"cookieName的值为："+getCookieValue("cookieName")+"\n"+"cookiePassword的值为："+                       getCookieValue("cookiePassword"));
//   }


//    function getCookieValue(cookieName)
//    {
//    
//      var cookies=document.cookie;//读取整个cookie文件中的内容
//      var cookieIndex=cookies.indexOf(cookieName);//查找cookie文件名在字符串的开始位置
//    
//    if(cookieIndex!=-1)//如果在cookie文件中查找到cookie名，则进一步查找它的值
//    {
//   
//     var cookieValueStart=cookieIndex+cookieName.length+1;//cookie值的开始位置，cookie名的开始位置加一（等于号占位1）
//     var cookieValueEnd=cookies.indexOf(";",cookieValueStart);
//     
//     if(cookieValueEnd==-1)
//     {
//       cookieValueEnd=cookies.length;
//     }
//     var cookieValue=cookies.substring(cookieValueStart,cookieValueEnd);
//     
//    
//    }
//     return cookieValue;
//     
//   }
   
function  block()
{
var url="../EHomeWeb/GetCookies.aspx";
     obj=CreateAjax();
     obj.onreadystatechange=function()
     {
        if(obj.readyState==4)
        {
        
          if(obj.status==200)
          {
          
             var words = obj.responseText.split('@')
             var uName = words[0];
             var uPwd=words[1];
             var RegMe = words[2];
            if((uName==undefined || uName=="")||(uPwd==undefined||uPwd==""))            
            {
             if(getMyCookie("regme")=="true" && ( getMyCookie("username")!=undefined || getMyCookie("username")!=""))
              {
               document.getElementById('textfield').value = getMyCookie("username");
                document.getElementById('ckbRegMe').checked = true;
                return;
              } 
            }
            else
            {
             document.getElementById('td').innerHTML=getMyCookie("username");
              document.getElementById('div1').style.display="none";
               document.getElementById('div2').style.display="block";      
               document.getElementById('ckbRegMe').checked = RegMe;
               document.getElementById('textfield').value = uName;
               document.getElementById('textfield2').value=uPwd;
               }  
          }
        }
     }
     obj.open("POST",url,true);
     obj.send(null);     
    document.getElementById('div1').style.display="block"; 
    document.getElementById('div2').style.display="none";     
}

function Skip()
 {  
    var id=document.getElementById('textfield').value;
    var usernbame=document.getElementById('textfield2').value; 
    show(id,usernbame);    
 }

function Exit()
{
       document.location.href="./EHomeWeb/LogOut.aspx";
      block();  
 }
 
function index()
{
    window.location.href="../EHomeWeb/index.aspx";
}

function CheckEnterKey(evt) {

//    var k = typeof (window.event) == "undefined" ? evt.keyCode : evt.which;
//    alert(evt.keyCode);
//    if(k==13) {

//        alert("fjdsl");
//       Skip();
//   }
    //
    var isie = (document.all) ? true : false;//判断是IE内核还是Mozilla 
    var key;
    if (isie) 
    {
        key = window.event.keyCode; //IE使用windows.event事件 
    }
     else if(navigator.userAgent.indexOf("Firefox")>0 || navigator.userAgent.indexOf("Chrome") >0)
    {
    key=evt.keyCode;
    }
    else 
    {
        key = e.which; //3个按键函数有一个默认的隐藏变量，这里用e来传递。e.which给出一个索引值给Mo内核（注释1） 
    } 

    if(key==13)
        Skip();

}

function GetBackPasswd()
 {
    var id=document.getElementById('textfield').value;
    var send_mail=document.getElementById("r_sendmail");
    var send_sms=document.getElementById("r_sendsms");
    if(id == "")
    {
      alert("帐号不能为空!");
      return;
     }
     
      obj=CreateAjax();
      if(obj)
      {

if(send_sms.checked==true)
var str="../EHomeWeb/Report/Report.aspx?type=send_sms&adsl="+ id+"&content="+ "您的天翼绿网系统的密码是:[GetBackPasswd]";
if(send_mail.checked==true)
var str="../EHomeWeb/Report/Report.aspx?type=send_email&adsl="+ id+"&content="+ "您的天翼绿网系统的密码是:[GetBackPasswd]";
         var url=str;
        
         obj.onreadystatechange=function()
         {
            if(obj.readyState==4)
            {
            
              if(obj.status==200)
              {
               
                 if(obj.responseText!="")
                 {
                    
                    if(obj.responseText=="1")
                    {                    
                       alert("您的密码发送成功");
                       location.href="index.html";
                      // closewindows();
                    }
                    else 
                    {
                       alert("您的密码发送失败("+obj.responseText+")");
                 //      closewindows();
                       return;
                    }     
                 }   
                
              }
              else
              {
                 alert("您的密码发送失败("+obj.status+")");
               //  closewindows();
                return;
              }
            }
         }
         obj.open("GET",url,true);
         obj.send(null);
      }
  }
  
  function ValidateLogin() {


      var code, userName, userPwd1, userPwd2, mobile,company,email;
      code = $("txtCode").value;
      userName = $("txtUserName").value;
      userPwd1 = $("txtPasswd1").value;
      userPwd2 = $("txtPasswd2").value;
      mobile = $("txtMobile").value;
      email=$("txtEmail").value;
//      if ($("company") != null) {
//          company = $("company").value;
//      }
//      else {
//          company = "EHOME";
//      }
      company = "TYLW";
      if (userName.length == 0) {
          alert("用户名不能为空！");
          $("txtUserName").focus();
          $("txtUserName").select();
          $("aValidateCode").click();
          return;
      }
      if (userName.length < 4) {
          alert("用户名长度至少4位！");
          $("aValidateCode").click();
          $("txtUserName").focus();
          $("txtUserName").select();
          return;
      }
      if (userName.length > 16) {
          alert("用户名长度应少于16位！");
          $("aValidateCode").click();
          $("txtUserName").focus();
          $("txtUserName").select();
          return;
      }
      if (userPwd1.length == 0) {
          alert("密码不能为空！");
          $("aValidateCode").click();
          $("txtPasswd1").focus();
          $("txtPasswd1").select();
          return;
      }
      if (userPwd2.length == 0) {
          alert("确认密码不能为空！");
          $("aValidateCode").click();
          $("txtPasswd2").focus();
          $("txtPasswd2").select();
          return;
      }
      if (userPwd1.length < 6) {
          alert("密码长度至少6位！");
          $("aValidateCode").click();
          $("txtPasswd1").focus();
          $("txtPasswd1").select();
          return;
      }
      if (userPwd2.length > 20) {
          alert("密码长度应少于20位！");
          $("aValidateCode").click();
          $("txtPasswd2").focus();
          $("txtPasswd2").select();
          return;
      }
      if (userPwd1.length >20) {
          alert("密码长度应少于20位！");
          $("aValidateCode").click();
          $("txtPasswd1").focus();
          $("txtPasswd1").select();
          return;
      }
      if (userPwd2.length < 6) {
          alert("密码长度至少6位！");
          $("aValidateCode").click();
          $("txtPasswd2").focus();
          $("txtPasswd2").select();
          return;
      }
      if (userPwd1 != userPwd2) {
          alert("两次密码输入不一致！");
          $("aValidateCode").click();
          $("txtPasswd1").focus();
          $("txtPasswd1").select();
          return;
      }
 /*     if(mobile.length==0)
      {
              alert("手机号码不能为空");
              $("aValidateCode").click();
              $("txtMobile").focus();
              $("txtMobile").select();
              return;      
      }      */
      if (mobile != "" && mobile != null) {
          if (/^18\d{9}$/g.test(mobile) || /^15\d{9}$/g.test(mobile) || /^14\d{9}$/g.test(mobile) || /^13\d{9}$/g.test(mobile)) {
          }
          else {
              alert("请输入正确的手机号码");
              $("aValidateCode").click();
              $("txtMobile").focus();
              $("txtMobile").select();
              return;
          }
      }
  /*     if(email.length==0)
      {
              alert("邮箱不能为空");
              $("aValidateCode").click();
              $("txtEmail").focus();
              $("txtEmail").select();
              return;      
      }      */
      if (email != "" && email != null) {
          if (/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/g.test(email)) {
          }
          else {
              alert("请输入正确的电子邮箱");
              $("aValidateCode").click();
              $("txtEmail").focus();
              $("txtEmail").select();
              return;
          }
      }    
      if (code.length == 0) {
          alert("验证码不能为空！");
          $("aValidateCode").click();
          $("txtCode").focus();
          $("txtCode").select();
          return;
      }
      if (code != codeStr) {
          alert("验证码输入错误！");
          $("aValidateCode").click();
          $("txtCode").focus();
          $("txtCode").select();
          return;
      }

      obj = CreateAjax();
      if (obj) {

          var str = "../EHomeWeb/Report/Report.aspx?type=reg_user&username=" + userName + "&pwd=" + userPwd1 + "&mobile=" + mobile+"&company="+company+"&email="+email;

          var url = str;

          obj.onreadystatechange = function() {
              if (obj.readyState == 4) {

                  if (obj.status == 200) {

                      if (obj.responseText == "true") {
                          alert("用户注册成功!");
//                          $("txtCode").value = "";
//                          $("txtPasswd1").value = "";
//                          $("txtPasswd2").value = "";
                          window.location.href = "index.html";

                      }
                      else {
                          alert(obj.responseText);
                          return;
                      }


                  }
                  else {
                      alert("网络异常(" + obj.status + ")");
                      $("aValidateCode").click();
                      return;
                  }
              }

          }
          obj.open("POST", url, true);
          obj.send(null);
      }

  }  
  
  function closewindows()
  {
  if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){ 
  window.open('','_self'); 
  window.close(); 
  return;
  }
  else if(navigator.appName == "Microsoft Internet Explorer")
 {
   if((navigator.appVersion.match(/7./i)=='7.')||(navigator.appVersion.match(/8./i)=='8.'))
   { 
    window.open('','_self'); 
   }     
  }
  window.opener=null;
  window.close(); 
  }
  
 

  function $(id) {
      return document.getElementById(id);
  }
  
  
  function getpasswod(id)
  {
  var mobile=document.getElementById('textfield').value;
  if(mobile!="")
  {
          if (/^133\d{8}$/g.test(mobile) || /^153\d{8}$/g.test(mobile) || /^180\d{8}$/g.test(mobile) || /^189\d{8}$/g.test(mobile)) {
          }
          else {
              alert("请输入正确的天翼手机号码");
              $("aValidateCode").click();
              $("txtMobile").focus();
              $("txtMobile").select();
              return;
          }
          
              obj = CreateAjax();
      if (obj) {

var str="../EHomeWeb/Report/Report.aspx?type=send_sms&adsl="+ mobile+"&content="+ "您的天翼绿网系统的密码是:[GetBackPasswd]";

          var url = str;

          obj.onreadystatechange = function() {
              if (obj.readyState == 4) {

                  if (obj.status == 200) {

                      if (obj.responseText == "1") {
                          alert("密码已经成功发送到您手机!");
                //          window.location.href = "index.html";

                      }
                      else {
                          alert(obj.responseText);
                          return;
                      }

                  }
                  else {
                      alert("网络异常(" + obj.status + ")");
                      $("aValidateCode").click();
                      return;
                  }
              }

          }
          obj.open("POST", url, true);
          obj.send(null);
      } 
   }
  else 
  {  
  window.location.href='getPassword.html'
  }  
  }
  
  //弹出div 错误提示;
  
    function show_div(div_pop_id){  
       document.body.scroll="no"; //隐藏当窗口的滚动条  
    document.getElementById("bg").style.width=document.body.clientWidth+"px"; //将背景框的宽度调到最宽  
       document.getElementById("bg").style.height=document.body.clientHeight+"px";//将背景框的高度调到最高  
        
       document.getElementById(div_pop_id).style.display="block";//将小窗口显示  
       document.getElementById("bg").style.display="block";//将背景框显示  
    }        
    function hide_div(div_hide_id){  
       document.body.scroll="auto";//当窗口的滚动条自动显示  
       document.getElementById(div_hide_id).style.display="none";//将小窗口隐藏  
       document.getElementById("bg").style.display="none";//将背景框隐藏  
    }  
    function  orderOK()
    {
        SetMyCookie("surpassdate", "true", 60);
        SetMyCookie("username", document.getElementById('textfield').value, 60);
        index();
    }
  
