/* define value */

var HINT_MAX_INST     = 100;
var HINT_LEFT         = "0";        /* specify horizontal offset of hint on page (in pixels) */
var HINT_TOP          = "0";        /* specify vertical offset of hint on page (in pixels) */
var HINT_TIMEOUT_MSEC = 3000;       /* default close timeout in mSec*/
var HINT_BGCOLOR      = "#FFFFE1";  /* hint background color */


/* Hint object constructor */
function Hint(id)
{
   var i = 0;

   /* generate the value of 1st member 'hintId' of this object */
   if(null == id)
   {
      while(document.getElementById("Hint_" + i))
      {
         /* if there is too many hint instance in this page */
         if(i >= HINT_MAX_INST)
         return null;
         i++
      }
      this.hintId = "Hint_" + i;
    }
    else
      this.hintId = id;
    
   /* para for the function pointer */
   this.param = null;
   
   /* 1st method of this object */
   this.Show = HintShow;

   /* 2nd method of this object */
   this.Hide = HintHide;

   /* 3th method of this object */
   this.SetTimeout = HintSetTimeout;

   /* 4th method of this object */
   this.Move = HintMove;

   /* 5th method of this object */
   this.SetBgColor = HintSetBgColor;

   /* 6th method of this object */
   this.ParseFunc = null;

   /* 7th method of this object */
   this.SetCSS = HintSetCSS;

   /* construct the object */
   var HintObj = document.createElement("DIV");

   HintObj.id = this.hintId;
   with(HintObj.style)
   {
      position = "absolute";
      display = "none";
      left = HINT_LEFT + "px";
      top = HINT_TOP + "px";
   }
   document.getElementsByTagName("BODY")[0].appendChild(HintObj);
   return;
}

/* dispaly the hint object */
function HintShow(src, srcType, x, y)
{
   var hintGui = document.getElementById(this.hintId);
//   var sec = (this.timeoutMSec) ? this.timeoutMSec : HINT_TIMEOUT_MSEC;

   if(hintGui == null || hintGui.style.display == "")
      return;

   /* move */
   if(typeof(x) == 'number' && typeof(y) == 'number')
      this.Move(x, y);

   if(srcType == "xmlhttp")
   {
      var result; 
      var conn;

      /* ceate a XMLHttp object */
      if((conn = XMLHTTPInit( )) == null)
         return;
      
      if((result = XMLHTTPSyncResult(conn, src)) == null)
         return;
         
      if(this.parseFunc != null)
      {
         result = this.parseFunc(result, this.param);
         
         if(!result)
            return;
      }
      hintGui.innerHTML = result;
   }
   else
   {
      hintGui.innerHTML = src;
   }
   hintGui.style.display = "";
   hintGui.onclick = new Function('document.getElementById("' + this.hintId + '").style.display = "none";');

   /* set a auto hide timer */
   if(this.timer)
      clearTimeout(this.timer);
   if(this.timeoutMSec)
   this.timer = setTimeout('document.getElementById("' + this.hintId + '").style.display = "none";', this.timeoutMSec);
   return;
}

/* hide the hint object */
function HintHide()
{
   if(this.timer)
   {
      clearTimeout(this.timer);
      this.timer = null;
   }
   document.getElementById(this.hintId).style.display = "none";
   return;
}

/* set timeout mSec for hide the hint */
function HintSetTimeout(mSec)
{
   this.timeoutMSec = mSec - 0;
   return;
}

/* move the hint object to the specific postion by (x, y) coordinate */
function HintMove(xLeft, yTop)
{
   var hintGui = document.getElementById(this.hintId).style;

   hintGui.left = xLeft + "px";
   hintGui.top = yTop + "px";
   return;
}

/* set background color of the hint gui */
function HintSetBgColor(color)
{
    document.getElementById(this.hintId).style.backgroundColor = color;
}

/* set the css class name to hint gui */
function HintSetCSS(className)
{
    document.getElementById(this.hintId).className = className;
}


