//--********************************************************************-->
//--                                                                    -->
//--   Frontier Software Pty Ltd                                        -->
//--                                                                    -->
//--   File Name     : ftrlocn.js                                       -->
//--                                                                    -->
//--   History       :                                                  -->
//--   jfmngt - 26.03.02 - Created, includes old ftrimage.js.           -->
//--   008676 - 19.09.03 - Image functions altered to only pre-load once-->
//--                       and store the image globally.                -->
//--   010104 - 10.09.04 - Ensure oGlob is set correctly.               -->
//--   010063 - 17.12.04 - Opera (10062) & Mozilla (10063) supported    -->
//--   013318 - 23.10.06 - HR21 works from within an iFrame             -->
//--   010874 - 25.10.06 - Support for Opera 9 & Netscape 8             -->
//--********************************************************************-->

// *********************************************************************
var oGlob, oForm, oDict, oMenu, oSearch;

// *********************************************************************
var sMainPage = "HR21";

// *********************************************************************
// 010874 - Not required for Opera v > 7
var bOpera = false;
var agent = navigator.userAgent.toLowerCase();
if (agent.indexOf("opera 7") != -1) bOpera = true;

// *********************************************************************
// Smoothly go back to the parent window
// 010063 - Ensure that all supported browsers work within a frameset
// 013318 - Ensure that all supported browsers work within an iFrame
function locnInitial(iLevel) {
    switch (iLevel) {
        case 1:
            if (window.parent == null) {
                parent.location.replace(sMainPage + ".htm");
            } else {
                oGlob = window.parent.parent;
            }
            break;
        case 2:
            if (window.parent.opener == null) {
                parent.location.replace(sMainPage + ".htm");
            } else {
                if (bOpera) {
                    if (window.parent.opener.name == "dataFrame" || (window.parent.opener.name.indexOf("commFrame") != -1)) oGlob = window.parent.opener.parent;
                    else if (window.parent.opener.name == "vertMenu") oGlob = window.parent.opener.parent.parent;
                    else oGlob = window.parent.opener.parent.opener.parent.parent;
                }
                else {
                    if (window.opener.length > 1 && window.opener[1].name == "dataFrame") oGlob = window.opener;
                    // we're within a frameset, we need to find the top level hr21 window
                    else {
                        for (var i = 0; i < window.opener.length; i++) {
                            for (j = 0; j < window.opener[i].length; j++) {
                                if (window.opener[i].frames[j].name == "dataFrame") oGlob = window.opener[i];
                            }
                        }
                    }
                }
            }
            break;
        case 3:
            if (window.parent.opener.parent == null) {
                parent.location.replace(sMainPage + ".htm");
            } else {
                if (bOpera) {
                    if (window.parent.opener.name == "dataFrame") oGlob = window.parent.opener.parent;
                }
                else {
                    if (window.parent.opener.length > 1 && window.parent.opener[1].name == "dataFrame") oGlob = window.parent.opener;
                    // we're within a frameset, we need to find the top level hr21 window
                    else {
                        for (var i = 0; i < window.parent.opener.length; i++) {
                            for (j = 0; j < window.parent.opener[i].length; j++) {
                                if (window.parent.opener[i].frames[j].name == "dataFrame") oGlob = window.parent.opener[i];
                            }
                        }
                    }
                }
            }
            break;
        default:
            if (parent.location.href == self.location.href) {
                parent.location.replace(sMainPage + ".htm");
            } else {
                oGlob = window.parent;
            }
            break;
    }
    return;
}

// *********************************************************************
var oDisable = null;

