﻿/*
 *lightBox类
 *
 *Author： y
 *Create At： 2009-3-13
 */
//overflowHandle("100%", "auto");
function lightBox() {
    /**
     * alert
     */
    this.alert = function(info) {
        //overflowHandle("100%", "hidden");
        var overLayer = document.createElement("<div id=\"overLayer\" />"); //创建覆盖层
        var lightBox = document.createElement("<div id=\"lightBox\" />"); //创建高亮层

        //高亮层中的元素
        lightBox.innerHTML += "<div id=\"msg\">" + info + "</div>"; //信息
        lightBox.innerHTML += "<div><input id=\"btnClose\" type=\"button\" value=\"关闭提示\" style=\"width: 100px;line-height:180%;\" /></div>"; //按钮

        var bod = document.getElementsByTagName("body")[0];
        bod.appendChild(overLayer);
        bod.appendChild(lightBox);

        overflowHandle();

        document.getElementById("btnClose").onclick = close;
    }

    /**
     * confirm
     */
    this.confirm = function(info, callback) {
        //overflowHandle("100%", "hidden");
        
        var overLayer = document.createElement("<div id=\"overLayer\" />"); //创建覆盖层
        var lightBox = document.createElement("<div id=\"lightBox\" />"); //创建高亮层
        //overLayer.style.height = document.body.clientHeight + "px";

        //高亮层中的元素
        lightBox.innerHTML += "<div id=\"msg\">" + info + "</div>"; //信息
        lightBox.innerHTML += "<div><input type=\"button\" value=\"是\" style=\"width: 100px;\"  id=\"b1\"/></div>"; //确定按钮
        lightBox.innerHTML += "<div><input type=\"button\" value=\"否\" style=\"width: 100px;\"  id=\"b2\"/></div>"; //取消按钮

        var bod = document.getElementsByTagName("body")[0];
        bod.appendChild(overLayer);
        bod.appendChild(lightBox);

        overflowHandle();
        
        document.getElementById("b1").onclick = function() {
            close();
            callback(0);
        }

        document.getElementById("b2").onclick = function() {
            close();
            callback(1);
        }
    }
    
    /**
     * 关闭窗口
     */
    function close() {
        //overflowHandle("100%", "auto");
        var overLayer = document.getElementById("overLayer");
        var lightBox = document.getElementById("lightBox");

        var bod = document.getElementsByTagName("body")[0];
        bod.removeChild(overLayer);
        bod.removeChild(lightBox);
    }

//    /*
//     * 限制浏览器高度
//     */
//    function overflowHandle(height, overflow) {
//        alert(height1);
//        var htm = document.getElementsByTagName("html")[0];
//        htm.style.height = height1;
//        //htm.style.overflow = overflow;
//        //    htm.style.margin = "0px";
//        //    htm.style.padding = "0px";

//        var bod = document.getElementsByTagName("body")[0];
//        bod.style.height = height1;
//        // bod.style.overflow = overflow;
//        //    bod.style.margin = "0px";
//        //    bod.style.padding = "0px";
    //    }

    /*
    * 限制浏览器高度
    */
    function overflowHandle() {
        var overLayer = document.getElementById("overLayer");
        overLayer.style.height = document.body.clientHeight + "px";

        var lightBox = document.getElementById("lightBox");

        if (document.documentElement.scrollTop != 0) {//有被卷起
            lightBox.style.top = window.screen.height/2 + document.documentElement.scrollTop - 150 + "px";
        } else {//没被卷起
            lightBox.style.top = window.screen.height/2 - 100 + "px";
        }
    }
}
