if (window.top.location.host == 'localhost')
    var ajax_url =  window.top.location.protocol+'//'+window.top.location.host+'/gpsforx/fd.php';
else
    var ajax_url =  window.top.location.protocol+'//'+window.top.location.host+'/fd.php';

function js_getAjax ()
{
    if (window.XMLHttpRequest) // eg Firefox
        req = new XMLHttpRequest();
    else if (window.ActiveXObject)
    {
        try {
            req = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {
            req = null;
        }
    }
    else
        req = null;

    return req;
}

function js_callAjax (ajax_args)
{
    req = js_getAjax();
    if (req)
    {
        req.onreadystatechange = function ()
        {
            if (req.readyState == 4 && req.status == 200)
            {
                for (i=0; req.responseXML.getElementsByTagName('itemname')[i]; i++)
                    js_set_html(req.responseXML.getElementsByTagName('itemname')[i].firstChild.nodeValue,req.responseXML.getElementsByTagName('htmltext')[i].firstChild.nodeValue);
            }
        }

//alert(ajax_url+'?'+ajax_args);
        req.open('GET',ajax_url+'?'+ajax_args,true);
        req.send(null);
    }
}

function js_set_html (divname,mycontent)
{
    var container = document.getElementById(divname);
    if (!container)
        return;

    container.innerHTML = mycontent;
}

function js_ShowPopup (hoveritem,gloss_item)
{
    hpt = document.getElementById("hoverpopup_title");
    hpt.innerHTML = 'Glossary';
    hpb = document.getElementById("hoverpopup_body");
    hpb.innerHTML = 'Loading...';

    js_callAjax('m=1&v1='+gloss_item);

    hp               = document.getElementById("hoverpopup");
    var placement    = js_findPos(hoveritem);
    hp.style.left    = eval(placement[0]+'-50') + "px";
    hp.style.top     = eval(placement[1]+'+20') + "px";
    hp.style.display = "block";

}

function js_HidePopup ()
{
  hp               = document.getElementById("hoverpopup");
  hp.style.display = "none";
}

function js_findPos (obj)
{
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft,curtop];
}

function js_ShowPopupForm (hoveritem)
{
    hpt = document.getElementById("hoverpopup_title");
    hpt.innerHTML = 'Contact Us';
    hpb = document.getElementById("hoverpopup_body");
    hpb.innerHTML = '<input type="submit">';

    hp               = document.getElementById("hoverpopup");
    var placement    = js_findPos(hoveritem);
    hp.style.left    = eval(placement[0]+'-50') + "px";
    hp.style.top     = eval(placement[1]+'+20') + "px";
    hp.style.display = "block";

}

function js_ShowPopupImage (hoveritem,title,imageurl)
{
    hpt = document.getElementById("hoverpopup_title");
    hpt.innerHTML = title;
    hpb = document.getElementById("hoverpopup_body");
    hpb.innerHTML = '<img src="'+imageurl+'">';

    hp               = document.getElementById("hoverpopup");
    var placement    = js_findPos(hoveritem);
    hp.style.left    = eval(placement[0]+'-50') + "px";
    hp.style.top     = eval(placement[1]+'+20') + "px";
    hp.style.display = "block";
}
