// JavaScript Document
var xmlHttp;

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 apriVota() {
	$("#boxVota").animate({ 
        height: "150px"
      }, 1500 );
}

function cambiaPagina(nP) {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="DBcambiaPagina.php";
	url=url+"?n="+nP;
	url=url+"&sid="+Math.random();

	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
			if (xmlHttp.responseText != "") {
				//cambio tendina provincia
				document.getElementById("gallery").innerHTML=xmlHttp.responseText;
			}
		} 
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function cambiaPassword() {
	errore = 0;
	msg = "";
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="CHKcambiapassword.php";
	url=url+"?v="+document.getElementById("vecchiaPassword").value;
	url=url+"&n="+document.getElementById("nuovaPassword").value;
	url=url+"&c="+document.getElementById("confermaPassword").value;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
			if (xmlHttp.responseText != "") {
				//errori
				$.prompt(xmlHttp.responseText);
			} else {
				//OK
				document.forms["frmCambiaPassword"].action = "cambiapassword.php";
				document.forms["frmCambiaPassword"].okp = "1";
				document.forms["frmCambiaPassword"].submit();
			}
		} 
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function cambiaProvince() {
	idReg = document.getElementById("idRegione").value;
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="DBcaricaProvince.php";
	url=url+"?n="+idReg;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
			if (xmlHttp.responseText != "") {
				//cambio tendina provincia
				document.getElementById("provincia").innerHTML=xmlHttp.responseText;
			}
		} 
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function cambiaProvincePrenota() {
	idReg = document.getElementById("idReg").value;
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="DBcaricaProvincePrenota.php";
	url=url+"?n="+idReg;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
			if (xmlHttp.responseText != "") {
				//cambio tendina provincia
				document.getElementById("prov").innerHTML=xmlHttp.responseText;
			}
		} 
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function chiudiVota() {
	$("#boxVota").animate({ 
        height: "0px"
      }, 1500 );
}
function validationArtista() {
	errore = 0;
	msg = "";
	
	if (document.getElementById("nome").value == "") {
		errore = 1;
		msg += "Occorre inserire il nome<br />";
	}
	
	if (document.getElementById("cognome").value == "") {
		errore = 1;
		msg += "Occorre inserire il cognome<br />";
	}
	
	if (document.getElementById("indirizzo").value == "") {
		errore = 1;
		msg += "Occorre inserire l'indirizzo<br />";
	}

	if (document.getElementById("cap").value == "") {
		errore = 1;
		msg += "Occorre inserire il cap<br />";
	}
	if (document.getElementById("comune").value == "") {
		errore = 1;
		msg += "Occorre inserire il comune<br />";
	}
	
	if (document.getElementById("provincia").value == "") {
		errore = 1;
		msg += "Occorre inserire la provincia<br />";
	}
	
	if (document.getElementById("telefono").value == "") {
		errore = 1;
		msg += "Occorre inserire il numero di telefono<br />";
	}

	if (document.getElementById("descrizioneOpera").value == "") {
		errore = 1;
		msg += "Occorre inserire la descrizione dell'opera<br />";
	}
	
	

	if (errore == 0) {
		//proseguo
		document.forms["frmRegistra"].action = "spazioartistaOK.php";
		document.forms["frmRegistra"].submit();
	} else {
		$.prompt(msg);
	}
	
}

