 var JobArray = [];
var ExecuteTime = [];
var ArrayCount = 1;
JobArray[0] = "http://www.bwebcentral.com/runjob.php?JobID=1";
TempTime = new Date ("2008-09-05 16:06:56");
	var curdate = "Fri, 05 Sep 2008 16:06:56 MST";
	ExecuteTime[0] = new Date(curdate);
var TimesExecuted = 0;

function checkclock ()
{
//Loop through ExecuteTime to see if there is an item to execute
//if there is execute it
var CurrentTime = new Date();
TimesExecuted ++;

if (TimesExecuted > 64)
{
	location.reload(true);
}
else
{
	var Done = 0;
	var i=0;
	if (ArrayCount == 0) Done = 1;
	while (Done == 0)
	{
	TheTime = ExecuteTime[i];
//	alert (TheTime.toLocaleString());
//	alert (CurrentTime.toLocaleString());
	if (TheTime < CurrentTime)
	{
		//Exec It
//		alert ("Timer Fired: " + JobArray[i]);
		var LoadImg = new Image(0,0);
		LoadImg.src = JobArray[i];
		elem = document.getElementById("img01");
		elem.src = LoadImg.src;
		var today = new Date();
		var dateInMS = today.getTime() + 1000 * 60 *60 * 25; //One Day
		var targetDate = new Date(dateInMS);
		ExecuteTime[i] = targetDate;
		Done = 1;

	}
	i++;
	if (i >= ArrayCount) Done = 1;
	}
}

}

function xmlhttpPost(strURL) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getquerystring());
}

function getquerystring() {
//This is where the "magic" happens. Get RunID from scheduler db
    qstr = "RunID=21";
    return qstr;
}

function updatepage(str){
     //If exists a secection show it otherise use status bar
	window.status = str;
//    alert(str);
}

//Get a new job id every x seconds
//Don't call xmlhttpPost IF jobid is going to be 0 ! 

function dopost()
{
var ran_unrounded= Math.random() * 150;
var ran_number=Math.floor(ran_unrounded); 
//alert ("5 seconds");
//xmlhttpPost("http://www.bwebcentral.com/runjob.php?RunID=" + ran_number);
checkclock();
setTimeout ('dopost();',62000); //62 seconds
}
setTimeout ('dopost();',20000); //20 second start

