// JavaScript Document

$(document).ready(function() {
	var i = 1;
	/*while ($("#contenitore_testo_totale").html().length > 1) {
		var h = document.getElementById("pagina3").offsetHeight;
		var offset = 0;
		var maxh = 801;
		if (i == 1) {
			maxh = 650;	
		}
		while(h <= maxh) {
			if (document.getElementById("contenitore_testo_totale").offsetHeight <= maxh) {
				$("#pagina"+i).html($("#contenitore_testo_totale").html());
				h = maxh+10;	
			} else {
				$("#pagina"+i).html($("#contenitore_testo_totale").html().substr(0,$("#contenitore_testo_totale").html().indexOf(" ",offset)));
				offset = $("#contenitore_testo_totale").html().indexOf(" ",offset) + 1;
				h = document.getElementById("pagina"+i).offsetHeight;
			}
		}
		$("#contenitore_testo_totale").html($("#contenitore_testo_totale").html().replace($("#pagina"+i).html(),""));
		i = i+1;
	}
	for(i=0;i<7;i++) {
		if ($("#pagina"+i).html() == "") {
				$("#pagina"+i).remove();
				if (i==2) {
					$("#actions").css("display","none");	
				}
		}
	}
	$("#contenitore_testo_totale").remove();
	var fl = "<span id='fl'>"+$("#pagina1").text().substr(0,1)+"</span>";
	$("#pagina1").html(fl+$("#pagina1").html().substr(1,$("#pagina1").html().length));*/
	/*$("#nextPage").mouseover(function() {
		if (!$(this).hasClass("disabled")) {
			$(this).css("background",$(this).css("backgroundImage").replace("_OFF","_ON"));
		}
	}).mouseout(function() {
		if (!$(this).hasClass("disabled")) {
			$(this).css("background",$(this).css("backgroundImage").replace("_ON","_OFF"));
		} else {
			$(this).css("background",$(this).css("backgroundImage").replace("_ON","_disabled"));
			$(this).css("background",$(this).css("backgroundImage").replace("_OFF","_disabled"));
		}
	});
	
	$("#prevPage").mouseover(function() {
		if (!$(this).hasClass("disabled")) {
			$(this).css("background",$(this).css("backgroundImage").replace("_OFF","_ON"));
			$(this).css("background",$(this).css("backgroundImage").replace("_disabled","_ON"));
		}
	}).mouseout(function() {
		if (!$(this).hasClass("disabled")) {
			$(this).css("background",$(this).css("backgroundImage").replace("_ON","_OFF"));
		} else {
			$(this).css("background",$(this).css("backgroundImage").replace("_ON","_disabled"));
			$(this).css("background",$(this).css("backgroundImage").replace("_OFF","_disabled"));
		}
	});*/
	$("input").example(function() {
		 return $(this).attr('title'); 
	});	
	
	$("#js_invia").mouseover(function() {
		$(this).attr("src",$(this).attr("src").replace("_OFF","_ON"));
	}).mouseout(function() {
		$(this).attr("src",$(this).attr("src").replace("_ON","_OFF"));
	});;
	
	$("#socials_download a img").mouseover(function() {
		$(this).attr("src",$(this).attr("src").replace("_OFF","_ON"));
	}).mouseout(function() {
		$(this).attr("src",$(this).attr("src").replace("_ON","_OFF"));
	});;
	
	setForm();
});

