var box;  //reference to tooptip box

var Xoffset= 10;    // modify these values to ...
var Yoffset= 20;    // change the popup position.
var showDelay = 400;   //Delay before showing tip
var autoKill = 16000;   //Delay to auto close;
var showTimer, killTimer; //timer handles
var toolTip = new Array(10);

toolTip[1] =  '<div id="tipimage"><img src="images/personal_loans.gif" border="0" height="45" width="45"></div><b>Unsecured Personal Loan</b> - A loan that is not secured on property or goods. The lender will use your personal credit history to decide whether to offer you the loan and at what interest rate.';
toolTip[2] = '<div id="tipimage"><img src="images/secured_loans.gif" border="0" height="45" width="45"></div><b>Secured Homeowner Loan</b> - A loan that is secured against your property. A homeowner loan generally allows you to borrow more and at a lower interest rate than an unsecured loan. However, if you fail to make payments your home can be at risk.';
box = null;

function setMessage(){
    /* Make sure the browser gives us a reference to the tip box */

}//eof setMessage

function popup(e,id){

    if (!e)  e = window.event;  //event object IE or DOM

    if (!box) {

      if (document.getElementById){
        box = document.getElementById("message-box");
      }
      else if (document.all) {
        box = document.all.message-box;
      }
      else if (document.layers) {
        box = document.layers.message-box;
      }
    }

    clearTimers();  //Clear any timers from previous tip

    /* Get reference to element triggering request for tip. */
    var obj = e.target || e.srcElement;
    while (obj.nodeType != 1) {
        /*  Some browsers register event on the text node (target or srcElement)
            so there is a loop to the first element. Example is Konqueror 3.2.
        */
        obj = obj.parentNode || obj.parentElement;
    }

    /* When following mouse */
    document.onmousemove=followMouse;
    if (window.event)
    {
      /* Set current position for IE */
      followMouse(false);
    }

    box.style.backgroundColor = "#ffffe1";

    if (typeof box.innerHTML != "undefined") {
        box.innerHTML=toolTip[id];
    }
    else if (document.layers) {
        box.document.write(toolTip[id]);
        box.document.close();
    }

    if (showDelay > 0) showTimer = setTimeout("showTip()", showDelay);

}//eof popup


function fitWindowWidth(tipX) {
    /* Determine best page X that keeps object in window. If object
     * doesn't fit adjust to left edge ot window.
     * Compare object X coordinate to max X not going out
     * of window and use left most.
     * Then check object X is not past left most visible
     * page coordinate.
     */

    /*Don't go past right edge of window */

    var rightMaxX = getRightPagePos() - (box.offsetWidth + 16); //16 for scrollbar

    tipX = (rightMaxX < tipX) ? rightMaxX : tipX;

    /* But, don't go past left edge of window either */
    var leftMinX = getLeftPagePos();
    tipX = (tipX < leftMinX) ? leftMinX : tipX;

    return tipX;
}//eof fitWindowWidth

function getRightPagePos() {
    /* Determine page offset at right of screen (it's different than window width)
     * Here the pixles the page has been scrolled left is added to window width
     */
    var nRight;

    if (typeof window.srcollX != "undefined") {
        //"NN6+ FireFox, Mozilla etc."
        nRight = window.innerWidth + window.scrollX;
    }
    else if (typeof window.pageXOffset != "undefined") {
        //NN4 code still in NN6 + but scrollX was added
        nRight = window.innerWidth + window.pageXOffset;
    }
    else if (document.documentElement && document.documentElement.clientWidth){
        //document.compatMode == "CSS1Compat" that is IE6 standards mode"
        nRight = document.documentElement.clientWidth + document.documentElement.scrollLeft;
    }
    else if (document.body && document.body.clientWidth) {
        //document.compatMode != "CSS1Compat" that is quirks mode IE 6 or IE < 6 and Mac IE
        nRight = document.body.clientWidth + document.body.scrollLeft;
    }

    return nRight;
}//eof getRightPagePos

