//<![CDATA[

function showAddress(address,html) {
  if (geocoder) {
	geocoder.getLatLng(
	  address,
	  function(point) {
		if (!point) {
		  //alert(address + " not found");
		} else {
		map.setCenter(point, 11);
		var marker = new GMarker(point);
		GEvent.addListener(marker, "click", function() {
		  marker.openInfoWindowHtml(address+html);
		});
		map.addOverlay(marker);
		}
	  }
	);
  }
}
//]]>



function mostraDiv(div){
	var nome_div = document.getElementById(div);
	nome_div.style.display = 'block';
}

function nascondiDiv(div){
	var nome_div = document.getElementById(div);
	nome_div.style.display = 'none';
}

function Cambia_sfondo(div,img){
	var nome_div = document.getElementById(div);
	nome_div.style.background = "url('"+img+"') top no-repeat";
}

function popup(url, w, h) {
	newWindow = window.open(url,'popupWindow','width='+w+', height='+h+', left=300, top=300, menubar=no, toolbar=no, location=no, bookmarks=no, status=no, scrollbars=no, resizable=no');
	if (window.focus) {
		newWindow.focus();
	}
}

function Verificadati_completo(form){
	var error = '';
	data_arrivo=new Date()
	data_partenza=new Date()
	today = new Date()
	today=Date.parse(today);


	inserire_nome = 'Inserire il nome';
	indirizzo_email = "Specificare l'indirizzo email";
	indirizzo_email_sbagliato = "L'indirizzo email non è stato digitato correttamente";
	indirizzo_conferma_email = "Le due email che hai inserito devono essere uguali";
	autorizzo = "Autorizzare al trattamento dei dati";
	data_arrivo_data_odierna="La data di arrivo non può essere inferiore dalla data odierna";
	data_partenza_data_arrivo="La data di partenza non può essere inferiore dalla data di arrivo";
	inserire_data_arrivo = "Inserire la data di arrivo";
	inserire_data_partenza = "Inserire la data di partenza";

	if(eval("document."+form+".nome.value")==""){
		alert(inserire_nome);
		eval("document."+form+".nome.focus()");
		return false;
	}
	if(eval("document."+form+".email.value")==""){
		alert(indirizzo_email);
		eval("document."+form+".email.focus()");
		return false;
	}
	if(!checkMail(eval("document."+form+".email.value"))){
		alert(indirizzo_email_sbagliato);
		eval("document."+form+".email.focus()");
		return false;
	}
	if(eval("document."+form+".email.value")!=eval("document."+form+".conferma_email.value")){
		alert(indirizzo_conferma_email);
		eval("document."+form+".conferma_email.focus()");
		return false;
	}
	if(eval("document."+form+".privacy.checked")==false){
		alert(autorizzo);
		eval("document."+form+".privacy.focus()");
		return false;
	}

	giorno_arrivo=eval("document."+form+".gg_arrivo.selectedIndex");
	mese_arrivo=eval("document."+form+".mm_arrivo.selectedIndex");
	anno_arrivo=eval("document."+form+".aa_arrivo.selectedIndex");
	giorno_partenza=eval("document."+form+".gg_partenza.selectedIndex");
	giorno_mese=eval("document."+form+".mm_partenza.selectedIndex");
	anno_partenza=eval("document."+form+".aa_partenza.selectedIndex");

	/*Date della prenotazione*/
	if( (giorno_arrivo>0) || (mese_arrivo>0) || (anno_arrivo>0) || (giorno_partenza>0) || (giorno_mese>0) || (anno_partenza>0) ) {
		//data di arrivo
		gg_arrivo=new String()
		gg_arrivo=eval("document."+form+".gg_arrivo.options[document."+form+".gg_arrivo.selectedIndex].value;");
		//gg_arrivo=document.dati.gg_arrivo.options[document.dati.gg_arrivo.selectedIndex].value;
		mm_arrivo=new String()
		mm_arrivo=eval("document."+form+".mm_arrivo.options[document."+form+".mm_arrivo.selectedIndex].value;");
		//mm_arrivo=document.dati.mm_arrivo.options[document.dati.mm_arrivo.selectedIndex].value;
		aa_arrivo=new String()
		aa_arrivo=eval("document."+form+".aa_arrivo.options[document."+form+".aa_arrivo.selectedIndex].value;");
		//aa_arrivo=document.dati.aa_arrivo.options[document.dati.aa_arrivo.selectedIndex].value;
		data_arrivo=new Date( mm_arrivo + "/" + gg_arrivo + "/" + aa_arrivo );
		data_arrivo=Date.parse(data_arrivo);

		//data di partenza
		gg_partenza=new String()
		gg_partenza=eval("document."+form+".gg_partenza.options[document."+form+".gg_partenza.selectedIndex].value;");
		//gg_partenza=document.dati.gg_partenza.options[document.dati.gg_partenza.selectedIndex].value;
		mm_partenza=new String()
		mm_partenza=eval("document."+form+".mm_partenza.options[document."+form+".mm_partenza.selectedIndex].value;");
		//mm_partenza=document.dati.al_mm.options[document.dati.mm_partenza.selectedIndex].value;
		aa_partenza=new String()
		aa_partenza=eval("document."+form+".aa_partenza.options[document."+form+".aa_partenza.selectedIndex].value;");
		//aa_partenza=document.dati.aa_partenza.options[document.dati.aa_partenza.selectedIndex].value;
		data_partenza=new Date( mm_partenza + "/" + gg_partenza + "/" + aa_partenza );
		data_partenza=Date.parse(data_partenza);

		if (data_arrivo <= today) {
			alert(data_arrivo_data_odierna);
			eval("document."+form+".gg_arrivo.focus()");
			return false;
		}
		if (data_partenza < data_arrivo) {
			alert(data_partenza_data_arrivo);
			eval("document."+form+".gg_partenza.focus()");
			return false;
		}
	}
	eval("document."+form+".conferma_email.value=''");

	if (error == ''){
		return true;
	}else{
		alert(error);
		return false;
	}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

/** Controlla la correttezza dell'indirizzo email.
	Forse si può sostituire con una funzione PHP per il controllo delle expr regolari, tipo eregi(). */
function checkMail(mail){
	var iAtPosition;
	var iDotPosition;

	iAtPosition = mail.indexOf("@");
	if (iAtPosition < 1 || iAtPosition == mail.length)
		return false;
	iDotPosition = mail.indexOf('.', iAtPosition);
	if (iDotPosition < 0)
		return false;
	return true;
}	// checkMail()


function VerificaNewsletter(lingua,form){
	var error = '';

	/*switch(lingua){
		case'it':*/
			indirizzo_email = "Specificare l'indirizzo email";
			indirizzo_email_sbagliato = "L'indirizzo email non è stato digitato correttamente";
			autorizzo = "Autorizzare al trattamento dei dati";
	/*	break;
		case'en':
			indirizzo_email = 'Specify email address';
			indirizzo_email_sbagliato = 'The Email address is not correct';
			autorizzo = "To authorize to the treatment of the data";
		break;
		case'fr':
			indirizzo_email = "Spécifier l'adresse email";
			indirizzo_email_sbagliato = "Le email address n'est pas correct";
			autorizzo = "Pour autoriser au traitement des données";
		break;
		case'de':
			indirizzo_email = "Geben Sie Ihre Email-Addresse an";
			indirizzo_email_sbagliato = "Die Email-Addresse ist nicht korrekt";
			autorizzo = "Zur Verarbeitung der Daten autorisieren";
		break;
	}*/
	if(eval("document."+form+".email_newsletter.value")==""){
		alert(indirizzo_email);
		eval("document."+form+".email_newsletter.focus()");
		return false;
	}
	if(!checkMail(eval("document."+form+".email_newsletter.value"))){
		alert(indirizzo_email_sbagliato);
		eval("document."+form+".email_newsletter.focus()");
		return false;
	}
	if(eval("document."+form+".privacy.checked")==false){
		alert(autorizzo);
		eval("document."+form+".privacy.focus()");
		return false;
	}

	if (error == ''){
		eval("document."+form+".submit()");
		return true;
	}else{
		alert(error);
		return false;
	}
}

function VerificaCancellazioneNewsletter(lingua,form){
	var error = '';

	/*switch(lingua){
		case'it':*/
			indirizzo_email = "Specificare l'indirizzo email";
			indirizzo_email_sbagliato = "L'indirizzo email non è stato digitato correttamente";
			autorizzo = "Autorizzare al trattamento dei dati";
	/*	break;
		case'en':
			indirizzo_email = 'Specify email address';
			indirizzo_email_sbagliato = 'The Email address is not correct';
			autorizzo = "To authorize to the treatment of the data";
		break;
		case'fr':
			indirizzo_email = "Spécifier l'adresse email";
			indirizzo_email_sbagliato = "Le email address n'est pas correct";
			autorizzo = "Pour autoriser au traitement des données";
		break;
		case'de':
			indirizzo_email = "Geben Sie Ihre Email-Addresse an";
			indirizzo_email_sbagliato = "Die Email-Addresse ist nicht korrekt";
			autorizzo = "Zur Verarbeitung der Daten autorisieren";
		break;
	}*/
	if( (eval("document."+form+".cancella_email_newsletter.value")=="") || (eval("document."+form+".cancella_email_newsletter.value")=="metti qui la tua email") ) {
		alert(indirizzo_email);
		eval("document."+form+".cancella_email_newsletter.focus()");
		return false;
	}
	if(!checkMail(eval("document."+form+".cancella_email_newsletter.value"))){
		alert(indirizzo_email_sbagliato);
		eval("document."+form+".cancella_email_newsletter.focus()");
		return false;
	}

	if (error == ''){
		eval("document."+form+".submit()");
		return true;
	}else{
		alert(error);
		return false;
	}
}

//conta click nella scheda
function conta(url){ 
	var s = document.createElement('SCRIPT');
	s.type = 'text/javascript';
	s.src = url;
	window.document.body.appendChild (s);
}

function ElencoHotelAvanti(totale_pagine){
	var indietro=1;
	var avanti=1;
	for(i=1;i<=totale_pagine;i++){
		var nome_div = document.getElementById('elenco_hotel_'+i);
		if(nome_div.style.display == 'block'){
			nome_div.style.display="none";
			indietro=i;
			avanti=(i+1);
		}
	}
	mostraDiv('elenco_hotel_'+avanti);
	var bottone_indietro = document.getElementById('bottone_indietro');
	if(avanti==totale_pagine){
		var bottone_avanti = document.getElementById('bottone_avanti');
		bottone_avanti.className="hotel_list_button_left2";
		bottone_avanti.innerHTML='';
	}
	bottone_indietro.className="hotel_list_button_right";
	bottone_indietro.innerHTML='<a href="#" onclick="ElencoHotelIndietro('+totale_pagine+', '+indietro+');" rel="nofollow">indietro</a>';

	loadOverlays();
}

function ElencoHotelIndietro(totale_pagine, precedente){
	var indietro=1;
	var avanti=1;
	for(i=1;i<=totale_pagine;i++){
		var nome_div = document.getElementById('elenco_hotel_'+i);
		if(nome_div.style.display == 'block'){
			nome_div.style.display="none";
			indietro=(i-1);
			avanti=i;
		}
	}
	mostraDiv('elenco_hotel_'+indietro);
	var bottone_indietro = document.getElementById('bottone_indietro');
	if(indietro>1){
		bottone_indietro.className="hotel_list_button_right";
		bottone_indietro.innerHTML='<a href="#" onclick="ElencoHotelIndietro('+totale_pagine+', '+indietro+');" rel="nofollow">indietro</a>';

		var bottone_avanti = document.getElementById('bottone_avanti');
		bottone_avanti.className="hotel_list_button_left";
		bottone_avanti.innerHTML='<a href="#" onclick="ElencoHotelAvanti('+totale_pagine+');" rel="nofollow"><strong>altri hotel</strong></a>';
	}else if(indietro==1){
		var bottone_avanti = document.getElementById('bottone_avanti');
		bottone_avanti.className="hotel_list_button_left";
		bottone_avanti.innerHTML='<a href="#" onclick="ElencoHotelAvanti('+totale_pagine+');" rel="nofollow"><strong>altri hotel</strong></a>';

		bottone_indietro.className="hotel_list_button_right2";
		bottone_indietro.innerHTML='';
	}else{
		bottone_indietro.className="hotel_list_button_right2";
		bottone_indietro.innerHTML='';
	}

	loadOverlays();
}

function PaginaVisualizzata(totale_pagine){
  var pagina=1;

  for(i=1;i<=totale_pagine;i++){
	var nome_div = document.getElementById('elenco_hotel_'+i);
	if(nome_div==null){ pagina=2; break; }
	if(nome_div.style.display == 'block'){
	  pagina=i;
	}
  }
  return pagina;
}
