

/****************************************************/

// pop-up function
var newWin = null;
function closeWin(){
	if (newWin != null){
		if(!newWin.closed)
			newWin.close();
	}
}
function popUp(strURL,strType,strHeight,strWidth) {
closeWin();
var strOptions="";
if (strType=="console") strOptions="resizable,height="+strHeight+",width="+strWidth;
if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
newWin = window.open(strURL, 'newWin', strOptions);
newWin.focus();
}


//preload immagini
function preloadIMG(){	
	var images = document.getElementsByTagName('img');
	var immagini=new Array();	
	var cont = 0;
	
	//percorro tutte le immagini		
	for (var i=0; i<images.length; i++){
		var image = images[i];
		var relAttribute = String(image.getAttribute('name'));
	
		//se hanno match preload... associo funzioni di preload
		if (relAttribute.toLowerCase().match('preload')){
			immagini[cont]=new Image();
			immagini[cont].src=image.src;
			cont++;
		}
	}
}

// Over delle immagini <img src=""..>
function attachSwitch(){	
	var images = document.getElementsByTagName('img');
	//percorro tutte le immagini		
	for (var i=0; i<images.length; i++){
		var image = images[i];
		var relAttribute = String(image.getAttribute('name'));
		
		//se hanno match over... associo funzioni di swap img
		if (relAttribute.toLowerCase().match('over')){
			image.onmouseover = function(){
				if(!this.className.match("_active")){
					this.src= this.src.replace('_off', '_on');
				} 
			};
			image.onmouseout = function(){
				if(!this.className.match("_active")){
					this.src= this.src.replace('_on', '_off');	
				}
			};
		}
		if(image.className.match("_active"))
		{
			image.src= image.src.replace('_off', '_on');
		}
	}
}





function movePrenota()
{	
	var sign_box = document.getElementById('prenota_box');
	var button = document.getElementById('linguetta_prenota');
	var main = document.getElementById('main');
	var side_menu = document.getElementById('menu_laterale');
		
	if(button.name.match('apri') && !button.name.match('moving'))
	{
		
		
		//$('vortal').style.display="";
		Effect.Appear($('vortal'),{duration: 1.00});
		Effect.Fade(side_menu,{duration: 0.0, afterFinish: myrestore2=function()
		{
			button.name+=' moving';
			new Effect.Move(main,{ x: -100, y: 0, duration: 1.00});
			new Effect.Move(sign_box,{ x: 67, y: 0, duration: 1.00,afterFinish: myrestore=function()
			{
				button.name = button.name.replace(' moving','');
				button.name = button.name.replace('apri','chiudi');
				//showSelectBoxes();
			}
			});
		
		}});

	}
	else if(button.name.match('chiudi') && !button.name.match('moving'))
	{

		button.name+=' moving';
		new Effect.Move(main,{ x: 100, y: 0, duration: 1.00});
		Effect.Fade($('vortal'),{duration: 1.00});
		new Effect.Move(sign_box,{ x: -67, y: 0, duration: 1.00,afterFinish: myrestore1=function()
		{
			button.name = button.name.replace(' moving','');
			button.name = button.name.replace('chiudi','apri');
			//side_menu.style.display = 'block';
			Effect.Appear(side_menu);
			//$('vortal').style.display="none";
			//hideSelectBoxes();
		}
		});		
	}
	return false;
}
//************************************************************************************


function setActive(the_button)
{
	var side_menu = document.getElementById('menu_laterale');
	the_button = $(the_button);
	if(!the_button.className.match('active'))
	{
		the_button.className += ' active';
	}
	for(var i=0;i<side_menu.childNodes.length;i++)
	{
		var child = side_menu.childNodes[i];
		if(child.nodeName == 'IMG' && child.src != the_button.src)
		{
			child.className = child.className.replace('active','');
		}
	}
}

//bottomAccordion.activate($('titolo_dove_siamo'));setActive(this);
function animatePage(the_title, the_button)
{
	bottomAccordion.activate($(the_title));
	//alert(the_button.src);
	setActive(the_button);	
}


function positioningMenu()
{
	var page = getPageSize();
	var larghezza_pagina = page[2];
	
	var menu_left = (larghezza_pagina/2) - ($('main').getDimensions().width/2) - ($('menu_laterale').getDimensions().width);
	if(navigator.userAgent.match('MSIE')) $('menu_laterale').setStyle({marginLeft: menu_left + 25 + 'px'});
	else $('menu_laterale').setStyle({left: menu_left + 15 + 'px'});
}




