﻿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 )+ '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 casecp()
{
   change_pwd_flow= "<div id='tc' name='#tc' style=padding-top:260px;margin-top:260px;><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 colspan='2'>&nbsp;请向中为询要密码</td></tr><tr><td>&nbsp;</td><td style='height: 38px'><a style='border:1px solid #2B2B2B;padding:2px;height: 38px' href='javascript:doCaseCheck()'>确 认</a>&nbsp;&nbsp;&nbsp;<a style='border:1px solid #2B2B2B;padding:2px;height: 38px' href='javascript:cancelSign()'>取 消</a></td></tr></tbody></table></div></div>";
    popSignFlow();
    scroller(window.document.getElementById('tc'), 1000) 
//    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 doCaseCheck()
 {
    CreateXmlHttpRequest();
    if(XmlHttp==null)
    {
      return;
    }
    var value=window.document.getElementById('txtPassword').value;
    if(value.length==0)
    {
        alert("请输入密码");
        return;
    }
     if(value.length<5)
    {
        alert("密码输入不正确");
        return;
    }
    XmlHttp.open("Post","AJAX/CasePower.aspx?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.location='NewCase.html';
            }
            else
            {
                alert("密码不正确，请与管理员联系，谢谢...");
            }
       }
    }
}
function intval(v) 
{ 
    v = parseInt(v); 
    return isNaN(v) ? 0 : v; 
} 

// 获取元素信息 
function getPos(e) 
{ 
    var l = 0; 
    var t  = 0; 
    var w = intval(e.style.width); 
    var h = intval(e.style.height); 
    var wb = e.offsetWidth; 
    var hb = e.offsetHeight; 
    while (e.offsetParent){ 
        l += e.offsetLeft + (e.currentStyle?intval(e.currentStyle.borderLeftWidth):0); 
        t += e.offsetTop  + (e.currentStyle?intval(e.currentStyle.borderTopWidth):0); 
        e = e.offsetParent; 
    } 
    l += e.offsetLeft + (e.currentStyle?intval(e.currentStyle.borderLeftWidth):0); 
    t  += e.offsetTop  + (e.currentStyle?intval(e.currentStyle.borderTopWidth):0); 
    return {x:l, y:t, w:w, h:h, wb:wb, hb:hb}; 
} 

function getScroll()  
{ 
    var t, l, w, h; 
     
    if (document.documentElement && document.documentElement.scrollTop) { 
        t = document.documentElement.scrollTop; 
        l = document.documentElement.scrollLeft; 
        w = document.documentElement.scrollWidth; 
        h = document.documentElement.scrollHeight; 
    } else if (document.body) { 
        t = document.body.scrollTop; 
        l = document.body.scrollLeft; 
        w = document.body.scrollWidth; 
        h = document.body.scrollHeight; 
    } 
    return { t: t, l: l, w: w, h: h }; 
} 

function scroller(el, duration) 
{ 
    if(typeof el != 'object') { el = document.getElementById(el); } 

    if(!el) return; 

    var z = this; 
    z.el = el; 
    z.p = getPos(el); 
    z.s = getScroll(); 
    z.clear = function(){window.clearInterval(z.timer);z.timer=null}; 
    z.t=(new Date).getTime(); 

    z.step = function(){ 
        var t = (new Date).getTime(); 
        var p = (t - z.t) / duration; 
        if (t >= duration + z.t) { 
            z.clear(); 
            window.setTimeout(function(){z.scroll(z.p.y, z.p.x)},13); 
        } else { 
            st = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.y-z.s.t) + z.s.t; 
            sl = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.x-z.s.l) + z.s.l; 
            z.scroll(st, sl); 
        } 
    }; 
    z.scroll = function (t, l){window.scrollTo(l, t)}; 
    z.timer = window.setInterval(function(){z.step();},13); 
}
