// Change Log
//   Date  Developer Comments
// 20001208   RDH    Remove Codelist from fnCallPage
// 20001218   RDH    Chop off underscore and after on sessionid in fnGetCookie
// 20001229   RDH    Move fnFinBrowserVersion from finReports and into here
// 20010114   RDH    Remove DRM from fnCallPage for Dee
// 20010125   RDH    Change binary | to logical || in fnCallPage. Thanks JT
// 20010126   RDH    Remove references to domain
// 20010307   RDH    Ken changed fnFinBrowserVersion for PAP
// 20010313   RDH    Always return false for fnInit
// 20010924   RDH    change reference of login.htm to index.html for new dirs

////////////////////////////////////////////////////////////////////////
function fnMakeCookie(name, value) 
{ 
  var x1 = fnMakeCookie.arguments; 
  var x2 = fnMakeCookie.arguments.length; 
  var permDate = new Date(); 
  permDate.setTime(permDate.getTime() +  (24 * 60 * 60 * 1000 * 365));   
  var expDate = (x2 > 2) ? x1[2] : permDate; 
  var path = (x2 > 3) ? x1[3] : "/"; 
  var domain = (x2 > 4) ? x1[4] : null; 
  var secure = (x2 > 5) ? x1[5] : false; 
  var buf = name + "=" + escape (value); 
  buf += ((expDate == null) ? "": ("; expires=" + expDate.toGMTString())); 
  buf += ((path == null)    ? "": ("; path="    + path)); 
  buf += ((domain == null)  ? "": ("; domain="  + domain)); 
  buf += ((secure == true)  ? "; secure" : ""); 
  document.cookie = buf; 
}

/////////////////////////////////////////
function fnMakeSpecialCookie(name, value)
{
  var x1 = fnMakeSpecialCookie.arguments;
  var x2 = fnMakeSpecialCookie.arguments.length;
  var permDate = new Date();
  permDate.setTime(permDate.getTime() + (24 * 60 * 60 * 1000 * 365));
  var lexpDate = (x2 > 2) ? x1[2] : permDate;
  var lpath = (x2 > 3) ? x1[3] : "/";
  var ldomain = (x2 > 4) ? x1[4] : null;
  var lsecure = (x2 > 5) ? x1[5] : false;
  var buf = name + "=" + value;
  buf += ((lexpDate == null) ? "": ("; expires=" + lexpDate.toGMTString()));
  buf += ((lpath == null)    ? "": ("; path="    + lpath));
  buf += ((ldomain == null)  ? "": ("; domain="  + ldomain));
  buf += ((lsecure == true)  ? "; secure" : "");
  document.cookie = buf;
}


//////////////////////////////////
function fnGetCookie(asCookieName)
{
  // Find the proper key in the cookie
  var lsName = asCookieName + "="; 
  var liCookieSearchLen = lsName.length; 
  var liCookieLen = document.cookie.length; 
  var li = 0; 
  var lj ;
  var lsReturnValue = "" ;  // make a return value

  while ( li < liCookieLen)
  {
    lj = li + liCookieSearchLen; 
    if (document.cookie.substring(li,lj) == lsName) 
    {
      lsReturnValue = fnGetCookieValue(lj) ;
      if (asCookieName == "sessionid")
      {
        //return lsReturnValue.substring(0,9) ;
        return lsReturnValue.substring(0,lsReturnValue.indexOf("_")) ;
      }
      else
      {
        return lsReturnValue ;
      }
    }
    li = document.cookie.indexOf(" ", li) + 1; 
    if (li == 0)
    {
      break; 
    }
  }
  return null; 
}

//////////////////////////////
function fnGetCookieValue(apos)
{
  // Find the value associated with the key in the cookie
  var temp = document.cookie.indexOf(";",apos); 
  if (temp == -1) 
  {
    temp = document.cookie.length; 
  }
  return unescape(document.cookie.substring(apos,temp)); 
}

//////////////////
function fnErase()
{
  /* clear the statusbar */
  window.status="";
}

/////////////////////
function fnTrim(arg1) 
{
  var ls = "";
  ls = fnTrimLeft(arg1);
  ls = fnTrimRight(ls);
  return ls;
}

/////////////////////////
function fnTrimLeft(arg1) 
{
  var ls = "";
  var i = len = 0;
  // Return immediately if an invalid value was passed in
  if (arg1 + "" == "undefined" || arg1 == null) 
    return "";
  // Make sure the argument is a string
  arg1 += "";
  if (arg1.length == 0) 
    ls = "";
  else
  {     
    // Loop through starting at the beginning as long as there are spaces.
    len = arg1.length;
    while ((i <= len) && (arg1.charAt(i) == " "))
      i++;
    // When the loop is done, we're sitting at the first non-space char,
    // so return that char plus the remaining chars of the string.
    ls = arg1.substring(i, len);
  }
  return ls;
}

