function ById(ID)
{
   return document.getElementById(ID)
}

function GetShowLinkHTML(ID)
{
   return GetDisplayLink("ShowLink.gif", ID)
}

function GetHideLinkHTML(ID)
{
   return GetDisplayLink("HideLink.gif", ID)
}

function GetDisplayLink(ImageName, ID)
{
   return '<span id="iLabel' + ID + '"><img'
            + ' src="/images/' + ImageName + '"'
            + ' width="7"'
            + ' height="8"'
            + ' onclick="ToggleDisplayState(' + ID + ')"'
            + ' onmouseover="SetHandCursor(this)"'
            + ' onmouseout="SetNormalCursor(this)"'
            + ' /></span>'
}

function ToggleDisplayState(ID)
{
   var BlockElement = document.getElementById("i" + ID)
   var LabelElement = document.getElementById("iLabel" + ID)
   if (BlockElement.style.display == 'block')
   {
      BlockElement.style.display = 'none'
      LabelElement.innerHTML = GetShowLinkHTML(ID)
   }
   else
   {
      BlockElement.style.display = 'block'
      LabelElement.innerHTML = GetHideLinkHTML(ID)
   }
}

function SetHandCursor(obj)
{
   obj.style.cursor = "pointer";
}

function SetNormalCursor(obj)
{
   obj.style.cursor = "normal";
}

function GetXmlHttpObject()
{
   var http

   if (typeof XMLHttpRequest != 'undefined')
   {
      http = new XMLHttpRequest()
   }
   try
   {
      http = new ActiveXObject("Msxml2.XMLHTTP")
   }
   catch (e)
   {
      try
      {
         http = new ActiveXObject("Microsoft.XMLHTTP")
      }
      catch (e) { }
   }

   if (http == undefined)
   {
      alert("Sorry, some content is not available because your web browser"
         + " doesn't support asynchronous HTTP requests.")
      http = false
   }

   return http;
}

function Trim(text)
{
   text = String(text)
   text = text.replace(/^\s+/, "")
   text = text.replace(/\s+$/, "")
   return text
}

