
    function getNavigationRequest(strNavComponent, strXMLFileName, strXSLFileName, strFunction, strWindowTarget, strSystemName,  strLinkID, strLinkType)
    {
        //prepares the html request for navigation.asp


        var strRequest = "?";
        strRequest += "SN=" + escape(strSystemName);
        strRequest += "&LINK=" + escape( strLinkID);
        strRequest += "&TYPE=" + strLinkType;
        strRequest += "&WT=" + strWindowTarget;
        strRequest += "&XML=" + strXMLFileName;
        strRequest += "&XSL=" + strXSLFileName;

        return strRequest;

    }



    function onClickModule(strModuleName, strSystemName, strMainBody)
    //-------------------------------------------
    //load left side navigation for selected top menu item
    //-------------------------------------------

    {

        if (blnIsEcom == false)
        {

            objApplications.clear();
            var strRequest = getNavigationRequest (strDefNavComponent, strDefXMLFileName, strDefXSLFileName, "", "LeftBar", strSystemName, strModuleName, "Module");
            parent.window.LeftBar.window.location.href = strServerLocation + strRequest;
        }
        else
        {
            parent.window.MainBody.window.location.href = strMainBody;
        }
    }

    function redrawLeftBar(strModuleName)
    {

        var strParameters = "";

        strParameters = "?ModuleName=" + escape( strModuleName);
        parent.window.LeftBar.window.location.href = strServerLocation + strParameters + "&FrameName=LeftBar";    //escape the argument to strip illegal characters

    }


    function onClickApplication ( strAppName, strRightBody )
    //-------------------------------------------
    //load application form (html page) associated with left side navigation item
    //-------------------------------------------
    {

          if (strRightBody != "")
        {
            if (strAppName != "")
            {

                  redirectApplicationForm (strAppName, true);
              }

              redirectRightBody (strRightBody);
          }
          else
          {
              if (strAppName != "")
            {

                  redirectApplicationForm (strAppName, false);
              }
          }

    }



    function addDataObjectToCentralStore(strKey, objDataObject)
    //-------------------------------------------
    //Repository for data objects to allow cross form data exchange
    //eg: customerID (primary,secondary keys)
    //-------------------------------------------

    {
        //TO DO: implementation
        objDataRepository[strKey] = objDataObject;

    }

    function getDataObjectFromCentralStore(strKey)
    {
        if (objDataRepository[strKey])
        {
            return objDataRepository[strKey];
        }
        else
        {
            return null;
        }

    }

    function removeObjectFromCentralStore (strKey)
    {
        if (objDataRepository[strKey])
        {
            objDataRepository[strKey] = null;
        }
        else
        {

        }
    }


    function redirectApplicationForm (strURLLocation, blnHasRight, strRightBody)
    {

        var intWidth = 0;

        //add leading slash for the sake of netscape
        strURLLocation = addLeadingSlash(strURLLocation);
        parent.window.MainBody.window.location.href = strURLLocation;

    }

    function redirectRightBody (strURLLocation)
    {
        gstrRightBody = strURLLocation;

        //add leading slash for the sake of netscape
        //strURLLocation = addLeadingSlash(strURLLocation);
        //parent.window.RightBody.window.location.href = strURLLocation;

    }

    function hideRightBody()
    {

    }

    function showRightBody(strNewLocation)
    {

    }

function getURLStrippedOfFile(strLocation)
{
//remove the last item from window.location
    var strFullPath = "";
    var urlToken = /\//;
    strFullPath = new String(strLocation);
    var objSplit = strFullPath.split(urlToken);
    strThisURL = "";
    for (var i = 0; i < (objSplit.length - 1); i++)
    {
        if (i != 0)
        {
            strThisURL = strThisURL + objSplit[i] + "/";
        }
    }

    if (isNetscape())
    {

        strThisURL = window.location.protocol + "/" + strThisURL;
    }
    else
    {
        strThisURL = window.location.protocol + "//" + strThisURL;
    }

    return strThisURL;


}

