﻿function G(id){
    return document.getElementById(id);
};
function GC(t){
   return document.createElement(t);
};
String.prototype.trim = function(){
          return this.replace(/(^\s*)|(\s*$)/g, '');
};
function isIE(){
      return (document.all && window.ActiveXObject && !window.opera) ? true : false;
} 
     var loginDivWidth = 300;

function loadSignInFlow(){
   G("sign_div").innerHTML = sign_in_flow;
    G("sign_email").focus();
};
function cancelSign(){
    G("sign_div").style.display = 'none';
    G("cover_div").style.display = 'none';
   document.body.style.overflow = '';
};
function popCoverDiv(){
   if (G("cover_div")) {
    G("cover_div").style.display = '';
   } else {
    var coverDiv = GC('div');
    document.body.appendChild(coverDiv);
    coverDiv.id = 'cover_div';
    with(coverDiv.style) {
     position = 'absolute';
     background = '#CCCCCC';
     left = '0px';
     top = '0px';
     var bodySize = getBodySize();
     width = bodySize[0] + 'px'
     height = bodySize[1] + 'px';
     zIndex = 98;
     if (isIE()) {
      filter = "Alpha(Opacity=60)";
     } else {
      opacity = 0.6;
     }
    }
   }
}
function getBodySize(){
   var bodySize = [];
   with(document.documentElement) {
    bodySize[0] = (scrollWidth>clientWidth)?scrollWidth:clientWidth;
    bodySize[1] = (scrollHeight>clientHeight)?scrollHeight:clientHeight;
   }
   return bodySize;
} 
function popSign(){
   if (G("sign_div")) {
    G("sign_div").style.display = '';
   } else {
    var signDiv = GC('div');
    document.body.appendChild(signDiv);
    signDiv.id = 'sign_div';
    signDiv.align = "center";
    signDiv.onkeypress = function(evt){
          var e = window.event?window.event:evt;
          if (e.keyCode==13 || e.which==13) {
           if (G("sign_button")) {
            G("sign_div").focus();
            G("sign_button").click();
           }
          }
         };
    with (signDiv.style) {
     position = 'absolute';
     left = ((document.documentElement.clientWidth - loginDivWidth)/2)-60 + 'px';
     top = (document.documentElement.clientHeight )-550 + 'px';
     width = loginDivWidth + 'px';
     zIndex = 99;
    }
   }
    G("sign_div").innerHTML = change_pwd_flow;
  
}
function popSignFlow(isLogin) {
   popCoverDiv();  
   popSign();  
   document.body.style.overflow = "hidden";
}

var change_pwd_flow ="";
function cp(id)
{
   window.document.getElementById('hidCase').value=id;
   change_pwd_flow= "<div id='tc' name='#tc' style='padding-top:260px;padding-left:100px;'><div><table style='padding: 10px;background-color:White;' width='240' border='0' cellspacing='0' cellpadding='0'><tbody><tr><td width='90' valign='middle' style='height: 35px'>&nbsp;请输入密码：</td><td colspan='2' valign='middle' style='height: 35px'><input type='password' id='txtPassword' runat='server' /></td></tr><tr><td>&nbsp;</td><td><a style='border:1px solid #2B2B2B;padding:3px;' href='javascript:doCheck()'>确 认</a>&nbsp;&nbsp;&nbsp;<a style='border:1px solid #2B2B2B;padding:3px;' href='javascript:cancelSign()'>取 消</a></td></tr></tbody></table></div></div>";
                    
    popSignFlow();
    window.location.hash="#tc"
}

var XmlHttp;
//创建一个Http对象
function CreateXmlHttpRequest()
{
  //浏览器的判断
  if(window.XMLHttpRequest)
  {
     XmlHttp=new XMLHttpRequest(); //Mozilla浏览器
  }
  else if(window.ActiveXObject)   //IE浏览器
  {
     try
     {
        XmlHttp=new ActiveXObject("Msxml2.XMLHttp");
     }
     catch (e)
     {
         try
         {
            XmlHttp=new ActiveXObject("Microsoft.XMLHttp");
         }
         catch(e)
         {
            alert("您的浏览器不支持AJAX，请安装....");
            return;
         }
     }
  }
}
function doCheck(id)
 {
    CreateXmlHttpRequest();
    if(XmlHttp==null)
    {
      return;
    }
    var parameter=window.document.getElementById('hidCase').value;
    var value=window.document.getElementById('txtPassword').value;
    if(value.length==0)
    {
        alert("请输入密码");
        return;
    }
     if(value.length<5)
    {
        alert("密码输入不正确");
        return;
    }
    XmlHttp.open("Post","AJAX/CheckPassword.aspx?parameter="+parameter+"&pwd="+value+"",true);
    XmlHttp.onreadystatechange=StateChange;
    XmlHttp.send(null);
 }
 function StateChange()
 {
    if(XmlHttp.readyState==4)
    {
       if(XmlHttp.status==200)
       {
            var res=XmlHttp.responseText;
            if(res!="Error")
            {
                cancelSign();
                window.open(res);
            }
            else
            {
                alert("密码不正确，请与管理员联系，谢谢...");
            }
       }
    }
}

