// JavaScript Document

var tempoCambioFoto = 3000;
var fotoNumero = 0;
var preloadImage = new Array();
var fotoAlterna = 1;
var rispostaArray;
var preloadFotoFatto1,preloadFotoFatto2= false;

MM_preloadImages('immagini/menuAlto/novitaSel.gif','immagini/menuAlto/newsSel.gif','immagini/menuAlto/lavoraConNoiSel.gif','immagini/menuAlto/contattiSel.gif','immagini/menuAlto/serviziSel.gif','immagini/menuAlto/orarioSel.gif','immagini/menuAlto/videoEfotoGallerySel.gif','immagini/menuAlto/provaIlClubSel.gif','immagini/menuAlto/lasciaUnCommentoSel.gif','immagini/menuAlto/linkSel.gif','immagini/menuAlto/egoSel.gif');




function linkMenuAlto(pagina)
{
	if(document.getElementById(pagina+"Img") && document.getElementById(pagina+"Img").src.match("menuAlto") != null)
	{
		img = document.getElementById(pagina+"Img");
		img.src = "immagini/menuAlto/"+pagina+"Sel.gif";
		img.onmouseout = "";
		img.onmouseover = "";
		//lnk = document.getElementById(pagina+"Lnk");
		//alert(lnk.href);
		//lnk.href = ""; 
		//alert(lnk.href);
	}
}

function linkMenuCentraleAlto(pagina)
{
	if(document.getElementById(pagina+"Img") && document.getElementById(pagina+"Img").src.match("menuCentraleAlto") != null)
	{
		img = document.getElementById(pagina+"Img");
		img.src = "immagini/menuCentraleAlto/"+pagina+"Sel.gif";
		img.onmouseout = "";
		img.onmouseover = "";
		
	}
}
function linkMenuFoto(pagina)
{
	
	if(document.getElementById(pagina+"Img") && document.getElementById(pagina+"Img").src.match("menuFoto") != null)
	{
		img = document.getElementById(pagina+"Img");
		img.src = "immagini/menuFoto/"+pagina+"Sel.png";
		img.onmouseout = "";
		img.onmouseover = "";
		//lnk = document.getElementById(pagina+"Lnk");
		//alert(lnk.href);
		//lnk.href = ""; 
		//alert(lnk.href);
	}
}


function cambiaFotoElink(pagina)
{	
	linkMenuAlto(pagina);
	linkMenuCentraleAlto(pagina);
	linkMenuFoto(pagina);
/*
	top:53px;
	left:20px;
*/
	//new Effect.Appear('menuInternoFoto', { duration: 1.5,delay: 2,to: 1 });
	new Effect.Move('menuInternoFoto', { x: 20, y: 53, mode: 'absolute',delay:2 });
	
	url = "script/caricaFoto.js.php?pagina="+pagina;

	//new Effect.Appear('fotoAltaImg', { duration: 1});

	new Ajax.Request(url,{ onSuccess: function(transport)
	{
		
		var risposta = '';
		if (transport.responseText != "")
		{
			var temp;
			temp			= transport.responseText;
			var test = temp.split("===");
			
			if ( test[0] == "errore" )
			{
				alert("<b>ERRORE</b>:<br/> "+test[1]);
			}
			else
			{
				rispostaArray 	= temp.split(" <&&&> ");
				
				numeroRecord 	= rispostaArray.length-1;
				for(i=0 ; i<(rispostaArray.length-1) ; i++)
				{	
					MM_preloadImages(rispostaArray[i]);
					preloadImage = new Image();
					preloadImage.src = rispostaArray[i];
					$('fotoAltaImg2').src = rispostaArray[0];
					new Ajax.Request($('fotoAltaImg2').src,{ onSuccess: function(transport)
															{ 
																new Effect.Appear('fotoAltaImg2', { duration: 1.5 });	
															} } );
					
				}
				
				if (rispostaArray.length > 2)
				{	
					for(var i=0; i < rispostaArray.length-1 ; i++)
					{
						//alert(rispostaArray[i]);
						//preloadImage[i] = new Image();
						//preloadImage[i].src = rispostaArray[i];
						MM_preloadImages(rispostaArray[i]);
						//alert(rispostaArray[i]);
					}
					
					cambiaFoto();
					
				}
				
			}
		}
			//ShowTip(this, "<b>Attenzione</b>:<br/> Nessun evento trovato!",true);
		
	}
	, onUninitialized: function(transport)
	{
		//ShowTip(this,"Caricando.",false);
	}				
	, onLoading: function(transport)
	{
		//ShowTip(this,"Caricando..",false);
	}		
	
	} );
}

