//-----------------------------------------------------------------------
// Module name   : GtLanguage.js
// Author        : Paul Battersby
// Creation Date : May 09/09
// Description   :
//  NOTE: this requires the presence of Lcookie.js
//
// NOTE: if cookies are to be used, call LCOOKIE_enabled() to check and
//       warn user
//
//  $Log: GtLanguage.js $
//  Revision 1.3  2010-11-13 10:36:30-04  Battersby
//  - renamed some functions (upper/lowercase)
//  - added ability to set the page name for the redirection
//
//  Revision 1.2  2009-05-10 11:17:53-04  Battersby
//  - set language cookie to persist for 20 years
//
//  Revision 1.1  2009-05-09 14:33:10-04  Battersby
//  Initial revision
//
//--------------------------------------------------------------------------

//---------------------------- INCLUDE FILES ----------------------------


//----------------------------- CONSTANTS -------------------------------


//----------------------------- VARIABLES -------------------------------


//----------------------------- FUNCTIONS -------------------------------

//************************************************************************
// Name   : GTLANGUAGE_setLang
//  This sets a "gtlanguage" cookie to expire in 20 years and vitually
//  clicks the reload button in the browser (to cause gtlanguage.php to
//  perform a translation)
//
//  This is meant to be called in a link like this
//    <a href="javascript:GTLANGUAGE_setlang('french')">francais</a>
//
//  where somewhere in the web page, there is a PHP call like this
//
//    < ? php echo Gtlanguage::xlat(Gtlanguage::stop()); ? >
//
//  where Gtlanguage::xlat() in the above call, gets it's destination language
//  from the gtlanguage cookie
//
//  (string) lang - the destination language of the translation. Valid
//                   values will depend on the contents of the translation
//                   xml files (examples: "english", "french")
//
//  (string) redirect - (default = "" = current page) the page to load after
//                       the cookie has been set
//
// Returns : (nothing)
//*************************************************************************
function GTLANGUAGE_setLang(lang,redirect) {
  var expireDate = new Date();

  redirect = redirect ? redirect : "";

  // set cookie to expire in 20 years
  expireDate.setDate(expireDate.getFullYear() + 20);

  // write the language to the cookie
  LCOOKIE_write("gtlanguage",lang,expireDate);

  // reload the page so the translation can be performed
  if (redirect === "") {
    window.location.reload(true);

  // redirect to the given page
  } else {
    window.location = redirect;
  } // endif
}  // end of GTLANGUAGE_setLang

//************************************************************************
// Name   : GTLANGUAGE_getLang
//  This attempts to read the "gtlanguage" cookie and return it's value
//
// Returns : (string) language string stored in the language cookie or
//                    null if the cookie doesn't exist
//*************************************************************************
function GTLANGUAGE_getLang()
{
  return LCOOKIE_read("gtlanguage");
} // end of GTLANGUAGE_getlang