//////////////////////////
function fnTrimRight(arg1) 
{
  var ls = "";
  var i = 0;
  // Return immediately if an invalid value was passed in
  if (arg1 + "" == "undefined" || arg1 == null) 
    return "";
  // Make sure the argument is a string
  arg1 += "";
  if (arg1.length == 0) 
    ls = "";
  else
  {
    // Loop through string starting at the end as long as there are spaces.
    i = arg1.length - 1;
    while ((i >= 0) && (arg1.charAt(i) == " "))
      i--;
   // When the loop is done, we're sitting at the last non-space char,
   // so return that char plus all previous chars of the string.
   ls = arg1.substring(0, i + 1);
  }
  return ls;
}

/////////////////
function fnInit()
{ 
  // fix for summary report servlets - no more checking
  return false;
  // look for a sessionid
  var vid = document.cookie; 
  var ls = ""; 
  window.status = "Loading the form"; 
  ls = fnGetCookie("sessionid"); 
  if (ls == null || ls == "" || ls == "null") 
    return true;
  else
    return false;
}

////////////////////////////
function fnMakeDisplayDate()
{
  var ldToday = new Date();
  var ls = "";
  ls = ldToday;
  return ls;
}

////////////////////////////////
function fnBrowserVersion(asArg)
{
  if(asArg == "appName")
    return navigator.appName;
  if(asArg == "appVersion")
    return navigator.appVersion;
    
  var nn45 = ((navigator.appName == "Netscape") && 
              (parseFloat(navigator.appVersion) >= 4.5 ));
  var nn4 = ((navigator.appName == "Netscape") &&
             ((parseFloat(navigator.appVersion) >= 4.0) &&
              (parseFloat(navigator.appVersion) < 4.5 ) ) );
  var ie4 = ((navigator.appName == "Microsoft Internet Explorer") && 
             (parseInt(navigator.appVersion) >= 4 ));
  var ie5 = ((navigator.appName == "Microsoft Internet Explorer") && 
             (navigator.appVersion.indexOf("MSIE 5") != -1 ));
  if (nn4)
    return "nn4";
  else if (nn45)
    return "nn45";
  else if (ie5)
    return "ie5";
  else if (ie4)
    return "ie4";
  else
    return "0";
}

///////////////////////////////
function fnCallPage ( asCategory )
{
  var lsSessionid = fnGetCookie ( "sessionid" ) ;
  if ( lsSessionid == null || lsSessionid == "" ) 
  {
    var ls = "You cannot perform this function without first logging " ;
    ls += "into I-SITE!" ;
    alert ( ls ) ;
    window.location="/index.html" ;
    return ;
  }

  lsSessionid = "&sessionid=" + lsSessionid ;
  var lsServletUrl = "" ;
  if ( fnCallPage.arguments.length > 1 )
    lsServletUrl = "/.." ;
  var lsUsername  = "?username="  + fnGetCookie ( "username" ) ;
  var lsCategory  = "&category="  + asCategory ;
  var lsLocation = "" ;

  lsLocation = lsServletUrl ;
  lsLocation += "/cgi-bin/isitefrm.cgi" ;
  lsLocation += lsUsername + lsCategory + lsSessionid ;
  window.location = lsLocation ;
}

//////////////////////////////////////////////////
// new browser version checking code for 7.27    
function fnFinBrowserVersion ( )
{
  var lsNN;
  var lsIE;
  var lfVersion;

  if ( navigator.appName == "Netscape" )
  {
    var liLeftBrace = navigator.userAgent.indexOf( "[" ) ;

    if( liLeftBrace > 0 )  // version 4.x
    {
      var liSlash = navigator.userAgent.indexOf( "/" ) + 1 ;
      lfVersion   = parseFloat(navigator.userAgent.substring( 
                               liSlash, liLeftBrace )) ;    
    }
    if( navigator.userAgent.lastIndexOf("Netscape") > 0 ) // version 6.x
    {
      var liSlash   = navigator.userAgent.lastIndexOf( "/" ) + 1;
      lfVersion = parseFloat(navigator.userAgent.substring( 
                               liSlash, navigator.userAgent.length ));
    }
    if(isNaN( lfVersion) )
      lfVersion = 0 ;
    lsNN =  "NN" + lfVersion ;
    return lsNN;
  }

  if  ( navigator.appName == "Microsoft Internet Explorer" )
  {
    var liE = navigator.userAgent.indexOf( "MSIE " ) ;
    var liSemicolon = navigator.userAgent.indexOf( ";", liE ) ;
    lfVersion = parseFloat( 
                    navigator.userAgent.substring( liE + 4, liSemicolon ) );
    if(isNaN( lfVersion) )
      lfVersion = 0 ;
    lsIE =  "IE" + lfVersion;
    return lsIE;
  }
}