function disableElements(disable)
{
    var forms = document.forms;
    for (i = 0; i <= forms.length - 1; i++)
    {
        objects = forms[i].elements;
        objlength = objects.length;
        for (j = 0; j <= objlength - 1; j++)
        {
            objects[j].disabled = disable;
        }
    }
}  

function showDialog(url, id, width, focusObj)
{
    var xmlhttp = false;
    
    try
    {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e)
    {
        try 
        {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } 
        catch (e) 
        {
            xmlhttp = false;
        }
    }

    if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
    {
        xmlhttp = new XMLHttpRequest();
    }

    xmlhttp.open("GET", url, true);
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4)
        {
            //alert(xmlhttp.responseText);
            createDialog(id, width, xmlhttp.responseText, focusObj);
        }
    }

    xmlhttp.send(null);
}

function createDialog(id, width, content, focusObj)
{
    disableElements(true);
    
    var pageSize        = getPageSize();
    var dialogParent    = document.getElementsByTagName("BODY")[0];
    var dialogObject    = document.createElement("DIV");
    var screenX         = window.screen.width;
    var screenY         = window.screen.height;
    var boxWidth        = width;
    var actualPageWidth = 760;
    var pageHeight      = pageSize[1];
    var xPos            = ((screenX - actualPageWidth) / 2) + ((actualPageWidth - boxWidth) / 2);
    var yPos            = document.body.scrollTop + 150;
    
    //alert(yPos);
    dialogParent.appendChild(dialogObject);
    
    dialogObject.style.width  = boxWidth + 'px';
    dialogObject.style.zIndex = '1001';
    dialogObject.style.position = 'absolute';
    dialogObject.style.left   = xPos;
    dialogObject.style.top    = yPos;
    dialogObject.id           = id;
    dialogObject.innerHTML    = content;
    
    if (document.getElementById(focusObj))
    {
      // IE Rendering fix! (yes IE also needs fixs)
      document.getElementById(focusObj).focus();
      document.getElementById(focusObj).focus();
    }

    showOverlay(id);
}

function destroyDialog(id, closeOverlay)
{
    var dialogParent  = document.getElementsByTagName("BODY")[0];
    var dialogObject  = document.getElementById(id);
    
    disableElements(false);
    
    if (dialogObject)
    {
        dialogParent.removeChild(dialogObject);

        if (closeOverlay)
        {
            hideOverlay();
        }
    }
}