function getAppFormLocation ()
{
    if (isNetscape())
    {

    }
    else
    {
        return getURLStrippedOfFile(document.all.IFormBody.src);
    }
}
function isNetscape()
{
    //test used was obtained from Wrox Press book -> professional Javascript
    if(document.layers)
    {
        return  true;
    }
    else
    {
        return false;
    }
}

function addLeadingSlash(strURL)
{
    var strReturn = new String(strURL);
    if (strReturn.charAt(0) != "/")
    {
        strReturn = "/" + strReturn.valueOf();
    }
    return strReturn.valueOf();
}



//-----------------------------------------------------------------
//user interface event handlers
function onMouseOverTopBar()
{
    if (isNetscape() == false)
    {
        parent.window.TopBar.event.srcElement.style.color = "C67B42";
    }

}

function onMouseOutTopBar()
{
    if (isNetscape() == false)
    {
        if(parent.window.TopBar.event.srcElement.id != strSelectedModuleName)
        {
            parent.window.TopBar.event.srcElement.style.color = "white";
        }
        else
        {
            parent.window.TopBar.event.srcElement.style.color = "C67B42"
        }

    }
}

function onMouseOverLeftBar()
{
    if (isNetscape() == false)
    {
        parent.window.LeftBar.event.srcElement.style.color = "C67B42";
        parent.window.LeftBar.event.srcElement.style.textDecorationUnderline = true;
    }
}

function onMouseOutLeftBar()
{
    if (isNetscape() == false)
    {
        parent.window.LeftBar.event.srcElement.style.color = "black";
        parent.window.LeftBar.event.srcElement.style.textDecorationUnderline = false;
    }
}

function highlightModule(strModuleName)
{
    if (isNetscape() == false)
    {
        var objModule = parent.window.TopBar.document.all.item(strModuleName);
        if (objModule)
        {
            objModule.style.color = "yellow";
        }
    }
}

function onFrameLoaded (strFrameLocation)
{

}

function Modules()
{
    this.colModules = new Array();
}

function Module()
{
    this.Name = "";
    this.MainBody = "";

}


//----------------------------------
//application objects for navigation
//Applications object
function Applications()
{

    this.colApplications = new Array();
    this.addApplication = IAddApplication;
    this.getInnerHTML = IGetInnerHTML;
    this.redrawLeftBar = IRedrawLeftBar;
    this.clear = IClear;
}

function IClear()
{
    for (objProperty in this.colApplications)
    {
        delete this.colApplications[objProperty];
    }
}

function IAddApplication( strName, strLink)
{
    var objApplication = new Application(strName, strLink)
    this.colApplications[strName] = objApplication;
    return this.colApplications[strName];
}

function IRedrawLeftBar()
{
    if (isNetscape())
    {
        var strHTML = "";
        strHTML = this.getInnerHTML();
        window.parent.frames["LeftBar"].document.open();
        window.parent.frames["LeftBar"].document.write(strHTML);
        window.parent.frames["LeftBar"].document.close();
    }
    else
    {
        window.parent.frames["LeftBar"].document.all.leftBodyDiv.innerHTML = this.getInnerHTML();
    }
}

