// JavaScript Document

//attiva slide show
jQuery.fn.carousel = function(previous, next, options){
	var sliderList = jQuery(this).children()[0];
	
	if (sliderList) {
		var increment = jQuery(sliderList).children().outerWidth("true"),
		elmnts = jQuery(sliderList).children(),
		numElmts = elmnts.length,
		sizeFirstElmnt = increment,
		shownInViewport = Math.round(jQuery(this).width() / sizeFirstElmnt),
		firstElementOnViewPort = 1,
		isAnimating = false;
		
		for (i = 0; i < shownInViewport; i++) {
			jQuery(sliderList).css('width',(numElmts+shownInViewport)*increment + increment + "px");
			jQuery(sliderList).append(jQuery(elmnts[i]).clone());
		}
		
		jQuery(previous).click(function(event){
			if (!isAnimating) {
				if (firstElementOnViewPort == 1) {
					jQuery(sliderList).css('left', "-" + numElmts * sizeFirstElmnt + "px");
					firstElementOnViewPort = numElmts;
				}
				else {
					firstElementOnViewPort--;
				}
				
				jQuery(sliderList).animate({
					left: "+=" + increment,
					y: 0,
					queue: true
				}, "swing", function(){isAnimating = false;});
				isAnimating = true;
			}
			
		});
		
		jQuery(next).click(function(event){
			if (!isAnimating) {
				if (firstElementOnViewPort > numElmts) {
					firstElementOnViewPort = 2;
					jQuery(sliderList).css('left', "0px");
				}
				else {
					firstElementOnViewPort++;
				}
				jQuery(sliderList).animate({
					left: "-=" + increment,
					y: 0,
					queue: true
				}, "swing", function(){isAnimating = false;});
				isAnimating = true;
			}
		});
	}
};

//inizializza slide show
jQuery(document).ready(function(){
jQuery('#slider-stage').carousel('#previous', '#next');
jQuery('#viewport').carousel('#simplePrevious', '#simpleNext');  
});
function slide(){
$('#simpleNext').click();
}

//scroll ogni tot seconds
var intervalId = window.setInterval(slide, 4000);

//disattiva auto-scrolling
$('#previous, #simpleNext').click(
 function(){
  window.clearInterval(intervalId);
 });    


//------------popup privacy-------------

function popUp_pr(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=600,left = 283,top = 84');");
}



//------------valida form-------------

function invio_iscr(){
	//alert("ciao");
	var nome = document.getElementById("nome").value;
	var cognome = document.getElementById("cognome").value;
	var eta = document.getElementById("eta").value;
	var via = document.getElementById("via").value;
	var num = document.getElementById("num").value;
	var cap = document.getElementById("cap").value;
	var citta = document.getElementById("citta").value;
	var pr = document.getElementById("pr").value;
	var tel = document.getElementById("tel").value;
	var mail = document.getElementById("mail").value;
	var piva = document.getElementById("piva").value;
	var dati = document.getElementById("dati");

	

if(nome==""){
alert("Il campo 'Nome' è obbligatorio");
}else if(cognome==""){
alert("Il campo 'Cognome' è obbligatorio");	
}else if(eta==""){
alert("Il campo 'Età' è obbligatorio");	
}else if(via==""){
alert("Il campo 'Via' è obbligatorio");	
}else if(num==""){
alert("Il campo 'N°' è obbligatorio");	
}else if(cap==""){
alert("Il campo 'CAP' è obbligatorio");	
}else if(citta==""){
alert("Il campo 'Città' è obbligatorio");	
}else if(pr==""){
alert("Il campo 'Provincia' è obbligatorio");	
}else if(tel==""){
alert("Il campo 'Telefono' è obbligatorio");	
}else if(mail==""){
alert("Il campo 'E-mail°' è obbligatorio");	
}else if(piva==""){
alert("Il campo 'Codice Fiscale/P.IVA' è obbligatorio");	
}else if(dati.checked==false){
alert("Selezionare: CONSENSO AL TRATTAMENTO DEI DATI PERSONALI");	
}else{
	document.getElementById("form_iscr").submit();	
		}

}
//------------valida form 2-------------

function invio_iscr2(){
	//alert("ciao");
	var nome = document.getElementById("nome").value;
	var cognome = document.getElementById("cognome").value;
	var citta = document.getElementById("citta").value;
	var tel = document.getElementById("tel").value;
	var mail = document.getElementById("mail").value;
	var piva = document.getElementById("piva").value;


	

if(nome==""){
alert("Il campo 'Nome' è obbligatorio");
}else if(cognome==""){
alert("Il campo 'Cognome' è obbligatorio");	
}else if(citta==""){
alert("Il campo 'Città' è obbligatorio");	
}else if(tel==""){
alert("Il campo 'Telefono' è obbligatorio");	
}else if(mail==""){
alert("Il campo 'E-mail°' è obbligatorio");	
}else if(piva==""){
alert("Il campo 'Informazioni' è obbligatorio");	
}else{
	document.getElementById("form_iscr2").submit();	
		}

}

//---------------------------------------------------------------------------------------------
/*
//email
function inv_ma(pre,post) {
document.write("<a href=mai");
document.write("lto:"+pre+"@"+post+">"+pre+"@"+post+"</a>");
}
//inv_ma('nome','dominio.it');
*/