myRootPath = "/livemanuals/";
rootPath=window.top.location.href.substr(0,window.top.location.href.toLowerCase().lastIndexOf('index.html'));
rootPath.length==0?rootPath=window.top.location.href:null;
((typeof(myRootPath)=='string') && (myRootPath.length != 0))?rootPath=myRootPath:null;
VsimWidth = 775;
VsimHeight = 550;
HsimWidth = 450;
HsimHeight = 700;
manualWidth = 620;
manualHeight = 620;
showLocationBar = 'no';
allowScrollBars = 'no';
showStatusBar = 'yes';
showStatusBarManual = 'no';

manOpenId = '';
simOpenId = '';

// MANUAL WINDOW FUNCTION

function openManualWindow()  {

  // DETERMINE ROOT PATH

//  rootPath=window.top.location.href.substr(0,window.top.location.href.toLowerCase().lastIndexOf('index.html'));
//  rootPath.length==0?rootPath=window.top.location.href:null;
  ((typeof(myRootPath)=='string') && (myRootPath.length != 0))?rootPath=myRootPath:null;

  // INPUT VARIABLES
  // **********************************
  // arguments[0] = Product Path
  // arguments[1] = Product ID
  // arguments[2] = Chapter
  // arguments[3] = Anchor
  // arguments[4] = Product Name
  // arguments[5] = Frame Border
  // arguments[6] = Style Sheet
  
  arguments[0] = arguments[0]?arguments[0].substr(0,5).toUpperCase():'';
  arguments[1] = arguments[1]?arguments[1]:'';
  arguments[2] = arguments[2]?arguments[2]:'';
  arguments[3] = arguments[3]?arguments[3]:'';
  arguments[4] = arguments[4]?escape(arguments[4]):'';
  arguments[5] = arguments[5]?arguments[5]:'1';
  arguments[6] = arguments[6]?arguments[6]:'0';
  
  // check to see if this is a call from the question and answer search results page
  if (((arguments[2] == null) || (arguments[2] == "")) && ((arguments[3] == null) || (arguments[3] == "")))
    qaHelp = false;
  else
    qaHelp = true;
    
  // make sure the manual window is open
  if ((window.manualHandler) && (!window.manualHandler.closed)) {
    // if the wrong product manual is in the window,
    // reload it to the correct product manual
    if (manOpenId.toLowerCase() != arguments[0].toLowerCase()) {
      window.manualHandler.close();
      window.manualHandler = window.open(rootPath + "common/loadmanual.html?prodPath=" + arguments[0].toUpperCase() + "&pid=" + arguments[1] + "&chapter=" + arguments[2] + "&anchor=" + arguments[3] + "&prodName=" + arguments[4] + "&fb=" + arguments[5] + "&ss=" + arguments[6], "manualWindow", "location=" + showLocationBar + ",height=" + manualHeight + ",width=" + manualWidth + ",toolbar=no,status=" + showStatusBarManual + ",top=0,left=0,screenx=0,screeny=0,resizable=yes,scrollbars=" + allowScrollBars);
      if (! manualHandler.opener) { manualHandler.opener = self }
      manOpenId = arguments[0];
    }
    // if it is the correct product manual, focus the window
    else {
      // load the appropriate qa help pages within the manual
      if (qaHelp) {
        theProdPath = getParameter(window.manualHandler.top.location.href.toLowerCase(), "prodpath");
        if (theProdPath != null) {
          window.manualHandler.top.TREE.document.location.href = rootPath + theProdPath.toUpperCase() + "/pkg/manual/" + arguments[2].toUpperCase() + "nav.html#" + arguments[3];
          window.manualHandler.top.WORK.document.location.href = rootPath + theProdPath.toUpperCase() + "/pkg/manual/" + arguments[2].toUpperCase() + ".html#" + arguments[3];
        }
      }
      // focus window
      manualHandler.window.focus();
    }
  }
  else {
    window.manualHandler = window.open(rootPath + "common/loadmanual.html?prodPath=" + arguments[0].toUpperCase() + "&pid=" + arguments[1] + "&chapter=" + arguments[2] + "&anchor=" + arguments[3] + "&prodName=" + arguments[4] + "&fb=" + arguments[5] + "&ss=" + arguments[6], "manualWindow", "location=" + showLocationBar + ",height=" + manualHeight + ",width=" + manualWidth + ",toolbar=no,status=" + showStatusBarManual + ",top=0,left=0,screenx=0,screeny=0,resizable=yes,scrollbars=" + allowScrollBars);
    if (! manualHandler.opener) { manualHandler.opener = self }
    manOpenId = arguments[0];
  }
}

// VERTICAL SIMULATION WINDOW FUNCTION

