var monitor=0;
var interval=1000;
var callcount=0;
var queue = new Array();
function request(w,x,y,z){
	this.url=w;
	this.target=x;
	this.mode=y;
	this.method=z;
}


function monitorqueue(){
	var html="";
	for(i=0; i<queue.length; i++){
		html+= i + " " + queue[i]['url'];
		html+= " " + queue[i]['target'];
		html+= " " + queue[i]['mode'];
		html+="<br>";
	}
	document.getElementById('queue').innerHTML=html;
	document.getElementById('mycallcount').innerHTML=callcount;
	document.getElementById('mycompleted').innerHTML=callcount-queue.length;
}


function checkqueue(){

	if (monitor==1){
		monitorqueue();
	}

	if (queue.length>0){
		tempobj=queue.shift();
		if(tempobj.method==1){
			getScript(tempobj.target,tempobj.url,tempobj.mode);
		}
		else if(tempobj.method==2){
			getAddedHTML(tempobj.target,tempobj.url,tempobj.mode);
		}
		else{
			getHTML(tempobj.target,tempobj.url,tempobj.mode);

		}
	}

}



var queuetimer = setInterval(checkqueue, interval);	 

function stopqueue(){
	clearInterval(queuetimer);
}

function startqueue(){
	queuetimer = setInterval(checkqueue, interval);	 
}




//		getHTML('ad'+pagelocation,url,'0');


var pagelocation=1;
function loadrequest()
{
		var url = 'http://gmcbpm-dev.ad.goodmanmfg.com:8181/result.jsp';
		var target='ad'+pagelocation;
		var mode=0;
		queue.push(new request(url,target,mode));
		pagelocation+=1;
		callcount+=1;
		if (pagelocation>4){pagelocation=1;}

		if (monitor==1){
			monitorqueue();
		}

}

function addToQueue(method,target,url)
{
		/* URL CANNOT BE ON A DIFFERENT SERVER THAN THE HOSTED APPLICATION UNLESS IT IS THE LOCAL MACHINE */
		//var url = 'http://gmcbpm-dev.ad.goodmanmfg.com:8181/result.jsp';
		//var url = 'result.jsp';

		/*
		//	method: 1=calls getScript() from checkqueue()
		//	method: 2=calls getAddedHTML() from checkqueue() for appending HTML
		//		'' calls getHTML() from checkqueue()
		//
		//	target: id of html entity to update
		//
		//	url: url to server-side processing script 
		//
		*/

		var mode=1;
		// mode =1 to force fresh data with appended time value

		queue.push(new request(url,target,mode,method));
		callcount+=1;
		if (monitor==1){
			monitorqueue();
		}

}


