String.prototype.right = function(count)
{
  return this.substr(this.length - count);
}

String.prototype.left = function(count)
{
  return this.substr(0, count);
}

String.prototype.ltrim = function()
{
  return this.replace(/^\s+/, '');
}

String.prototype.rtrim = function()
{
  return this.replace(/\s+$/, '');
}

String.prototype.trim = function()
{
  return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, "");
}

String.prototype.fulltrim = function()
{
  return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, "").replace(/\s+/g, " ");
}

String.prototype.lpad = function(new_len, pad_str)
{
  var pad_len = new_len - this.length;
  var pad     = '';

  if (pad_len > 0)
  {
    while (pad.length < pad_len) pad += pad_str;
    return pad.substr(0, pad_len) + this.substr(0);
  }
  else
    return this.substr(0);
}

String.prototype.rpad = function(new_len, pad_str)
{
  var pad_len = new_len - this.length;
  var pad     = '';

  if (pad_len > 0)
  {
    while (pad.length < pad_len) pad += pad_str;
    return this.substr(0) + pad.substr(0, pad_len);
  }
  else
    return this.substr(0);
}

function isEmptyDate(m, d, y)
{
  return ((m == '00') && (d == '00') && (y == '0000'));
}

function isDate(m, d, y, ca)
{
  var mm = m * 1;
  var dd = d * 1;
  var yy = y * 1;

  if (isNaN(mm) || isNaN(dd) || isNaN(yy)) return false;

  if (yy == 0) return ((mm == 0) && (dd == 0) && !ca);

  var curr_date = new Date()
  var curr_year = curr_date.getFullYear() * 1;
  if ((yy < 1900) || (yy > curr_year)) return false;

  if (mm == 0) return (dd == 0);
  if ((mm < 1) || (mm > 12)) return false;

  var val_days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  if (((yy % 4 == 0) && (yy % 100 != 0)) | (yy % 400 == 0)) val_days[2] = 29;

  return !((dd < 0) || (dd > val_days[mm]));
}


function PopupWin(strURL)
{
  window.open(strURL + "&popupwin=1",
              'newWin',
              'height=500,width=700,scrollbars,resizable,toolbar,status')
}

function HighliteCB(objCheckbox)
{
  objLabel = objCheckbox.parentNode;

  if (objCheckbox.checked)
  {
    objLabel.style.backgroundColor = '#0a246a';
    objLabel.style.color = '#fff';
  }
  else
  {
    objLabel.style.backgroundColor = '#fff';
    objLabel.style.color = '#000';
  }
}

function HighliteRadio(objRadio)
{
  objRadios = objRadio.form.elements[objRadio.name];
  for (var i = 0; i < objRadios.length; i++)
  {
    objLabel = objRadios[i].parentNode;

    if (objRadios[i].checked)
    {
      objLabel.style.backgroundColor = '#0a246a';
      objLabel.style.color = '#fff';
    }
    else
    {
      objLabel.style.backgroundColor = '#fff';
      objLabel.style.color = '#000';
    }
  }
}

function MoveToLinkedLB(strLinked, strAvail)
{
  var objAvail  = document.getElementById(strAvail);
  var objLinked = document.getElementById(strLinked);

  for (var i = 0; i < objAvail.length; i++)
  {
    if (objAvail.options[i].selected == true)
    {
       objLinked.options[objLinked.length] = 
         new Option(objAvail.options[i].text, objAvail.options[i].value);
       objAvail.options[i] = null;
       i = i - 1;
    }
  }
}

function MoveToAvailLB(strLinked, strAvail)
{
  var objAvail  = document.getElementById(strAvail);
  var objLinked = document.getElementById(strLinked);

  for (var i = 0; i < objLinked.length; i++)
  {
    if (objLinked.options[i].selected == true)
    {
      objAvail.options[objAvail.length] = 
        new Option(objLinked.options[i].text, objLinked.options[i].value);
      objLinked.options[i] = null;
      i = i - 1;
    }
  }
}

function ListboxValue(strListbox)
{
  var objListbox = document.getElementById(strListbox);
  var result = "";
  var delim = "";

  for (var i = 0; i < objListbox.options.length; i++)
  {
    result = result + delim + objListbox.options[i].value;
    delim = ",";
  }

  return result;
}

function SelectAll(strListbox)
{
  var objListbox = document.getElementById(strListbox);

  for (var i = 0; i < objListbox.length; i++)
    objListbox.options[i].selected = true;
}

function ToggleLayer(strLayer)
{
  if (document.getElementById)
  {
    // this is the way the standards work

    var style2 = document.getElementById(strLayer).style;
    style2.display = style2.display ? "" : "none";
  }

  else if (document.all)
  {
    // this is the way old MSIE versions work

    var style2 = document.all[strLayer].style;
    style2.display = style2.display ? "" : "none";
  }

  else if (document.layers)
  {
    // this is the way NS4 works

    var style2 = document.layers[strLayer].style;
    style2.display = style2.display ? "" : "none";
  }
}

function ShowLayer(strLayer)
{
  if (document.getElementById)
    document.getElementById(strLayer).style.display = "";

  else if (document.all)
    document.all[strLayer].style.display = "";

  else if (document.layers)
    document.layers[strLayer].style.display = "";
}

function HideLayer(strLayer)
{
  if (document.getElementById)
    document.getElementById(strLayer).style.display = "none";

  else if (document.all)
    document.all[strLayer].style.display = "none";

  else if (document.layers)
    document.layers[strLayer].style.display = "none";
}
