var myimages=new Array();
var path_img="/";

var myreg_name=new RegExp("^[a-zA-Z ']+$");
var myreg_num=new RegExp("^[0-9]+$");
var myreg_email=new RegExp("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+[\.]([a-z0-9-]+)*([a-z]{2,3})$");

function preloadimages(){
	for (i=0;i<preloadimages.arguments.length;i++) { 
		myimages=new Image();
		myimages.src=preloadimages.arguments;
	}
}

preloadimages(path_img+"img/pulsanti/contatti.png", path_img+"img/pulsanti/contatti_over.png", path_img+"img/pulsanti/dovesiamo.png", path_img+"img/pulsanti/dove_siamo_over.png", path_img+"img/pulsanti/news_letter.png", path_img+"img/pulsanti/news_letter_over.png");


function sel_aree_newsletter() {
	a=document.registrazione;
	
	a.area_cinema.checked='checked';
	a.area_musica.checked='checked';
	a.area_teatro.checked='checked';
	a.area_altro.checked='checked';
	
}

function ctl_registrazione() {


	a=document.registrazione;
	
	if(a.email.value=="") {

		alert("Attenzione: la casella email e' obbligatoria.");
		return;
	
	} else {
	
		res=myreg_email.test(a.email.value);
		if(!res) {
			alert("La casella email e' sbagliata. Si prega di fornire una casella email valida");
			return;
		}
		
	}
	
	nome="ok";
	cognome="ok";
	
	
	
	if(a.nome.value!="") {
		res=myreg_name.test(a.nome.value);
		
		if(!res) {
			nome="ko";
		}
		
	}
		
	if(a.cognome.value!="") {
		res=myreg_name.test(a.nome.value);
		
		if(!res) {
			cognome="ko";
		}
	}

	
	
	
	if(cognome=="ko" || nome=="ko") {
		if(!confirm("Il nome o il cognome non sembrano scritti correttamente.\n\rConfermi l'iscrizione ?")) {
			
			return;
		}
	
	}
	
	checks=0;
	
	for(i=0; i<a.elements.length; i++) {
		/*
		if(a.elements[i].type=="checkbox") {
			alert(i);	
		} */
	
		if(a.elements[i].type=="checkbox" && a.elements[i].checked==true &&a.elements[i].name!="consenso") {
			
			checks++;
		
		}
		
	
	}
	
	if(checks==0) {
		alert("Indicare almeno un'area tematica.");
		return;
	}
	
	if(a.somma.value=="") {
		alert("Indicare la somma dei due numeri riportati");
		return;
	}
	
	if(a.somma.value!=a.res_somma.value) {
		alert("La somma dei due numeri non e' corretta");
		return;
	}
	
	if(a.consenso.checked==true) {
		a.submit();
	} else {
		alert("Prestare il consenso al trattamento dei dati personali.");	
	}
	   


}

function SetOpacity(object,opacityPct)
{
  // IE.
  object.style.filter = 'alpha(opacity=' + opacityPct + ')';
  // Old mozilla and firefox
  object.style.MozOpacity = opacityPct/100;
  // Everything else.
  object.style.opacity = opacityPct/100;
}
function ChangeOpacity(id,msDuration,msStart,fromO,toO)
{
  var element=document.getElementById(id);
  var opacity = element.style.opacity * 100;
  var msNow = (new Date()).getTime();
  opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
  if (opacity<0) 
    SetOpacity(element,0)
  else if (opacity>100)
    SetOpacity(element,100)
  else
  {
    SetOpacity(element,opacity);
    element.timer = window.setTimeout("ChangeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")",1);
  }
}
function FadeIn(id)
{
  var element=document.getElementById(id);
  if (element.timer) window.clearTimeout(element.timer); 
  var startMS = (new Date()).getTime();
  element.timer = window.setTimeout("ChangeOpacity('" + id + "',1000," + startMS + ",0,100)",1);
}
function FadeOut(id)
{
  var element=document.getElementById(id);
  if (element.timer) window.clearTimeout(element.timer); 
  var startMS = (new Date()).getTime();
  element.timer = window.setTimeout("ChangeOpacity('" + id + "',1000," + startMS + ",100,0)",1);
}
function FadeInImage(foregroundID,newImage,backgroundID)
{
  var foreground=document.getElementById(foregroundID);
  if (backgroundID)
  {
    var background=document.getElementById(backgroundID);
    if (background)
    {
      background.style.backgroundImage = 'url(' + foreground.src + ')';
      background.style.backgroundRepeat = 'no-repeat';
    }
  }
  SetOpacity(foreground,0);
  foreground.src = newImage;
  if (foreground.timer) window.clearTimeout(foreground.timer); 
  var startMS = (new Date()).getTime();
  foreground.timer = window.setTimeout("ChangeOpacity('" + foregroundID + "',1000," + startMS + ",0,100)",10);
}



