/***********************************************************************
*                                                                      *
*               Confidentiality Information:                           *
*                                                                      *
* This module is the confidential and proprietary information of       *
* PeopleSoft, Inc.; it is not to be copied, reproduced, or transmitted *
* in any form, by any means, in whole or in part, nor is it to be used *
* for any purpose other than that for which it is expressly provided   *
* without the written permission of PeopleSoft.                        *
*                                                                      *
* Copyright (c) 1988-2002 PeopleSoft, Inc.  All Rights Reserved.       *
*                                                                      *
************************************************************************/

/* Version 8.4 */

function goToDest(bookmark) {
  var jumpdest = langcode + '/' + bookmark.substring(bookmark.indexOf('||')+2,bookmark.length);
  if (f1js_debug) alert("jumping to " + jumpdest);
  window.location.replace(jumpdest);
}

function getHelpTitle(strProdCode) {
  strProdCode = strProdCode.toLowerCase();
  var strBookPath = "";
  for (var b = 0; b < helpnames.length; b++) {
        strBookPath = helpnames[b].substring(0, helpnames[b].indexOf("||")).toLowerCase();
        if (f1js_debug) alert("strBookPath=" + strBookPath);
        if (strBookPath == strProdCode) break;
  }
  if (b == helpnames.length) return "";
    else return helpnames[b].substring(helpnames[b].indexOf("||") + 2, helpnames[b].length);
}

function goToLibrary() {
  self.location.replace(oldlang + '/index.htm');
}

function goToPeopleCode() {
  self.location.replace(langcode + '/psbooks/tpcr/book.htm');
}

function writePopup(hits) {
if (f1js_debug) alert("writePopup hits.length=" + hits.length);
with ( selPop ) {
if (bFirstTry) {
  if (!bPCString) {
    document.write("<P>" + strMultipleTopics);
  } else {
    document.write("<P>" + strMultiplePCTopics);
  }
} else {
  document.write("<P>" + strPCFuzzyMatch1 + " \"<B>" + unescape(contextid) + "</B>\".  "
      + strPCFuzzyMatch2);
}
if (!bPCString) {
  document.writeln("  " + strClickTopic + "</P>");
} else {
  document.writeln(" " + strClickPCTopic
      + " <A HREF=\"JavaScript:opener.returnLink('../../" + langcode + "/psbooks/tpcr/book.htm', self)\">"
      + "PeopleCode Reference Guide.</A></P>");
}
if (bPCString) {
  //alert("writing table");
  document.writeln("<TABLE BORDER=0 WIDTH='100%' CELLSPACING=0 CELLPADDING=4><TR><TD>"
      + "<B>Term</B></TD><TD>&nbsp;&nbsp;</TD><TD WIDTH='100%'><B>Description</B></TD></TR>");
}
var strOldType = "";
var colorChg = 0.0;
var bgClr = "#FFFFFF";
for (x = 0; x < hits.length; x++) {
  if (f1js_debug) alert("hits[x]=" + hits[x]);
  colorChg ++;
  if (colorChg/2 == Math.floor(colorChg/2)) {
    bgClr = "#FFFFCC";
  } else {
    bgClr = "#FFFFFF";
  }
  localjumpdest = hits[x].substring(hits[x].indexOf("||")+2,hits[x].lastIndexOf("||"));
  if (f1js_debug) alert("localjumpdest=" + localjumpdest);
  localnewtarget = "../../" + langcode + "/" + localjumpdest;
  if (f1js_debug) alert("localnewtarget=" + localnewtarget);
  if (localjumpdest.indexOf('?')!=-1) {
    strThisCode = localjumpdest.substring(0, localjumpdest.lastIndexOf("?"));
  } else {
    strThisCode = localjumpdest.substring(0, localjumpdest.lastIndexOf("/"));
  }
  strThisCode = strThisCode.substring(0, strThisCode.lastIndexOf("/"));
  if (f1js_debug) alert("strThisCode=" + strThisCode);
  var strThisType = localjumpdest.substring(0, localjumpdest.indexOf("/"));
  if (f1js_debug) alert("strThisType=" + strThisType);
  for (t = 0; t < helptypes.length; t++) {
    if (strThisType == helptypes[t].substring(0, helptypes[t].indexOf("||"))) {
      strTypeName = helptypes[t].substring(helptypes[t].indexOf("||") + 2, helptypes[t].length);
      break;
    }
  }
  strBookName = getHelpTitle(strThisCode);
  if (f1js_debug) alert("strBookName=" + strBookName);
  if ( hits[x].substr(hits[x].length - 2, 2) != "||" ) {
    strBookName += ": " + hits[x].substring(hits[x].lastIndexOf("||") + 2, hits[x].length);
  } else if (strThisType.toLowerCase() == "wla" ) {
    var strFileName = localjumpdest.substring(localjumpdest.lastIndexOf("/") + 1, localjumpdest.lastIndexOf("."));
    while (strFileName.indexOf("_") != -1) {
      strFileName = strFileName.substr(0, 1).toUpperCase()
          + strFileName.substring(1, strFileName.indexOf("_"))
          + " " + strFileName.substr(strFileName.indexOf("_") + 1, 1).toUpperCase()
          + strFileName.substring(strFileName.indexOf("_") + 2, strFileName.length);
    }
    strBookName = strBookName + ": " + strFileName;
  }
  if (bPCString) {
    strPCTerm = hits[x].substring(0, hits[x].indexOf('__'));
    strPCDesc = hits[x].substring(hits[x].indexOf('__') + 2, hits[x].indexOf('||'));
  }
  if (!bPCString) {
    if (strOldType != strTypeName) {
      document.writeln("<P CLASS=DT>" + strTypeName + "</P>");
      strOldType = strTypeName;
      intHeight = intHeight + 38;
    }
    document.writeln("<NOBR><P CLASS=HIT><A HREF=\"JavaScript:opener.returnLink('"
        + localnewtarget + "', self)\">" + strBookName + "</A></P></NOBR>");
  } else {
    document.writeln("<TR BGCOLOR=" + bgClr + "><TD VALIGN=TOP NOWRAP><A HREF=\"JavaScript:opener.returnLink('"
        + localnewtarget + "', self)\">" + strPCTerm + "</A></TD><TD>&nbsp;&nbsp;</TD><TD VALIGN=TOP NOWRAP>"
        + strPCDesc + "</TD></TR>");
  }
}
if (bPCString) document.writeln("</TABLE>");
}
}

