//-------------------------------------------------------------------------------------------------
var dialogXmlHttp = null;
var dialogBoxLevel = 0;
var dialogBoxUrl = new Array('');
//-------------------------------------------------------------------------------------------------
function GetDialogBox(url, evt)
{
    dialogXmlHttp = GetXmlHttpObject();
    if(dialogXmlHttp == null)
    {
        alert("No HTTP request object support. Update your browser.");
        return;
    }
    //create conteiner
    dialogBoxLevel++;    
    div = document.createElement('div');
    div.id = '__dialogBox' + dialogBoxLevel;
    div.className = 'fullScreenBox';
    div.style.height = '100%';//GetWindowHeight() + 'px';
    //check if event of the mouse is given
    if(evt === undefined)
    {
        x = GetWindowWidth() / 2;
        y = GetWindowHeight() / 2;
    }
    else
    {
        x = evt.clientX + GetScrollX();
        y = evt.clientY + GetScrollY();
    }
    if(document.body.urlErr === undefined) //put another waiting icon if no error
        div.innerHTML = '<img class = "ajaxLoad" style = "top: ' + y + 'px; left: ' + x + 'px;" src = "cms_data/ajax_load.gif"></img>';
    else document.body.urlErr = undefined; //clear error request
    document.body.appendChild(div);
    var req_url = "http_req.php?" + url;
    dialogBoxUrl[dialogBoxLevel] = url;
    dialogXmlHttp.onreadystatechange = DialogHttpRequestDone;
    dialogXmlHttp.open("GET", req_url, true); //provide request information
    dialogXmlHttp.send(null); //send request
}
//-------------------------------------------------------------------------------------------------
function RefreshDialogBox(url, evt)
{
    dialogXmlHttp = GetXmlHttpObject();
    if(dialogXmlHttp == null)
    {
        alert("No HTTP request object support. Update your browser.");
        return;
    }
    div = document.getElementById('__dialogBox' + dialogBoxLevel);
    if(!div) //no object found
    {
        div = document.getElementById('__dialogBox'); //find with no ID
        if(div)
        {
            dialogBoxLevel++;
            div.id = '__dialogBox' + dialogBoxLevel;
        }
    }
    if(div)
    {
        div.innerHTML += '<img class = "ajaxLoad" style = "top: ' + evt.clientY + 'px; left: ' + evt.clientX + 'px;" src = "cms_data/ajax_load.gif"></img>';
        var req_url = "http_req.php?" + url;
        dialogBoxUrl[dialogBoxLevel] = url;
        dialogXmlHttp.onreadystatechange = DialogHttpRequestDone;
        dialogXmlHttp.open("GET", req_url, true); //provide request information
        dialogXmlHttp.send(null); //send request
    }
}
//-------------------------------------------------------------------------------------------------
function RefreshDialogBoxOnFormUpload()
{
    dialogXmlHttp = GetXmlHttpObject();
    if(dialogXmlHttp == null)
    {
        alert("No HTTP request object support. Update your browser.");
        return;
    }
    frame = document.getElementById('__submitWindow');
    if(frame)
    {
		if(!(frame.closePrevious === undefined)) DropDialogBox();
    }
    //now chech if error was requested - we need to create higher level dialog box
    if(document.body.urlErr)
    {
        GetDialogBox(document.body.urlErr);
    }
    else
    {
        var req_url = "http_req.php?" + document.body.urlBack;
        dialogXmlHttp.onreadystatechange = DialogHttpRequestDone;
        dialogXmlHttp.open("GET", req_url, true); //provide request information
        dialogXmlHttp.send(null); //send request
    }
}
//-------------------------------------------------------------------------------------------------
function DialogHttpRequestDone()
{
    if ((dialogXmlHttp.readyState == 4) || (dialogXmlHttp.readyState == "completed")) //request finished
    {
        //delete frame for file upload if present
        frame = document.getElementById('__submitWindow');
        if(frame) document.body.removeChild(frame);        
        div = document.getElementById('__dialogBox' + dialogBoxLevel);
        div.innerHTML = dialogXmlHttp.responseText;
		div.style.height = (GetScrollY() + GetWindowHeight()) + "px";
		div.style.paddingTop = (GetScrollY() + 100) + "px";
    }
}
//-------------------------------------------------------------------------------------------------
function DropDialogBox()
{
    div = document.getElementById('__dialogBox' + dialogBoxLevel); 
    if(div)
    {
        document.body.removeChild(div);
        dialogBoxLevel--;
    }
}
//-------------------------------------------------------------------------------------------------