function chiamaBlockUI(titolo, testo, other) {
	var str;
	str = '<div style="position:relative;"><div></div><br />';
	str += '<div><p class="titolo">'+titolo+'</p>';
	str += '<p>'+testo+'</p></div>';
	
	str = str + '<div><span id="chiudi_blockui" style="cursor:pointer;" class="btn testo" >chiudi</span><br /><br /></div></div>';
	
	$.blockUI({ 
		css: { 
			border: 'none', 
			padding: '15px', 
			backgroundColor: '#000', 
			color: '#C7C7C7',
			cursor: 'default',
			margin:'auto',
			top: '200px',
			width: '28%'			
		},

		message: str,
		overlayCSS: {
			cursor: 'default',
			backgroundColor:'#000', 
			opacity:'0.8' 
			/*sfondo*/
		}
	});
	
	$("#chiudi_blockui").click(function() {
		$.unblockUI();
		$("input").each(function() {
			if ($(this).val() == "") { $(this).val($(this).attr('title')) };						 
		});
	});
}

function setForm() {
		
	$("#js_invia").click(function() {
		$(document).find('.example').val('');
		var privacy = $("input[name='privacy']:checked").val();
		var nome = $("input[name='nome']").val();
		var email = $("input[name='email']").val();
		if(privacy != 1) {
			chiamaBlockUI("Attenzione",'Accetta la privacy'); return false;
		}
		if (nome == "") {
			chiamaBlockUI("Attenzione",'Inserisci il tuo nome.'); return false;
		}
		if(!CheckMail(email, true)) {
			chiamaBlockUI('Attenzione','Inserisci correttamente il tuo indirizzo e-mail.');  return false;
		}
		var dataString = 'nome='+ nome + "&email=" + email;
		$.ajax({
			type: "POST",
			url: "save.customer.php",
			data: dataString,
			success: function(msg) {
				if(msg == 'success') {
					$("#form_incontenitor").css("background","url(img/formbg_e.gif)").html("<div style='padding:50px 20px 0 20px; text-align:center; font-size:14px; color:#FFF; font-weight:bold;'>Grazie per esserti registrato.<br>I tuoi dati sono stati salvati con successo.</div>");
				} else {
					$("#form_incontenitor").css("background","url(img/formbg_e.gif)").html("<div style='padding:50px 20px 0 20px; text-align:center; font-size:14px; color:#FFF; font-weight:bold;'>"+msg+"</div>");
				}
			}
		});
		return false;
	});
}

function chiamaBlockUIprivacy() {
	var str;
	str = '<div style="position:relative;"><div></div><br />';
	str += '<div><p class="titolo"><strong>TUTELA DEI SUOI DATI PERSONALI</strong></p>';
	str += '<div style="margin-top:10px; margin-bottom:15px; text-align:justify;">Informativa privacy (tutela dei dati personali D. LGS 196/2003)<br><br>I dati che ci fornir&agrave; compilando questo modulo saranno trattati, con o senza l\'ausilio di sistemi elettronici o automatizzati, al fine di fornire informazioni commerciali e/o promozionali, inviare materiale pubblicitario su prodotti, servizi ed altre attivit&agrave; della Fondazione Cinema per Roma, anche via telefono, a mezzo fax e posta ordinaria od elettronica.<br>Il conferimento dei Suoi dati &egrave; facoltativo, tuttavia, un eventuale rifiuto di fornirli rende impossibile perseguire la suddetta finalit&agrave;.<br>Titolare e responsabile del trattamento dei Suoi dati personali &egrave; la Fondazione Cinema per Roma con sede in Roma.</div></div>';
	
	str = str + '<div><span id="chiudi_blockui" style="cursor:pointer;" class="btn testo" >chiudi</span><br /><br /></div></div>';
	
	$.blockUI({ 
		css: { 
			border: 'none', 
			padding: '15px', 
			backgroundColor: '#000', 
			color: '#C7C7C7',
			cursor: 'default',
			margin:'auto',
			top: '200px',
			width: '28%'			
		},

		message: str,
		overlayCSS: {
			cursor: 'default',
			backgroundColor:'#000', 
			opacity:'0.8' 
			/*sfondo*/
		}
	});
	
	$("#chiudi_blockui").click(function() {
		$.unblockUI();
		$("input").each(function() {
			if ($(this).val() == "") { $(this).val($(this).attr('title')) };						 
		});
	});
}