//Author Arijit Pal Chaudhury
//Company: Descon Limited

//***************************************************//
//  <script type="text/javascript">                  //
//      window.onload=function(){enableTooltips()};  //
//  </script>                                        //
//***************************************************//

function enableTooltips(id) {  // Initialize bubble tool tips on basis of title tag & anchor
    var links, i, h, f;
    if (!document.getElementById || !document.getElementsByTagName) return;
    AddCss();
    f = CreateFrame();
    h = document.createElement("span");
    h.id = "btc";
    h.setAttribute("id", "btc");
    h.style.position = "absolute";
    h.style.zIndex = f.style.zIndex + 1;
    document.getElementsByTagName("body")[0].appendChild(h);
    document.getElementsByTagName("body")[0].appendChild(f);
    if (id == null) links = document.getElementsByTagName("a");
    else links = document.getElementById(id).getElementsByTagName("a");
    for (i = 0; i < links.length; i++) {
        Prepare(links[i], false);
    }
}

function Prepare(el, ShowLink) {  //Converting title 2 bubble
    var tooltip, t, b, s, l;
    t = el.getAttribute("title");
    if (t == null || t.length == 0) return;
    el.removeAttribute("title");
    tooltip = CreateEl("span", "tooltip");

    s = CreateEl("span", "top");
    //s.appendChild(document.createTextNode(t));
    tooltip.appendChild(s);

    m = CreateEl("span", "middle");
    m.appendChild(document.createTextNode(t));
    tooltip.appendChild(m);



    b = CreateEl("span", "bottom");
    l = el.getAttribute("href");
    if (l != "" && ShowLink) {
        bl = CreateEl("b", "bottom");
        if (l.length > 30) l = l.substr(0, 27) + "...";
        bl.appendChild(document.createTextNode(l));
        b.appendChild(bl);
    }
    tooltip.appendChild(b);

    setOpacity(tooltip);
    el.tooltip = tooltip;
    el.onmouseover = showTooltip;
    el.onmouseout = hideTooltip;
    el.onmousemove = Locate;
}

function showTooltip(e) { //Calling bubble

    //document.getElementById('cmbModel').disabled = true;
    document.getElementById('btc').appendChild(this.tooltip);
    document.getElementById('HelpShim').style.width = document.getElementById('btc').offsetWidth;
    document.getElementById('HelpShim').style.height = document.getElementById('btc').offsetHeight;
    document.getElementById('HelpShim').style.display = "block";

    Locate(e);
}

function hideTooltip(e) {  //Hiding on mouse out
    var d = document.getElementById("btc");
    //document.getElementById('cmbModel').disabled = false;
    if (d.childNodes.length > 0) {
        document.getElementById('HelpShim').style.display = "none";
        d.removeChild(d.firstChild);
    }
}

function setOpacity(el) {  //Determining transparency
    el.style.filter = "alpha(opacity:95)";
    el.style.KHTMLOpacity = "0.95";
    el.style.MozOpacity = "0.95";
    el.style.opacity = "0.95";
}

function CreateEl(t, c) { //Creating a html element
    var x = document.createElement(t);
    x.className = c;
    x.style.display = "block";
    return (x);
}

function CreateFrame() {  //Creating iframe to suppress SELECT type control
    var x = document.createElement("iframe");
    x.id = "HelpShim";
    x.setAttribute("id", "HelpShim");
    x.style.display = "none";
    x.src = "javascript:void;";
    x.scrolling = "no";
    x.style.position = "absolute";
    x.style.top = "0px";
    x.style.left = "0px";
    x.style.filter = "alpha(opacity:0)";
    x.style.KHTMLOpacity = "0";
    x.style.MozOpacity = "0";
    x.style.opacity = "0";
    x.style.zIndex = 99;
    return (x);
}

function AddCss() {  //implementing Style sheet
    var l = CreateEl("link");
    l.setAttribute("type", "text/css");
    l.setAttribute("rel", "stylesheet");
    l.setAttribute("href", "CSS/bt.css");
    l.setAttribute("media", "screen");
    document.getElementsByTagName("head")[0].appendChild(l);
}

function Locate(e) {  //Positioning bubble
    var posx = 0, posy = 0;
    if (e == null) e = window.event;
    if (e.pageX || e.pageY) {
        posx = e.pageX; posy = e.pageY;
    } else if (e.clientX || e.clientY) {
        if (document.documentElement.scrollTop) {
            posx = e.clientX + document.documentElement.scrollLeft;
            posy = e.clientY + document.documentElement.scrollTop;
        } else {
            posx = e.clientX + document.body.scrollLeft;
            posy = e.clientY + document.body.scrollTop;
        }
    }
    document.getElementById("btc").style.top = (posy + 10) + "px";
    document.getElementById("btc").style.left = (posx - 160) + "px";
    document.getElementById('HelpShim').style.top = (posy + 10) + "px";
    document.getElementById('HelpShim').style.left = (posx - 160) + "px";
}

// Code End - Arijit
