﻿// JScript 文件
function LoginLoad()
{
     var LoginModal = document.getElementById("divlogin");
     if(!LoginModal)
     {
        LoginModal = document.createElement("div");
        LoginModal.id = 'divlogin';
        LoginModal.className = "lg";
        LoginModal.style.width = "300px";
        LoginModal.style.height = "150px";
        document.body.appendChild(LoginModal);
        
        
            var strLogin = "<img src='/image/xxx.png' onclick='NoShowLogin()' class='right' style='cursor:pointer;' /><dl>"
                            + "<dt class='left'>用户名:</dt>"
                            + "<dd><input type='text' name='tbUserName' id='tbUserName'"
                                    + "maxlength='19' size='20' class='ip1' /></dd>"
                            + "<dt class='clear left'>密&nbsp;&nbsp;&nbsp;&nbsp;码:</dt>"
                            + "<dd><input type='password' name='tbPassword' id='tbPassword'"
                               + "maxlength='8' size='20' class='ip1' onkeydown='LoginKeyDown()' /></dd>"
                            + "<dt class='clear left'>&nbsp;</dt>"
                            + "<dd><img id='imgLogin' src='/image/btn02.gif' style='cursor:pointer;' onclick='Login()' alt='登录' /></dd>"
                            + "</dl>"
                            + "<p class='text_mid margin_top10'>"
                                    + "<a href='/about/contactinfo.html' class='a03'>忘记密码</a> <a href='/reg.aspx'"
                                        + "class='a06'>免费注册会员</a>"
                            + "</p>" ;
        LoginModal.innerHTML = strLogin;
     }
     ShowLogin();
}

 function   LoginKeyDown()   
{   
        var   gk = event.keyCode;   
        if(gk==13)     
        {   
          //event.keyCode   =   9;   
          document.getElementById("imgLogin").onclick(); 
          return;     
        }   
}   



function ShowLogin()
{
    placeCenter(document.getElementById("divlogin"));
    document.getElementById("divlogin").style.visibility='visible';
}

setInterval("onscrollDiv()", 50); 

function onscrollDiv()
{
    var LoginModal = document.getElementById("divlogin");
    if(LoginModal)
    {
        placeCenter(LoginModal);
    }
}

function NoShowLogin()
{
    placeCenter(document.getElementById("divlogin"));
    document.getElementById("divlogin").style.visibility='hidden';
}


function Login()
{
    var oHttpReq  = null;
    if(window.XMLHttpRequest)
    {
        oHttpReq = new XMLHttpRequest();
    }
    else
    {
        oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
    }
    var userName = document.getElementById("tbUserName").value;
    var password = document.getElementById("tbPassword").value;
    oHttpReq.open("POST", "/control/divLogin.aspx?name="+ userName +"&pwd="+ password,false);
    oHttpReq.send(""); 
    result = oHttpReq.responseText; 
    var loginState = result; // 登陆状态
    if(loginState == 1)
    {
        location.reload();
    }
    else if(loginState == 0)
    {
        alert("用户名或密码错误");
    }
}


function placeCenter(element)
{
    //var bounds = Sys.UI.DomElement.getBounds(element);
    var elementHeight = parseInt(element.style.height);
    var elementWidth = parseInt(element.style.width);
    var bWidth = Geometry.getViewportWidth();
    var bHeight = Geometry.getViewportHeight();
    //Sys.UI.DomElement.setLocation(element, parseInt((bWidth - bounds.width)/2), Geometry.getVerticalScroll() + parseInt((bHeight - bounds.height)/2));
    element.style.left = parseInt((bWidth - elementWidth)/2);
    element.style.top = Geometry.getVerticalScroll() + parseInt((bHeight - elementHeight)/2);
}

var Geometry = {};

//getWindowX(): return the X position of the window on the screen
//getWindowY(): return the Y position of the window on the screen
if(window.screenLeft)
{
    //IE and others
    Geometry.getWindowX = function() { return window.screenLeft; };
    Geometry.getWindowY = function() { return window.screenTop; };
}
else
{
    if(window.screenX)
    {
        //Firefox and others
        Geometry.getWindowX = function() { return window.screenX; };
        Geometry.getWindowY = function() { return window.screenY; };
    }
}

//getViewportWidth/Height(): return the size of the browser viewport area
//getHorizontalScroll(): return the position of the horizontal scrollbar
//getVerticalScroll(): return the position of the vertical scrollbar
if(window.innerWidth)
{
    //All browsers but IE
    Geometry.getViewportWidth = function() { return window.innerWidth; };
    Geometry.getViewportHeight = function() { return window.innerHeight; };
    Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
    Geometry.getVerticalScroll = function() { return window.pageYOffset; };
}
else
{
    if(document.documentElement && document.documentElement.clientWidth)
    {
        //These function are for IE 6 when there is a DOCTYPE
        Geometry.getViewportWidth = function() { return document.documentElement.clientWidth; };
        Geometry.getViewportHeight = function() { return document.documentElement.clientHeight; };
        Geometry.getHorizontalScroll = function() { return document.documentElement.scrollLeft; };
        Geometry.getVerticalScroll = function() { return document.documentElement.scrollTop; };
    }
    else
    {
        if(document.body.clientWidth)
        {
            //These are for IE4, IE5 and IE6 with out DOCTYPE
            Geometry.getViewportWidth = function() { return document.body.clientWidth; };
            Geometry.getViewportHeight = function() { return document.body.clientHeight; };
            Geometry.getHorizontalScroll = function() { return document.body.scrollLeft; };
            Geometry.getVerticalScroll = function() { return document.body.scrollTop; };
        }
    }
}

//These function return the size of the document. They are not window related, but they are useful to have here anyway
if(document.documentElement && document.documentElement.scrollWidth)
{
    Geometry.getDocumentWidth = function() { return document.documentElement.scrollWidth; };
    Geometry.getDocumentHeight = function() { return document.documentElement.scrollHeight; };
}
else
{
    if(document.body.scrollWidth)
    {
        Geometry.getDocumentWidth = function() { return document.body.scrollWidth; };
        Geometry.getDocumentHeight = function() { return document.body.scrollHeight; };
    }
}