
/*
Called to display or hide the loading overlay.

Params:
    bShow       If true the loading overlay is displayed, else it is hidden.
    eContent    Reference to the element over which the overlay should be 
                shown (if not given the element with the id "ContentTable" is
                used)
*/
function showLoading(bShow, eContent){
	var iCorrectionTop = 0;
	var iCorrectionLeft = 0;

    //  Create loading elements if not already available
    if (document.getElementById("Loading") == null)    {
        var	eElement = document.createElement("div");
		eElement.setAttribute("id", "Loading");
 		
 		var eHeader = document.createElement("div");
 		eHeader.setAttribute("id", "LoadingHeader");
 		eHeader.innerHTML = gsLoading;
 		
 		var eText = document.createElement("div");
 		eText.setAttribute("id", "LoadingText");
 		eText.innerHTML = gsPleaseWait;
 		
 		eElement.appendChild(eHeader);
 		eElement.appendChild(eText);
 		document.body.appendChild(eElement);
    }   
    
    //  Use the element with id "ContentTable" if no other given
    if (typeof(eContent) != "object"){
        var eContent = document.getElementById("ContentTable");
    } else {
		iCorrectionTop = document.getElementById("html").scrollTop;
		iCorrectionLeft = document.getElementById("html").scrollLeft;
	}
    //  Find the references
    var eLoading = document.getElementById("Loading");
    var eLoadingHeader = document.getElementById("LoadingHeader");
    var eLoadingText = document.getElementById("LoadingText");
    
    //  Display or hide the overlay loading thingy
    if (bShow){
        eLoading.style.width = eContent.offsetWidth + "px";
        eLoading.style.height = eContent.offsetHeight + "px";
        
        eLoading.style.top = browser.gui.getAbsoluteOffsetTop(eContent) + iCorrectionTop + "px";
        eLoading.style.left = browser.gui.getAbsoluteOffsetLeft(eContent) + iCorrectionLeft + "px";

        eLoadingHeader.style.marginLeft = eLoadingText.style.marginLeft = ((eContent.offsetWidth) / 2) + 100 + "px";
        eLoadingHeader.style.marginTop = (eContent.offsetHeight / 2) - 5 + "px";        
        
        eLoading.style.display = "block";
        if (document.getElementById("LoadingMenu")) document.getElementById("LoadingMenu").style.display = "block";
        if (document.getElementById("menu")) document.getElementById("menu").style.display = "none";
    }else{
        eLoading.style.display = "none";
        if (document.getElementById("menu")) document.getElementById("menu").style.display = "";        
        if (document.getElementById("LoadingMenu")) document.getElementById("LoadingMenu").style.display = "none";
        
    }
    
}


function showError(sErrorText,sClass){
    var oErrorArea = document.getElementById("errorArea");
    
    var	oErrorTable = document.createElement("table");
    setAttributeClass(oErrorTable,"errorTable " + sClass);
    oErrorTable.setAttribute("cellspacing","0");
    oErrorTable.setAttribute("cellpadding","0");
 	oErrorTable.cellPadding="0";
 	oErrorTable.cellSpacing="0";
    
    //Error row
    var oRow = oErrorTable.insertRow(0);
    
    var oIconCell = oRow.insertCell(0);
    setAttributeClass(oIconCell,"icon");
    var oIcon = document.createElement("img");
    oIcon.src = "images/error.gif"
    oIconCell.appendChild(oIcon);
    
    
    var eTextCell = oRow.insertCell(1);
    setAttributeClass(eTextCell,"text");
    var eText = document.createTextNode(sErrorText);
    eTextCell.appendChild(eText);
 	
 	oErrorArea.appendChild(oErrorTable);
}

function clearError(sClass){
    
    var oErrorArea = document.getElementById("errorArea");
    var aErrors = browser.dom.getElementsByClassName(oErrorArea,"*",sClass)
    
    for(var iCount in aErrors)
    {	
        oErrorArea.removeChild(aErrors[iCount]);
    }
}