function validationRegistrazione() {
	errore = 0;
	msg = "";
	
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	if (document.getElementById("nome").value == "") {
		errore = 1;
		msg += "Occorre inserire il nome<br />";
	}
	
	if (document.getElementById("cognome").value == "") {
		errore = 1;
		msg += "Occorre inserire il cognome<br />";
	}
	
	if (document.getElementById("indirizzo").value == "") {
		errore = 1;
		msg += "Occorre inserire l'indirizzo<br />";
	}

	if (document.getElementById("cap").value == "") {
		errore = 1;
		msg += "Occorre inserire il cap<br />";
	}
	if (document.getElementById("comune").value == "") {
		errore = 1;
		msg += "Occorre inserire il comune<br />";
	}
	
	if (document.getElementById("provincia").value == "") {
		errore = 1;
		msg += "Occorre inserire la provincia<br />";
	}

	if (document.getElementById("email").value == "") {
		errore = 1;
		msg += "Occorre inserire l'indirizzo e-mail<br />";
	}
	if (document.getElementById("username").value == "") {
		errore = 1;
		msg += "Occorre inserire l'username<br />";
	}

	if (document.getElementById("password").value == "") {
		errore = 1;
		msg += "Occorre inserire la password<br />";
	}
	if (document.getElementById("confermaPassword").value == "") {
		errore = 1;
		msg += "Occorre inserire la conferma della password<br />";
	}

	if (document.getElementById("password").value != document.getElementById("confermaPassword").value) {
		errore = 1;
		msg += "La password e la relativa conferma non corrispondono<br />";
	}

	if (document.getElementById("nomeOpera").value == "") {
		errore = 1;
		msg += "Occorre inserire il nome dell'opera<br />";
	}

	if (document.getElementById("descrizioneOpera").value == "") {
		errore = 1;
		msg += "Occorre inserire la descrizione dell'opera<br />";
	}
	
	if (document.getElementById("privacy").checked == "") {
		errore = 1;
		msg += "Occorre dare il consenso alla privacy<br />";
	}


	u = document.getElementById("username").value;
	e = document.getElementById("email").value;
	var url="CHKregistra.php";
	url=url+"?u="+u;
	url=url+"&e="+e;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
			if (xmlHttp.responseText != "") {
				//erorri: li visualizzo
				errore = 1;
				msg += xmlHttp.responseText;
			} 
			
			if (errore == 0) {
				//proseguo
				document.forms["frmRegistra"].action = "registrazioneOK.php";
				document.forms["frmRegistra"].submit();
			} else {
				$.prompt(msg);
			}
		} 
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
		
	
	
}

function validationRicerca() {
	errore = 0;
	msg = "";
	
	if ((document.getElementById("ricUser").value == "") && (document.getElementById("ricTitolo").value == "")) {
		errore = 1;
		msg += "Occorre inserire almeno un testo di ricerca<br />";
	}
	
	if (errore == 0) {
		//proseguo
		document.forms["ricercaOpere"].action = "ricerca.php";
		document.forms["ricercaOpere"].submit();
	} else {
		$.prompt(msg);
	}
}

function validationVota() {
	errore = 0;
	msg = "";

	xmlHttp = GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	
	if (document.getElementById("nomeVota").value == "") {
		errore = 1;
		msg += "Occorre inserire il nome<br />";
	}
	
	if (document.getElementById("cognomeVota").value == "") {
		errore = 1;
		msg += "Occorre inserire il cognome<br />";
	}
	
	if (document.getElementById("emailVota").value == "") {
		errore = 1;
		msg += "Occorre inserire l'indirizzo email<br />";
	}
	
	if (document.getElementById("privacy").checked == "") {
		errore = 1;
		msg += "Occorre dare il consenso alla privacy<br />";
	}

	
	if (errore == 0) {
		//proseguo
		n = document.getElementById("nomeVota").value;
		c = document.getElementById("cognomeVota").value;
		e = document.getElementById("emailVota").value;
		i = document.getElementById("idArt").value;
		var url="CHKvoto.php";
		url=url+"?n="+n;
		url=url+"&c="+c;
		url=url+"&e="+e;
		url=url+"&i="+i;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
				if (xmlHttp.responseText != "") {
					//erorri: li visualizzo
					$.prompt(xmlHttp.responseText);
				} else {
					//voto registrato
					$.prompt("grazie per il tuo voto.<br />Per renderlo valido clicca il link nella mail che ti abbiamo spedito.");
					chiudiVota();
				}
			} 
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		
	} else {
		$.prompt(msg);
	}
}