/* 
* TITLE: AJAX include 
* AUTHOR: Robert Lloyd
* DEPT: Centre for Occupational Health and Safety Training
* DATE: 22 10 2009
*/


function getXMLHttpRequestObject(){
	var ajax = false;
	if(window.XMLHttpRequest){
		ajax = new XMLHttpRequest();
	}else if(window.ActiveXObject){
		try{
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				ajax = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e){}
		}
	}
	return ajax;
}//end function

/*
window.onload = init;
function init(){
	var ajax = getXMLHttpRequestObject();
	if(ajax){
	}//end of ajax IF
}//end function
*/



// AJAX form functions
function htmlData(url, qStr, targetDiv){
	function stateChanged(){
	document.getElementById(targetDiv).innerHTML = 'Ready to populate - parent';
	if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById(targetDiv).innerHTML = xmlHttp.responseText;
		//alert(xmlHttp.readyState);
	}
	else{
		//alert(xmlHttp.status);
	}
}
	if(url.length==0){
		document.getElementById(targetDiv).innerHTML="";
		return;
	}
	xmlHttp=getXMLHttpRequestObject();
	if(xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	}
	url=url+'?'+qStr;
	url=url+'&sid='+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

/*
if(ajax){
	if(document.getElementById('results')){
		document.getElementById('dept_form').onsubmit = function(){
			ajax.open('get', 'courseSelect.ajax.php?did'+encodeURIComponent(did));
			ajax.onreadystatechange = function(){
			handleResponse(ajax);
			ajax.send(null);
			return false;
		}//End anonymous function
	}// End DOM check
}//if AJAX
*/