function cambiaFoto()
{
	if (fotoNumero == rispostaArray.length-1)	fotoNumero = 0;
	if (fotoAlterna == 1)
	{
		$("fotoAltaImg2").src = rispostaArray[fotoNumero];
		new Effect.Fade('fotoAltaImg', { duration: 1.5,to:0.0001}); 	
		new Effect.Appear('fotoAltaImg2', { duration: 1.5,afterFinish: function(){setTimeout(cambiaFoto,tempoCambioFoto);} });
		fotoAlterna = 2;
	}
	else
	{
		$("fotoAltaImg").src = rispostaArray[fotoNumero];
		new Effect.Fade('fotoAltaImg2', { duration: 1.5,to:0.0001}); 
		new Effect.Appear('fotoAltaImg', { duration: 1.5,afterFinish: function(){setTimeout(cambiaFoto,tempoCambioFoto);} });
		fotoAlterna = 1;		
	}
	fotoNumero++;
}

function cambiaFotoOld()
{
	
	if (fotoNumero == rispostaArray.length-1)	fotoNumero = 0;


	if (fotoAlterna == 1)
	{
		
		/*if(	!preloadFotoFatto1 )
		{
			new Ajax.Request(rispostaArray[fotoNumero],{ onSuccess: function(transport){ 
				//alert("cambio src");
				
				new Effect.Fade('fotoAltaImg', { duration: 1.5,to:0.0001}); 
				//alert("avvio cambio foto fade src");
				$("fotoAltaImg2").src = rispostaArray[fotoNumero];
				new Effect.Appear('fotoAltaImg2', { duration: 1.5 });
				// ,afterFinish: function(){setTimeout(cambiaFoto,tempoCambioFoto);}
				//alert("avvio cambio foto appear 2 src");
				fotoAlterna = 2;							   
													   
			}  } );
			preloadFotoFatto1 = true;
		}
		else
		{*/
				//alert(rispostaArray[fotoNumero])
				$("fotoAltaImg2").src = rispostaArray[fotoNumero];
				new Effect.Fade('fotoAltaImg', { duration: 1.5,to:0.0001}); 
			
				new Effect.Appear('fotoAltaImg2', { duration: 1.5,afterFinish: function(){setTimeout(cambiaFoto,tempoCambioFoto);} });
				fotoAlterna = 2;							   
		//}
	
	}
	else
	{
		//alert("secondo");
		/*if(	!preloadFotoFatto2 )
		{
			new Ajax.Request(rispostaArray[fotoNumero],{ onSuccess: function(transport){ 
					new Effect.Fade('fotoAltaImg2', { duration: 1.5,to:0.0001}); 
					
					$("fotoAltaImg").src = rispostaArray[fotoNumero];
					new Effect.Appear('fotoAltaImg', { duration: 1.5,afterFinish: function(){setTimeout(cambiaFoto,tempoCambioFoto);} });
					fotoAlterna = 1;
				
			}});
			preloadFotoFatto2 = true;
		}
		else
		{*/
			//new Ajax.Request(rispostaArray[fotoNumero],{ onSuccess: function(transport){ 
					new Effect.Fade('fotoAltaImg2', { duration: 1.5,to:0.0001}); 
					
					$("fotoAltaImg").src = rispostaArray[fotoNumero];
					new Effect.Appear('fotoAltaImg', { duration: 1.5,afterFinish: function(){setTimeout(cambiaFoto,tempoCambioFoto);} });
					fotoAlterna = 1;
				
			//}});
		//}
	}	
	
	fotoNumero++;

}


function checkFormLasciaCommento(form)
{	
	if(conSeVuoto(form.nome))
	{
		erroreMsg("Inserire il nome",form.nome)
		return false;
	}
	if(conSeVuoto(form.cognome))
	{
		erroreMsg("Inserire il cognome",form.cognome)
		return false;
	}
	if(conSeVuoto(form.email))
	{
		erroreMsg("Inserire l'email",form.email)
		return false;
	}
	if(conEmail(form.email))
	{
		erroreMsg("Inserire l'email correttamente",form.email)
		return false;
	}
	if(conSeVuotoTextArea(form.messaggio))
	{
		erroreMsg("Inserire il messaggio",form.messaggio)
		return false;
	}
	if(form.privacy[1].checked)
	{
		erroreMsg("E' necessario accettare la legge sulla privacy",form.privacy[1])
		return false;
	}	
	inviaEmailCommento();
	return false;
}

