getAttributeClass=function(oElement){return oElement.getAttribute('className')||oElement.getAttribute('class');};
setAttributeClass=function(oElement,sValue){oElement.setAttribute('className',sValue)/*IE*/;oElement.setAttribute('class',sValue)/*FF,NN,OP*/};

function getElementsByClassName(oElm,sTagName,sClassName)
{
	var aElements=(sTagName=="*"&&document.all)?document.all:oElm.getElementsByTagName(sTagName);
	var aReturnElements=new Array();
	sClassName=sClassName.replace(/\-/g,"\\-");
	var oRegExp=new RegExp("(^|\\s)"+sClassName+"(\\s|$)");
	var oElement;

	iPos=aElements.length;
	while(iPos--)
	{
		oElement=aElements[iPos];
		if(oRegExp.test(oElement.className))
		{
			aReturnElements[aReturnElements.length]=oElement;
		}
	}
	return (aReturnElements)
};



function readValue(oXML,sValueName)
{
    var sValue;
    
    if (browser.xml.findFirst(oXML,sValueName).firstChild)
    {
        sValue = browser.xml.findFirst(oXML,sValueName).firstChild.nodeValue;
    }
 
    return sValue;      
}


function loadValue (sName, sValue, oXML)
{
    if (document.getElementById(sName))
    {
        if (browser.xml.findFirst(oXML, sValue))
        {
            if (browser.xml.findFirst(oXML, sValue).firstChild)
            {                
                document.getElementById(sName).value = browser.xml.findFirst(oXML, sValue).firstChild.nodeValue
            }
        }
    }    
    oValidator.validateField(document.getElementById(sName));
}


function showLoading(bShow, oContent)
{
    if (document.getElementById("Loading") == null)
    {
        var	oElement = document.createElement("div");
		oElement.setAttribute("id", "Loading");
 		
 		var oHeader = document.createElement("div");
 		oHeader.setAttribute("id", "LoadingHeader");
 		oHeader.innerHTML = gsLoading;
 		
 		var oText = document.createElement("div");
 		oText.setAttribute("id", "LoadingText");
 		oText.innerHTML = gsPleaseWait;
 		
 		oElement.appendChild(oHeader);
 		oElement.appendChild(oText);
 		document.body.appendChild(oElement);
    }   
    
    if (typeof(oContent) != "object"){
        var oContent = document.getElementById("ContentTable");
    }
    var oLoading = document.getElementById("Loading");
    var oLoadingHeader = document.getElementById("LoadingHeader");
    var oLoadingText = document.getElementById("LoadingText");

    if (bShow)
    {
        oLoading.style.width = oContent.offsetWidth + "px";
        oLoading.style.height = oContent.offsetHeight + "px";
        
        oLoading.style.top = browser.gui.getAbsoluteOffsetTop(oContent) + "px";
        oLoading.style.left = browser.gui.getAbsoluteOffsetLeft(oContent) + "px";

        oLoadingHeader.style.marginLeft = oLoadingText.style.marginLeft = ((oContent.offsetWidth) / 2) + 100 + "px";
        oLoadingHeader.style.marginTop = (oContent.offsetHeight / 2) - 5 + "px";        
        
        oLoading.style.display = "block";
        if (document.getElementById("LoadingMenu")) document.getElementById("LoadingMenu").style.position = "absolute";
        if (document.getElementById("LoadingMenu")) document.getElementById("LoadingMenu").style.display = "block";
        if (document.getElementById("menu")) document.getElementById("menu").style.visibility = "hidden";
    }
    else
    {
        oLoading.style.display = "none";
        if (document.getElementById("menu")) document.getElementById("menu").style.visibility = "visible";        
        if (document.getElementById("LoadingMenu")) document.getElementById("LoadingMenu").style.position = "absolute";
        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 oTextCell = oRow.insertCell(1);
    setAttributeClass(oTextCell,"text");
    var oText = document.createTextNode(sErrorText);
    oTextCell.appendChild(oText);
 	
 	oErrorArea.appendChild(oErrorTable);
}

function clearError(sClass){
    
    var oErrorArea = document.getElementById("errorArea");
    var aErrors = getElementsByClassName(oErrorArea,"*",sClass)
    
    for(var iCount in aErrors)
    {	
        oErrorArea.removeChild(aErrors[iCount]);
    }
}
