﻿function $(obj) {
    return document.getElementById(obj);
}

function ThickBoxDiv(width, height, title, body) {
    width = width > 0 ? width : 0;
    height = height > 0 ? height : 0;

    var winWidth = document.documentElement.clientWidth;
    var winHeight = document.documentElement.clientHeight > document.documentElement.scrollHeight ? document.documentElement.clientHeight : document.documentElement.scrollHeight;

    var sBG = '\
		<div id="thickBoxBG" style="position:absolute; z-index:1998; filter:alpha(opacity=50); top:0px;left:0px;width:' + winWidth + 'px;height:' + winHeight + 'px;">\
		<iframe style="position: absolute; z-index: 1997; width: ' + winWidth + 'px; height: ' + winHeight + 'px; left: 0px;" frameborder="0" marginheight="0" marginwidth="0"></iframe>\
		<div style="position:absolute; z-index:1999; filter:alpha(opacity=50); background-color:#555; top:0px;left:0px;width:' + winWidth + 'px;height:' + winHeight + 'px;"></div>\
		</div>\
	';

    var top = document.documentElement.clientHeight > height ? ((document.documentElement.clientHeight - height) / 2) + document.documentElement.scrollTop : 50 + document.documentElement.scrollTop;

    //<div style="position:absolute; z-index:2000; top:' + (80 + document.documentElement.scrollTop) + 'px; width:100%;">\
    var sBox = '\
	    <div style="position:absolute; z-index:2000; top:' + top + 'px; width:100%;">\
	    <div id="thickBoxBody" style="margin:auto; text-align:center; width:' + width + 'px; height:' + height + '; background-color:#ececec; border:3px solid #666;">\
	    \
	    <div id="thickBoxTitle" style="margin:1px; padding:5px; background-color:#999; color:#fff;">\
	    <div style="float:left; font-weight:bold;">' + title + '</div><div style="float:right; padding-top:3px;">\
	    <a href="javascript:DelThickBox()" style="text-decoration:none; font-size:12px; color:#fff;">关闭</a></div><div style="clear:both"></div></div>\
	    \
	    ' + body + '\
	    \
	    </div>\
	    </div>';

    this.init = function() {
        $('dialogCase') ? $('dialogCase').parentNode.removeChild($('dialogCase')) : function() { };
        var oDiv = document.createElement('span');
        oDiv.id = "dialogCase";

        oDiv.innerHTML = '<div id="thickBoxDiv">' + sBG + sBox + '</div>';
        document.body.appendChild(oDiv);
    }
}

function ThickBox(width, height, title, body) {
    var thickBox = new ThickBoxDiv(width, height, title, body);
    thickBox.init();
}

function DelThickBox() {
    $('thickBoxDiv').style.display = 'none';
}

function DelThickBoxLoad() {
    window.location.reload();
    $('thickBoxDiv').style.display = 'none';
}

var HTMLDocType = "HTML";
if (document.documentElement.clientHeight > 0) {
    HTMLDocType = "XHTML"
}

function curostx(obj) {
    obj.style.cursor = "move";
    return false;
}
var DarwIsMove = false;
var DarwMoveDivX_ = 0;
var DarwMoveDivY_ = 0;
function Darw_StartDrag(obj, evt) {
    var tmpScroolLeft = 0;
    var tmpScroolTop = 0;
    if (HTMLDocType == "XHTML") {
        tmpScroolLeft = document.documentElement.scrollLeft;
        tmpScroolTop = document.documentElement.scrollTop;
    }
    else {
        tmpScroolLeft = document.body.scrollLeft;
        tmpScroolTop = document.body.scrollTop;
    }
    if (evt.button == 1 || evt.button == 0) {
        obj.style.cursor = "move";

        DarwMoveDivX_ = evt.clientX - (obj.parentNode.parentNode.offsetLeft - tmpScroolLeft);
        DarwMoveDivY_ = evt.clientY - (obj.parentNode.parentNode.offsetTop - tmpScroolTop);

        if (document.all)
            obj.setCapture();
        DarwIsMove = true;
    }
}

function Darw_Drag(obj, evt) {
    if (DarwIsMove) {

        var oldwin = obj.parentNode.parentNode;

        var tmpScroolLeft = 0;
        var tmpScroolTop = 0;
        if (HTMLDocType == "XHTML") {
            tmpScroolLeft = document.documentElement.scrollLeft;
            tmpScroolTop = document.documentElement.scrollTop;
        }
        else {
            tmpScroolLeft = document.body.scrollLeft;
            tmpScroolTop = document.body.scrollTop;
        }

        var x, y;
        if (!document.all) {
            evt = evt || window.event;
            x = tmpScroolLeft + evt.clientX;
            y = tmpScroolTop + evt.clientY;
        }
        else {
            x = tmpScroolLeft + event.clientX;
            y = tmpScroolTop + event.clientY;
        }

        oldwin.style.top = (y - DarwMoveDivY_) + "px";
        oldwin.style.left = (x - DarwMoveDivX_) + "px";

    }
}

function Darw_StopDrag(obj) {
    if (document.all)
        obj.releaseCapture();
    DarwIsMove = false;
}