function allFunctions()
{
	var loading = document.getElementById('page_loading');		
	var main = document.getElementById('main');
	/*
	main.style.visibility="hidden";
	$('prenota_box').style.visibility="hidden";	
	*/
	preloadIMG();
	attachSwitch();
	positioningMenu();
	var loading_page = document.getElementById('page_loading');
		
	loading_page.style.display = 'none';
	main.style.visibility="visible";
	/*
	$('prenota_box').style.visibility="visible";
	
	//$('offerte_vortal').style.display="none";
	//$('prenota_vortal').style.display="none";
	
	
	
	
	
	
		var linguetta = document.getElementById('linguetta_prenota');
		linguetta.onclick = function(){showSection('linguetta_prenota','prenota_box')}
		
		linguetta = document.getElementById('linguetta_offerte');
		linguetta.onclick = function(){showSection('linguetta_offerte','show_offerte_box')}

*/	
}



function CheckForm_It()
{	

	if (document.contatti.frm_privacy.checked==false)
	{
	     alert ("E' necessario prestare il consenso al trattamento dei dati personali");
	     return (false);
	}	
	if (document.contatti.nome.value == "")
	{
         alert ("Attenzione!!! Non e' stato inserito il campo nome");
         return (false);
	}
	if (document.contatti.email.value == "")
	{
         alert ("Attenzione!!! Non e' stato inserito il campo e-mail");
         return (false);
	}	
}   
   


function showSection(linguetta_rif,elemento)
{
	var main = document.getElementById('main');
	var newsletter = document.getElementById(elemento);
	var linguetta = document.getElementById(linguetta_rif);
	var iframe;
	var altro_main;
	var altra_linguetta;
	var altra_newsletter;
	var altro_iframe;
	
	
	if(linguetta_rif=='linguetta_prenota') altro_main = 'show_offerte_container';
	else  altro_main = 'prenota_container';
	if(linguetta_rif=='linguetta_prenota') altra_linguetta = $('linguetta_offerte');
	else  altra_linguetta = $('linguetta_prenota');		
	if(linguetta_rif=='linguetta_prenota') altra_newsletter = $('show_offerte_box');
	else  altra_newsletter = $('prenota_box');
	var movimento=0;
	if(linguetta_rif=='linguetta_prenota') 
	{		
		pageTracker._trackPageview("/eventi/clickprenotazione.htm");
		
		altro_iframe = $('offerte_vortal');	
		iframe = $('prenota_vortal');	
	}
	else 
	{
	 	altro_iframe = $('prenota_vortal');	
	 	iframe = $('offerte_vortal');	
	 }	

		
		
	if(linguetta.name.match('chiudi') && !linguetta.name.match('muovendo') && (altra_linguetta == undefined || !altra_linguetta.name.match('muovendo')))
	{
		
		//1 aperto --> chiudo 1 e chiudo 2 se chiuso
		//alert('chiudo');
		
		//spengo iframe		
		Effect.Fade(iframe,{duration: 1.00});
		
		//faccio comparire menu se presente
		if ($('menu')) Effect.Appear($('colonnaSx'));
		linguetta.name += ' muovendo';

		movimento=-70;
		new Effect.Move(main,{ x: 100, y: 0, duration: 1.00});
		
		//caso senza altra newsletter
		if(altra_linguetta==undefined)
		{
		
		}
		else if(altra_linguetta!=undefined)
		{
			new Effect.Move(altra_newsletter,{ x: 100, y: 0, duration: 1.00,afterFinish: ciao1=function()			
			{

			}
		
			
			});
		}
		new Effect.Move(newsletter,{ x: movimento, y: 0, duration: 1.00, afterFinish: ciao2=function()
		{
			linguetta.name = linguetta.name.replace('muovendo', '');
			linguetta.name = linguetta.name.replace('chiudi', 'apri');
			//linguetta.src = linguetta.src.replace('chiudi', 'apri');
						
		}
		});
		
			
	}
	else if(linguetta.name.match('apri') && !linguetta.name.match('muovendo') && (altra_linguetta==undefined || !altra_linguetta.name.match('muovendo')))
	{
		//1 chiuso
		//alert('apri');
		
		//apro iframe
		Effect.Appear(iframe,{duration: 1.00});

		
		//faccio scomparire menu se presente		
		if ($('menu')) Effect.Fade($('colonnaSx'));
		
		linguetta.name += ' muovendo';

		//caso home page
		if(altra_linguetta==undefined)
		{
			movimento=70;
			new Effect.Move(main,{ x: -100, y: 0, duration: 1.00});		
		}
		else if(altra_linguetta.name.match('apri'))
		{
			movimento=70;
			new Effect.Move(main,{ x: -100, y: 0, duration: 1.00});
			new Effect.Move(altra_newsletter,{ x: -100, y: 0, duration: 1.00, afterFinish: ciao3=function()
			{

			}			
			});			
		}
		else
		{
			//alert('casino?');
			//chiudo la 2
			movimento=170;

			//spengo altro iframe
			Effect.Fade(altro_iframe,{duration: 1.00});
							
			if(altra_linguetta)
			{
				altra_linguetta.name += ' muovendo';
				new Effect.Move(altra_newsletter,{ x: -170, y: 0, duration: 1.00, afterFinish: ciao4=function()
				{
					
					altra_linguetta.name =  altra_linguetta.name.replace('muovendo', '');
					altra_linguetta.name =  altra_linguetta.name.replace('chiudi', 'apri');
					//altra_linguetta.src = altra_linguetta.src.replace('chiudi', 'apri');				
				}			
				});					
			}
		}

		new Effect.Move(newsletter,{ x: movimento, y: 0, duration: 1.00, afterFinish: ciao5 = function()
		{
			linguetta.name =  linguetta.name.replace('muovendo', '');
			linguetta.name =  linguetta.name.replace('apri', 'chiudi');
			//linguetta.src = linguetta.src.replace('apri', 'chiudi');			
		}
		});			
		
	}

}


