// XMLHTTPRequest object intantiation and data retrieval script



function makeRequest(url,strParams){	

//http request object
var httpRequest = false;
	
	//creates proper request object by traversing the exception tree
	try{
		try{	
			//IE branch
			try{
				httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
			}catch(e){
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}catch(e){
			//mozilla and friends branch
			httpRequest = new XMLHttpRequest();
		}
	}catch(e){
		//if object cannot be instantiated it's false
		alert('XMLHTTP object instantiation failed');
		httpRequest = false;
		return false;
	}
	
	httpRequest.onreadystatechange = function(){processStateChange(httpRequest);};
	
	try{
	    httpRequest.open('POST', url, true);
	    //check for the type of form data
		httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

		httpRequest.send(strParams);
	}catch(e){
		alert('You\'ve made an invalid request');
	}
	
}
//processes the state change 
function processStateChange(httpRequest){
	if(httpRequest.readyState == 4){
		if(httpRequest.status == 200){
		    
		    //try to use the innerhtml or value attribute.
		    try{
			        document.getElementById(id).innerHTML = httpRequest.responseText;
		    }catch(err){
		        try{
			        document.getElementById(id).value = httpRequest.responseText;
			    }catch(err){
			        //alert(httpRequest + ' ' + err.description );
			    }
		    }
		    //check for the type of element
		    //alert(document.getElementById(id).type);
		}else{
			//print an error message if the state is never complete = 4
			alert('There is a problem retreiving the data: \n ' + httpRequest.statusText);
		}
	}
}