/** Demo js to implement the most basic of ajax functionality **/


/* Its good practice in AJAX to declare all the urls you will
 be using at the start of the script. */
 
//var url="lookup.cgi?name=";

/* To use AJAX you need at least one http object, which will do the 
   communication
*/
var http = getHTTPObject();

function handleHttpResponse() {
	
	// 4 is the signal for finished
  if (http.readyState == 4) {
//
	//var pic = document.getElementById( 'loading' );
	//pic.src = "";
	
    // Split the comma delimited response into an array
/*
    results = http.responseText.split(",");
	fnametext=results[0];

	var fname=document.getElementById( 'fname' );
	fname.innerHTML = fnametext; 
	
	snametext=results[1];
	
	var sname=document.getElementById( 'sname' );
	sname.innerHTML = snametext; 

	picsrc=results[2];
	var pic = document.getElementById( 'img1' );
	pic.src = results[2];

	quotetext=results[3];
	var quote=document.getElementById('quote' );
    quote.innerHTML = quotetext;
	*/
	//read and assign the response from the server
        var response = http.responseText;
		var ajaxCall=document.getElementById('ajaxCall');
		ajaxCall.innerHTML = response;
		//document.getElementById('ajaxCall').innerHTML = response;

		
        //do additional parsing of the response, if needed
		
        //in this case simply assign the response to the contents of the <div> on the page. 
       // document.getElementById('description').innerHTML = response;
		
        //If the server returned an error message like a 404 error, that message would be shown within the div tag!!. 
        //So it may be worth doing some basic error before setting the contents of the <div>

	//alert(response);
	

  }
}

function performLookup(url)
{

/* Get the name, we know its >= characters */
//var name = document.getElementById(idname).value;

//Begin communication with lookup.cgi, passing in 
// name as a parameter
http.open("GET", url, true);
//alert(url);
// This bit says "If its loading, display a loading gif
if(http.readyState == 1)
{
//var pic = document.getElementById( 'loading' );
//pic.src = "searching.gif";
}
 //alert("this");	
// When the state changes call our other method
// handleHttpResponse
http.onreadystatechange = handleHttpResponse;

// end comms, only do this at the end of your interaction
http.send(null);
}


/* This method is pretty much standard AJAX, you'll see it 
everywhere. The curious can read into its details, the rest of
you can just know that this gives you a HTTP object */

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;
}


