

function ajax(url, cliccato, onload, parameters, onerror){
	var	xhr = window.XMLHttpRequest ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP"),
		onreadystatechange = function(){
			if(xhr.readyState === 4) {
				if(xhr.status === 200){
				if(xhr.responseText != "concluso" && finito != true){
				  document.getElementById('results').innerHTML = ""
					document.getElementById('status').innerHTML = xhr.responseText
					x = window.setTimeout("ajax('check.php')", 10000);
				}else if(xhr.responseText == "concluso"){
					finito = true
					ajax('view.php')
				}else{
				  document.getElementById('status').innerHTML = ""
					document.getElementById('results').innerHTML = xhr.responseText
				}
				}else if(onerror){
					onerror(xhr);
					}
			}
		},
		post = [],
		key;
	for(key in parameters)
		post.push("&", key, "=", encodeURIComponent(parameters[key]));
	post.shift();
	xhr.open("post", url, true);
	xhr.onreadystatechange = onreadystatechange;
	xhr.send(post.join("") || null);
};

function start(){
  finito = false;
  x = window.setTimeout("ajax('check.php')", 2000);
}
 



