
// -----------------------------------------------------------------------------------

function sommaTotaleSpesa(a, b) {
	c = a.toInt() + b.toInt();
	$('totalespesa').setHTML(c);
}

// -----------------------------------------------------------------------------------

function nextImage(lista_immagini, lista_zoomed) {
	if(indice < lista_immagini.length-1)
	{
		indice = indice + 1;
		if(lista_immagini[indice] != undefined)
		{
			$('minigal').src = lista_immagini[indice];
			$('minigal_zoom').href = lista_zoomed[indice];
		}	
	}
	settaPosizione();
}

// -----------------------------------------------------------------------------------

function prevImage(lista_immagini, lista_zoomed) {
	if(indice > 0)
	{
		indice = indice - 1;
		if(lista_immagini[indice] != undefined)
		{
			$('minigal').src = lista_immagini[indice];
			$('minigal_zoom').href = lista_zoomed[indice];
		}
	}
	settaPosizione();
}

// -----------------------------------------------------------------------------------


function settaPosizione() {
	$('posizione').setHTML((indice+1) + ' / ' + gallery.length);
} 

// -----------------------------------------------------------------------------------

window.addEvent('domready', function(){

	var hli = $$(".highlight");
	
	hli.each(function(element) {

		element.addEvent('click', function(e) {
			
			e = new Event(e).stop();
			expanded = new Element('div', {'class': 'expanded', 'events': {
				'click': function(e){
					e = new Event(e).stop();
					new Fx.Style(this, 'opacity', {duration: 300}).start(0);
				}}
			});
			
			var hide = new Fx.Style(expanded, 'opacity', {duration: 300});
			
			expanded.inject(document.body);
			expanded.setOpacity(0);

			loadedImages = '';

			var neww = 0;
			var newh = 0;
			
			new Asset.images(element, {
			
				onProgress: function() {
				
					expanded.setStyles({
						'left': e.page.x - (this.width / 2),
						'top': e.page.y - (this.height / 2),
						'width': this.width,
						'height': this.height
					});

					loadedImages = this;										
				},
			
				onComplete: function() {
					
					loadedImages.inject( expanded );
					
					hide.start(0, 1);
					
				}
				
			});

		});				

	});
	
});


// -----------------------------------------------------------------------------------

function Convalida()
{
	var input=document.frm.getElementsByTagName("input");
	var validationOK=true;
	for(var i=0;i<input.length;i++){
		var inp=input[i];
		if(inp.className=="vuoto") inp.className="richiesto";
    	if(inp.className=="richiesto"){
		if(inp.value==""){
            inp.className="vuoto";   //input vuoto
            validationOK=false;
            }
		}
	}
	return(validationOK);
}

// -----------------------------------------------------------------------------------

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}


// -----------------------------------------------------------------------------------

function invia(){
if(!document.frm.privacy == 0) 
  {
  	alert("Attenzione! E' necessario acconsentire al trattamento dei dati personali secondo quanto indicato nell'informativa.");
	return;
  }

  
    if(!Convalida()) 
  {
  	alert("Alcuni campi sono obbligatori. E' necessario compilare i campi evidenziati.");
	return;
  }
	document.frm.submit();
	return false;
}

// -----------------------------------------------------------------------------------

function invia_en(){
if(!document.frm.privacy.checked) 
  {
  	alert("Attenzione! E' necessario acconsentire al trattamento dei dati personali secondo quanto indicato nell'informativa.");
	return;
  }

  
    if(!Convalida()) 
  {
  	alert("Some fields are mandatory. You have to compile them.");
	return;
  }
	document.frm.submit();
	return false;
}


function invia_form(form, lang)	{
	if (lang=='it')	{
		if(!isValidEmail(form.email1.value))	{
			alert("Indirizzo mittente non valido!");
			return;
		}
		if(!isValidEmail(form.email2.value))	{
			alert("Indirizzo destinatario non valido!");
			return;
		}
	}
	else	{
		if(!isValidEmail(form.email1.value))	{
			alert("Invalid sender address!");
			return;
		}
		if(!isValidEmail(form.email2.value))	{
			alert("Invalid recipient address!");
			return;
		}
	
	}
	form.submit();
	
}

// -----------------------------------------------------------------------------------

function invia_form2(form, lang)	{
	if (lang=='it')	{
		if(!isValidEmail(form.email.value))	{
			alert("Indirizzo email non valido!");
			return;
		}
		  if(!Convalida_form(form)) 
		  {
		  	alert("Per poter inviare il messaggio e\' necessario compilare tutti i campi contrassegnati con il simbolo *, in quanto campi obbligatori.");
			return;
		  }

		  if(!document.getElementById('privacy_check').checked) 
  			{
			  	alert("Per poter inviare il messaggio e\' necessario dare l'autorizzazione come manifestazione di consenso.");
				return;
			  }

	}
	else	{
		if(!isValidEmail(form.email.value))	{
			alert("Invalid email address!");
			return;
		}
		if(!Convalida_form(form)) 
		  {
		  	alert("In order to send the message, all fields with this symbol* must be completed: * required fields.");
			return;
		  }
		  if(!document.getElementById('privacy_check').checked) 
  			{
			  	alert("In order to send the message, you must provide your authorization by completing the statement of consent.");
				return;
			  }
	
	}
	form.submit();
	
}

// -----------------------------------------------------------------------------------

function Convalida_form(form)
{
	var input=form.getElementsByTagName("input");
	var validationOK=true;
	for(var i=0;i<input.length;i++){
		var inp=input[i];
		if(inp.className=="vuoto") inp.className="richiesto";
    	if(inp.className=="richiesto"){
		if(inp.value==""){
            inp.className="vuoto";   //input vuoto
            validationOK=false;
            }
		}
	}
	return(validationOK);
}

// -----------------------------------------------------------------------------------



// -----------------------------------------------------------------------------------
//  Funzioni per il FIR
// -----------------------------------------------------------------------------------

function firdom(){
  if(document.getElementsByTagName && document.createElement){
	  alert('ok');
    for (i=1;i<=1;i++){
      h1s=document.getElementsByTagName('h'+i);
      scanandreplace(h1s,'h'+i);
      }
    }
  }

function scanandreplace(h1s,tag){
	if(h1s.length > 0)
  for(i=0;i<h1s.length;i++){
      thish1=document.getElementsByTagName(tag)[i];
      testo=thish1.firstChild.nodeValue;
      newimg=document.createElement('script');	
      newimg.innerHTML = 'tit_generico(\'' + testo + '\');';

        /*
        newimg=document.createElement('img');			
        newimg.setAttribute('alt',testo);
		newimg.setAttribute('class', 'img' + tag);
        newimg.setAttribute('src','labeler/do.php?type=h1&text=' + urlencode(testo));
		
		*/
		thish1.replaceChild(newimg,thish1.firstChild)
        // or newimg.src=chunks[1];
    }
  }

function urlencode(str) {
	str = escape(str);
	str = str.replace('+', '%2B');
	str = str.replace('%20', '+');
	str = str.replace('*', '%2A');
	str = str.replace('/', '%2F');
	str = str.replace('@', '%40');
return str;
}