// JavaScript Document

function createRequestObject() {
	var req = false;
	if (typeof XMLHttpRequest != "undefined")
		req = new XMLHttpRequest();
	if (!req && typeof ActiveXObject != "undefined") {
		try {
			req=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				req=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				try {
					req=new ActiveXObject("Msxml2.XMLHTTP.4.0");
				} catch (e3) {
					req=null;
				}
			}
		}
	}

	if(!req && window.createRequest)
		req = window.createRequest();

	if (!req) alert("Il browser non supporta AJAX");

	return req;
}


var http = createRequestObject();

var isBusy ='';
function sndReq(action,idoutput) {
	if (isBusy == true)
	{
		http.onreadystatechange = null;
		http.abort();
	}
	http.open('get', '/include/getgrab.inc.php?'+action+'&idoutput='+idoutput);
	isBusy = true;
	http.onreadystatechange = handleResponse;
	http.send(null);
}

function sndReqnew(action,idoutput) {
	if (isBusy == true)
	{
		http.onreadystatechange = null;
		http.abort();
	}
	http.open('get', '/include/getgrabnew.inc.php?'+action+'&idoutput='+idoutput);
	isBusy = true;
	http.onreadystatechange = handleResponse;
	http.send(null);
}

function handleResponse() {
	if(http.readyState == 4){
		var response = http.responseText;
		var update = new Array();

		if(response.indexOf(']|[' != -1)) {
			update = response.split(']|[');
			document.getElementById(update[0]).src = update[1];
			if (update[1]=='http://img.bloo.it/preload.gif') {
				/*handleResponse.intervallo = window.setInterval(function () {
				//var intervallo = window.setInterval(function () {
				  sndReq('Url='+update[2],update[0]);
				},5000);*/
			} else {
				//clearInterval(handleResponse.intervallo);
			}
		}
	} else {
		isBusy = false;
	}
}

function remdiv(divid) {
	document.getElementById(divid+'minus').style.display='none';
	document.getElementById(divid).innerHTML = '';
	//var DIVtoRemove = document.getElementById(divid);
	//DIVtoRemove.parentNode.removeChild(DIVtoRemove);
}

