﻿function $(id) {
    return document.getElementById(id);
}

function GoAlipayLogin() {
    location.href = "/Alipay/Login/Default.aspx";
}

/*弹出层用户登录*/
var xmlIncLogin = false;
try {
    xmlIncLogin = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
    try {
        xmlIncLogin = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e2) {
        xmlIncLogin = false;
    }
}
if (!xmlIncLogin && typeof XMLHttpRequest != 'undefined') {
    xmlIncLogin = new XMLHttpRequest();
}
function IncUserLogin() {
    var now = new Date();
    var user = $("txtName").value;
    var pass = $("txtPass").value;
    var url = "/Users/LoginAjax.aspx?user=" + user + "&pass=" + pass + "&md5=" + vMd5 + "&time=" + now;
    xmlIncLogin.open("GET", url, true);
    xmlIncLogin.onreadystatechange = IncUpdate;
    xmlIncLogin.send(null);
}
function IncUpdate() {
    if (xmlIncLogin.readyState == 4) {
        var response = xmlIncLogin.responseText;
        var str = response.split(",");
        if (str[0] == "-1") {
            alert("用户名或密码错误！")
        } else if (str[0] == 1) {
            parent.location.reload();
            window.location.href = location.href;
        } else {
            alert("未知错误，请联系客服！");
        }
    }
}


//用户退出登录
var xmlTCLogin = false;
try {
    xmlTCLogin = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
    try {
        xmlTCLogin = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e2) {
        xmlTCLogin = false;
    }
}
if (!xmlTCLogin && typeof XMLHttpRequest != 'undefined') {
    xmlTCLogin = new XMLHttpRequest();
}
function TCLogin() {
    var now = new Date();
    var url = "/Users/LoginAjax.aspx?type=qw&md5=" + vMd5 + "&time=" + now;
    xmlTCLogin.open("GET", url, true);
    xmlTCLogin.onreadystatechange = TcLoginAlert;
    xmlTCLogin.send(null);
}
function TcLoginAlert() {
    if (xmlTCLogin.readyState == 4) {
        var response = xmlTCLogin.responseText;
        var str = response.split(",");
        if (str[0] == 1) {
            parent.location.reload();
            window.location.href = location.href;
        }
    }
}


/*打开登录层*/
function showdiv() {
    IncGetPageWH();
    var vTop = getScrollTop() + 200 + "px";
    $('logindiv').style.left = (document.body.offsetWidth - 322) / 2 + "px";
    $('logindiv').style.top = vTop;
    $("logindiv").style.display = "block";
    $("loginBG").style.display = "block";
}
/*关闭登录层*/
function closediv() {
    $("logindiv").style.display = "none";
    $("loginBG").style.display = "none";
}
var vPageWidth, vPageHeight; /*页面宽高*/
/*获得页面宽高*/
function IncGetPageWH() {
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) {
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else {
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    if (self.innerHeight) {
        vPageWidth = self.innerWidth;
        vPageHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        vPageWidth = document.documentElement.clientWidth;
        vPageHeight = document.documentElement.clientHeight;
    } else if (document.body) {
        vPageWidth = document.body.clientWidth;
        vPageHeight = document.body.clientHeight;
    }
    vPageHeight = yScroll < vPageHeight ?vPageHeight : yScroll;
    vPageWidth = xScroll < vPageWidth ? vPageWidth : xScroll;
    if (document.all) {
        $('loginBG').style.height = (100+vPageHeight) + "px";
    } else {
        $('loginBG').style.height = vPageHeight + "px";
    }
    $('loginBG').style.width = vPageWidth + "px";
}
//收藏网址
function AddFavorite(sURL, sTitle) {
    try {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e) {
        try {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加!");
        }
    }
}
//设置为首页
function setHomepage() {
    if (document.all) {
        document.body.style.behavior = 'url(#default#homepage)';
        document.body.setHomePage('http://www.16cp.com');
    }
    else if (window.sidebar) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'");
            }
            if (confirm("您是否确认将当前页设置为首页！")) {
                var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                prefs.setCharPref('browser.startup.homepage', 'http://www.16cp.com');
            }
        }
    }
}
/*取窗口滚动条高度**/
function getScrollTop() {
    var scrollTop = 0;
    if (document.documentElement && document.documentElement.scrollTop) {
        scrollTop = document.documentElement.scrollTop;
    }
    else if (document.body) {
        scrollTop = document.body.scrollTop;
    }
    return scrollTop;
}
