/*#############################################################################
#
#
#                             Dialog Class
#
#                           By:John Calabrese 
#
#                       -----------------------
#                     Tested under IE and Firefox
#                      Use this however you want.
#                         Lets call it GPL.
#
###################################################################x7x#######*/
function Dialog(initName)
{
    var headID = document.body;
    var cssNode = document.createElement('link');
    cssNode.type = 'text/css';
    cssNode.rel = 'stylesheet';
    cssNode.href = './dialog/dialog.css';
    cssNode.media = 'screen';
    headID.appendChild(cssNode);
    this.initName = initName;
    /*#########################################################
    #           Dialog Defaults
    #########################################################*/
    this.topnotset = true;
    this.leftnotset = true;
    this.modal = true;
    this.backgroundcolor = 'white';
    this.bordercolor = 'lightgrey';
    this.borderwidth = '1';
    this.bordertype = 'solid';
    this.LockColor = 'lightgrey';
    this.dialogWidth = '400';
    this.dialogHeight = '400';
    this.headercolor = 'lightgrey';
    /*#######################################################*/


    this.showDialog = function()
    {
        if( window.innerHeight && window.scrollMaxY )
        { pageWidth = window.innerWidth + window.scrollMaxX; pageHeight = window.innerHeight + window.scrollMaxY;}
        else if( document.body.scrollHeight > document.body.offsetHeight )
        { pageWidth = document.body.scrollWidth; pageHeight = document.body.scrollHeight;}
        else
        { pageWidth = document.body.offsetWidth + document.body.offsetLeft; pageHeight = document.body.offsetHeight + document.body.offsetTop; }
        var pappa = document.body;
        var dialog = document.getElementById(this.initName+"_dialog");
        var lockout = document.getElementById(this.initName+'_lockout');
        var dialog = document.createElement('div');
        dialog.setAttribute('id',this.initName+"_dialog");
        if(this.modal)
        {
            var lockout = document.createElement('div');
            lockout.setAttribute('id',this.initName+'_lockout');
            lockout.style.position = 'absolute';
            lockout.style.width = pageWidth;
            lockout.style.height = pageHeight;
            lockout.style.background=this.LockColor;
            lockout.style.top = '0px';
            lockout.style.left = '0px';
            lockout.style.zIndex = '5000';
            lockout.className = 'transparent';
            pappa.appendChild(lockout);
        }
        dialog.style.position = 'absolute';
        var browser=navigator.appName;
        if(browser == 'Microsoft Internet Explorer')
        {
            var ht = document.body.offsetHeight;
            var wt = document.body.offsetWidth;
        }else{
            var ht = screen.availHeight;
            var wt = screen.availWidth;
        }
        if(this.topnotset){this.top = document.body.scrollTop+((ht/2)-(this.dialogHeight/2));}
        if(this.leftnotset){this.left = document.body.scrollLeft+((wt/2)-(this.dialogWidth/2));}
        if(this.top<10){this.top=10};
        if(this.left<10){this.left=10};
        dialog.style.top = this.top+'px';
        dialog.style.left = this.left+'px';
        dialog.style.width = this.dialogWidth+'px';
        dialog.style.height = this.dialogHeight+'px';
        dialog.style.borderColor = this.bordercolor;
        dialog.style.borderWidth = this.borderwidth;
        dialog.style.borderStyle = this.bordertype;
        dialog.style.background = this.backgroundcolor;
        dialog.style.zIndex = '6000';
        dialog.innerHTML = '<div style="background:url(\'https://www.BnBFinder.com/admin/innTraffic/dialog/img/menu.jpg\');width:'+this.dialogWidth+'px;height:30px;"><div style="position:relative;left:5px;top:3px;text-align:center;cursor:pointer;font-weight:bold;width:25px;height:25px;" onclick=\'javascript:closeDialog("'+this.initName+'");\'><img title=\'Close This Window\' src=\'https://www.BnBFinder.com/admin/innTraffic/dialog/img/x.gif\'></div></div>';
        bodyWidth = (parseInt(this.dialogHeight)-30);
        dialog.innerHTML += '<div style="width:'+this.dialogWidth+';height:'+bodyWidth+';overflow:hidden;">'+this.dialogbody+'</div>';
        pappa.appendChild(dialog);
    }
    this.setTop = function(top)
    {
        this.top = top;
        this.topnotset = false;
    }
    this.setLeft = function(left)
    {
        this.left = left;
        this.leftnotset = false;
    }
    this.setDialogBody = function(dialogbody)
    {
        this.dialogbody = dialogbody;
    }
    this.setBorderWidth = function(width)
    {
        this.borderwidth = width;
    }
    this.setBorderType = function(type)
    {
        this.bordertype = type;
    }
    this.setHeaderColor = function(color)
    {
        this.headercolor = color;
    }
    this.setBorderColor = function(color)
    {
        this.bordercolor = color;
    }
    this.setBackgroundColor = function(color)
    {
        this.backgroundcolor = color;
    }
    this.setModal = function(modal)
    {
        this.modal = modal;
    }
    this.setWidth = function(width)
    {
        this.dialogWidth = width;
    }
    this.setHeight = function(height)
    {
        this.dialogHeight = height;
    }
    this.setLockColor = function(color)
    {
        this.LockColor = color;
    }
    this.closeDialog = function()
    {
        closeDialog(this.initName, this.modal);
    }
}
function closeDialog(initName,modal)
{
    var pappa = document.body;
    var dialog = document.getElementById(initName+"_dialog");
    if(modal)
    {
        var lockout = document.getElementById(initName+'_lockout');
        pappa.removeChild(lockout);
    }
    pappa.removeChild(dialog);
    
}