// Place the following script tag at the top of each .jsp or .htm page //////
// <script language="JavaScript1.2" SRC="/getit/js/globals.js"></script> ////
// Author: John Rutherford Peregrine Systems, Inc. 3/22/2000 ////////////////


/**
  * Global variables Used in any function
  */
var _version = parseInt(navigator.appVersion);
var isNS = (navigator.appName=="Netscape" && _version>=4);
var isNS4 = (navigator.appName=="Netscape" && _version==4);
var isNS5 = (navigator.appName=="Netscape" && _version==5);
var isIE = (navigator.appName=="Microsoft Internet Explorer" && _version>=4);
var isIE4 = (navigator.userAgent.indexOf('MSIE 4')>0);
var isIE5 = (navigator.userAgent.indexOf('MSIE 5')>0);

var linkSelected = null;
var selectedHeader = "";
/**
  * Global function to show mesages in the browser's status bar
  */

function displayStatusMsg(msgStr) { window.status=msgStr; return true; }




/**
 * INPUT BOX VALUE SET BY IMAGE EVENT
 */
function spinner(inputText, iChange) {
 var d = eval("document.forms[0]." + inputText);
 var i = d.value - 0;  // convert to a number
 iChange = iChange - 0; // make sure we are a number
 if (isNaN(i))  i = 0;// not a number, start at zippity doo da
 d.value = Math.max(i + iChange, 0); // not less than zero
}


/**
 * IE ONLY - Client side function that sets the selected module link
 * ALL OTHERS - Call AppHead.jsp to set the selected header module.
 */
function setSelectedModule( strName )
{
  if (isIE)
  {
    var i; var headerLinks = document.links; var iMax = headerLinks.length;
    for ( i = 0; i != iMax; i++ ) 
    {
      if ( headerLinks[i].id == strName )
        headerLinks[i].parentElement.className="SelectedHeaderMenu";
      else if ( headerLinks[i].id != "" )
        headerLinks[i].parentElement.className="HeaderMenu";
    }
  }
  else if( top.getit_header && selectedHeader != strName )
  {
    selectedHeader = strName;
    top.getit_header.location="apphead.jsp?SelectedHeader="+strName;
  }
}

/**
 * IE ONLY - Client side function called when a module link is clicked 
 */
function onModuleClick(linkClicked){ 
if (!isNS){ 
  if ( linkSelected != null )
    linkSelected.parentElement.className="HeaderMenu";
  linkSelected = linkClicked;
  linkSelected.parentElement.className="SelectedHeaderMenu";
  return true;}
else return;     
  }

/**
 * IE - ONLY Client side function called when a module link moved over 
 */
function onModuleOver(linkOver){ 
if (!isNS){
  if (linkOver.parentElement.className != "SelectedHeaderMenu")
    linkOver.parentElement.className="ActiveHeaderMenu"; return true;}
else return;
  }

/**
 * IE ONLY - Client side function called when a module link moved out of 
 */
function onModuleOut(linkOut){ 
if (!isNS){
  if (linkOut.parentElement.className != "SelectedHeaderMenu")
    linkOut.parentElement.className="HeaderMenu"; return true;}
else return;      
  }

/**
 * Client function to refresh the header when access rights change 
 */
function refresh(strAccess)
{
  if ( document.f != null &&  document.f.access != null )
    if (document.f.access.value != strAccess)
    {
      location.reload(true);
      if( top.frames.framesep != null )
        top.frames.framesep.location.reload(true);
    }
}


/**
 * IE ONLY - Client side function called when a module menu link is clicked
 */
function onMenuClick(linkClicked){
  if (parent.getit_header != null)
    if (parent.getit_header.setSelectedModule != null)
      parent.getit_header.setSelectedModule(linkClicked.name);
  return true;}

