
    /**
    * o------------------------------------------------------------------------------o
    * | This package is licensed under the Phpguru license 2008. A quick summary is  |
    * | that the code is free to use for non-commercial purposes. For commercial     |
    * | purposes of any kind there is a small license fee to pay. You can read more  |
    * | at:                                                                          |
    * |                  http://www.phpguru.org/static/license.html                  |
    * o------------------------------------------------------------------------------o
    *
    * © Copyright 2008 Richard Heyes
    */

/**
* Shows a modal dialog
* 
* @param string contentID ID of content layer to use HTML of
* @param int    width     Width of dialog
*/
__visibleDialog = null;

function ModalDialog_Show(contentID, width)
{
    /**
    * Hide all selects
    */
    if (document.all) {
        var selectObjs = document.getElementsByTagName('select');

        for (var i=0; i<selectObjs.length; ++i) {
            if (!selectObjs[i].md_nohide) {
                selectObjs[i].md_vis = selectObjs[i].style.visibility;
                selectObjs[i].style.visibility = 'hidden';
            }
        }
    }
    
    /**
    * Create the background layer if necessary
    */
    var dialogBg = document.getElementById('modalBg');
    
    if (!dialogBg) {
        var bgDiv = document.createElement('div');
        bgDiv.id = 'modalBg';
        bgDiv.className = 'modalBg';
    
        document.body.appendChild(bgDiv);
        
        var dialogBg = document.getElementById('modalBg');
    }
    
    
    /**
    * Create the shadow layer
    */
    var dialogShadow = document.getElementById('modalShadow');
    
    if (!dialogShadow) {
        var shadowDiv = document.createElement('div');
        shadowDiv.id = 'modalShadow';
        shadowDiv.className = 'modalShadow';
        
        document.body.appendChild(shadowDiv);
        
        var dialogShadow = document.getElementById('modalShadow');
    }

    // Show the dialog
    var dialog = document.getElementById(contentID);
    dialog.style.visibility = 'hidden';
    dialog.style.width = width + 'px';
    
    dialogShadow.style.visibility = 'visible';
    dialogShadow.style.width = dialog.offsetWidth + 'px';
    dialogShadow.style.height = dialog.offsetHeight + 'px';

    /**
    * Insert the header into the dialog
    */
    var dialogHeader = document.createElement('div');
    dialogHeader.id = 'dialogHeader';
    dialogHeader.className = 'modalDialogHeader';
    dialog.appendChild(dialogHeader);
    dialogHeader = document.getElementById('dialogHeader');

    Fade(dialogBg, true, null, null, 70);
    Fade(dialog, true, null, null, 100);
    Fade(dialogShadow, true, null, null, 50, 'ModalDialog_FinishFade');
    
    
    // Moz stuff
    if (!document.all) {
        dialogBg.style.width  = document.body.scrollWidth + 'px';
        dialogBg.style.height = document.body.scrollHeight + 'px';
        
        dialog.style.left = document.body.offsetWidth / 2 - width / 2 + 'px';
        dialog.style.top  = document.body.clientHeight / 2 - dialog.offsetHeight / 2 + 'px';
        
        dialogShadow.style.left = (document.body.offsetWidth / 2 - width / 2) + 4 + 'px';
        dialogShadow.style.top  = (document.body.clientHeight / 2 - dialog.offsetHeight / 2) + 4 + 'px';
        
        dialogHeader.style.width = (dialog.offsetWidth - 2) + 'px';
        dialogHeader.style.paddingTop = '5px';
    
    // IE stuff
    } else {
        dialogHeader.style.width = dialog.offsetWidth + 'px';
    }
    
    // Set visible dialog var
    __visibleDialog = contentID;
}


/**
* Closes a modal dialog
*/
function ModalDialog_Close()
{
    var dialogBg     = document.getElementById('modalBg');
    var dialog       = document.getElementById(__visibleDialog);
    var dialogShadow = document.getElementById('modalShadow');

    
    // Lose the dialog header
    dialog.removeChild(document.getElementById('dialogHeader'));

    // Hide stuff
    dialogBg.style.MozOpacity = 0;
    dialogBg.style.visibility = 'hidden';
    
    dialog.style.MozOpacity = 0;
    dialog.style.visibility = 'hidden';
    dialogShadow.style.visibility = 'hidden';
    
    
    __visibleDialog = null;
    
    /**
    * Unhide all selects
    */
    var selectObjs = document.getElementsByTagName('select');
    
    for (var i=0; i<selectObjs.length; ++i) {
        if (!selectObjs[i].md_nohide) {
            selectObjs[i].style.visibility = selectObjs[i].md_vis;
        }
    }
}

function ModalDialog_FinishFade()
{
    var shadow  = document.getElementById('modalShadow');
    var visible = document.getElementById(__visibleDialog)

    shadow.style.width = visible.offsetWidth;
    shadow.style.height = visible.offsetHeight;
    shadow.style.filter = 'Alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius=2)';
}