var bFirstTry = true;
thewholething :
if (!popupOpen) {
  if (contextid != "") {
    if (contextid == "index") goToLibrary();
    var multi = new Array(0);
    var bMultiples = false;
    var allString = "";
    var chkString = "";
    var re;
    var bmLength = bookmarks.length;
    var delimiter = "||";
    if (bPCString || bE1String) delimiter = "__";
    if (f1js_debug) alert("delimiter=" + delimiter);
    if (f1js_debug) alert("bmLength=" + bmLength);
justtheloop :
    for (i = 0; i < bmLength; i++) {
      re = new RegExp(contextid, "gi");
      allString = bookmarks[i];
      if (bPCString || (bE1String && allString.indexOf("__") >= 0)) chkString = allString.substring(0,allString.indexOf("__"));
          else chkString = allString.substring(0,allString.indexOf("||"));
      chkString = escape(chkString).toLowerCase();
      if (bE1String && allString.indexOf("__") < 0) chkString = "";
      if (chkString=="") continue justtheloop;
      if (f1js_debug) alert("chkString=" + chkString);
      var jumpdest = allString.substring(allString.indexOf('||')+2,allString.length);
      var newtarget = langcode + '/' + jumpdest;
      if (bFirstTry) {
        if (contextid.toLowerCase() == chkString) {
          if (f1js_debug) alert("found match: " + allString);
          multi[multi.length] = bookmarks[i];
          if (i < bookmarks.length - 1) {
            if (chkString == escape(bookmarks[i + 1].substring(0,bookmarks[i + 1].indexOf(delimiter))).toLowerCase()) {
              while (chkString == escape(bookmarks[i + 1].substring(0,bookmarks[i + 1].indexOf(delimiter))).toLowerCase()) {
                bMultiples = true;
                if (f1js_debug) alert("found multiple: "+ bookmarks[i + 1]);
                multi[multi.length] = bookmarks[i + 1];
                i = i + 1;
                if (i >= bookmarks.length - 1) break;
              }
            }
          }
          FoundIt = true;
          for (a = 0; a < arraycount.length; a++) {
            if (i <= arraycount[a]) {
              i = arraycount[a];
              continue justtheloop;
            }
          }
          break justtheloop;
        } else
          FoundIt = false;
      } else if (bPCString) {
        if (re.test(chkString)) {
          multi[multi.length] = bookmarks[i];
          continue justtheloop;
        } else
          FoundIt = false;
      }
      if (i == bookmarks.length - 1 && bFirstTry && bPCString && multi.length > 2) {
        bFirstTry = false;
        i = 0;
        continue justtheloop;
      }
    }
    if (f1js_debug) alert("multi.length=" + multi.length);
    if (multi.length == 1 && bFirstTry) {
      if (f1js_debug) alert("single match");
      goToDest(multi[0]);
      break thewholething;
    } else if (multi.length >= 1 && bE1String && widecontextid != "") {
      // we have multiple formID matches and a programID was passed. now we need to try and match programIDs 
      if (f1js_debug) alert("multiple matches");
      var secondaryMulti = new Array(0);
      var bm_wcid = "";
      var bm_pcid = "";
      if (f1js_debug) alert("widecontextid=" + widecontextid);
      for (var f = 0; f < multi.length; f++) {
        checkString = multi[f].substring(multi[f].indexOf("__")+2,multi[f].indexOf("||"));
        bm_wcid = checkString.substring(0,checkString.indexOf("__")).toLowerCase();
        if (f1js_debug) alert("bm_wcid=" + bm_wcid);
        if (bm_wcid == widecontextid.toLowerCase()) secondaryMulti[secondaryMulti.length] = multi[f];
      }
      if (f1js_debug) alert("secondaryMulti.length=" + secondaryMulti.length);
      if (secondaryMulti.length == 0) {
        // no matching programIDs. pass multi array to multiPopup()
        multiPopup(multi);
      } else if (secondaryMulti.length == 1) {
        // we found only one matching programID. jump to this bookmark
        goToDest(secondaryMulti[0]);
      } else if (precontextid != "") {
        // multiple programID matches and a preprogramID was passed, now try to match preprogramIDs
        var tertMulti = new Array(0);
        for (var p = 0; p < secondaryMulti.length; p++) {
          bm_pcid = secondaryMulti[p].substring(secondaryMulti[p].lastIndexOf("__")+2,secondaryMulti[p].indexOf("||")).toLowerCase();
          if (bm_pcid == precontextid.toLowerCase()) tertMulti[tertMulti.length] = secondaryMulti[p];
        }
        if (f1js_debug) alert("tertMulti.length=" + tertMulti.length);
        if (tertMulti.length == 0) {
          // no matching preprogramIDs. pass secondary array to multiPopup()
          multiPopup(secondaryMulti);
        } else if (tertMulti.length == 1) {
          // only found one matching preprogramID. jump to this bookmark
          goToDest(tertMulti[0]);
        } else {
          // multiple preprogramID matches. pass tertiary array to multiPopup()
          multiPopup(tertMulti);
        }
      } else {
        // multiple programID matches, but no preprogramID was passed. pass secondary array to multiPopup()
        multiPopup(secondaryMulti);
      }
      break thewholething;
    } else if (multi.length > 1 || (!bFirstTry && multi.length == 1)) {
      multiPopup(multi);
      break thewholething;
    }
  }
  FoundIt=false;
  if (langcode != "eng" && !bPCString && bEngInstalled ) {
    var strNewURL = "f1search.htm?ContextID=" + contextid + "&LangCD=eng&OrigLangCD=" + oldlang;
    if (bE1String) strNewURL += "&PreContextID=" + precontextid + "&WideContextID=" + widecontextid;
    self.location.replace(strNewURL);
    break thewholething;
  }
  if (window.location.search != "") {
    if (contextid != "" && bE1String && !FoundIt) {
      document.write("<P>" + strNoTopicFound + " \"<B>" + unescape(contextid) + "</B>\"  " + strWideContext + " \"<B>"
          + unescape(widecontextid) + "</B>\" " + strPreContext + " \"<B>" + unescape(precontextid) + "</B>\". ");
      if (!bPCString) document.writeln(strToViewLibrary);
          else document.writeln();

    } else if (contextid != "" && !FoundIt) {
      document.write("<P>" + strNoTopicFound + " \"<B>" + unescape(contextid) + "</B>\".  ");
      if (!bPCString) document.writeln(strToViewLibrary);
          else document.writeln();
    } else if (!FoundIt) document.writeln("<P>" + strNoF1Passed + ".  " + strToViewLibrary);
  } else top.location.replace("index.htm");
}
bLoaded = true;