cc=new Array(0,0,0,0,0,0,0,0,0,0);

function cambia()
{
 
 ran=Math.round(Math.random() * 10);
 if (ran == 0) ran = 1;
 
 if (cc[parseInt(ran)-1] == 0)
 {
	 
       FadeInImage('attori'+ran+'c','http://www.luccacinema.it/img/attori/'+ran+'b.jpg','attore'+ran)
	   cc[parseInt(ran)-1] = 1
		}
		else
		{
			
       FadeInImage('attori'+ran+'c','http://www.luccacinema.it/img/attori/'+ran+'a.jpg','attore'+ran)
	   cc[parseInt(ran)-1] = 0
 }
       
}
//$(document).ready(function(){
//$(".scrollable").scrollable({circular: true}).autoscroll({autoplay:true,interval: 5000});
	//					   });

function carica_loading2(campo) {
	
	$.ajax({
		  type: "GET",
		  dataType: "html",
		  url: "/loader2.php",
		  data: "",
		  success: function(dati) {
			   // Aggiorno il contenuto del DIV con i dati ricevuti
			   document.getElementById(campo).innerHTML=dati;
			   
		  },
		  error: function(richiesta,stato,errori) {
			   // Visualizzo un messaggio di errore in caso di chiamata fallita
			   alert("Errore caricamento foto");
			   
		  }
	 });		
	
}


function carica_offerte(tipo, sala) {
	
	par="tipo="+tipo+"&sala="+sala;
	campo='cont_oscurato';
	
	document.getElementById('oscuratore').style.visibility='visible';
	//carica_loading2(campo);
	
	$.ajax({
		  type: "GET",
		  dataType: "html",
		  url: "scheda_richiesta.php",
		  data: par,
		  success: function(dati) {
			   // Aggiorno il contenuto del DIV con i dati ricevuti
			   document.getElementById(campo).innerHTML=dati;
			   
		  },
		  error: function(richiesta,stato,errori) {
			   // Visualizzo un messaggio di errore in caso di chiamata fallita
			   alert('Errore nella chiamata AJAX:'+errori);
		  }
	 });
	
}

function ctl_richiesta_convegni() {
	a=document.richiesta_info;
	
	obblighi=0;
	
	if(a.azienda.value=="") {
		obblighi++;
	}
	if(a.telefono.value=="") {
		obblighi++;	
	}
	if(a.riferimento.value=="") {
		obblighi++;	
	}
	if(a.email.value=="") {
		obblighi++;	
	}
	if(a.indirizzo.value=="") {
		obblighi++;	
	}
	if(a.comune.value=="") {
		obblighi++;	
	}
	if(a.provincia.value=="") {
		obblighi++;	
	}
	
	if(obblighi>0) {
		alert("A parte 'data evento' e 'ulteriori informazioni'\n\ri dati richiesti sono tutti obbligatori.");
		return;
	}
	
	res=myreg_email.test(a.email.value);
	if(!res) {
		alert("Attenzione ! La casella email non e' corretta.");
		return;
	}
	
	if(a.privacy.checked==false) {
		alert("E' necessario prestare consenso al trattamento dei dati personali.");
		return;
	}
	
	a.submit();
	
}

function chiudi_offerte() {
	document.getElementById('cont_oscurato').innerHTML='';
	document.getElementById('oscuratore').style.visibility='hidden';	
}


/******   GOOGLE ANALYTICS    ********/
var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-23875351-5']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();



/******	   FINE GOOGLE ANALYTICS ****/





