﻿var isIe = (document.all) ? true : false;
var Get = {
windowSize: function(documentobj) {
        var width = 0, height = 0;
        if (typeof window.innerWidth == 'number') //Non-IE
        {
            width = window.innerWidth;
            height = window.innerHeight;
        }
        else if (documentobj.documentElement && (documentobj.documentElement.clientWidth || documentobj.documentElement.clientHeight)) {
            //IE 6+ in 'standards compliant mode'
        width = documentobj.documentElement.clientWidth;
        height = documentobj.documentElement.clientHeight;
        }
        else if (documentobj.body && (documentobj.body.clientWidth || documentobj.body.clientHeight)) {
            //IE 4 compatible
        width = documentobj.body.clientWidth;
        height = documentobj.body.clientHeight;
        }
        return [width, height];
    }
,
    scroll: function() {
        var x = 0, y = 0;
        if (typeof (window.pageYOffset) == 'number') {
            //Netscape compliant
            x = window.pageXOffset;
            y = window.pageYOffset;
        }
        else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
            //DOM compliant
            x = document.body.scrollLeft;
            y = document.body.scrollTop;
        }
        else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
            //IE6 standards compliant mode
            x = document.documentElement.scrollLeft;
            y = document.documentElement.scrollTop;
        }
        return [x, y];
    },
    screenPosition: function(obj, showobj) {
        var acPosition = ac(obj);
        var x = acPosition[0] + 50;
        var y = acPosition[1] + 30;
        var scroll = Get.scroll();
        var bsl = scroll[0];
        var bst = scroll[1];
        if ((y - bst + 200) > Get.windowSize()[1]) {
            y = y - 200;

        }
        return [x, y];
    }
}
function getItem(obj) {
    var itemname;
    if (typeof (obj) != String) {
        itemname = obj.toString();
    } else {
        itemname = obj;
    }
    return document.getElementById(itemname);
}
function setIteM(targ, values) {
    var targobj = getItem(targ);
    targobj.value = values;
}

function login(obj,documentobj) {
    var bWidth = parseInt(documentobj.documentElement.scrollWidth);
    var bHeight = parseInt(documentobj.documentElement.scrollHeight);
    var back = documentobj.createElement("div");
    back.id = "back";
    var styleStr = "top:0px;left:0px;position:absolute;background:#666;width:" + bWidth + "px;height:" + bHeight + "px;";
    styleStr += (isIe) ? "filter:alpha(opacity=75);" : "opacity:75;";
    back.style.cssText = styleStr;
    documentobj.body.appendChild(back);
    //showBackground(back, 50);
    obj.style.display = "block";
    obj.style.left = Get.windowSize(documentobj)[0] / 2 - 125;
    obj.style.top = Get.windowSize(documentobj)[1] / 2 - 50;
}
function butlogin() {
    var obj = document.getElementById("login");
    var bWidth = parseInt(document.documentElement.scrollWidth);
    var bHeight = parseInt(document.documentElement.scrollHeight);
    var back = document.createElement("div");
    back.id = "back";
    var styleStr = "top:0px;left:0px;position:absolute;background:#666;width:" + bWidth + "px;height:" + bHeight + "px;";
    styleStr += (isIe) ? "filter:alpha(opacity=75);" : "opacity:75;";
    back.style.cssText = styleStr;
    document.body.appendChild(back);
    //showBackground(back, 50);
    obj.style.display = "block";
    obj.style.left = Get.windowSize(document)[0] / 2 - 125;
    obj.style.top = Get.windowSize(document)[1] / 2 - 50;
}
function closeBox() {
    if (document.getElementById('back') != null) {
        document.getElementById('back').parentNode.removeChild(document.getElementById('back'));
    }
    document.getElementById("login").style.display = "none";
    document.getElementById("login").style.left = "250px";
}
function info() {
    alert("请先登录后再领取");
}
function reslogin() {
    getItem("TextBox1").value = "";
    getItem("TextBox2").value = "";
    getItem("TextBox3").value = "";
}

//让背景渐渐变暗
function showBackground(obj, endInt) {
    if (isIe) {
         
            obj.filters.alpha.opacity += 5;
            if (obj.filters.alpha.opacity < endInt) {
                setTimeout(function() { showBackground(obj, endInt) }, 5);
           
        
        }
    } else {
        var al = parseFloat(obj.style.opacity); al += 0.05;
        obj.style.opacity = al;
        if (al < (endInt / 100))
        { setTimeout(function() { showBackground(obj, endInt) }, 5); }
    }
}