/*
* Used by Weblication links to submit form data to alternative destinations
*/
/*
* Used by Weblication links to submit form data to alternative destinations
*/
function trySubmit( sDestination, sSubmit, sTarget )
{
  if( sSubmit == "true" &&
       self.document != null &&
       self.document.forms != null )
  {
    var f = self.document.forms[0];
    if ( f != null )
    {
      // If sDestination contains a ? param, pass it as a form field
      var i = sDestination.lastIndexOf( "?", sDestination.length );
      if ( i >= 0 )
      {
        var sParam = sDestination.substring( i+1, sDestination.length );
        sDestination = sDestination.substring( 0, i );

        i = sParam.lastIndexOf( "=", sParam.length );
        if ( i >=0 )
        {
          var sName = sParam.substring( 0, i );
          var sValue = sParam.substring( i+1, sParam.length );

          // Pass this new param using the __x hidden field found in all of our forms
          f.__x.value = sValue;
          f.__x.name= sName;
        }
      }

      // Submit the form
      f.action = sDestination;
      f.submit( "GET" );
      return;
    }
  }
  if( sTarget && sTarget != "" )
  {
    var frame = top.frames.getit_main.frames[sTarget];
    if( frame != null )    
    {
      frame.location.href=sDestination;
      return;
    }
  }
  location.href= sDestination;
}
 
 
/*
* Used to create a pop-up window
*/  
function popUpWindow( filename , title , windowHeight , windowWidth , scroll, options) 
{
  var ScrollBar = 0;
  if (scroll == "yes" || scroll == "Yes")
    ScrollBar = 1;
  var features = "alwaysRaised=1,scrollbars=" + ScrollBar + ",width=" + windowWidth + ",height=" + windowHeight
  if ( options != " " )
  {
    var strChopList = options.split( ",");
    var strOptions = "?";
    for (count = 0 ; count < strChopList.length; count++ )
    {
      strOptions = strOptions + "&" + strChopList[ count ];
    } 
  }else
	strOptions = "";
  var theWin=window.open(filename + strOptions, "title", features);
}


/** 
 *   Client side array of functions to test for work to be done
 *   before we head for home.
 */
var homeInvokeArray = new Array();
function invokeOnHome(invokeFunc)
{
  var i;
  for( i = 0; i < homeInvokeArray.length; ++i )
  {
    if( homeInvokeArray[i] == "" )
    {
      homeInvokeArray[i] = invokeFunc;
      break;
    }
  }
  if( i == homeInvokeArray.length )
    homeInvokeArray[i] = invokeFunc;
}

/**
 *   Remove an item from the homeInvokeArray
 */
function removeInvokeOnHome(invokeFunc)
{
  if( homeInvokeArray.length > 0 )
  {
    var i;
    for( i = 0; i < homeInvokeArray.length; ++i )
    {
      if( homeInvokeArray[i] == invokeFunc )
      {
        homeInvokeArray[i] = "";
        break;
      }
    }
  }
}

/*
* Used with the ""HOME""  btn in forms to return to the home page
*/  
function onHome()
{
  if( homeInvokeArray.length > 0 )
  {
    var i;
    for( i = 0; i < homeInvokeArray.length; ++i )
    {
      if( homeInvokeArray[i] != "" )
        eval( homeInvokeArray[i] );
    }
  }
  if( top.getit_main != null )
    top.getit_main.location.href = top._HomePage;
  else
    top.location.href= top._HomePage;
}

/*
* Used with the ""HOME""  btn in forms to return to the home page
*/  
function onLogout()
{
  if( top.getit_main != null )
    top.getit_main.location.href = top._LogoutPage;
  else
    top.location.href= top._LogoutPage;
}



/**
 * Used to check if a selection box has been selected - part of form validation 
 */
function checkSelect(e) 
{
  var i = e.selectedIndex;
  var sText = e.options[i].text;
  if(sText=="" && e.options[0].selected)
  { 
    return false 
  }
  else
  {
    return true
  }
}

/**
 *  Set the value of a selection box to the given value.  Return false if value
 *  not found in set of options.
 */
function setSelect(e,value)
{
  for( var i=0; i < e.length; ++i )
  {
    var sText = e.options[i].text;
    if( sText==value)
    {
      e.selectedIndex=i;
      return true;
    }
  }
  return false;
}

/**
 *  Calls a server side javascript function 
 */
function postBackChannel(msg)
{
  if(top.backchannel)
    top.backchannel.location.replace("/servlet/archway?"+msg);
}

/**
 *  Calls a server side javascript function 
 */
function simpleLivePublishQuery(strQ)
{
  location.replace("http://getanswer/lpBin20/lpext.dll?f=hitlist&t=main-hit-h.htm&x=Simple&v=2.0&s=Relevance-Weight&m=100&n=25&a=Title-Path&h1=Hit[Hit,10]&h2=Relevance-Weight[Rank,5]&h3=Title-Path[Document,85]&q=" + strQ);
}


