/** 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="lookup2.asp?name=";
var set1 = 3;
var set2 = 3;
var set3 = 3;
var set4 = 6;
var set5 = 6;
var set6 = 9;
var curdate = new Date()
var time1 = curdate.getMonth() + "" + curdate.getDate() + "" + curdate.getYear() + "" +  curdate.getHours() + "" + curdate.getMinutes() + "" + curdate.getSeconds()

/* To use AJAX you need at least one http object, which will do the 
   communication
*/
var http = getHTTPObject();

function videopageload() {    
    //setTimeout("performLookup('Salsa',3)",1200)
    setTimeout("performLookup2('ITALIANFEST',3)",1200);
    setTimeout("performLookup3('LATINFEST',3)",1200);
}


// Single Line Handler

function handleHttpResponse() {
	// 4 is the signal for finished
  if (http.readyState == 4) {
	var pic = document.getElementById( 'loading1' );
        pic.height = 0;
        pic.width = 0;
	pic.src = "";
	
    // Split the comma delimited response into an array

    results = http.responseText.split(",");

	first1=results[0];
	var fbox=document.getElementById( 'first' );
	fbox.innerHTML = first1; 
	
	second1=results[1];
	var sbox=document.getElementById( 'second' );
	sbox.innerHTML = second1; 

	third1=results[2];
	var thbox = document.getElementById( 'third' );
	thbox.innerHTML = third1;
  }
}


// Trying to setup another Handler
function handleHttpResponse2() {
	// 4 is the signal for finished
  if (http.readyState == 4) {

	var pic = document.getElementById( 'loading2' );
        pic.height = 0;
        pic.width = 0;
	pic.src = "";
	
    // Split the comma delimited response into an array

    results = http.responseText.split(",");

	first1=results[0];
	var fbox=document.getElementById( 'four' );
	fbox.innerHTML = first1; 
	
	second1=results[1];
	var sbox=document.getElementById( 'five' );
	sbox.innerHTML = second1; 

	third1=results[2];
	var thbox = document.getElementById( 'six' );
	thbox.innerHTML = third1;
  }
}

// Trying to setup another Handler
function handleHttpResponse3() {
	// 4 is the signal for finished
  if (http.readyState == 4) {

	var pic = document.getElementById( 'loading3' );
        pic.height = 0;
        pic.width = 0;
	pic.src = "";
	
    // Split the comma delimited response into an array

    results = http.responseText.split(",");

	first1=results[0];
	var fbox=document.getElementById( 'seven' );
	fbox.innerHTML = first1; 
	
	second1=results[1];
	var sbox=document.getElementById( 'eight' );
	sbox.innerHTML = second1; 

	third1=results[2];
	var thbox = document.getElementById( 'nine' );
	thbox.innerHTML = third1;
  }
}

// Two Line Handler
function handleHttpResponse4() {
	// 4 is the signal for finished
  if (http.readyState == 4) {

	var pic = document.getElementById( 'loading1' );
        pic.height = 0;
        pic.width = 0;
	pic.src = "";
	
    // Split the comma delimited response into an array

    results = http.responseText.split(",");

        first1=results[0];
	var box1=document.getElementById( 'first' );
	box1.innerHTML = first1; 
	
	second1=results[1];
	var box2=document.getElementById( 'second' );
	box2.innerHTML = second1; 

	third1=results[2];
	var box3 = document.getElementById( 'third' );
	box3.innerHTML = third1;

	first2=results[3];
	var box4=document.getElementById( 'four' );
	box4.innerHTML = first2; 
	
	second1=results[4];
	var box5=document.getElementById( 'five' );
	box5.innerHTML = second1; 

	third1=results[5];
	var box6 = document.getElementById( 'six' );
	box6.innerHTML = third1;
  }
}

function handleHttpResponse5() {
	// 4 is the signal for finished
  if (http.readyState == 4) {

	var pic = document.getElementById( 'loading2' );
        pic.height = 0;
        pic.width = 0;
	pic.src = "";
	
    // Split the comma delimited response into an array

    results = http.responseText.split(",");

	first2=results[0];
	var box4=document.getElementById( 'four' );
	box4.innerHTML = first2; 
	
	second1=results[1];
	var box5=document.getElementById( 'five' );
	box5.innerHTML = second1; 

	third1=results[2];
	var box6 = document.getElementById( 'six' );
	box6.innerHTML = third1;

	first1=results[3];
	var box7=document.getElementById( 'seven' );
	box7.innerHTML = first1; 
	
	second1=results[4];
	var box8=document.getElementById( 'eight' );
	box8.innerHTML = second1; 

	third1=results[5];
	var box9 = document.getElementById( 'nine' );
	box9.innerHTML = third1;
  }
}

