
/*
Disclaimer

While we make every effort to ensure that this code is fit for its intended purpose, we
make no guarantees as to its functionality. CoreTrek AS will accept no
responsibility for the loss of data or any other damage or financial loss caused by use
of this code.


Copyright

This programming code is copyright of CoreTrek AS. Permission to run this code is given to
approved users of CoreTrek's publishing system CorePublish.

This source code may not be copied, modified or otherwise repurposed for use by a third
party without the written permission of CoreTrek AS.

Contact webmaster@coretrek.com for information.

*/

function roxarTopMenuDisplayLayer(id) {
    
    submenuLayerId = "bottom-pane-" + id;
    topmenuItemId = "top-menu-item-" + id;
    
    //define variable to hold the previous layer
    if(typeof roxarTopMenuDisplayLayer.prevSubmenuLayerId == 'undefined') {
        roxarTopMenuDisplayLayer.prevSubmenuLayerId = null;
    }
    
    //define variable to hold the previous topmenu item 
    if(typeof roxarTopMenuDisplayLayer.prevTopmenuItemId == 'undefined') {
        roxarTopMenuDisplayLayer.prevTopmenuItemId = null;
    }
    
    //define variable to hold the previous topmenu item class
    if(typeof roxarTopMenuDisplayLayer.prevTopmenuItemClass == 'undefined') {
        roxarTopMenuDisplayLayer.prevTopmenuItemClass = null;
    }
    
    //alert(roxarTopMenuDisplayLayer.prevSubmenuLayerId);
    layerObj = document.getElementById(submenuLayerId);
    
    if(layerObj != null) {
        
        //hide the previous menu
        if(roxarTopMenuDisplayLayer.prevSubmenuLayerId != null) {
            hideLayer(roxarTopMenuDisplayLayer.prevSubmenuLayerId);
        }
        
        //reset the style on the previous selected top menu item
        if(roxarTopMenuDisplayLayer.prevTopmenuItemId != null) {
            topMenuItem = document.getElementById(roxarTopMenuDisplayLayer.prevTopmenuItemId);
            //alert("current: " + topMenuItem.className);
            topMenuItem.className = roxarTopMenuDisplayLayer.prevTopmenuItemClass;
            //alert("resetting to: \"" + roxarTopMenuDisplayLayer.prevTopmenuItemClass + "\"");
            //alert("after reset: " + topMenuItem.className);
        }
        
    
        roxarTopMenuDisplayLayer.prevSubmenuLayerId = submenuLayerId;
        
        //store current class so we can restore it later
        topmenuObj = document.getElementById(topmenuItemId);
        if(topmenuObj != null) {
            roxarTopMenuDisplayLayer.prevTopmenuItemId = topmenuItemId;
            roxarTopMenuDisplayLayer.prevTopmenuItemClass = topmenuObj.className;
            topmenuObj.className = topmenuObj.className + " active";
            //alert(roxarTopMenuDisplayLayer.prevTopmenuItemClass);
        }
        
        roxarTopMenuDisplayLayer.prevTopmenuItemId = topmenuItemId;
        
        //debug(submenuLayerId);
        displayLayer(submenuLayerId);
        
    
    }
}
function validateForm(formname,fields,types,aliases) {
        for (i=0;i<fields.length;i++) {

        // First, get the value out
        var elem = document.forms[formname].elements[fields[i]];
        var val = "";

        // Then switch between different form elements.
        if (elem.type == "text" || elem.type == "password" || elem.type == "checkbox") {
            val = elem.value;
        } else if (elem.type == "select-one" || elem.type == "select-multiple") {
            val = elem.options[elem.selectedIndex].value;
        }  else {
            // build on here as we need more.
            val = elem.value;
        }

        // Check whether there are any content at all
                if (val.length ==0 ) {
                        alert("The element " + aliases[i] + " is empty.");
            elem.focus();
                        return false;
                }

        // Check for valid integer.
        if(types[i]==2) {
            if (isNaN(val)) {
                                alert("The element " + aliases[i] + " is not an Integer.");
                elem.focus();
                                return false;
            }
        }
    }
    return true;
}