function IGetInnerHTML()
{
    var strInnerHTML = "";

    if (isNetscape())
    {
        strInnerHTML += "<html> <body class='DialogBody'>";
        strInnerHTML += "<table background=\"images/side2.jpg\" topmargin=\"0\" name=\"tblMain\" id=\"tblMain\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
        strInnerHTML += "<tr name=\"trMain\" height=\"100%\">";
        strInnerHTML += "<td id=\"TDLeftBar\"";
        strInnerHTML += " name=\"TDLeftBar\"";
        strInnerHTML += " left=\"0\" ";
        strInnerHTML += " width=\"20%\"";
        strInnerHTML += " valign=\"top\"";
        strInnerHTML += " height=\"100%\"";
        strInnerHTML += ">";
        strInnerHTML += "<div id=\"leftBodyDiv\" name=\"leftBodyDiv\">";

    }


    for (objProperty in this.colApplications)
    {

        var objApplication = this.colApplications[objProperty];
        strInnerHTML += "<img src=\"/Images/bullet.gif\" border=\"0\"/>";
        if (objApplication.mainBody.valueOf() == "")
        {
            strInnerHTML += "<a class=\"LeftNavBar\" title=\"" + objApplication.title + "\">" + objApplication.name + "</a>";
        }
        else
        {
            strInnerHTML += "<a class=\"LeftNavBar\" onmouseout=\"window.parent.Data.onMouseOutLeftBar()\" onmouseover=\"window.parent.Data.onMouseOverLeftBar()\" title=\"" + objApplication.title + "\"";
            strInnerHTML += " href=\"javascript:window.parent.Data.onClickApplication('" + objApplication.mainBody + "', '" + objApplication.rightBody + "')\">" + objApplication.name + "</a>";
        }

        for (strSubApplication in objApplication.subApplications)
        {
            var objSubApplication = objApplication.subApplications[strSubApplication];
            strInnerHTML += "<img src=\"/Images/blank12.gif\" width=\"1\" border=\"0\"/>";
            strInnerHTML += "<br></br>";
            strInnerHTML += "<span class='LeftNavSubMenu'>";
            strInnerHTML += "<img src=\"/Images/dot.gif\" border=\"0\"/>";
            strInnerHTML += "<a class=\"navigationAnchor\" onmouseout=\"window.parent.Data.onMouseOutLeftBar()\" onmouseover=\"window.parent.Data.onMouseOverLeftBar()\"";
            strInnerHTML += " title=\"" + objSubApplication.title + "\"";
            strInnerHTML += " href=\"javascript:window.parent.Data.onClickApplication('" + objSubApplication.mainBody + "','" + objSubApplication.rightBody + "')\">";
            strInnerHTML += objSubApplication.name + "</a>";
            strInnerHTML += "</span>";
        }
        strInnerHTML += "<br></br>";

    }

    if (isNetscape())
    {
        strInnerHTML += "</td>";
        strInnerHTML += "</table>";
        strInnerHTML += "</body> </html>";
    }

    return strInnerHTML;
}

//Application object
function Application(strName, strMainBody, strRightBody, strTitle)
{

    this.name = strName;
    this.mainBody = strMainBody;
    this.rightBody = strRightBody;
    this.title = strTitle;
    this.subApplications = new Array();
    this.addSubApplication = IAddSubApplication;
}

function IAddSubApplication(strName, strMainBody, strRightBody, strTitle)
{
    var objSubApplication = new SubApplication(strName, strMainBody, strRightBody, strTitle);
    this.subApplications[strName] = objSubApplication;
    return this.subApplications[strName];
}

//SubApplication object
function SubApplication(strName, strMainBody, strRightBody, strTitle)
{
    this.name = strName;
    this.mainBody = strMainBody;
    this.rightBody = strRightBody;
    this.title = strTitle;
}


function onChangeLang(strLangCode)
{
    strLangID = strLangCode;
    setCookie("LangID", strLangCode);
    strDefXMLFileName = removeExtFromFile(strBaseXMLFileName) + strLangID + "." + getFileExt(strBaseXMLFileName);
    //strDefXSLFileName = removeExtFromFile(strBaseXSLFileName) + strLangID + "." + getFileExt(strBaseXSLFileName);
    var strRequest = getNavigationRequest (strDefNavComponent, strDefXMLFileName, strDefXSLFileName, "", "TopBar", "Total Business Online", "Home", "Module");
    window.parent.TopBar.location.href = strServerLocation + strRequest;
    if (blnIsEcom)
    {
     window.parent.LeftBar.location.href = "../departments.asp";
    }
    else
    {
        var strRequest = getNavigationRequest (strDefNavComponent, strDefXMLFileName, strDefXSLFileName, "", "LeftBar", "Total Business Online", "Home", "Module");
        window.parent.LeftBar.location.href = strServerLocation + strRequest;
    }
}


