// JavaScript Document
var sendingHTML = '<img src="/_img/webtrax/loader.gif" border="0" height="16" width="16">';
/* preload */
loading= new Image(16,16); 
loading.src="/_img/webtrax/loader.gif"; 


// -=-=-=-=-=-=-=-[ generic stateChanged function]-=-=-=-=-=-=-=-
function stateChanged(elmtID) { 
	//alert(xmlHttp.readyState);
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		//alert (xmlHttp.responseText);
		document.getElementById(targetElmt).innerHTML=xmlHttp.responseText;
	} else {
		document.getElementById(targetElmt).innerHTML=sendingHTML;
	}
}

// -=-=-=-=-=-=-=-[ stateChanged function -  creates new child node ]-=-=-=-=-=-=-=-
function stateChangedMLS() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 		
		var oldchild = document.all ? document.all[childElmt] : document.getElementById(childElmt);
		var pardiv = oldchild.parentNode;
		//remove earlier instances of same child
		pardiv.removeChild(oldchild);
		// replace with new child
		var parElmt = document.all ? document.all[targetElmt] : document.getElementById(targetElmt);
		var newdiv = document.createElement('div');
		newdiv.setAttribute("id",childElmt);
		newdiv.innerHTML=xmlHttp.responseText;
		parElmt.appendChild(newdiv);
	} 
} 

// -=-=-=-=-=-=-=-[ ajax get functions ]-=-=-=-=-=-=-=-

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
 		// Firefox, Opera 8.0+, Safari
		 xmlHttp=new XMLHttpRequest();
 	} catch (e) {
 		//Internet Explorer
		 try {
		 	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

// -=-=-=-=-=-=-=-[ ajax post functions ]-=-=-=-=-=-=-=
   
   function postRequest(url,parameters,responseDiv) {
      // new ajax obj
	  	//alert('posting');
	  	var respDiv = responseDiv;
		http_PostReq=GetXmlHttpObject()
		if (http_PostReq==null) { 
			alert ("Browser does not support HTTP Request");
			return;
		}
		// loading feedback
		//document.getElementById(respDiv).innerHTML = 'Please wait...';
		document.getElementById(respDiv).innerHTML = '<img src="/_img/webtrax/loader.gif" border="0" height="16" width="16">';
		
		//ajax request
		http_PostReq.onreadystatechange = function() {
			if (http_PostReq.readyState == 4 || http_PostReq.readyState == 'complete')  {
				if (http_PostReq.status == 200) {
					//alert(http_PostReq.responseText);
					result = http_PostReq.responseText;
					document.getElementById(respDiv).innerHTML = result;
				 } else { 
				 	alert(http_PostReq.status + '(' + url + ')');
				 }// if status = 200
			}// if readystate = 4
		} //function;
		http_PostReq.open('POST', url, true);
      	http_PostReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     	http_PostReq.setRequestHeader("Content-length", parameters.length);
     	http_PostReq.setRequestHeader("Connection", "close");
      	http_PostReq.send(parameters);
   }

   function alertContents(responseDiv) {
   		alert('ready');
      if (http_PostReq.readyState == 4) {
         if (http_PostReq.status == 200) {
            alert(http_request.responseText);
            result = http_PostReq.responseText;
            document.getElementById(responseDiv).innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
  
// -=-=-=-=-=-=-=-[ ajax glossary functions ]-=-=-=-=-=-=-=

   function glossary(vis,term) {
		var mode = vis == 'hide' ? 'hidden' : 'visible';
		var popDivBG = document.getElementById('glossary_bg').style.visibility = mode;
		var popDiv = document.getElementById('glossary_wrap').style.visibility = mode;
		fechTerm(term);
	}
	
	function fechTerm(term) {		
		var url="/_ajx/glossary.php";
		var poststr = "term=" + encodeURI(term);		
		postRequest(url,poststr,'glossary')
	}
   