// Invio email

function inviaEmailCommento()
{
	url = 'script/inviaCommento.php';
	var form1 = document.lavora;
	
	variabili = 'nome=' + form1.nome.value + '&cognome=' + form1.cognome.value ;
	variabili += '&socio=' + form1.socio[0].checked;
	variabili += '&telefono=' + form1.tel.value;
	variabili += '&email=' + form1.email.value + '&messaggio=' + form1.messaggio.value ;

	new Ajax.Request(url,{method:'post', postBody:variabili , onSuccess: function(transport)
	{
		var risposta = '';
		if (transport.responseText != "errore" && transport.responseText == "ok")
		{
			ShowTip(this, "<b>Invio eseguito con successo</b>:<br/> Email inviata correttamente.",true);
			
		}
		else
			ShowTip(this, "<b>Errore</b>:<br/> Email <b>NON</b> inviata!<br/>Riprovare più tardi. ",true);
		
	}
	, onUninitialized: function(transport)
	{
		ShowTip(this,"Invio in corso. <img src=\"immagini/loading.gif\"/>",false);
	}				
	, onLoading: function(transport)
	{
		ShowTip(this,"Invio in corso.. <img src=\"immagini/loading.gif\"/>",false);
	}		
	
	} );
}


function checkFormLavoraConNoi(form)
{	
	if(conSeVuoto(form.nome))
	{
		erroreMsg("Inserire il nome",form.nome)
		return false;
	}
	if(conSeVuoto(form.cognome))
	{
		erroreMsg("Inserire il cognome",form.cognome)
		return false;
	}
	if(conSeVuoto(form.email))
	{
		erroreMsg("Inserire l'email",form.email)
		return false;
	}
	if(conEmail(form.email))
	{
		erroreMsg("Inserire l'email correttamente",form.email)
		return false;
	}
	if(conSeVuoto(form.cv))
	{
		erroreMsg("Inserire il CV",form.cv)
		return false;
	}
	if(form.privacy[1].checked)
	{
		erroreMsg("E' necessario accettare la legge sulla privacy",form.privacy[1])
		return false;
	}	
	return true;
}


function checkFormProvaIlClub(form)
{	
	if(conSeVuoto(form.nome))
	{
		erroreMsg("Inserire il nome",form.nome)
		return false;
	}
	if(conSeVuoto(form.cognome))
	{
		erroreMsg("Inserire il cognome",form.cognome)
		return false;
	}
	if(conSeVuoto(form.email))
	{
		erroreMsg("Inserire l'email",form.email)
		return false;
	}
	if(conEmail(form.email))
	{
		erroreMsg("Inserire l'email correttamente",form.email)
		return false;
	}

	if(form.privacy[1].checked)
	{
		erroreMsg("E' necessario accettare la legge sulla privacy",form.privacy[1])
		return false;
	}	
	inviaEmailProvaIlClub();
	return false;
}

// Invio email

function inviaEmailProvaIlClub()
{
	url = 'script/inviaProvaIlClub.php';
	var form1 = document.prova;
	
	variabili = 'nome=' + form1.nome.value + '&cognome=' + form1.cognome.value ;
	variabili += '&come=' + form1.come.value;
	variabili += '&telefono=' + form1.tel.value;
	variabili += '&email=' + form1.email.value ;

	new Ajax.Request(url,{method:'post', postBody:variabili , onSuccess: function(transport)
	{
		var risposta = '';
		if (transport.responseText != "errore" && transport.responseText == "ok")
		{
			ShowTip(this, "<b>Invio eseguito con successo</b>:<br/> Richiesta inviata correttamente.<br>Riceverai il messaggio al più presto!",true);
			
		}
		else
			ShowTip(this, "<b>Errore</b>:<br/> Email <b>NON</b> inviata!<br/>Riprovare più tardi. ",true);
		
	}
	, onUninitialized: function(transport)
	{
		ShowTip(this,"Invio in corso. <img src=\"immagini/loading.gif\"/>",false);
	}				
	, onLoading: function(transport)
	{
		ShowTip(this,"Invio in corso.. <img src=\"immagini/loading.gif\"/>",false);
	}		
	
	} );
}

function checkFormLogin(form)
{	
	if(conSeVuoto(form.entered_login))
	{
		erroreMsg("Inserire la username",form.entered_login)
		return false;
	}
	if(conSeVuoto(form.entered_password))
	{
		erroreMsg("Inserire la password",form.entered_password)
		return false;
	}
	checkLoginAjax();
	return false;

	
}

