/** 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.php?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 = "blank.gif";
	
    // Split the comma delimited response into an array

    results = http.responseText.split("|");
	fnametext=results[2];

	var fname=document.getElementById( 'fname' );
	fname.innerHTML = fnametext; 
	
	snametext=results[3];
	
	var sname=document.getElementById( 'sname' );
	sname.innerHTML = snametext; 

	picsrc=results[2];
//	var pic = document.getElementById( 'img1' );
//	pic.src = results[2];

	quotetext=results[4];
	var quote=document.getElementById('quote' );
    quote.innerHTML = quotetext;

  }
}
function performLookup()
{
/* Get the name, we know its >= characters */
var name = document.getElementById("name").value;

//Begin communication with lookup.cgi, passing in 
// name as a parameter
http.open("GET", url + escape(name), true);

// This bit says "If its loading, display a loading gif
if(http.readyState == 1)
{
	var pic = document.getElementById( 'loading' );
	pic.src = "searching.gif";

	var fname=document.getElementById( 'fname' );
	fname.innerHTML = ""; 
	
	var sname=document.getElementById( 'sname' );
	sname.innerHTML = ""; 

	var quote=document.getElementById('quote' );
      quote.innerHTML = "";
}

// 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);
}

var url1 = "lookup1.php?name=";
var http1 = getHTTPObject();
function handleHttpResponse1() {
	// 4 is the signal for finished
  if (http1.readyState == 4) {
    results = http1.responseText.split("|");
	hasil=results[0];
	hadil=results[1];

	if (hadil == 'a'){
	var fname=document.getElementById( 'AA' );
	fname.innerHTML = hasil; 
	}
	if (hadil == 'b'){
	var fname=document.getElementById( 'BB' );
	fname.innerHTML = hasil; 
	}

	var pic = document.getElementById( 'img2' );
	pic.src = "blank.gif";

}
}
var nocache = 0;
function performLookup1()
{
/* Get the name, we know its >= characters */
var name = document.getElementById("name").value;
nocache = Math.random();
//Begin communication with lookup.cgi, passing in 
// name as a parameter
http1.open("GET", url1 + escape(name) + '&nocache = '+nocache, true);

// This bit says "If its loading, display a loading gif
if(http1.readyState == 1)
{
	var pic = document.getElementById( 'img2' );
	pic.src = "searching.gif";

}

// When the state changes call our other method
// handleHttpResponse
http1.onreadystatechange = handleHttpResponse1;

// end comms, only do this at the end of your interaction
http1.send(null);
}


var url2 = "lookup2.php?shbox=";
var http2 = getHTTPObject();
function handleHttpResponse2() {
	// 4 is the signal for finished
  if (http2.readyState == 4) {
    results = http2.responseText;

	var shbox=document.getElementById( 'shp' );
	shbox.innerHTML =  results + shbox.innerHTML ;

	var shbox1=document.getElementById( 'shbox' );
	shbox1.value =  "" ;

	document.fsh.shbox.focus();

}
}
var nocache = 0;
function performLookup2()
{
/* Get the name, we know its >= characters */
var shbox = document.getElementById("shbox").value;
nocache = Math.random();
//Begin communication with lookup.cgi, passing in 
// name as a parameter
http2.open("GET", url2 + escape(shbox) + '&nocache = '+nocache, true);

// This bit says "If its loading, display a loading gif
if(http2.readyState == 1)
{
}

// When the state changes call our other method
// handleHttpResponse
http2.onreadystatechange = handleHttpResponse2;

// end comms, only do this at the end of your interaction
http2.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;
}
