
//---- hints ----
/* ---- Hints ---- */
formhint = {
    name: "formhint",
    hint: null,
    stick: null,
    trigger: null,
    initialized: false
}

formhint.init = function() {
    if (this.initialized == false) {
        this.initialized = true;

        if ($('#formhint').length == 0) {
            $('body').append('<div id="formhint"></div>');
        }
        var e = $('#formhint');
        if (e.length > 0) {
            this.hint = e[0];
        }
    }
}

formhint.InitFromElement = function(triggerId, contentId, align, sticky) {
/*    alert('InitFromElement(' + triggerId + ', ' + contentId + ')'); */
    if (!this.hint) return;
 
        var t = document.getElementById(triggerId);
        if (t) {
            t.onmouseover = function() { formhint.ShowTip(triggerId, contentId, align, sticky); }
            if (sticky) {
                t.onblur=function() { formhint.HideTip(); }
            } else {
                t.onmouseout=function() { formhint.HideTip(); }
            }

            /*
            t.mouseover(function() { formhint.ShowTip(triggerId, contentId, align, sticky); });
            if (sticky) {
                t.blur(function() { formhint.HideTip(); });
            } else {
                t.mouseout(function() { formhint.HideTip(); });
            }
            */
        }
}

formhint.ShowTip = function(triggerId, contentId, align, sticky) {
/*     alert('ShowTip(' + triggerId + ', ' + contentId + ', ' + align + ', ' + sticky + ')'); */
    if (!this.hint || this.trigger == triggerId) return;

    var e = $('#'+contentId);
    var t = document.getElementById(triggerId);
    if (e.length > 0 && t) {
        this.hint.innerHTML = e.attr('hint') + '<div id="formhint_' + align + '">&nbsp;</div>';
        this.stick = sticky;
        this.trigger = triggerId;
        this.hint.style.display = "block";
        var x = 0, y = 0;
        var obj = t;

        while (obj) {
            x += obj.offsetLeft;
            y += obj.offsetTop;
            obj = obj.offsetParent;
        }
        this.hint.style.left = (x + t.offsetWidth + 10) + "px";
        this.hint.style.top = (y - 5) + "px";
    }
}

formhint.HideTip = function() {
    if (this.hint) {
        this.hint.innerHTML = "";
        this.hint.style.display = "none";
        this.stick = null;
        this.trigger = null;
    }
}