function checkLoginAjax()
{
	url = 'script/collegamento.php';
	var form1 = document.checkLogin;
	
	variabili = 'entered_login=' + form1.entered_login.value + '&entered_password=' + form1.entered_password.value ;
	variabili += '&ajax=true';


	new Ajax.Request(url,{method:'post', postBody:variabili , onSuccess: function(transport)
	{
		var risposta = '';
		//alert(transport.responseText);
		var test = transport.responseText.split("=");
		if (transport.responseText != "errore" && test[0] == "ok")
		{
			ShowTip(this, "<b>Login eseguito con successo</b><br/>Ciao "+test[1]+",<br>Puoi ora visitare tutte le sezioni del nostro sito",false);
			document.getElementById("boxLogin").innerHTML = "<span class='boxLogin'>Ciao,<br /> "+test[1]+"</span>";
			
			
			t = setTimeout("HideTip();", 3000);
			//return true;
		}
		else
		{	
			ShowTip(this, "<b>Errore</b>:<br/> Username o Password <b>SBAGLIATA</b> <br/>Riprovare. ",true);
			//return false;
		}
		
	}
	, onUninitialized: function(transport)
	{
		ShowTip(this,"Invio in corso. <img src=\"immagini/loading.gif\"/>",false);
	}				
	, onLoading: function(transport)
	{
		ShowTip(this,"Invio in corso.. <img src=\"immagini/loading.gif\"/>",false);
	}		
	
	} );
}
function checkFormRegistrati(form)
{	
	if(conSeVuoto(form.nome))
	{
		erroreMsg("Inserire il nome",form.nome)
		return false;
	}
	if(conSeVuoto(form.cognome))
	{
		erroreMsg("Inserire il cognome",form.cognome)
		return false;
	}
	if(!conSeVuoto(form.cap))
	{
		if(conSoloNumeri(form.cap) || conLunghezza(form.cap,5))
		{
			erroreMsg("Inserire il cap correttamente",form.cap)
			return false;
		}
	}
	if(!conSeVuoto(form.provincia))
	{
		if(conLunghezza(form.provincia,2))
		{
			erroreMsg("Inserire la provincia correttamente",form.provincia)
			return false;
		}
	}
	if(conSeVuoto(form.email))
	{
		erroreMsg("Inserire l'email",form.email)
		return false;
	}
	if(conEmail(form.email))
	{
		erroreMsg("Inserire l'email correttamente",form.email)
		return false;
	}
/*	
	if(conSeSelezionato(form.sesso) )
	{
		erroreMsg("Scegliere il sesso",form.sesso)
		return false;
	}	
*/	
	if(conSeVuoto(form.username))
	{
		erroreMsg("Inserire l'username scelto",form.username)
		return false;
	}
	if(conLungMinima(form.username,6))
	{
		erroreMsg("L'username scelto deve essere minimo di 6 caratteri",form.username)
		return false;
	}
	if(caratteriBrutti(form.username))
	{
		erroreMsg("Attenzione, caratteri non autorizzati nel campo Username",form.username)
		return false;
	}
	if(conSeVuoto(form.password))
	{
		erroreMsg("Inserire la password",form.password)
		return false;
	}
	if(conLungMinima(form.password,6))
	{
		erroreMsg("La password scelta deve essere minimo di 6 caratteri",form.password)
		return false;
	}
	if(caratteriBrutti(form.password))
	{
		erroreMsg("Attenzione, caratteri non autorizzati nel campo Password",form.password)
		return false;
	}
	if(form.privacy[1].checked)
	{
		erroreMsg("E' necessario accettare la legge sulla privacy",form.privacy[1])
		return false;
	}	
	
	controllaUsername();
	return false;
}
function invioEmailAttivazione()
{
	//HideTip();
	url = 'script/inviaAttivazione.php';
	var form1 = document.formRegistrati;
	if(form1.news.checked)
		news = 1;
	else
		news = 0;
		
	variabili = 'nome=' + form1.nome.value + '&cognome=' + form1.cognome.value + '&news=' + news ;
	variabili += '&indirizzo=' + form1.indirizzo.value + '&comune=' + form1.comune.value + '&cap=' + form1.cap.value ;
	variabili += '&provincia=' + form1.provincia.value + '&tel=' + form1.tel.value + '&cel=' + form1.cel.value ;
	variabili += '&email=' + form1.email.value  + '&username=' + form1.username.value + '&password=' + form1.password.value ;

	new Ajax.Request(url,{method:'post', postBody:variabili , onSuccess: function(transport)
	{
		var risposta = '';
		//alert(transport.responseText);
		if (transport.responseText != "errore" && transport.responseText == "ok")
		{
			ShowTip(this, "<b>Richiesta inviata correttamente</b>:<br/> Riceverai un'email di conferma al più presto, leggila e segui le istruzioni",true);
			
		}
		else
			ShowTip(this, "<b>Errore</b>:<br/> Email <b>NON</b> inviata!<br/>Riprovare più tardi. ",true);
		
	}
	, onUninitialized: function(transport)
	{
		ShowTip(this,"Invio in corso. <img src=\"immagini/loading.gif\"/>",false);
	}				
	, onLoading: function(transport)
	{
		ShowTip(this,"Invio in corso.. <img src=\"immagini/loading.gif\"/>",false);
	}		
	
	} );
}