function getLeftPagePos() {
    var nLeft;

    if (typeof window.srcollX != "undefined") {
        //"NN6+ FireFox, Mozilla etc."
        nLeft = window.scrollX;
    }
    else if (typeof window.pageXOffset != "undefined") {
        //NN4 code still in NN6 + but scrollX was added
        nLeft = window.pageXOffset;
    }
    else if (document.documentElement && document.documentElement.scrolLeft){
        //document.compatMode == "CSS1Compat" that is IE6 standards mode"
        nLeft = document.documentElement.scrollLeft;
    }
    else if (document.body && document.body.scrollLeft) {
        //document.compatMode != "CSS1Compat" that is quirks mode IE 6 or IE < 6 and Mac IE
        nLeft = document.body.scrollLeft;
    }

    return nLeft;
}//eof getLeftPagePos

function fitWindowHeight(tipY) {
    /* Compare calculated max acceptable page offset to toolTip X and return smallest */

    /* Don't go below bottom of window. Put above target if moved. */
    var bottomMaxY = getBottomPagePos() - (box.offsetHeight);
    tipY = (bottomMaxY < tipY ) ? tipY - (Yoffset + box.offsetHeight) : tipY;

    /* But, don't go past the top of window either */
    var topMinY = getTopPagePos();
    tipY = (tipY < topMinY) ? topMinY : tipY;

    return tipY
}//eof fitWindowHeight

function getBottomPagePos() {
    /* Determine page offset at bottom of screen (it's different than window height)
     * Here the pixles the page has been scrolled up is added to window height
     */
    var nBottom;

    if (typeof window.scrollY != "undefined" ) {
        //NN6+ FireFox, Mozilla etc.
        nBottom = window.innerHeight + window.scrollY;
    }
    else if (typeof window.pageYOffset != "undefined") {
        //NN4 still in NN6 + but NN6 and Mozilla added scrollY
        nBottom = window.innerHeight + window.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.clientHeight){
        //document.compatMode == "CSS1Compat" that is IE6 standards mode
        nBottom = document.documentElement.clientHeight + document.documentElement.scrollTop;
    }
    else if (document.body && document.body.clientHeight) {
        //document.compatMode != "CSS1Compat" that is quirks mode IE 6 or IE < 6 and Mac IE
        nBottom = document.body.clientHeight + document.body.scrollTop;
    }
    return nBottom;
}//eof getBottomPagePos

function getTopPagePos() {
    var nTop;

    if (typeof window.scrollY != "undefined" ) {
        //NN6+ FireFox, Mozilla etc.
        nTop= window.scrollY;
    }
    else if (typeof window.pageYOffset != "undefined") {
        //NN4 still in NN6 + but NN6 and Mozilla added scrollY
        nTop = window.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop){
        //document.compatMode == "CSS1Compat" that is IE6 standards mode
        nTop = document.documentElement.scrollTop;
    }
    else if (document.body && document.body.scrollTop) {
        //document.compatMode != "CSS1Compat" that is quirks mode IE 6 or IE < 6 and Mac IE
        nTop = document.body.scrollTop;
    }
    return nTop;
}//eof getTopPagePos
function showTip(){
    box.style.visibility='visible';
    if (autoKill > 0) killTimer = setTimeout("kill()", autoKill);
}//eof showTip

function followMouse(e){
    /* Get mouse coordinates */
    var x;
    var y;

    if (box){
        if (e) {
          x =  e.pageX
          y =  e.pageY
        }
        else if (document.documentElement && document.documentElement.clientWidth){
            //document.compatMode == "CSS1Compat" that is IE6 standards mode"
            x = window.event.clientX + document.documentElement.scrollLeft;
            y = window.event.clientY + document.documentElement.scrollTop;
        }
        else if (document.body && document.body.clientWidth) {
          //document.compatMode != "CSS1Compat" that is quirks mode IE 6 or IE < 6 and Mac IE
          x = window.event.clientX + document.body.scrollLeft;
          y = window.event.clientY + document.body.scrollTop;
        }
        /* Adjust position for screen right and bottom screen edge */
        x = fitWindowWidth(x + Xoffset);
        y = fitWindowHeight(y + Yoffset);

        box.style.left = x + 'px';
        box.style.top = y + 'px';
    }
}//eof followMouse

function kill(){
    if (box) {
        clearTimers();

        document.onmousemove="";

        if (box.style.visibility == "visible") box.style.visibility = "hidden";
    }
}//eof kill

function clearTimers() {
    if (killTimer) clearTimeout(killTimer);
    if (showTimer) clearTimeout(showTimer);
}//eof clearTimers