function openVSimWindow()  {

  // DETERMINE ROOT PATH

//  rootPath=window.top.location.href.substr(0,window.top.location.href.toLowerCase().lastIndexOf('index.html'));
//  rootPath.length==0?rootPath=window.top.location.href:null;
  ((typeof(myRootPath)=='string') && (myRootPath.length != 0))?rootPath=myRootPath:null;

  // INPUT VARIABLES
  // **********************************
  // arguments[0] = Product Path
  // arguments[1] = Product ID
  // arguments[2] = Application Name
  // arguments[3] = Scenario Name
  // arguments[4] = Scenario Number
  // arguments[5] = Product Name
  // arguments[6] = Frame Border
  // arguments[7] = Style Sheet
  
  arguments[0] = arguments[0]?arguments[0].substr(0,5).toUpperCase():'';
  arguments[1] = arguments[1]?arguments[1]:'';
  arguments[2] = arguments[2]?arguments[2]:'';
  arguments[3] = arguments[3]?arguments[3]:'';
  arguments[4] = arguments[4]?arguments[4]:'';
  arguments[5] = arguments[5]?escape(arguments[5]):'';
  arguments[6] = arguments[6]?arguments[6]:'1';
  arguments[7] = arguments[7]?arguments[7]:'0';
  
  // make sure the simulation window is open
  if ((window.VsimHandler) && (!window.VsimHandler.closed)) {
    // if the wrong product is in the window, reload it to the correct product
    if (simOpenId.toLowerCase() != arguments[0].toLowerCase()) {
      window.VsimHandler.close();      
      window.VsimHandler = window.open(rootPath + arguments[0].toUpperCase() + "/pkg/simulation/sim.html?prodPath=" + arguments[0].toUpperCase() + "&pid=" + arguments[1] + "&prodName=" + arguments[5] + "&applicationName=" + arguments[2].toLowerCase() + "&scenarioName=" + arguments[3].toLowerCase() + "&scenarioNumber=" + arguments[4] + "&fb=" + arguments[6] + "&ss=" + arguments[7], "VSimWindow", "height=" + VsimHeight + ",width=" + VsimWidth + ",toolbar=no,status=" + showStatusBar + ",location=" + showLocationBar + ",top=0,left=0,screenx=0,screeny=0,resizable=yes,scrollbars=" + allowScrollBars);
      if (! VsimHandler.opener) { VsimHandler.opener = self }
      simOpenId = arguments[0];
    }
    // if it is the correct product, load scenario if requested and focus the window
    else {
      // load scenario if requested
      if (scenarioFromManual(arguments[2], arguments[3], arguments[4])) {
        if (VsimHandler.window.nav) {
          VsimHandler.window.nav.scenarioLoader(arguments[2].toLowerCase(), arguments[3].toLowerCase(), arguments[4]);
        }
        else {
          VsimHandler.window.scenarioLoader(arguments[2].toLowerCase(), arguments[3].toLowerCase(), arguments[4]);
        }
      }
      // focus window
      VsimHandler.window.focus();
    }
  }
  // if simulation window is not open, open up a new window with
  // the proper product and url variables
  else {
    window.VsimHandler = window.open(rootPath + arguments[0].toUpperCase() + "/pkg/simulation/sim.html?prodPath=" + arguments[0].toUpperCase() + "&pid=" + arguments[1] + "&prodName=" + arguments[5] + "&applicationName=" + arguments[2].toLowerCase() + "&scenarioName=" + arguments[3].toLowerCase() + "&scenarioNumber=" + arguments[4] + "&fb=" + arguments[6] + "&ss=" + arguments[7], "VSimWindow", "height=" + VsimHeight + ",width=" + VsimWidth + ",toolbar=no,status=" + showStatusBar + ",location=" + showLocationBar + ",top=0,left=0,screenx=0,screeny=0,resizable=yes,scrollbars=" + allowScrollBars);
    if (! VsimHandler.opener) { VsimHandler.opener = self }
    simOpenId = arguments[0];
  }
}




// SCENARIO VARIABLES CHECKER

function scenarioFromManual(applicationName, scenarioName, scenarioNumber) {
  // make sure that all variables for loading scenario exist
  if ((applicationName != null) && (applicationName.length != 0)) {
    if ((scenarioName != null) && (scenarioName.length != 0)) {
      if ((scenarioNumber != null) && (scenarioNumber.length != 0)) {
        return true;
      }
    }
  }
  // one or more of the variables are missing or null
  return false;
}

// gets the value of a parameter from a URL
// URL is written in the standard query format: http://site/page?param1=value1&param2=value2&...
// returns null if the parameter was not found in the URL

function getParameter(url, name) {
    // get the parameters(query) portion of the URL
    var i = url.lastIndexOf("?");
    if(i==-1)
       return null;
    var paramStr = url.substring(i+1, url.length); // can't use substr - JavaScript 1.2+
    var params = paramStr.split("&");

    // scan all parameters for the specified parameter name
    for(i=0; i<params.length; i++) {
       var nv = params[i].split("=", 2);
       if(nv[0] == name)
          return (nv.length>1) ? nv[1] : "";
    }
    return null; // parameter was not found
}

// CLOSE ALL OPEN WINDOWS

function unload() {
  if ((window.manualHandler) && (!window.manualHandler.closed)) { window.manualHandler.close(); }
  if ((window.VsimHandler) && (!window.VsimHandler.closed)) { window.VsimHandler.close(); }
  if ((window.HsimHandler) && (!window.HsimHandler.closed)) { window.HsimHandler.close(); }
}
