﻿function DivButton(btnID, btnText, btnEvent)
{
    this.btnID = btnID;
    this.btnText = btnText;
    this.btnEvent = btnEvent;
    this.toString = function(){
        return '<input type="button" id="' + this.btnID + '" value="' + this.btnText + '" onclick="' + this.btnEvent + '" style="margin-left:10px;" />';
    }
}

function DivCheckBox(chbID, chbText, chbValue, chbEvent)
{
    this.chbID = chbID;
    this.chbText = chbText;
    this.chbValue = chbValue;
    this.chbEvent = chbEvent;
    this.toString = function(){
        return '<input type="checkbox" id="' + this.chbID + '" value="' + this.chbValue + '" onclick="' + this.chbEvent + '" /><label for="' + this.chbID + '">' + this.chbText + '</label>';
    }
}

function DivDialog(dialogName)
{
    this.dialogName = dialogName;
    
    this.init = function(){
        var divDialogTitle = document.getElementById("divDialogTitle");
            divDialogTitle.onmousedown = function(evt){
            var divDialogMain = document.getElementById("divDialogMain");
            var ifrDialogMain = document.getElementById("ifrDialogMain");
            
            curMoveObj = divDialogMain;
            curMoveIframe = ifrDialogMain;
            if (evt) { //firefox
                pX = evt.pageX - getInt(curMoveObj.style.left);
                pY = evt.pageY - getInt(curMoveObj.style.top);
            }
            else { //ie
                pX = event.x - curMoveObj.style.pixelLeft;
                pY = event.y - curMoveObj.style.pixelTop;
            }
        }
    }
    
    this.getDivBack = function(){
        var str = '<div id="divDialogBack" style="filter:Alpha(Opacity=40);opacity:.4;background:#fff;z-index:999;position:absolute;left:0px;top:0px;"></div>';
        return str;
    }

    this.getIframe = function(){
        var str = '<iframe id="ifrDialogMain" style="filter:Alpha(Opacity=0);opacity:0;position:absolute;display:none;"></iframe>';
        return str;
    }

    this.getDialog = function(){
        var str = "";
        str += this.getDivBack();
        str += this.getIframe();
        str += '<div id="divDialogMain" style="position:absolute;z-index:1000;display:none;">';
        str += '<table cellpadding="0" cellspacing="0" style="width:100%;" id="divDialogTitle">';
        str += '    <tr>';
        str += '        <td style="background:url(http://images.hr33.com/image/dialog/dia_t_l.gif);width:5px;height:30px;"></td>';
        str += '        <td style="background:url(http://images.hr33.com/image/dialog/dia_t_c.gif);" valign="top"><div id="divTitleText" style="float:left;color:#ffffff;font-weight:bold;font-size:14px;padding:6px;"></div><div style="float:right;" id="divDialogCloseBtn"><a href="javascript:void(0);" onmousedown="' + dialogName + '.close()"><img src="http://images.hr33.com/image/dialog/dia_close.gif" style="border:0px;" /></a></div></td>';
        str += '        <td style="background:url(http://images.hr33.com/image/dialog/dia_t_r.gif);width:6px;height:30px;"></td>';
        str += '    </tr>';
        str += '</table>';
        str += '<table cellpadding="0" cellspacing="0" style="width:100%;">';
        str += '    <tr>';
        str += '        <td style="background:url(http://images.hr33.com/image/dialog/dia_m_l.gif);width:5px;"></td>';
        str += '        <td id="divContentText" align="center" style="font-size:12px; padding:8px 8px 8px 5px; background-color:#ffffff;">';
        str += '        </td>';
        str += '        <td style="background:url(http://images.hr33.com/image/dialog/dia_m_r.gif);width:6px;"></td>';
        str += '    </tr>';
        str += '    <tr>';
        str += '        <td style="background:url(http://images.hr33.com/image/dialog/dia_b_l.gif);width:5px;height:6px;"></td>';
        str += '        <td style="background:url(http://images.hr33.com/image/dialog/dia_b_c.gif);height:6px;"></td>';
        str += '        <td style="background:url(http://images.hr33.com/image/dialog/dia_b_r.gif);width:6px;height:6px;"></td>';
        str += '    </tr>';
        str += '</table>';
        str += '</div>';
        return str;
    }
    
    this.toString = function(){
        return this.getDialog();
    }

    this.close = function()
    {
        var divDialogBack = document.getElementById("divDialogBack");
        var divDialogMain = document.getElementById("divDialogMain");
        var ifrDialogMain = document.getElementById("ifrDialogMain");

        divDialogBack.style.display = "none";
        divDialogMain.style.display = "none";
        ifrDialogMain.style.display = "none";
    }

    this.show = function(title, content, width, height){
        //设置默认值
        if(title == null) title = "&nbsp;";
        if(content == null) content = "&nbsp;";
        if(width == null) width = 400;
        if(height == null) height = 250;

        var divDialogBack = document.getElementById("divDialogBack");
        var divDialogMain = document.getElementById("divDialogMain");
        var divTitleText = document.getElementById("divTitleText");
        var divContentText = document.getElementById("divContentText");
        var divDialogTitle = document.getElementById("divDialogTitle");
        var ifrDialogMain = document.getElementById("ifrDialogMain");
        
        divDialogBack.style.width = document.documentElement.clientWidth + "px";
        divDialogBack.style.height = document.documentElement.scrollHeight + "px";
        //if(getInt(divDialogBack.style.height) < 768) divDialogBack.style.height = "768px";
        divDialogBack.style.display = "";

        divContentText.height = (height - 55) + "px";
        divContentText.innerHTML = content;
        divTitleText.innerHTML = title;

        divDialogMain.style.width = width + "px";
        divDialogMain.style.height = height + "px";
        divDialogMain.style.left = ((document.documentElement.clientWidth - width) / 2) + "px";
        var sTop = document.body.scrollTop || document.documentElement.scrollTop;
        divDialogMain.style.top = ((screen.availHeight - height) / 2 + sTop - 100) + "px";
        divDialogMain.style.display = "";
        
        ifrDialogMain.style.width = width + "px";
        ifrDialogMain.style.height = height + "px";
        ifrDialogMain.style.display = "";
    }

    this.getYesNoButton = function(btnYesEvent, btnNoEvent) {
        var btnYesNo = new Array();
        btnYesNo[0] = new DivButton("btnYes", "　是　", btnYesEvent);
        btnYesNo[1] = new DivButton("btnNo", "　否　", btnNoEvent);
        return btnYesNo;
    }

    this.getOKCancelButton = function(btnOKEvent, btnCancelEvent) {
        var btnOKCancel = new Array();
        btnOKCancel[0] = new DivButton("btnOK", " 确定 ", btnOKEvent);
        btnOKCancel[1] = new DivButton("btnCancel", " 取消 ", btnCancelEvent);
        return btnOKCancel;
    }

    this.getOKButton = function(btnOKEvent) {
        var btnOK = new Array();
        btnOK[0] = new DivButton("btnOK", " 确定 ", btnOKEvent);
        return btnOK;
    }

    this.showAlert = function(title, content, width, height, isClose){
        if(isClose == null) isClose = true;
    
        var divDialogCloseBtn = document.getElementById("divDialogCloseBtn");
        if(isClose) divDialogCloseBtn.style.display = "";
        else divDialogCloseBtn.style.display = "none";
        
        this.show(title, content, width, height);
    }

    this.showConfirm = function(title, content, width, height, arrButton){
        var str = "";
        for(var i=0;i<arrButton.length;i++){
            str += arrButton[i];
        }
        content += '<div style="text-align:center; margin-top:20px;">' + str + '</div>';
        var divDialogCloseBtn = document.getElementById("divDialogCloseBtn");
        divDialogCloseBtn.style.display = "";
        this.show(title, content, width, height);
    }

    this.showIframe = function(title, url, width, height, scrolling) {
        if (scrolling == null) scrolling = false;
        var content = '<iframe frameborder="0" scrolling="' + (scrolling ? 'yes' : 'no') + '" src="' + url + '" style="width:100%;height:' + (height - 55) + 'px;"></iframe>';
        var divDialogCloseBtn = document.getElementById("divDialogCloseBtn");
        divDialogCloseBtn.style.display = "";
        this.show(title, content, width, height);
    }
}

var divDialog = new DivDialog("divDialog");
document.write(divDialog);
divDialog.init();