// Three Line Handler
function handleHttpResponse6() {
	// 4 is the signal for finished
  if (http.readyState == 4) {

	var pic = document.getElementById( 'loading1' );
        pic.height = 0;
        pic.width = 0;
	pic.src = "";
	
    // Split the comma delimited response into an array

    results = http.responseText.split(",");

        first1=results[0];
	var box1=document.getElementById( 'first' );
	box1.innerHTML = first1; 
	
	second1=results[1];
	var box2=document.getElementById( 'second' );
	box2.innerHTML = second1; 

	third1=results[2];
	var box3 = document.getElementById( 'third' );
	box3.innerHTML = third1;

	first2=results[3];
	var box4=document.getElementById( 'four' );
	box4.innerHTML = first2; 
	
	second1=results[4];
	var box5=document.getElementById( 'five' );
	box5.innerHTML = second1; 

	third1=results[5];
	var box6 = document.getElementById( 'six' );
	box6.innerHTML = third1;

	first1=results[6];
	var box7=document.getElementById( 'seven' );
	box7.innerHTML = first1; 
	
	second1=results[7];
	var box8=document.getElementById( 'eight' );
	box8.innerHTML = second1; 

	third1=results[8];
	var box9 = document.getElementById( 'nine' );
	box9.innerHTML = third1;
  }
}



/* PerformLookUp Section By 1 Row */

function performLookup(events,amount)
{
/* Get the name, we know its >= characters */
name = set1;
set1 = set1 + 3;

//Begin communication with lookup.cgi, passing in 
// name as a parameter
http.open("GET", url + escape(name) + '&time=' + time1 + '&events=' + events + '&amount=' + amount, true);

// This bit says "If its loading, display a loading gif
if(http.readyState == 1)
{
    var pic = document.getElementById( 'loading1' );
    pic.height = 14;
    pic.width = 14;
    pic.src = "searching.gif";
}

// 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);
}


function performLookup2(events,amount)
{
/* Get the name, we know its >= characters */
//var name = document.getElementById("name").value;
name = set2;
set2 = set2 + 3;

//Begin communication with lookup.cgi, passing in 
// name as a parameter
http.open("GET", url + escape(name) + '&time=' + time1 + '&events=' + events + '&amount=' + amount, true);

// This bit says "If its loading, display a loading gif
if(http.readyState == 1)
{
    var pic = document.getElementById( 'loading2' );
    pic.width = 14;
    pic.height = 14;    
    pic.src = "searching.gif";
}

// When the state changes call our other method
// handleHttpResponse
http.onreadystatechange = handleHttpResponse2;

// end comms, only do this at the end of your interaction
http.send(null);
}


function performLookup3(events,amount)
{
/* Get the name, we know its >= characters */
//var name = document.getElementById("name").value;
name = set3;
set3 = set3 + 3;

//Begin communication with lookup.cgi, passing in 
// name as a parameter
http.open("GET", url + escape(name) + '&time=' + time1 + '&events=' + events + '&amount=' + amount, true);

// This bit says "If its loading, display a loading gif
if(http.readyState == 1)
{
    var pic = document.getElementById( 'loading3' );
    pic.width = 14;
    pic.height = 14;    
    pic.src = "searching.gif";
}

// When the state changes call our other method
// handleHttpResponse
http.onreadystatechange = handleHttpResponse3;

// end comms, only do this at the end of your interaction
http.send(null);
}


/*
 *  PerformLookUp Section By 2 Row
 */

function performLookup4(events,amount)
{
/* Get the name, we know its >= characters */
name = set4;
set4 = set4 + 6;

//Begin communication with lookup.cgi, passing in 
// name as a parameter
http.open("GET", url + escape(name) + '&time=' + time1 + '&events=' + events + '&amount=' + amount, true);

// This bit says "If its loading, display a loading gif
if(http.readyState == 1)
{
    var pic = document.getElementById( 'loading1' );
    pic.height = 14;
    pic.width = 14;
    pic.src = "searching.gif";
}

// When the state changes call our other method
// handleHttpResponse
http.onreadystatechange = handleHttpResponse4;

// end comms, only do this at the end of your interaction
http.send(null);
}

function performLookup5(events,amount)
{
/* Get the name, we know its >= characters */
name = set5;
set5 = set5 + 6;

//Begin communication with lookup.cgi, passing in 
// name as a parameter
http.open("GET", url + escape(name) + '&time=' + time1 + '&events=' + events + '&amount=' + amount, true);

// This bit says "If its loading, display a loading gif
if(http.readyState == 1)
{
    var pic = document.getElementById( 'loading2' );
    pic.height = 14;
    pic.width = 14;
    pic.src = "searching.gif";
}

// When the state changes call our other method
// handleHttpResponse
http.onreadystatechange = handleHttpResponse5;

// end comms, only do this at the end of your interaction
http.send(null);
}


/*
 *  PerformLookUp Section By 3 Row
 */

function performLookup6(events,amount)
{
/* Get the name, we know its >= characters */
name = set6;
set6 = set6 + 9;

//Begin communication with lookup.cgi, passing in 
// name as a parameter
http.open("GET", url + escape(name) + '&time=' + time1 + '&events=' + events + '&amount=' + amount, true);

// This bit says "If its loading, display a loading gif
if(http.readyState == 1)
{
    var pic = document.getElementById( 'loading1' );
    pic.height = 14;
    pic.width = 14;
    pic.src = "searching.gif";
}

// When the state changes call our other method
// handleHttpResponse
http.onreadystatechange = handleHttpResponse6;

// 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;
}