// *********************************************************************
// Kick things off for the page here
//
function locnInitPage() {
    // Set up a variable that will be used in both switch statements
    var bPageType = oGlob.loadPageType(self.location.href);
    // Sort out various things for the particular pages
    switch (bPageType) {
        case "E":
            oDisable = oGlob.oMessWin;
            break;
        case "M":
            if (oGlob.bHorizMenu) {
                oDisable = oGlob.horizFrame;
            } else {
                oDisable = oGlob.vertFrame;
            }
            break;
        case false:
            if (oGlob.bHorizMenu) {
                if (oGlob.bHorizShort) oDisable = oGlob.horizFrame.frames.shortMenu;
                else oDisable = oGlob.horizFrame.frames.horizMenu;
            } else {
                if (oGlob.bVertShort) oDisable = oGlob.vertFrame.frames.shortMenu;
                else oDisable = oGlob.vertFrame.frames.vertMenu;
            }
            break;
        default:
            oDisable = oGlob.dataFrame;
            break;
    }
    // Set events
    if (oGlob.bDisableKeys) {
        oDisable.document.body.onkeypress = locnDisableKeys;
        oDisable.document.body.onmousedown = locnDisableMouse;
    }
    // Set background colour for certain pages
    if (oGlob.hWindowBG) {
        switch (bPageType) {
            case "E":
            case "M":
            case false:
                break;
            default:
                oDisable.document.bgColor = oGlob.hWindowBG;
                break;
        }
    }
    // Fire off the page
    switch (bPageType) {
        case "E":
        case "M":
        case false:
            initPage();
            break;
        default:
            if (oGlob.loadPageManager()) {
                oGlob.optnsLoadTable();
            }
            break;
    }
    return;
}

// *********************************************************************
// Catch Page Events
//
function locnDisableKeys() {
	if ((oDisable.event.keyCode == 78) && (oDisable.event.ctrlKey)) {
		alert("Launching a new window has been disabled");
	} else if ((oDisable.event.keyCode == 79) && (oDisable.event.ctrlKey)) {
		alert("Opening a new URL has been disabled");
	}
    return;
}

// *********************************************************************
function locnDisableMouse() {
	if (oDisable.event.button == 2) {
    	alert("Function disabled");
		return false;
	}
    return;
}

// *********************************************************************
// Preload Images
//
// 008676 obsolete variables removed
var imgName, imgSrc;
var imgArraysDone = false;      // set to true once preloading is complete

// *********************************************************************
// 008676 altered to load images into a global array - aImageArray
function locnImageCreate(aImages) {
    // Scan through and load up all the images
    if ((document.images) && (aImages) && (aImages.length != 0)) {
        // Load up those images specific to this page only
        for (var i=0; i<aImages.length; i++) {
            if (aImages[i] != null) {
                imgName = imgSrc = aImages[i];
                // Code for the occurance of two identical images on the same page
                imgSrc = oGlob.validStripUnderScore(imgName);
                // 008676 If the image doesn't exist in the aImageArray then add it
                if (!oGlob.aImageArray[imgSrc]) oGlob.loadPageImage(imgSrc);
            }
        }
    }
    imgArraysDone = true;
    return;
}   

// *********************************************************************
// args:    state - "up" or "dn"
//          imgName - imgPlace to swap
//          sMsg - msg displayed in statusline (or "" to clear it) & img alt
//
// 008676 src value references the global image array - aImageArray
function locnImageSwap(state, imgName, sMsg) {
    // set imgSrc to the value of the name of the image in aImageArray
    imgSrc = oGlob.validStripUnderScore(imgName) + "_" + state;
    // Check all images are preloaded.
    if (!imgArraysDone) return true;
    if (document.images) {
        document[imgName].src = oGlob.aImageArray[imgSrc].src;
        document[imgName].alt = sMsg;
    }
    window.status = sMsg;
    return true;
}

// *********************************************************************
// args:    state - "up" or "dn"
//          imgName - imgPlace to swap
//
// 008676 src value references the global image array - aImageArray
function locnImageList(state, imgName) {
    // set imgSrc to the value of the name of the image in aImageArray
    imgSrc = oGlob.validStripInteger(imgName) + "_" + state;
    // Check all images are preloaded.
    if (!imgArraysDone) return true;
    if (document.images) {
        // 010063 - In Netscape, the list image src gets truncated
        if (oGlob.is.nav) oGlob.loadPageImage("view");
        document[imgName].src = oGlob.aImageArray[imgSrc].src;
    }
    return true;
}

// *********************************************************************
