// $Revision: 1.24.12.1 $
var nls_js_Revision = "$Revision: 1.24.12.1 $";
var DialogFilePrefix = "";
// change to something like DialogFilePrefix = "intl/FR/FR";
var serverLanguage;    // Set by outside nls.js

String.prototype.trim = StringTrim;
function StringTrim()
{
var TestString = this;
var SpaceChar  = " ";
	while (TestString.charAt(0) == SpaceChar) {
	   TestString = TestString.substr(1);
	}
	while (TestString.charAt(TestString.length-1) == SpaceChar) {
	   TestString = TestString.substr(0,TestString.length-1);
	}
	return TestString.toString();
}

// get the language from the cookie
function GetLangCookie() 
{
var a = document.cookie.split(';');
  var a_length = a.length;
  for (var i=0;i < a_length; i++)
  {
	a[i] = a[i].split('=');
	if (a[i][0].trim() == "IBIWF_language")
	{
		if(typeof a[i][1] == "undefined")
			return null 
		else
		  return unescape(a[i][1]);
	}
  }
  return null;
}

// Calculate the length as byte
function NLSlength( str )
{
  var nlen   = 0;

  if( str != null )
  {
	var str_length=str.length;
    for( var i=0; i<str_length; i++ )
    {
      if( ( str.charCodeAt(i) >=  8208 && str.charCodeAt(i) <=  8231 ) || /* 0x2010 through 0x2027            */
          ( str.charCodeAt(i) >=  8240 && str.charCodeAt(i) <=  8262 ) || /* 0x2030 through 0x2046            */
          ( str.charCodeAt(i) >= 12288 && str.charCodeAt(i) <= 13311 ) || /* 0x3000 through 0x33ff            */
          ( str.charCodeAt(i) >= 19968 && str.charCodeAt(i) <= 40959 ) || /* 0x4e00 through 0x9fff            */
          ( str.charCodeAt(i) >= 57344 && str.charCodeAt(i) <= 59223 ) || /* 0xe000 through 0xe757 UDC        */
          ( str.charCodeAt(i) >= 44032 && str.charCodeAt(i) <= 55215 ) || /* 0xac00 through 0xd7af Hangle     */
          ( str.charCodeAt(i) >= 63744 && str.charCodeAt(i) <= 64255 ) || /* 0xf900 through 0xfaff Ideographs */
          ( str.charCodeAt(i) >= 65281 && str.charCodeAt(i) <= 65374 )    /* 0xff01 through 0xff5e Halfwidth and Fullwidth Forms */
        )  nlen += 2;
      else nlen++;
    }
  }

  return nlen;
}

// encodeURIComponent for IBI
function IBIencodeURIComponent( str )
{
  var retstr = "";

  if( str != null )
  {
    var codeat = "";

    /* If contents of str has numeric only, str becomes numeric variable */
    /* The str.length becomes undefined means 0.  */
    str += "";
    for( var i=0; i<str.length; i++ )
    {
      if     ( str.charCodeAt(i) < 128 )
        retstr += encodeURIComponent( str.charAt(i) );
      else if( str.charCodeAt(i) < 256 )
        retstr += escape( str.charAt(i) );
      else
      {
        codeat = str.charCodeAt(i).toString(16);
        if( codeat.length < 4 ) codeat = "0" + codeat;
        retstr += encodeURIComponent( "%u" + codeat );
      }
    }
  }
  else retstr = str;

  return retstr;
}

// escape for IBI
function IBIescape( str )
{
  var retstr = "";

  if( str != null )
  {
    var chkstr = "";

    /* If contents of str has numeric only, str becomes numeric variable */
    /* The str.length becomes undefined means 0.  */
    str += "";
    for( var i=0; i<str.length; i++ )
    {
      chkstr = escape( str.charAt(i) );
      if( chkstr.length == 6 && chkstr.substring(0,2) == "%u" )
           retstr += escape( chkstr );
      else retstr += chkstr;
    }
  }
  else retstr = str;

  return retstr;
}

if( serverLanguage != undefined &&
    serverLanguage != '' )  currentLanguage = serverLanguage;
else                        currentLanguage = GetLangCookie();
if (currentLanguage != null && currentLanguage != 'en')
  DialogFilePrefix = "intl/"+currentLanguage.toUpperCase()+"/"+currentLanguage.toUpperCase();


