/*
   Script name  : banners
   File Name 	: banners.js
   Developed By : Kell
   last Updated : 05-06-10
*/

var image = Math.floor(Math.random()*25); // there should be more than 25
setInterval ( "newBanner(image)", 10000 );  // 10 seconds

function newBanner(imageName)
{
 myRand = parseInt(Math.random()*999999999999999);
 if ( imageName == "" || imageName == 0 || imageName == undefined ) { imageName = 1; }
 var url = "zyzzyx/ajax_server.php?banner="+imageName+"&"+myRand;  // build the URL of the server script we wish to call
 myRequest.open("GET", url, true);        // ask our XMLHTTPRequest object to open a server connection
 myRequest.onreadystatechange = doBanner; // prepare a function responseAjax() to run when the response has arrived
 myRequest.send(null);                    // and finally send the request
}

function doBanner()
{
 if ( myRequest.readyState == 4 )   // we are only interested in readyState of 4, i.e. "completed"
    {
     if ( myRequest.status == 200 ) // if server HTTP response is "OK"
        {
         //alert("text: "+myRequest.responseText);
         response    = myRequest.responseText;
         parts       = response.split("|");
         image       = parts[0];
         response    = parts[1];
         iconGraphic = document.getElementById("bannerH");
         iconGraphic.innerHTML = response;
        }
     else
        {
         // issue an error message for any other HTTP response
         // alert("An error has occurred: " + myRequest.statusText); // best not
        }
    }
}
