function altezzafinestra() {
  var myHeight = 0;
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function larghezzafinestra() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

function mostrabox(larghezza,altezza,data) {
	
	var larghezzapx = larghezza + 'px';
	var altezzapx = altezza + 'px';
	var alto = $(window).scrollTop() + altezzafinestra()/2 - altezza/2;
	var alto2 = $(window).scrollTop();
	var altomax = Math.max(alto,alto2);
	var altopx =  altomax + 'px';
	var sinistra = $(window).scrollLeft() + larghezzafinestra() / 2 - larghezza /2;
	var sinistra2 = $(window).scrollLeft();
	var sinistramax = Math.max(sinistra,sinistra2);
	var sinistrapx = sinistramax + 'px';
	
	$('#popup').html(data);
	$('#popup').css({width: larghezzapx, height: altezzapx, left: sinistrapx, top: altopx});
	 $('#popup').fadeIn(1000);
	$('#coprente').fadeIn(200);
}



function seleziona(field)
	{field.focus(); field.blur(); field.select(); }
function valid(moduloid)
	{
		modulo = document.getElementById(moduloid);
	if(modulo.nome.value.length < 2){alert("ERRORE:\nNome non valido"); seleziona(modulo.nome); return false}
	if (modulo.email.value.indexOf("@") == -1 ) {alert ("ERRORE\nNon hai scritto correttamente l'indirizzo email!"); seleziona(modulo.email); return false;}
	if(modulo.telefono.value.length < 7){alert("ERRORE:\nNome hai scritto correttamente il numero di telefono"); seleziona(modulo.telefono); return false}
	if(modulo.messaggio.value.length <  50){alert("ERRORE:\nNon hai scritto con sufficente dettaglio quali sono le tue richieste. Descrivi con più precisione che cosa desideri sapere."); seleziona(modulo.messaggio); return false}	

	return true;
	}
	
function nascondipopup(nomeid)
{
document.getElementById(nomeid).style.display = 'none';
document.getElementById("coprente").style.display='none';
document.getElementById(nomeid).innerHTML='';
}
function nascondipopup2(nome)
{
nome.fadeOut(1000);
$("#coprente").hide(1000);
}

function popola(nomeid)
{
	document.getElementById(nomeid).elements[0].value = getCookie('nome');
	document.getElementById(nomeid).elements[1].value = getCookie('email');
	document.getElementById(nomeid).elements[2].value = getCookie('telefono');
}

function aprichiudi(nomeid)
{
var elemento = document.getElementById(nomeid);
if (elemento.style.display == 'inline') {elemento.style.display = 'none'}
else {elemento.style.display = 'inline'}
}


// funzioni per le caselle di ricerca
$(document).bind("click focusin", function (e) {
      if ( $(e.target).closest("#bimbumbamnome").attr('id') != 'bimbumbamnome' ) {$('#strutturemostra').hide('slow'); $('#strutturecerca').attr('value','Scrivi il nome della struttura'); scnome = '';};
	  // if ( $(e.target).closest("#bimbumbamlocalita").attr('id') != 'bimbumbamlocalita' ) {$('#localitamostra').hide('slow');$('#localitacerca').attr('value','Scrivi il nome della località'); sclocalita = '';};
	  	  if ( $(e.target).closest("#bimbumbamlocalitac").attr('id') != 'bimbumbamlocalitac' ) {$('#localitamostrac').hide('slow'); sclocalitac = '';};

	  
    });
$(document).bind("dblclick", function (f) {
 if ( $(f.target).closest("#popup").attr('id') != 'popup' ) { $("#popup").fadeOut(1000);
$("#coprente").hide(1000);	}
	  
    });
var scnome = ''; var sclocalita = '';
function suggeriscistrutture2() {
    elemento = document.getElementById('strutturecerca').value;
 	$.get('/inclusioni/suggerimentistrutture.php', {cartella: elemento}, function(data) { $('#strutturemostra').html(data) } ); 
} 
function suggeriscilocalita2() {
    elemento = document.getElementById('localitacerca').value;
 	$.get('/inclusioni/suggerimenti.php', {cartella: elemento}, function(data) { $('#localitamostra').html(data) } ); 
} 

function suggeriscilocalita2bis() {
    elemento = document.getElementById('localitacerca').value;
 	$.get('/inclusioni/suggerimentibis.php', {cartella: elemento}, function(data) { $('#localitamostra').html(data) } ); 
} 

function suggeriscilocalitac() {
    elemento = document.getElementById('localitac').value;
 	$.get('/inclusioni/suggeriscilocalitac.php', {cartella: elemento}, function(data) { $('#localitamostrac').html(data) } ); 
} 

function suggeriscilocalitacv() {
    elemento = document.getElementById('localitacv').value;
 	$.get('/inclusioni/suggeriscilocalitacv.php', {cartella: elemento}, function(data) { $('#localitamostracv').html(data) } ); 
}

//funzioni per cerca localita
	function riempilocalita(localita,localitacartella)
	{

	localita = unescape(localita);
	localita = localita.replace(/\+/g,' ');
	document.getElementById('localitac').value = localita; 
	document.getElementById('localitacartellac').value = localitacartella;
	$('#localitamostrac').hide('slow');
	return false;
	}

	function riempilocalitav(localita,localitacartella)
	{

	localita = unescape(localita);
	localita = localita.replace(/\+/g,' ');
	document.getElementById('localitacv').value = localita; 
	document.getElementById('localitacartellacv').value = localitacartella;
	$('#localitamostracv').hide('slow');
	return false;
	}	
	
	function validRedirect(modulo) {
	if((modulo.localitac.value=="") || (modulo.localitac.value == "Scrivi il nome della localita"))  { alert("Dati incompleti: non hai selezionato la località\nScrivi parte del nome nella casella e poi\nSELEZIONALA DAL MENU A TENDINA"); return false; } 
		if(modulo.arrivo.value==""){ alert("Dati incompleti: non hai selezionato la DATA DI ARRIVO"); return false; } 
				if(modulo.numpersone.value==""){ alert("Dati incompleti: non hai selezionato il NUMERO DI ADULTI"); return false; } 
	if(modulo.notti.value==""){ alert("Dati incompleti: non hai selezionato il NUMERO DI NOTTI della tua permanenza"); return false; } 
	return true;
	}
	
function validCerca(modulo) {
	if(modulo.nome.value.length < 2){ alert("Dati incompleti: non hai indicato il tuo NOME"); return false; } 
	if(modulo.email.value.indexOf("@") == -1 ){ alert("Dati incompleti: non hai scritto la tua EMAIL"); return false; } 
	if(modulo.telefono.value.length < 8){ alert("Dati incompleti: non hai scritto correttamente il tuo NUMERO DI TELEFONO"); return false; } 
	if(modulo.messaggio.value.length < 5) {alert("Attenzione: non hai scritto con sufficente dettaglio le tue richieste. In particolare, indica QUANTE PERSONE siete! Leggi i CONSIGLI"); return false; }
	var checchi = false;
	if(modulo.agriturismo && modulo.agriturismo.checked) {checchi = true}
	if(modulo.beb && modulo.beb.checked) {checchi = true}
	if(modulo.appartamento && modulo.appartamento.checked) {checchi = true}
	if(modulo.casevacanze && modulo.casevacanze.checked) {checchi = true}
	if(modulo.hotel && modulo.hotel.checked) {checchi = true}
	if(modulo.altro && modulo.altro.checked) {checchi = true}
	if( !checchi ) {alert("Non hai selezionato i TIPI DI STRUTTURA a cui sei interessato"); return false;}
	
	return true;
	}
	
	function validcercalocalita(modulo) {
	if( (modulo.cartellacerca.value.length < 2) || (modulo.cartellacerca.value == 'Scrivi il nome della localita') ){ alert("Non hai scritto il nome della località!"); return false; } 
	
	return true;
	}