function controllaUsername()
{
	url = 'script/controllaUsername.php';
	var form1 = document.formRegistrati;
	
	variabili = 'username=' + form1.username.value;

	new Ajax.Request(url,{method:'post', postBody:variabili , onSuccess: function(transport)
	{
		var risposta = '';
		//alert(transport.responseText);
		var test = transport.responseText.split("=");
		if (transport.responseText != "errore" && test[0] == "ok")
		{
			HideTip();
			invioEmailAttivazione();
		}
		else
		{	
			ShowTip(this, "L'username scelto è già stato registrato, sceglierne un'altro ",true);
			return false;
		}
		
	}
	, onUninitialized: function(transport)
	{
		ShowTip(this,"Ricerca Username in corso. <img src=\"immagini/loading.gif\"/>",false);
	}				
	, onLoading: function(transport)
	{
		ShowTip(this,"Ricerca Username in corso.. <img src=\"immagini/loading.gif\"/>",false);
	}		
	
	} );
}

function checkFormNewsletter(form)
{	
	if(conSeVuoto(form.email))
	{
		erroreMsg("Inserire l'email",form.email)
		return false;
	}
	if(conEmail(form.email))
	{
		erroreMsg("Inserire un indirizzo email valido",form.email)
		return false;
	}
	if(form.privacy[1].checked)
	{
		erroreMsg("E' necessario accettare la legge sulla privacy",form.privacy[1])
		return false;
	}	

	controllaEmailNewsletter();
	return false;
}
function controllaEmailNewsletter() {
	url = 'script/controllaEmailNewsletter.php';
	var form1 = document.formRegistrati;
	
	variabili = 'email=' + form1.email.value;
	new Ajax.Request(url,{method:'post', postBody:variabili , 
		onSuccess: function(transport)
		{
			var risposta = '';
			var test = transport.responseText.split("=");
			if (transport.responseText != "errore" && test[0] == "ok")
			{
				HideTip();
				invioEmailAttivazioneNewsletter();
			}
			else
			{	
				ShowTip(this, "L'indirizzo email scelto è già presente nella lista, scegliene un altro",true);
				return false;
			}
			
		}
		, onUninitialized: function(transport)
		{
			ShowTip(this,"Ricerca Email in corso. <img src=\"immagini/loading.gif\"/>",false);
		}				
		, onLoading: function(transport)
		{
			ShowTip(this,"Ricerca Email in corso.. <img src=\"immagini/loading.gif\"/>",false);
		}		
	} );
}
function invioEmailAttivazioneNewsletter()
{
	//HideTip();
	url = 'script/inviaAttivazioneNewsletter.php';
	var form1 = document.formRegistrati;
	variabili = 'email=' + form1.email.value;
	new Ajax.Request(url,{method:'post', postBody:variabili , 
		onSuccess: function(transport)
		{
			var risposta = '';
			//alert(transport.responseText);
			if (transport.responseText != "errore" && transport.responseText == "ok")
			{
				ShowTip(this, "<b>Richiesta inviata correttamente</b>:<br/> Riceverai un'email di conferma al più presto, leggila e segui le istruzioni",true);
			}
			else
				ShowTip(this, "<b>Errore</b>:<br/> Email <b>NON</b> inviata!<br/>Riprovare più tardi. ",true);
			
		}
		, onUninitialized: function(transport)
		{
			ShowTip(this,"Invio in corso. <img src=\"immagini/loading.gif\"/>",false);
		}				
		, onLoading: function(transport)
		{
			ShowTip(this,"Invio in corso.. <img src=\"immagini/loading.gif\"/>",false);
		}		
	} );
}


