String.prototype.ToUnicode = function ()
{  var charmap = unescape(
    "%u0402%u0403%u201A%u0453%u201E%u2026%u2020%u2021%u20AC%u2030%u0409%u2039%u040A%u040C%u040B%u040F"+
    "%u0452%u2018%u2019%u201C%u201D%u2022%u2013%u2014%u0000%u2122%u0459%u203A%u045A%u045C%u045B%u045F"+
    "%u00A0%u040E%u045E%u0408%u00A4%u0490%u00A6%u00A7%u0401%u00A9%u0404%u00AB%u00AC%u00AD%u00AE%u0407"+
    "%u00B0%u00B1%u0406%u0456%u0491%u00B5%u00B6%u00B7%u0451%u2116%u0454%u00BB%u0458%u0405%u0455%u0457"
  );
  var code2char = function(code)
  {
    if(code >= 0xC0 && code <= 0xFF) return String.fromCharCode(code - 0xC0 + 0x0410)
    if(code >= 0x80 && code <= 0xBF) return charmap.charAt(code - 0x80)
    return String.fromCharCode(code)
  };
  var res = "";
  for(var i = 0; i < this.length; i++) res = res + code2char(this.charCodeAt(i));
  return res;
}
String.prototype.ToUtf8 = function ()
{  return encodeURIComponent(this);
}
String.prototype.UrlGetVariable = function (VarName)
{  var n = new String(VarName);
  var s = new String(this);
  var i1 = s.indexOf('?' + n + '=');
  var i2 = s.indexOf('&' + n + '=');
  var i;
  if(i1 >= 0)
  {
    i = i1 + 1 + n.length + 1;
  }
  else if(i2 >= 0)
  {
    i = i2 + 1 + n.length + 1;
  }
  else
  {
    i = -1;
  }
  if(i >= 0)
  {
    s = s.substring(i);
    s = s.replace(/^([^&]*)(.*)$/g, '$1');
    return s;
  }
  return '';
}
String.prototype.Trim = function ()
{  return this.replace(/^[\s]+/g, '').replace(/[\s]+$/g, '');
}
Array.prototype.IndexOf = function (Value)
{  for(var i = 0; i < this.length; i++)
  {    if(Value == this[i]) return i;  }
  return -1;}

var XLCommon = {};

XLCommon.Quote = '"';
XLCommon.ScreenWidth = 0;
XLCommon.ScreenHeight = 0;
XLCommon.Browser = {};
XLCommon.Browser.IsIE = (navigator.userAgent.toLowerCase().indexOf("msie") != -1 && navigator.userAgent.toLowerCase().indexOf("opera") == -1 && navigator.userAgent.toLowerCase().indexOf("webtv") == -1);
XLCommon.Browser.IsOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);
XLCommon.Browser.IsGecko = (navigator.userAgent.toLowerCase().indexOf("gecko") != -1);
XLCommon.Browser.IsSafari = (navigator.userAgent.toLowerCase().indexOf("safari") != -1);
XLCommon.Browser.IsKonqueror = (navigator.userAgent.toLowerCase().indexOf("konqueror") != -1);

XLCommon.StrWinToUnicode = function (str)
{
  if(str != null)
  {    return str.ToUnicode();
  }
  return "";
}
XLCommon.GetElement = function (Identifier)
{
  if(Identifier != null && Identifier != "")
  {
    return document.getElementById(Identifier);
  }
  return false;
}
XLCommon.GetVarFromUrl = function (VarName, CustomUrl)
{  if(VarName != null && CustomUrl != null)
  {
    return CustomUrl.UrlGetVariable(VarName);
  }
  return "";
}
XLCommon.GetVar = function (VarName)
{
  if(VarName != null)
  {
    return document.location.href.UrlGetVariable(VarName);
  }
  return "";
}
XLCommon.Trim = function (S)
{
  if(S != null)
  {
    return S.Trim();
  }
  return "";
}
XLCommon.GetElementPosition = function (E)
{  var x = y = 0;
  while(E)
  {
    x += E.offsetLeft;
    y += E.offsetTop;
    E = E.offsetParent;
  }
  return {x:x, y:y};
}
XLCommon.Focus = function (Identifier)
{  var obj = XLCommon.GetElement(Identifier);
  if(obj != null)
  {    obj.focus();  }
}
XLCommon.Sleep = function (msec)
{  var start = new Date().getTime();
  while (new Date().getTime() - start < msec);
}

