// $Revision: 1.31 $
var nls_js_Revision = "$Revision: 1.31 $";
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 )
{
  if( str !== null )
  {
    str = escape(str);
    str = str.replace(/%u/g,'%25u').replace(/%([89A-F])/g,'%25u00$1');
    str = unescape(str);
    str = encodeURIComponent(str);
  }

  return str;
}

// escape for IBI
function IBIescape( str )
{
  if( str !== null )
  {
    str = escape(str);
    str = str.replace(/%u/g,'%25u').replace(/%([89A-F])/g,'%25u00$1');
  }

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

