﻿// ----------------------------- js 文件  ---------------------------------------//


var W = screen.width; //取得屏幕分辨率宽度
var H = screen.height; //取得屏幕分辨率高度

function M(id) {
    return document.getElementById(id); //用M()方法代替document.getElementById(id)
}
function MC(t) {
    return document.createElement(t); //用MC()方法代替document.createElement(t)
};
//判断浏览器是否为IE
function isIE() {
    return (document.all && window.ActiveXObject && !window.opera) ? true : false;
}
//取得页面的高宽
function getBodySize() {
    var bodySize = [];
    with (document.documentElement) {
        bodySize[0] = (scrollWidth > clientWidth) ? scrollWidth : clientWidth; //如果滚动条的宽度大于页面的宽度，取得滚动条的宽度，否则取页面宽度
        bodySize[1] = (scrollHeight > clientHeight) ? scrollHeight : clientHeight; //如果滚动条的高度大于页面的高度，取得滚动条的高度，否则取高度
        bodySize[2] = clientHeight; //取页面高度
    }
    return bodySize;
}
//创建遮盖层
function popCoverDiv() {
    if (M("cover_div")) {
        //如果存在遮盖层，则让其显示 
        M("cover_div").style.display = 'block';
    } else {
        //否则创建遮盖层
        var coverDiv = MC('div');
        document.body.appendChild(coverDiv);
        coverDiv.id = 'cover_div';
        with (coverDiv.style) {
            position = 'absolute';
            background = '#000000';
            left = '0px';
            top = '0px';
            var bodySize = getBodySize();
            width = bodySize[0] + 'px'
            height = bodySize[1] + 'px';
            //	 width = bodySize[0] + 'px'

            zIndex = 0;
            if (isIE()) {
                filter = "Alpha(Opacity=0)"; //IE逆境
            } else {
                opacity = 0;
            }
        }
    }
}




//让登陆层显示为块 
function showpopdiv() {
    var popdiv = M("popdiv");
    popdiv.style.display = "block";
}

//设置DIV层的样式
function change() {
    var popdiv = M("popdiv");
    popdiv.style.position = "absolute";
    popdiv.style.border = "1px solid #CCCCCC";
    popdiv.style.background = "#ffffff";
    var i = 0;
    var bodySize = getBodySize();  
//    popdiv.style.left = (bodySize[0] - widthdiv) / 2 + "px";
//    popdiv.style.top = "450px";

    var re = getLT(widthdiv, heightdiv);
    popdiv.style.left = re[0] + "px";
    popdiv.style.top = re[1] + "px";

    popdiv.style.width = widthdiv + "px";
    popdiv.style.height = heightdiv + "px";

    popChange(i);
}
//让DIV层大小循环增大
function popChange(i) {
    var popdiv = M("popdiv");
    var bodySize = getBodySize();
//    popdiv.style.left = (bodySize[0] - widthdiv) / 2 + "px";
//    popdiv.style.top = "450px";
    var re = getLT(widthdiv, heightdiv); 
    popdiv.style.left = re[0] + "px";
    popdiv.style.top = re[1] + "px";

    popdiv.style.width = widthdiv + "px";
    popdiv.style.height = heightdiv + "px";
    if (i <= 10) {
        i++;
        setTimeout("popChange(" + i + ")", 10); //设置超时10毫秒
    }
}
//打开DIV层
function itsopen() {   
    change();
    showpopdiv();
    //        popCoverDiv();
    //void(0);//不进行任何操作,如：<a href="#">aaa</a>
    //		location.href = "#top";
}
//关闭DIV层
function close() {
    M('popdiv').style.display = 'none';
    //         M("cover_div").style.display = 'none';
    void (0);
}


function getLT(_w, _h) {
    var de = document.documentElement;

    // 获取当前浏览器窗口的宽度和高度  
    // 兼容写法，可兼容ie,ff  
    var w = self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
    var h = (de && de.clientHeight) || document.body.clientHeight;

    // 获取当前滚动条的位置  
    // 兼容写法，可兼容ie,ff  
    var st = (de && de.scrollTop) || document.body.scrollTop;

    var topp = 0;
    if (h > _h)
        topp = (st + (h - _h) / 2);
    else
        topp = st;

    var leftp = 0;
    if (w > _w)
        leftp = ((w - _w) / 2);

    // 左侧距，顶部距  
    return [leftp, topp];
}  


function ChangeClass(sId) {
    if (document.getElementById(sId).style.display == 'none') {
        document.getElementById(sId).style.display = "block";
    }
    else {
        document.getElementById(sId).style.display = "none";
    }
}
