// JavaScript Document
// AJAX <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function cambiaPagina(pagina,id) 
{
	
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
			  alert ("Your browser does not support AJAX!");
			  return;
		  }
	limite = pagina*50;

	xmlHttp.onreadystatechange=cambioStatoProvincia;
	var url="up_img.php?limit="+limite+"&id="+id;
	url=url+"&kaes="+Math.random();


	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
}

function cambioStatoProvincia() 
{
	
	if (xmlHttp.readyState==4)
		{ 
			//document.getElementById("statotext").appendChild="Stato aggiornato";
			//alert("Stato cambiato !");
			var t = xmlHttp.responseText;
			document.getElementById("photocontainer").innerHTML = t;
		}
	if (xmlHttp.readyState==3)
		{ 
			var t ="Operazione in corso....";
			document.getElementById("select_provincia").innerHTML = t;
			document.getElementById("select_comune").innerHTML = "";
			
		}
	if (xmlHttp.readyState==2)
		{ 
			var t ="Operazione in corso....";
			document.getElementById("select_provincia").innerHTML = t;
			document.getElementById("select_comune").innerHTML = "";
			
		}
	if (xmlHttp.readyState==1)
		{ 
			var t ="Invio....";
			document.getElementById("select_provincia").innerHTML = t;
			document.getElementById("select_comune").innerHTML = "";
		}
	if (xmlHttp.readyState==0)
		{ 
			alert("richiesta non inviata");
		}
		
}

function cambioStatoComune() 
{
	
	if (xmlHttp.readyState==4)
		{ 
			//document.getElementById("statotext").appendChild="Stato aggiornato";
			//alert("Stato cambiato !");
			var t = xmlHttp.responseText;
			document.getElementById("select_comune").innerHTML = t;
		
		}
	if (xmlHttp.readyState==3)
		{ 
			var t ="Operazione in corso....";
			document.getElementById("select_comune").innerHTML = t;
			//alert("per la via");
		}
	if (xmlHttp.readyState==2)
		{ 
			var t ="Operazione in corso....";
			document.getElementById("select_comune").innerHTML = t;
			//alert("per la via");
		}
	if (xmlHttp.readyState==1)
		{ 
			var t ="Invio....";
			document.getElementById("select_comune").innerHTML = t;

		}
	if (xmlHttp.readyState==0)
		{ 
			alert("richiesta non inviata");
		}
		
}

function cambioStatoProvinciaDest() 
{
	
	if (xmlHttp.readyState==4)
		{ 
			//document.getElementById("statotext").appendChild="Stato aggiornato";
			//alert("Stato cambiato !");
			var t = xmlHttp.responseText;
			document.getElementById("select_provincia_dest").innerHTML = t;
			document.getElementById("select_comune_dest").innerHTML = "";
			
		}
	if (xmlHttp.readyState==3)
		{ 
			var t ="Operazione in corso....";
			document.getElementById("select_provincia_dest").innerHTML = t;
			document.getElementById("select_comune_dest").innerHTML = "";
			
		}
	if (xmlHttp.readyState==2)
		{ 
			var t ="Operazione in corso....";
			document.getElementById("select_provincia_dest").innerHTML = t;
			document.getElementById("select_comune_dest").innerHTML = "";
		}
	if (xmlHttp.readyState==1)
		{ 
			var t ="Invio....";
			document.getElementById("select_provincia_dest").innerHTML = t;
			document.getElementById("select_comune_dest").innerHTML = "";
		}
	if (xmlHttp.readyState==0)
		{ 
			alert("richiesta non inviata");
		}
		
}

function cambioStatoComuneDest() 
{
	 
	if (xmlHttp.readyState==4)
		{ 
			var t = xmlHttp.responseText;
			document.getElementById("select_comune_dest").innerHTML = t;
		}
	if (xmlHttp.readyState==3)
		{ 
			var t ="Operazione in corso....";
			document.getElementById("select_comune_dest").innerHTML = t;
			//alert("per la via");
		}
	if (xmlHttp.readyState==2)
		{ 
			var t ="Operazione in corso....";
			document.getElementById("select_comune_dest").innerHTML = t;
			//alert("per la via");
		}
	if (xmlHttp.readyState==1)
		{ 
			var t ="Invio....";
			document.getElementById("select_comune_dest").innerHTML = t;

		}
	if (xmlHttp.readyState==0)
		{ 
			alert("richiesta non inviata");
		}
		
}

function loginCheck() {
	
	username = document.getElementById("user").value;
	password = document.getElementById("pass").value;
	if ((username!=='')&&(password!=='')){
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null) {
			  alert ("Your browser does not support AJAX!");
			  return;
		 }
		xmlHttp.onreadystatechange=login_response;
		var url="login_check.php?user="+username+"&pass="+md5(password);
		url=url+"&kaes="+Math.random();
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}else{
		alert('Inserire nome utente e password');
		document.getElementById("user").value = '';
		document.getElementById("pass").value ='';
	}
}

function login_response(){
	 
	if (xmlHttp.readyState==4){ 
			var t = xmlHttp.responseText;
			document.getElementById("login_box").innerHTML = t;
			window.location.reload( false );
	}
}

function logout() {
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null) {
			  alert ("Your browser does not support AJAX!");
			  return;
		 }
		xmlHttp.onreadystatechange=logout_response;
		var url="login_check.php?action=logout";
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
}

function logout_response(){
	 
	if (xmlHttp.readyState==4){ 
			window.location.reload( false );
	}
}

function select_updater() {
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null) {
			  alert ("Your browser does not support AJAX!");
			  return;
		 }
		xmlHttp.onreadystatechange=select_updater_response;
		var url="select_updater.php";
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
}

function select_updater_response(){
	if (xmlHttp.readyState==4){ 
			var t = xmlHttp.responseText;
			document.getElementById("select_regione").innerHTML = t;
	}
}