function setCookie(strName, strValue)
{
    var strCookie;
    var today = new Date()
    var expires = new Date()
    expires.setTime(today.getTime() + 1000*60*60*24*365)

    strCookie = strName + "=" + escape(strValue) + "; path=/";
    strCookie = strCookie + "; expires=" + expires;
    document.cookie = strCookie;
}


function checkForLangCookie()
{
    //is called on window load
    var strLangCookie = getCookie("LangID");
    if (!strLangCookie)
    {
        strLangID = strDefLangID;
        setCookie("LangID", strLangID);
    }
    else
    {
        strLangID = strLangCookie;
    }
}

function checkForUserCookie()
{
    //is called on window load
    var strUserCookie = getCookie("UserID");
    if (!strUserCookie)
    {
        //generate a unique id for this user
        strUserID = getKeyID();
        setCookie("UserID", strUserID);
    }
    else
    {
        strUserID = strUserCookie;
    }
}

function getCookie (strName)
{
    var intBegin = 0;
    var intEnd = 0;
    var strCookieName = strName + "=";
    var objCookie = document.cookie;
    if (objCookie.length > 0)
    {
        intBegin = objCookie.indexOf(strCookieName);
            if (intBegin != -1)
            {
                intBegin += strCookieName.length;
                intEnd = objCookie.indexOf(";", intBegin);

                if (intEnd == -1)
                {
                    intEnd = objCookie.length;
                }
                return unescape(objCookie.substring(intBegin, intEnd));
            }
    }
    return null;

}

function removeExtFromFile(strFileName)
{
    return strFileName.substr(0, (strFileName.length - 4));
}

function getFileExt(strFileName)
{
    return strFileName.substr((strFileName.length - 3), 3 );
}

function onBack()
{
    var oHistory = getDataObjectFromCentralStore("BackHistoryObject");

    if (oHistory)
    {
        if (oHistory.backArray.length > 0)
        {
            var oLoc = oHistory.backArray[oHistory.backArray.length - 2];
            oHistory.back = true;
            //alert(oLoc.primaryLoc + "\n" + oLoc.secondaryLoc + "\n" + oLoc.frameName);
            parent.window.frames['MainBody'].location.href = oLoc.primaryLoc;
            oHistory.backArray.length -= 1;
            oHistory.frameLocation = oLoc.secondaryLoc;
            oHistory.frameName = oLoc.frameName;
            addDataObjectToCentralStore("BackHistoryObject", oHistory);
        }
    }

}

function onViewHistory()
{
    var sHTML = "";
    var oHistory = getDataObjectFromCentralStore("BackHistoryObject");

    if (oHistory)
    {
        if (oHistory.backArray.length > 0)
        {
            sHTML += '<table border="1" width="100%" style="font-family: arial; font-size: 8pt">';
            //sHTML += '<tr bgcolor="yellow"><td>frameLocation = "' + oHistory.frameLocation + '"</td></tr>';
            //sHTML += '<tr bgcolor="yellow"><td>frameName = "' + oHistory.frameName + '"</td></tr>';
            //sHTML += '<tr><td>&#160;</td></tr>';
            for (var i = 0; i < oHistory.backArray.length; i++)
            {
                var oLoc = oHistory.backArray[i];
                sHTML += '<tr><td>primaryLoc = "' + oLoc.primaryLoc + '"</td></tr>';  
                sHTML += '<tr><td>secondaryLoc(frameLocation) = "' + oLoc.secondaryLoc + '"</td></tr>';  
                sHTML += '<tr><td>frameName = "' + oLoc.frameName + '"</td></tr>';  
                sHTML += '<tr><td>&#160;</td></tr>';  
            }
            sHTML += '</table>';
            var oPopupWin = window.open();
            oPopupWin.document.write(sHTML);
            //parent.window.frames['MainBody'].document.write(sHTML);
        }
    }
    
}