//
//  Copyright (c) 1999, 2000 Oracle Corporation.  All rights reserved.
//
//  NAME
//       browser.js.
//  FUNCTION
//       JavaScripts for use with the WebDiscoverer HTML pages.
//
//  NOTES
//
//  MODIFIED
//    msaranga - 03 Jul 02 - Fox bug #2249127 modified doNotRedirect() method.
//    msaranga - 10 Jun 02 - Fix bug #2407794. With JInitiator 1.3.x onwards plugins[i].name
//                           not returning version number, so using plugins[i].description.
//    msaranga - 25 Jan 02 - fix bug #2184199: IE plug-in detect workaround.
//    rbchen   - 01 May 01 - fix bug #1585260:  do not redirect if FrameDisplayStyle=download
//    rbchen   - 24 Oct 00 - added getURLPath(): strip off the filename portion from
//                           the URL and return the URL path
//    rbchen   - 16-Oct-00 - don't need to append if the URL is ended with ? in
//                           the function passUrlParams
//    kbaldwin - 15 Jun 00 - added hasMRJ()
//    kbaldwin - 03 Dec 99 - added hasSeparateFrameDisplayStyle(), updated copyright
//    kbaldwin - 13 Dec 99 - fix hasJInitiator() by indexing array from 0
//    kbaldwin - 03 Dec 99 - added hasUrlParameters()
//                           added solaris detection
//    kbaldwin - 30 Nov 99 - Changed doNotRedirect() to detect ? only
//                         - Added redirect()
//                         - Added passUrlParams()
//    kbaldwin - 17 Nov 99 - Added doNotRedirect()
//    kbaldwin - 12 Nov 99 - Added hasJInitiator()
//    kbaldwin - 05 Nov 99 - Creation


function getBrowser()
{
  var name = navigator.appName.toLowerCase();
  var version = navigator.appVersion.toLowerCase();

  if (version.indexOf("sunos")>-1)
  {
    return "sol";
  }
  else if (name.indexOf("netscape")>-1)
  {
    return "nn";
  }
  else if (name.indexOf("microsoft internet explorer")>-1)
  {
    return "ie";
  }

  return "";
}

function hasJInitiator(version)
{
  if( getBrowser() == "ie" )
    return true;
  for (var i = 0; i < navigator.plugins.length; i++)
  {
    if (navigator.plugins[i].name.indexOf("Oracle") >= 0 &&
        navigator.plugins[i].description.indexOf("JInitiator") >= 0 &&
        navigator.plugins[i].description.indexOf(version) >= 0)
    {
      return(true);   //  Netscape with the plugin
    }
  }
  return false;
}

function hasMRJ(version)
{
  // assume MRJ is not available
  return false;
}

function getBrowserVersion()
{
  var version = navigator.appVersion;
  return version;
}

//rbchen - fix bug#1585260: also not to redirect is the URL contains FrameDisplayStyle=download
function doNotRedirect()
{
  return(!redirect(document.URL) || document.URL.indexOf("FrameDisplayStyle=download") != -1 || document.URL.indexOf("doNotRedirect=yes") != -1);
}

function redirect(url)
{
  return(url.indexOf("?") != url.length-1);
}

// takes the url parameters from paramUrl and
// appends them to nextUrl and returns the resulting
// url string
// rbchen:  don't need to append if the URL is ended with ?
function passUrlParams(paramUrl, nextUrl)
{
  if ( (paramUrl.indexOf("?")== -1) || (paramUrl.indexOf("?") == paramUrl.length-1) )
  {
    return nextUrl;
  }

  return nextUrl + paramUrl.substring(paramUrl.indexOf("?"), paramUrl.length);
}

function passUrlParamsLink(paramUrl, nextUrl, text)
{
  document.write('<a href="' + passUrlParams(paramUrl, nextUrl) + '">');
  document.write(text + '</a>');
}

function hasUrlParameters(url)
{
  return (url.indexOf("?")>-1 && url.indexOf("?")!=url.length-1);
}

function hasSeparateFrameDisplayStyle(url)
{
  var s = unescape(url);
  return (s.toLowerCase().indexOf("framedisplaystyle=separate")>-1);
}

function getURLPath(url)
{
  var u = unescape(url);

  //chop off anything after the ? character
  if (u.indexOf("?") != -1)
  {
    u = u.slice(0, u.indexOf("?"));
  }

  //chop off the file name and return the URL path name
  return (u.slice(0, u.lastIndexOf("/")+1));
}
