/*	 
	Purpose: Set up a pipline to get data from the server and display it on the page without making
			  the user re-load the page.
	@author Yashkirat Singh <yash5@ufl.edu>
	@version 0.1
	@since 0.1
	@access public
	@copyright Yashkirat Singh	
	@date May 10 2006
	@Notes:
	1. The user triggers a request for data (function updateText)
	2. This request, along with its unique name, is sent to a PHP script.
	3. The response is in a comma delimited string which is split into an array.
	4. Depending on the requestName (which is the first entry in the response string)
	   a particualar case is executed (function handleHttpResponse()).
	   
	We need not bother with the function  getHTTPObject(). It basically generates
	the HTTP object used for asynchronous communication with the server. 
*/
	// Specify the script that will service user requests
	// One can define url2 url3 ... and then pass the url to function updateText(request, url3)
	// of course you'll have to modify
	var url = "/ajax/server_side.php"; 
	// We create the HTTP Object for communicating with the server
	var http = getHTTPObject();


// The object created using this function will process all transactions with the server.
// ------------------------- DON'T LOOK AT THIS FUNCTION ---------------------------
function getHTTPObject() {
	  var xmlhttp;
	  /*@cc_on
	  @if (@_jscript_version >= 5)
		try {
		  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		  try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		  } catch (E) {
			xmlhttp = false;
		  }
		}
	  @else
	  xmlhttp = false;
	  @end @*/
	  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
		  xmlhttp = new XMLHttpRequest();
		} catch (e) {
		  xmlhttp = false;
		}
	  }
	  return xmlhttp;
}// end function getHTTPObject() {

// The "request for data" comes in, and I pass this request to the object (called http).
// I also pass the name of the script that will process the request.
// The object (http) is instructed to use the POST method for communicating with the server. 
function updateText(request, url) {
	  //alert(request);
	  http.open('POST', url, true);
	  http.onreadystatechange = handleHttpResponse;
	  http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	  http.send(request);	
}// end function updateText(postString) {	
	
// The "response" from the server is processed here. The server script sends data, and I use
// javascript to alter the page (to display this data). This response is comma delimited, and the
// first entry ALWAYS contains the "name of the request". This helps me identify the response,
// and subsequently process it.
// ------------------------- THIS FUNCTION IS IMPORTANT---------------------------
function handleHttpResponse() {
	  if (http.readyState == 4) {
		// Split the comma delimited response into an array			
		results = http.responseText.split(',');
		// request name is always the first entry
		var requestName=results[0];
		
		// Depending on the request, process it.
		switch(requestName){		
			
			
			// The resolution of the user was sent back from the server 
			// I am not going to do anything
			case "resolution":
				//var Success=results[1];	
				//alert(Success);
			break;			
			
		

			
			
		
			
	
			

			
		}// end switch(requestName){
	  }// end  if (http.readyState == 4) {
}// end function handleHttpResponse() {


