﻿function addEvent(elem, type, handler) {
    if (!handler.$guid) handler.$guid = addEvent.guid++;
    if (!elem.events) elem.events = {};
    var handlers = elem.events[type];
    if (!handlers) {
        handlers = elem.events[type] = {};
        if (elem["on" + type]) handlers[0] = elem["on" + type];
    }
    handlers[handler.$guid] = handler;
    elem["on" + type] = handleEvent;
}
addEvent.guid = 1;
function removeEvent(elem, type, handler) {
    if (elem.events && elem.events[type]) delete elem.events[type][handler.$guid];
}
function handleEvent(event) {
    var reValue = true;
    event = event || fixEvent(window.event);
    var handlers = this.events[event.type];
    for (var i in handlers) {
        this.$handleEvent = handlers[i];
        if (this.$handleEvent(event) === false) reValue = false;
    }
    return reValue;
}
function fixEvent(event) {
    event.preventDefault = fixEvent.preventDefault;
    event.stopPropagation = fixEvent.stopPropagation;
    return event;
    fixEvent.preventDefault = function() {
        this.returnValue = false;
    }
    fixEvent.stopPropagation = function() {
        this.cancelBubblu = true;
    }
}
document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/Css/Popup.css\" />");
var markBox = {
    width : 0,
    height : 0,
    show : function(title, url, width, height, close) {
        var minW = screen.availWidth-20;
        var minH = screen.availHeight;
        var bodyW = document.body.scrollWidth;
        var bodyH = document.body.scrollHeight;
        var w = (minW>bodyW) ? minW : bodyW;
        var h = (minH>bodyH) ? minH : bodyH;
        h = h + 30;
        markBox.width = width;
        markBox.height = height;
        var div = document.createElement("DIV");
        div.id = "mark";
        var h = "<div class='mark_bg' style='width:"+w+"px;height:"+h+"px;'></div>"
            h += "<div id='mark_shadow' style='width:"+width+";height:"+(height+25)+"px;'></div>"
            h += "<div id='mark_box' style='width:"+width+"px;height:"+height+"px;'>";
            h += "<div class='mark_title_left'></div><div class='mark_title' style='width:"+(width-6)+"px;'>";
            h += "<h3 style='width:" + (width-50) + "px;'>" + title + "</h3>";
            h += close ? "<span style='float:right;padding:5px;'><img src='/Images/mark_close.gif' alt='关闭' onmousemove='this.src=\"/Images/mark_close_on.gif\"' onmouseout='this.src=\"/Images/mark_close.gif\"' onclick='markBox.close();'></span>" : "";
            h += "</div><div class='mark_title_right'></div><div class='mark_info'>";
            h += "<iframe width='100%' height='100%' scrolling='no' frameborder='0' src='"+url+"'></iframe>";
            h += "</div></div>";
        div.innerHTML = h;
        document.body.appendChild(div);
        markBox.adjust();
        addEvent(window, "resize", markBox.adjust);
        addEvent(window, "scroll", markBox.adjust);
        return false;
    },
    close : function() {
        removeEvent(window, "resize", markBox.adjust);
        removeEvent(window, "scroll", markBox.adjust);
        document.body.removeChild($("mark"));
    },
    adjust : function() {
        var w = (document.documentElement.clientWidth-markBox.width)/2 + "px";
        var h = (document.documentElement.clientHeight-markBox.height)/2 + document.documentElement.scrollTop + "px";
        var box = $("mark_box");
        box.style.top = h;
        box.style.left = w;
        var sha = $("mark_shadow");
        sha.style.left = w;
        sha.style.top = h;
    }
}