function Form_Validator_En(theForm)
{

		var strsublista = '';
		var typelista = window.document.form1.typelista.value;
		for (i=0; i < document.form1.elements.length; i++) {
			    if ((document.form1.elements[i].name=='sublista[]')) {
				 if (document.form1.elements[i].checked)     
				      strsublista+=','+document.form1.elements[i].value;

			    }
	
		}

		if (document.form1.privacy.checked==false)
		{
		     alert('You have to give us the authorization for your personal data');
		     return (false);
		}
	
		if ((strsublista=='') && (typelista=='sublista')){
		     alert ('Select one sublist at least');
		     return (false);
		 }
		 if (document.form1.email.value == ""){

			 alert ("Attention!!!  It has not been inserted the field email ");
			 return (false);
		     }else{ 
			
			function isValidEmail(addressS){

				emailRegexp = RegExp('^[A-Za-z0-9._-]+[@]([A-Za-z0-9-]+[.])+([A-za-z]{2,4})$', 'i');
				if (emailRegexp.test(addressS)){

				    //return (true);

				}else{
				    alert ("ATTENTION!!!  The format of the email is not corrected!!!");
				    return (false);
				} 
			    }
			    
			    return (isValidEmail(theForm.email.value))

		     }
}

function Form_Validator(theForm) 
{

	var strsublista = '';
	var typelista = window.document.form1.typelista.value;
	for (i=0; i < document.form1.elements.length; i++) {
		    if ((document.form1.elements[i].name=='sublista[]')) {
			 if (document.form1.elements[i].checked)     
			      strsublista+=','+document.form1.elements[i].value;

		    }

	}

	if (document.form1.privacy.checked==false)
	{
	     alert ("E' necessario prestare il consenso al trattamento dei dati personali");
	     return (false);
	}	
	if ((strsublista=='') && (typelista=='sublista')){
	     alert ('Selezionare almeno una sublista');
	     return (false);
	 }
	 if (document.form1.email.value == ""){

		 alert ("Attenzione!!! Non � stato inserito il campo email ");
		 return (false);
	     }else{ 
		
		function isValidEmail(addressS){

			emailRegexp = RegExp('^[A-Za-z0-9._-]+[@]([A-Za-z0-9-]+[.])+([A-za-z]{2,4})$', 'i');
			if (emailRegexp.test(addressS)){

			    //return (true);

			}else{
			    alert ("ATTENZIONE!!! Il formato della e-mail non � corretto!!!");
			    return (false);
			} 
		    }
		    
		    return (isValidEmail(theForm.email.value))

	     }
}