//  Copyright (c)  2000 Oracle Corporation.  All rights reserved.
//
//  NAME
//       nlshelp.js
//  FUNCTION
//       Mapping from nls languages to help directories
//
//  NOTES
//
//  MODIFIED
//    kbaldwin - 09 Aug 00 - Creation
//    shrao    - 24-Sep-02 - modifications in getHelpForURL() 
//		and the mapping as mentioned in bug 2585977 
//    anchopra - 15-nov-02 - added function getHelpDir(URL) for bug fix 2645603

var DEFAULT_HELP = "../applet/help/"; // use English help as default

function append(elem)
{
  this[this.length] = elem;
}

var nlshelp = new Array();
nlshelp.append = append;


// nlshelp
// [nls language, help directory]

nlshelp.append(["brazilian portuguese","../applet/help/ptb/"]);
nlshelp.append(["czech","../applet/help/cs/"]);
nlshelp.append(["danish","../applet/help/dk/"]);
nlshelp.append(["dutch","../applet/help/nl/"]);
nlshelp.append(["finnish","../applet/help/sf/"]);
nlshelp.append(["french","../applet/help/f/"]);
nlshelp.append(["german","../applet/help/d/"]);
nlshelp.append(["greek","../applet/help/el/"]);
nlshelp.append(["hungarian","../applet/help/hu/"]);
nlshelp.append(["italian","../applet/help/i/"]);
nlshelp.append(["japanese","../applet/help/ja/"]);
nlshelp.append(["korean","../applet/help/ko/"]);
nlshelp.append(["latin american spanish","../applet/help/e/"]);
nlshelp.append(["norwegian","../applet/help/n/"]);
nlshelp.append(["polish","../applet/help/pl/"]);
nlshelp.append(["portuguese","../applet/help/pt/"]);
nlshelp.append(["russian","../applet/help/ru/"]);
nlshelp.append(["simplified chinese","../applet/help/zhs/"]);
nlshelp.append(["spanish","../applet/help/e/"]);
nlshelp.append(["swedish","../applet/help/s/"]);
nlshelp.append(["traditional chinese","../applet/help/zht/"]);
nlshelp.append(["turkish","../applet/help/tr/"]);

// added as part of bug fix 2645603
// mapping added to map the language directory structure with the nls language.
nlshelp.append(["tchinese","../applet/help/zht/"]);
nlshelp.append(["brazilian","../applet/help/ptb/"]);
nlshelp.append(["schinese","../applet/help/zhs/"]);

// given an nls_language find the help
function getHelpForLanguage(language)
{
  language = language.toLowerCase();
  var help = DEFAULT_HELP;

  // find the first matching territory
  for (i=0; i<nlshelp.length; i++)
  {
    if(nlshelp[i][0]==language)
    {
      help = nlshelp[i][1];
      break;
    }
  }
  return help;
}

// given an nls_lang (nlslanguage_nlsterritory.characterset) find the help
function getHelpForLang(lang)
{
  var language = lang.substring(0, lang.indexOf("_"));
  return getHelpForLanguage(language);
}

// given a url (or the search portion) parse for nls_lang and return the
// associated help directory. This is the function clients should call
function getHelpForURL(url)
{
  url = unescape(url);
  if (url.indexOf("?") == -1) return DEFAULT_HELP;
  url = url.substring(url.indexOf("NLS_LANG"), url.length);
  var nls_param = "NLS_LANG=";
  var start = url.indexOf(nls_param) + nls_param.length;
  var end = url.indexOf("&");
  if (end == -1) end = url.length;
  nlslang = url.substring(start, end);
  return getHelpForLang(nlslang);
}

// added for bug fix 2645603
// given a url finds the HELPDIR for the language passed in the NLS_LANG
// parameter(if the NLS_LANG parameter is passed by the client)
// otherwise parse the URL for the langauge and finds the HELPDIR for that
// language 
function getHelpDir(url)
{
 url = unescape(url);
 if(url.indexOf("NLS_LANG") >=0)
 {
   var helpDir = getHelpForURL(url);
   // to strip off the '/' from the heldir
   return (helpDir.slice(0,helpDir.lastIndexOf("/")));
 }
 else
 {
   var start = url.indexOf("html");
   url = url.substring(start,url.length);
   lang = url.substring(5,url.indexOf("/",5));
   var helpDir = getHelpForLanguage(lang);
   return (helpDir.slice(0,helpDir.lastIndexOf("/")));
 }
   
}
