if( typeof ContextHelp != "function" ) {
  function ContextHelp(helpDivId) {

    this.divId= helpDivId;
    this.isIE6= false;

    this.getDiv= function () {
      var first, top, topleft, topright, bot, botleft, botright;
      if( ! this.div ) {
        this.div= document.getElementById(this.divId);
        this.div.contextHelp= this;
        this.div.onclick= function (t) {
          this.contextHelp.stopHide(this);
          this.contextHelp.target.focus();
        }

        // add corners
        first= this.div.firstChild;
        // top
        top= document.createElement("div");
        top.className="boxtop";
        this.div.insertBefore(top, first);
        // top left
        topleft= document.createElement("div");
        topleft.className="boxtopleft";
        //this.div.insertBefore(topleft, first);
        top.appendChild(topleft);
        // top right
        topright= document.createElement("div");
        topright.className="boxtopright";
        //this.div.insertBefore(topright, first);
        top.appendChild(topright);
        // close
        closeButton= document.createElement("a");
        closeButton.className="boxclosebutton";
        closeButton.href= "javascript:void(0)";
        closeButton.contextHelp= this;
        closeButton.onclick= function () { this.contextHelp.hide() }
        top.appendChild(closeButton);
        // bot
        bot= document.createElement("div");
        bot.className="boxbot";
        this.div.appendChild(bot);
        // bot left
        botleft= document.createElement("div");
        botleft.className="boxbotleft";
        //this.div.appendChild(botleft);
        bot.appendChild(botleft);
        // bot right
        botright= document.createElement("div");
        botright.className="boxbotright";
        //this.div.appendChild(botright);
        bot.appendChild(botright);
      }
      return this.div;
    }

    this.getRelativeCoords= function (target) {
      return this.getCoords(target, true);
    }

    this.show= function (a, direction) {
      this.isIE6= ( navigator.appVersion.indexOf("MSIE 6") > 0 );
      div= this.getDiv();
      this.target= a;
      this.container= this.target.parentNode;
      this.container.style.position="relative";
      document.getElementById("wrapper").appendChild(div);
      coords= this.getCoords(a);
      x= coords[0];
      y= coords[1];
      div.style.display="block";
      if( this.isIE6 ) this.showIE6();
      switch( direction ) {
        case "left-up" :
          div.style.top= (y - this.div.offsetHeight) + "px";
          div.style.left= (x - this.div.offsetWidth - 5) + "px";
          break;
        case "right-up" :
          div.style.top= (y - this.div.offsetHeight) + "px";
          div.style.left= (x + this.target.offsetWidth + 5) + "px";
          break;
        case "left-down" :
          div.style.top= y + "px";
          div.style.left= (x - this.div.offsetWidth - 5) + "px";
          break;
        case "right-down" :
        default :
          div.style.top= y + "px";
          div.style.left= (x + this.target.offsetWidth + 5) + "px";
      }
    }

    this.getCoords= function (target) {
      isStopAtRelative= arguments.length > 1 ? arguments[1] : false;
      x= target.offsetLeft;
      y= target.offsetTop;
      target= target.offsetParent;
      while( target && target.id != "wrapper" ) {
        x += target.offsetLeft;
        y += target.offsetTop;
        target= target.offsetParent;
      }
      return [x,y];
    }

    this.hide= function () {
      this.timeout= setTimeout( "ContextHelp.prototype.hideDivStatic('" + this.divId + "')", "200" );
    }

    this.hideDiv= function () {
      if( this.isIE6 ) this.hideIE6();
      this.getDiv().style.display="none";
    }

    this.stopHide= function () {
      clearTimeout(this.timeout);
    }

    this.showIE6= function () {
      selects= document.getElementsByTagName("select");
      for( s=0; s < selects.length; s++ ) {
        selects[s].style.visibility="hidden";
      }
    }

    this.hideIE6= function () {
      selects= document.body.getElementsByTagName("select");
      for( s=0; s < selects.length; s++ ) {
        selects[s].style.visibility="visible";
      }
    }

  }

}


// @static (IE requires this be out of the if() block >:O
ContextHelp.prototype.hideDivStatic= function (divId) {
  document.getElementById(divId).contextHelp.hideDiv();
}
