
  String.prototype.leftTrim = function () {
    return (this.replace(/^\s+/,""));
  };
  String.prototype.rightTrim = function () {
    return (this.replace(/\s+$/,""));
  };
  //combination of "leftTrim" and "rightTrim";
  String.prototype.basicTrim = function () {
    return (this.replace(/\s+$/,"").replace(/^\s+/,""));
  };
  
// #############################################################################
// ###
// ### Highlight Text
// ###
// #############################################################################

  function capitalize(Text) {
    c=Text.split(""); c[0]=c[0].toUpperCase(); return c.join("");
  }

  function highlight_text(text) {
     var exp = "";
     for (var i = 0; i < text.length; i++) 
       exp += "(" + text.charAt(i) + "|" + text.toUpperCase().charAt(i) + "|" + text.toLowerCase().charAt(i) + ")";
     var regexp = new RegExp( "(" + exp + ")", "g");
     var el = document.getElementsByTagName("body")[0];
     var content=el.innerHTML.split("<"); 
     for(var mb=0; mb < content.length; mb++) {
        var cell = content[mb].split(">");
        if(cell[1] && cell[1]!="" && cell[1].basicTrim()!="") { 
           cell[1] = cell[1].replace( regexp, "<span class=\"highlight\">$1</span>"); 
           content[mb]=cell.join(">");
        }
     }
     content=content.join("<"); 
     el.innerHTML=content; 
  }

  function do_highlight(text) { 
    window.setTimeout("highlight_text('"+text+"')",100);
  }

// #############################################################################
// ### open_function:
// #############################################################################
function open_function(url,width,height,options)
  {
    if ( height > screen.availHeight || width > screen.availWidth) {
      if ( options.indexOf( "scrollbars=") < 0) {
        if ( height > screen.availHeight)
          height = screen.availHeight;
        if ( width > screen.availWidth)
          width = screen.availWidth;
        options += ",scrollbars=yes";
      }
    }
    self.msgWindow = open(url, "Window", "width=" + width + ",height=" + height
      + ",screenX=" + (screen.width-width)/2
      + ",screenY=" + (screen.height-height)/2
      + ",dependent=yes"
      + ",left=" + (screen.width-width)/2
      + ",top=" + (screen.height-height)/2
      + options
      );
    if (self.msgWindow) {
      self.msgWindow.focus();
      if (self.msgWindow.opener == null) self.msgWindow.opener = self;
    }
  }
