/*******************************************************************************

  File:    history.js
  Author:  bwl
  Date:    04/13/99

  Changes Made:
    10/08/99 bwl    TB#26692 Added API functionality
    05/24/00 bwl    TB# 5361 Reference Javascript frame objects by name
    03/14/01 rghm;TB# e6605 eliminate cookies and use webregistry session
        record for cookie values. Added GetFrame and check browse function.
    04/03/01 rps; TB# e8495 Add cascading style sheets functionality
    04/25/00  jms; TB e8879 Change spelling of regestry to registry.
    06/17/02 kjg; TB e13895 new function CheckStyle for Advanced Templates
    08/26/03 kjg; TB x178 new function UpdateLink
*******************************************************************************/


// define the reference to the document object based on the browser type
if (navigator.appName == "Netscape") {
    DocRef = ".document";
}
else {
    DocRef = "";
}

/*------------------------------------------------------------------------------
  Function   :  GetFrame
  Purpose    :  Search and retrieve a frame handle based on a given frame name.
  Applies To :
  Parameter  :  fname - frame name
  Returns    :  None
------------------------------------------------------------------------------*/
function GetFrame(fname) {
   var i;
   var aux;

   aux = self;
   while (aux != top) {
      aux = aux.parent;
      for (i = 0; i < aux.length; i++)  {
         if (aux.frames[i].name == fname) {
            return aux.frames[i];
         }
      }
   }
   return self;
}

/*------------------------------------------------------------------------------
  Function   :  GetLink
  Purpose    :  Retrieve an URL from a hidden object in the hidden frame.
  Applies To :
  Parameter  :
    label - identification of the hidden object
  Returns    :  None
------------------------------------------------------------------------------*/
function GetLink(label) {

    AuxFrame = GetFrame("oldlinks");
    return eval("AuxFrame" + DocRef + ".links." + label + ".value");

}  // GetLink


/*------------------------------------------------------------------------------
  Function   :  SaveLink
  Purpose    :  Save the URL of the current document into a specific hidden
                object in the hidden frame.
  Applies To :
  Parameter  :
    label - identification of the hidden object
  Returns    :  None
------------------------------------------------------------------------------*/
function SaveLink(label) {

    var fieldPos;
    var lastSlash;
    var url = self.location.href;

    fieldPos = url.lastIndexOf("&loadtime=");
    lastSlash = url.lastIndexOf("/");
    AuxFrame = GetFrame("oldlinks");
    if (fieldPos == -1) {
       eval("AuxFrame" + DocRef + ".links." + label +".value = url.substring(lastSlash + 1, url.length)");
    }
    else {
       eval("AuxFrame" + DocRef + ".links." + label +".value = url.substring(lastSlash + 1, fieldPos)");
    }

}  // SaveLink

/*------------------------------------------------------------------------------
  Function   :  UpdateLink
  Purpose    :  Change the value for an item in the URL query string of a history item
  Applies To :
  Parameter  :  1) hdnFld  - name of hidden field in history.htm
                2) argName - name of argument in query string whose value is to be changed
                3) argVal  - new value for argument
  Returns    :  nothing

------------------------------------------------------------------------------*/

function UpdateLink(hdnFld,argName,argVal) {
    var hdnUrl = GetLink(hdnFld);
    var pos = hdnUrl.indexOf("?");
    var webObj = hdnUrl.substring(0,pos);
    var query = hdnUrl.substring(pos + 1);
    var pairs = query.split("&");
    for (var i = 0; i < pairs.length; i++) {
        pos = pairs[i].indexOf("=");
        if (pairs[i].substring(0,pos) == argName) {
            pairs[i] = argName + "=" + argVal;
        }
    }
    query = "";
    for (var i = 0; i < pairs.length; i++) {
        query += "&" + pairs[i];
    }
    hdnUrl = webObj + "?" + query.substring(1);
    AuxFrame = GetFrame("oldlinks");
    eval("AuxFrame" + DocRef + ".links." + hdnFld + ".value = hdnUrl");
}

/*------------------------------------------------------------------------------
  Function   :  CheckBrowse
  Purpose    :  Check the type of browser being used in order to select the
                appropriate style sheet.
  Applies To :
  Parameter  :
  Returns    :

------------------------------------------------------------------------------*/
// define the reference to the style sheet based on the browser type

function CheckBrowse() {
 document.writeln('<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">');

 if ((navigator.platform == "mac") && (navigator.appName == "MSIE")) {
   document.writeln('<link REL=STYLESHEET type="text/css" href="/WI_Web/css/MACie.css">');
 }
 else if ((navigator.platform == "mac") && (navigator.appName == "Netscape"))  {
   document.writeln('<link REL=STYLESHEET type="text/css" href="/WI_Web/css/MACnetscape.css">');
 }
 else {
   document.writeln('<LINK REL=STYLESHEET type="text/css" href="/WI_Web/css/pcbrowsers.css">');
 }
} //CheckBrowse


function CheckStyle() {
    document.writeln('<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">');
    document.writeln('<LINK REL=STYLESHEET type="text/css" href="/WI_Web/css/advtemplate.css">');
}
function CheckCatStyle() {
    document.writeln('<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">');
    document.writeln('<LINK REL=STYLESHEET type="text/css" href="/WI_Web/css/advcatcss.css">');
}