function FormatText(text)
{
   text = String(text)
   text = Trim(text)
   text = text.replace(/(\b[^\s]+@[^\s]+\b)/i,
      "<a href='mailto:$1'>$1</a>")
   text = text.replace(/(\b(http:\/\/)?www\.[^\s]+\b)/gi,
      "<a href='$1' target='_blank'>$1</a>")
   text = text.replace(/<a href='www/gi, "<a href='http://www")
   text = text.replace(/\r\n/g, "\n")
   text = text.replace(/ +\n/g, "\n")
   text = text.replace(/\n +/g, "\n")
   text = text.replace(/\n{2,}/g, "\n\n")
   text = "<p>" + text
   text = text.replace(/\n\n/g, "</p><p>")
   text = text + "</p>"
   text = text.replace(/\n/g, "<br/>")
   return text
}

function htmlspecialchars(text)
{
   text = String(text)
   text = text.replace(/&/g, '&amp;')
   text = text.replace(/</g, '&lt;')
   text = text.replace(/>/g, '&gt;')
   text = text.replace(/"/g, '&quot;')
   text = text.replace(/'/g, '&#039;')
   text = text.replace(/\xA0/g, ' ') // &nbsp; may create broken layout
   text = text.replace(/\xA1/g, '&iexcl;')
   text = text.replace(/\xA2/g, '&cent;')
   text = text.replace(/\xA3/g, '&pound;')
   text = text.replace(/\xA4/g, '&curren;')
   text = text.replace(/\xA5/g, '&yen;')
   text = text.replace(/\xA6/g, '&brvbar;')
   text = text.replace(/\xA7/g, '&sect;')
   text = text.replace(/\xA8/g, '&uml;')
   text = text.replace(/\xA9/g, '&copy;')
   text = text.replace(/\xAA/g, '&ordf;')
   text = text.replace(/\xAB/g, '&laquo;')
   text = text.replace(/\xAC/g, '&not;')
   text = text.replace(/\xAD/g, '&shy;')
   text = text.replace(/\xAE/g, '&reg;')
   text = text.replace(/\xAF/g, '&macr;')
   text = text.replace(/\xB0/g, '&deg;')
   text = text.replace(/\xB1/g, '&plusmn;')
   text = text.replace(/\xB2/g, '&sup2;')
   text = text.replace(/\xB3/g, '&sup3;')
   text = text.replace(/\xB4/g, '&acute;')
   text = text.replace(/\xB5/g, '&micro;')
   text = text.replace(/\xB6/g, '&para;')
   text = text.replace(/\xB7/g, '&middot;')
   text = text.replace(/\xB8/g, '&cedil;')
   text = text.replace(/\xB9/g, '&sup1;')
   text = text.replace(/\xBA/g, '&ordm;')
   text = text.replace(/\xBB/g, '&raquo;')
   text = text.replace(/\xBC/g, '&frac14;')
   text = text.replace(/\xBD/g, '&frac12;')
   text = text.replace(/\xBE/g, '&frac34;')
   text = text.replace(/\xBF/g, '&iquest;')
   text = text.replace(/\xC0/g, '&Agrave;')
   text = text.replace(/\xC1/g, '&Aacute;')
   text = text.replace(/\xC2/g, '&Acirc;')
   text = text.replace(/\xC3/g, '&Atilde;')
   text = text.replace(/\xC4/g, '&Auml;')
   text = text.replace(/\xC5/g, '&Aring;')
   text = text.replace(/\xC6/g, '&AElig;')
   text = text.replace(/\xC7/g, '&Ccedil;')
   text = text.replace(/\xC8/g, '&Egrave;')
   text = text.replace(/\xC9/g, '&Eacute;')
   text = text.replace(/\xCA/g, '&Ecirc;')
   text = text.replace(/\xCB/g, '&Euml;')
   text = text.replace(/\xCC/g, '&Igrave;')
   text = text.replace(/\xCD/g, '&Iacute;')
   text = text.replace(/\xCE/g, '&Icirc;')
   text = text.replace(/\xCF/g, '&Iuml;')
   text = text.replace(/\xD0/g, '&ETH;')
   text = text.replace(/\xD1/g, '&Ntilde;')
   text = text.replace(/\xD2/g, '&Ograve;')
   text = text.replace(/\xD3/g, '&Oacute;')
   text = text.replace(/\xD4/g, '&Ocirc;')
   text = text.replace(/\xD5/g, '&Otilde;')
   text = text.replace(/\xD6/g, '&Ouml;')
   text = text.replace(/\xD7/g, '&times;')
   text = text.replace(/\xD8/g, '&Oslash;')
   text = text.replace(/\xD9/g, '&Ugrave;')
   text = text.replace(/\xDA/g, '&Uacute;')
   text = text.replace(/\xDB/g, '&Ucirc;')
   text = text.replace(/\xDC/g, '&Uuml;')
   text = text.replace(/\xDD/g, '&Yacute;')
   text = text.replace(/\xDE/g, '&THORN;')
   text = text.replace(/\xDF/g, '&szlig;')
   text = text.replace(/\xE0/g, '&agrave;')
   text = text.replace(/\xE1/g, '&aacute;')
   text = text.replace(/\xE2/g, '&acirc;')
   text = text.replace(/\xE3/g, '&atilde;')
   text = text.replace(/\xE4/g, '&auml;')
   text = text.replace(/\xE5/g, '&aring;')
   text = text.replace(/\xE6/g, '&aelig;')
   text = text.replace(/\xE7/g, '&ccedil;')
   text = text.replace(/\xE8/g, '&egrave;')
   text = text.replace(/\xE9/g, '&eacute;')
   text = text.replace(/\xEA/g, '&ecirc;')
   text = text.replace(/\xEB/g, '&euml;')
   text = text.replace(/\xEC/g, '&igrave;')
   text = text.replace(/\xED/g, '&iacute;')
   text = text.replace(/\xEE/g, '&icirc;')
   text = text.replace(/\xEF/g, '&iuml;')
   text = text.replace(/\xF0/g, '&eth;')
   text = text.replace(/\xF1/g, '&ntilde;')
   text = text.replace(/\xF2/g, '&ograve;')
   text = text.replace(/\xF3/g, '&oacute;')
   text = text.replace(/\xF4/g, '&ocirc;')
   text = text.replace(/\xF5/g, '&otilde;')
   text = text.replace(/\xF6/g, '&ouml;')
   text = text.replace(/\xF7/g, '&divide;')
   text = text.replace(/\xF8/g, '&oslash;')
   text = text.replace(/\xF9/g, '&ugrave;')
   text = text.replace(/\xFA/g, '&uacute;')
   text = text.replace(/\xFB/g, '&ucirc;')
   text = text.replace(/\xFC/g, '&uuml;')
   text = text.replace(/\xFD/g, '&yacute;')
   text = text.replace(/\xFE/g, '&thorn;')
   text = text.replace(/\xFF/g, '&yuml;')
   return text
}

var g_TabIndex = 100
function GetNextTabIndex()
{
   return ++g_TabIndex
}

function CalculateTextAreaRows(text, LineLen)
{
   var LineBreaksCount = text.split("\n").length - 1
   return 10 + text.length / LineLen + LineBreaksCount
}
