/*
# Basic AJAX code was taken from "Mantis - a php based bugtracking system" 
# Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 - 2007  Mantis Team   - mantisbt-dev@lists.sourceforge.net
*/

var processURI = 'trackerstate';
var liveReq = false;

// on !IE we only have to initialize it once
if (window.XMLHttpRequest) {
	liveReq = new XMLHttpRequest();
}

/**
 * Build the XMLHttpRequest and send it
 */
function getTrackerState( targetElementId, queryString ) {
	if (liveReq && liveReq.readyState < 4) {
		liveReq.abort();
	}

	if (window.XMLHttpRequest) {
		// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		liveReq = new ActiveXObject("Microsoft.XMLHTTP");
	}

	name = this.id;
	liveReq.onreadystatechange = function() { liveReqProcessReqChange( targetElementId ); };
	liveReq.open("GET", processURI + "?" + queryString);

	liveReq.send(null);

	return false;
}

/**
 * Processes the results of the XMLHttpRequest
 */
function liveReqProcessReqChange( targetElementId ) {
  if (liveReq.readyState == 4) {
    var xml = liveReq.responseXML;
    var displaytext="";
    if (xml.documentElement.nodeName=="error") {
      displaytext="Error: "+xml.documentElement.firstChild.data;
    } else {
      var sec = xml.documentElement.childNodes[0];
	  do {
        if (sec.nodeName=="displaytext") { 
          displaytext=sec.firstChild.nodeValue;
        }
	  } while (sec=sec.nextSibling);
    }
    if (displaytext!="") {
      alert(displaytext);
    }
  }
}
