/* This notice must remain at all times.

ajax.js
Copyright (c) Balamurugan S, 2005. sbalamurugan @ hotmail.com

This package is free software. It is distributed under GPL - legalese removed, it means that you can use this for any purpose, but cannot charge for this software. Any enhancements you make to this piece of code, should be made available free to the general public! 

Latest version can be downloaded from http://www.sbmkpm.com

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

*/

var url    = "";
var loaded = 0;
var req;

function setHelp(m_url)
{
 url = m_url;
}

function toggleHelp()
{
  var d1 = document.getElementById('help_box');
  var d2 = document.getElementById('help_text');

  
  if(loaded == 0)
    {
     if(url == "")
        {
         d2.innerHTML = "No help specified for this page";
        }
     else
        {
         loadXMLDoc(url)
        }
     loaded = 1;
    }

  if(d1.style.visibility == 'visible')
     d1.style.visibility='hidden';
  else
     d1.style.visibility='visible';
}

// Load help doc via AJAX
function loadXMLDoc(url)
{
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        //req = new ActiveXObject("Microsoft.XMLHTTP");
        req = new ActiveXObject("MSXML2.XMLHTTP.3.0");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function processReqChange()
{
    // only if req shows "complete"
    if (req.readyState == 4) {
        // only if "OK"
        var d2 = document.getElementById('help_text');
        if (req.status == 200) {
	    d2.innerHTML = req.responseText;
        } else {
	    d2.innerHTML = "Error Loading help";
        }
    }
}
