//verificata
function NomeHotel(lingua,form){
	switch(lingua){
		case'it':
			inserire_nome = "Inserire il nome dell'hotel";
		break;
		case'en':
			inserire_nome = "Inserire il nome dell'hotel";
		break;
		case'fr':
			inserire_nome = "Inserire il nome dell'hotel";
		break;
		case'de':
			inserire_nome = "Inserire il nome dell'hotel";
		break;
	}
	if( (eval("document."+form+".ric_nome_hotel.value")=="") || (eval("document."+form+".ric_nome_hotel.value")=="nome hotel") ) {
		alert(inserire_nome);
		eval("document."+form+".ric_nome_hotel.value='';");
		eval("document."+form+".ric_nome_hotel.focus()");
		return false;
	}

	eval("document."+form+".submit()");
	return true;
}


function VerificadatiRichiesta(lingua){
	switch(lingua){
		case'it':
			inserire_nome = 'Inserire il nome';
			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':
			inserire_nome = 'Insert name';
			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':
			inserire_nome = 'Insérer le nom';
			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':
			inserire_nome = 'Geben Sie Ihren Namen an';
			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(document.richiesta_info.nome.value==""){
		alert(inserire_nome);
		document.richiesta_info.nome.focus();
		return false;
	}
	if(document.richiesta_info.email.value==""){
		alert(indirizzo_email);
		document.richiesta_info.email.focus();
		return false;
	}

	if(!checkMail(document.richiesta_info.email.value)){
		alert(indirizzo_email_sbagliato);
		document.richiesta_info.email.focus();
		return false;
	}
	if(document.richiesta_info.privacy.checked==false){
		alert(autorizzo);
		document.richiesta_info.privacy.focus()
		return false;
	}

	if (error == ''){
		document.richiesta_info.submit();
		return true;
	}else{
		alert(error);
		return false;
	}
}

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 mostra_nascondiDiv(div){
	var nome_div = document.getElementById(div);
	if(nome_div.style.display =='block'){
		nome_div.style.display = 'none';
	}else{
		nome_div.style.display = 'block';
	}
}

function MostraDescrizioni(div){
	//var box_descrizione = document.getElementById('box_descrizione');
	//box_descrizione.style.top='0px';

	//div è l'id della div da mostrare
	nascondiDiv('descrizione'); if(document.getElementById('tit_descrizione')) CambioSfondo('tit_descrizione','no_current'); 
	nascondiDiv('servizi'); if(document.getElementById('tit_servizi')) CambioSfondo('tit_servizi','no_current'); 

	nascondiDiv('novita'); if(document.getElementById('tit_novita')) CambioSfondo('tit_novita','no_current'); 
	nascondiDiv('listino'); if(document.getElementById('tit_listino')) CambioSfondo('tit_listino','no_current'); 
	nascondiDiv('dove_siamo'); if(document.getElementById('tit_dove_siamo')) CambioSfondo('tit_dove_siamo','no_current'); 

	nascondiDiv('last_minute'); if(document.getElementById('tit_last_minute')) CambioSfondo('tit_last_minute','no_current'); 
	nascondiDiv('offerte'); if(document.getElementById('tit_offerte')) CambioSfondo('tit_offerte','no_current'); 

	mostraDiv(div); if(document.getElementById('tit_'+div)) CambioSfondo('tit_'+div,'current'); 
}

/*function MostraListino(div){
	nascondiDiv('listino_prezzi'); if(document.getElementById('tit_listino_prezzi')) CambioSfondo('tit_listino_prezzi','no_current'); 
	nascondiDiv('note'); if(document.getElementById('tit_note')) CambioSfondo('tit_note','no_current'); 

	mostraDiv(div); if(document.getElementById('tit_'+div)) CambioSfondo('tit_'+div,'current'); 
}*/

function bookmarksite(title, url){
	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "")
}

function CambioSfondo(div,nomeClasse){
	var nome_div = document.getElementById(div);
	nome_div.className=nomeClasse;
}


/** 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()



// FUNZIONE PER DATE - Inizio
	//La funzione verifica il formato del campo data contenuto nel form
	// Parametri: campo --> nome campo data
	//            form  --> nome form 
	//            lingua  --> alert in lingua 
	//            campo_focus  --> nome del campo su cui fare il focus 
function Check_dmg(campo,form,lingua,campo_focus) {
	var valore,giorno,barra1,mese,barra2,anno,str_mesi,str_giorni,pos_mese,max_giorno_mese;
	str_mesi   = '01*02*03*04*05*06*07*08*09*10*11*12*';
	str_giorni = '31*29*31*30*31*30*31*31*30*31*30*31*';
	valore = eval(form+"."+campo+".value");
	// gg/mm/aaaa
	// 0123456789
	// il secondo parametro di substring indica la posizione +1 dell'ultimo carattere da selezionare
	giorno = valore.substring(0,2);
	barra1 = valore.substring(2,3);
	mese = valore.substring(3,5);
	barra2 = valore.substring(5,6);
	anno = valore.substring(6,10);


switch(lingua){
	case'it':
		data_arrivo_valori_alert = 'Data '+valore+' non valida. Formato gg/mm/aaaa';
	break;
	case'en':
		data_arrivo_valori_alert = 'Date '+valore+' is wrong. Format gg/mm/aaaa';
	break;
	case'fr':
		data_arrivo_valori_alert = 'Date '+valore+' est mal. Format gg/mm/aaaa';
	break;
	case'de':
		data_arrivo_valori_alert = 'Datum '+valore+' ungültig. Format gg/mm/aaaa';
	break;
}

	if (isNaN(giorno)){
		alert (data_arrivo_valori_alert);
		eval("document."+form+"."+campo_focus+".focus()");
		return false;
	}else if(giorno <1 || giorno >31){
		alert (data_arrivo_valori_alert);
		eval("document."+form+"."+campo_focus+".focus()");
		return false;
	}
		
/*	if(barra1 != '/' || barra1 != '-'){
		alert (data_arrivo_valori_alert);
		eval("document."+form+"."+campo_focus+".focus()");
		return false;
	}
*/	if (isNaN(mese)){
		alert (data_arrivo_valori_alert);
		eval("document."+form+"."+campo_focus+".focus()");
		return false;
	}else if(mese <1 || mese >12){
		alert (data_arrivo_valori_alert);
		eval("document."+form+"."+campo_focus+".focus()");
		return false;
	}else{
		pos_mese = str_mesi.indexOf(mese+'*');
		max_giorno_mese = str_giorni.substring(pos_mese,pos_mese + 2);
		if (giorno > max_giorno_mese){
			alert (data_arrivo_valori_alert);
			eval("document."+form+"."+campo_focus+".focus()");
			return false;
		}
	}

/*	if(barra2 != '/' || barra2 != '-'){
		alert (data_arrivo_valori_alert);
		eval("document."+form+"."+campo_focus+".focus()");
		return false;
	}
*/		
	if (isNaN(anno)){
		alert (data_arrivo_valori_alert);
		eval("document."+form+"."+campo_focus+".focus()");
		return false;
	}else if(anno < 1900){
		alert (data_arrivo_valori_alert);
		eval("document."+form+"."+campo_focus+".focus()");
		return false;
	}else if(valore.length != 10){
		alert (data_arrivo_valori_alert);
		eval("document."+form+"."+campo_focus+".focus()");
		return false;
	}

	// Gestione bisestile
	if (mese === '02'){
		if (eBisestile(anno)){
			if (giorno > 29){
				alert (data_arrivo_valori_alert);
				eval("document."+form+"."+campo_focus+".focus()");
				return false;
			}
		}else if (giorno > 28){
			alert (data_arrivo_valori_alert);
			eval("document."+form+"."+campo_focus+".focus()");
			return false;
		}
	}
	return true;
}	

/*
L'anno bisestile cade normalmente ogni quattro anni, 
Il problema di questo 'strano' 29 febbraio nasce dal calendario gregoriano, introdotto nel 1582, 
che fissa un anno bisestile ogni quattro, ma prevede anche che la regola non si applichi agli anni divisibili per 100,
esclusi quelli divisibili per 400. Non sono quindi stati bisestili il 1700, il 1800 e il 1900, mentre lo è stato il 1600 e lo è il 2000.
La fonte di potenziali problemi sta nel fatto che non tutti i programmatori possono aver conosciuto nel dettaglio 
la clausola del 'bisesto se divisibile per 400' e che quindi abbiano considerato il 2000 'divisibile per 100' e quindi con un febbraio da 28 giorni.
*/
function eBisestile(anno){ 
	if(anno%4 == 0 && (anno%100!=0 || anno%400==0)){
	//	alert (anno + ' bisestile');
		return true; 
	}else {
	//	alert (anno + ' NON bisestile');
		return false; 
	}
}

function VerificaDatiContatto(){

	inserire_nome = 'Inserire il nome';
	inserire_cognome = 'Inserire il cognome';
	indirizzo_email = "Specificare l'indirizzo email";
	indirizzo_email_sbagliato = "L'indirizzo email non è stato digitato correttamente";
	inserire_telefono = 'Inserire il telefono';
	autorizzo = "Autorizzare al trattamento dei dati";

	if(eval("document.contattaci.nome.value")==""){
		alert(inserire_nome);
		eval("document.contattaci.nome.focus()");
		return false;
	}
	if(eval("document.contattaci.cognome.value")==""){
		alert(inserire_cognome);
		eval("document.contattaci.cognome.focus()");
		return false;
	}
	if(eval("document.contattaci.email.value")==""){
		alert(indirizzo_email);
		eval("document.contattaci.email.focus()");
		return false;
	}
	if(!checkMail(eval("document.contattaci.email.value"))){
		alert(indirizzo_email_sbagliato);
		eval("document.contattaci.email.focus()");
		return false;
	}
	if(eval("document.contattaci.telefono.value")==""){
		alert(inserire_telefono);
		eval("document.contattaci.telefono.focus()");
		return false;
	}
	if(eval("document.contattaci.privacy.checked")==false){
		alert(autorizzo);
		eval("document.contattaci.privacy.focus()");
		return false;
	}

	eval("document.contattaci.submit()");
	return true;
}

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 checkPriority(source){
	//if (source.value != "")
	if (parseFloat(source.value) >= 0.1 && parseFloat(source.value) <= 1.0)
		source.value = parseFloat(source.value).toFixed(1);
	else
		source.value = 0.5;

}	// checkFloat()

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];}}
}

function apriFinestra(path){
	window.open(path,'_new','width=970, height=600, resizable=yes, scrollbars=auto');
	return false;
}

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")+1;
	mese_arrivo=eval("document."+form+".mm_arrivo.selectedIndex")+1;
	anno_arrivo=eval("document."+form+".aa_arrivo.selectedIndex")+1;
	giorno_partenza=eval("document."+form+".gg_partenza.selectedIndex")+1;
	mese_partenza=eval("document."+form+".mm_partenza.selectedIndex")+1;
	anno_partenza=eval("document."+form+".aa_partenza.selectedIndex")+1;

	/*Date della prenotazione*/
	if( (giorno_arrivo>0) || (mese_arrivo>0) || (anno_arrivo>0) || (giorno_partenza>0) || (mese_partenza>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;");
		mm_arrivo=new String()
		mm_arrivo=eval("document."+form+".mm_arrivo.options[document."+form+".mm_arrivo.selectedIndex].value;");
		aa_arrivo=new String()
		aa_arrivo=eval("document."+form+".aa_arrivo.options[document."+form+".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;");
		mm_partenza=new String()
		mm_partenza=eval("document."+form+".mm_partenza.options[document."+form+".mm_partenza.selectedIndex].value;");
		aa_partenza=new String()
		aa_partenza=eval("document."+form+".aa_partenza.options[document."+form+".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;
		}
	}
	if( (giorno_arrivo==0) || (mese_arrivo==0) || (anno_arrivo==0) ) {
		alert(inserire_data_arrivo);
		eval("document."+form+".gg_arrivo.focus()");
		return false;
	}
	
	if( (giorno_partenza==0) || (mese_partenza==0) || (anno_partenza==0) ) {
		alert(inserire_data_partenza);
		eval("document."+form+".gg_partenza.focus()");
		return false;
	}
	eval("document."+form+".conferma_email.value=''");

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

function isIE7() {
  if ((document.documentElement && typeof document.documentElement.style.maxHeight!="undefined") && !(/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))) return true
  else 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);
}

/**************************** per geomaps  - inizio ****************************************************************************/
// Call this function when the page has been loaded 
function initialize(div, html, geomaps) { 
	var map = new google.maps.Map2(document.getElementById(div));

	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());

	var array=geomaps.split(", ");
	var longi=parseFloat(array[0]);
	var latit=parseFloat(array[1]);

	point = new google.maps.LatLng(longi, latit);
	map.setCenter(point, 13);

	var marker = new GMarker(point);
	GEvent.addListener(marker, "click", function() {
	  marker.openInfoWindowHtml(html);
	});
	map.addOverlay(marker);
}

function showAddress(address, html, geomaps, address_hotel) {
  var map = new google.maps.Map2(document.getElementById("map"));
  map.addControl(new GLargeMapControl());
  map.addControl(new GMapTypeControl());

  var array=geomaps.split(", ");
  var longi=parseFloat(array[0]);
  var latit=parseFloat(array[1]);

  point = new google.maps.LatLng(longi, latit);
  map.setCenter(point, 13);

  var marker = new GMarker(point);
  GEvent.addListener(marker, "click", function() {
	marker.openInfoWindowHtml(address_hotel);
  });
  map.addOverlay(marker);

  
  geocoder = new GClientGeocoder();
  if (geocoder) {
	geocoder.getLatLng(
	  address,
	  function(point) {
		if (!point) {
		  alert(address + " not found");
		} else {
		map.setCenter(point, 13);
		var marker2 = new GMarker(point);
		GEvent.addListener(marker2, "click", function() {
		  marker2.openInfoWindowHtml(address+html);
		});
		map.addOverlay(marker2);
		}
	  }
	);
  }
}
/**************************** per geomaps  - fine ****************************************************************************/


/**************************** init.js  - inizio ****************************************************************************/
function bn_init () {
	BnElencoClick();

	BnEmptyClick();
	BnTooltipInit();
	BnConfrontaInit();
}

function BnElencoClick(){ //aggiunge un hotel nel block notes
  var bnList = $('div.maniglia_hotel');
  if (bnList.length>0){
	for (var i=0; i<bnList.length; i++) {
	  var tmp = new BnInterface('pulsante');
	  var code = tmp.pulsante.getCode($(bnList[i]));
	  if ($("#bn_elenco img[alt='"+code+"']").length>0){
		tmp.pulsante.switchIco($(bnList[i]));
		$(bnList[i]).toggle(
		  function(e){tmp.pulsante.rem(e.target);},
		  function (e) {tmp.pulsante.add(e.target);}
		);
	  } else {
		$(bnList[i]).toggle(
		  function(e){tmp.pulsante.add(e.target);},
		  function (e) {tmp.pulsante.rem(e.target);}
		);
	  }
	}
  }
	BnIcoClick();
}

function BnIcoClick () {
  var bnIco = $('#menu').find('.addIcoLast');
  if (bnIco.length>0) {
	var tmp = new Array(bnIco[0]);
	var bnIco = tmp;
	for (var i=0;i<bnIco.length;i++) {
	  var tmp = new BnInterface('scheda');
	  var code = tmp.scheda.getCode(bnIco[i]);
	  if ($("#bn_elenco img[alt='"+code+"']").length>0){
		tmp.scheda.switchIco(bnIco[i]);
		$(bnIco[i]).toggle(
		  function(e){tmp.scheda.rem(e.target);},
		  function (e) {tmp.scheda.add(e.target);}
		);
	  } else {
		$(bnIco[i]).toggle(
		  function(e){tmp.scheda.add(e.target);},
		  function (e) {tmp.scheda.rem(e.target);}
		);
	  }
	}
  }

  var bnIco = $('#menu').find('.addIcoOff');
  if (bnIco.length>0) {
	var tmp = new Array(bnIco[0]);
	var bnIco = tmp;
	for (var i=0;i<bnIco.length;i++) {
	  var tmp = new BnInterface('scheda');
	  var code = tmp.scheda.getCode(bnIco[i]);
	  if ($("#bn_elenco img[alt='"+code+"']").length>0){
		tmp.scheda.switchIco(bnIco[i]);
		$(bnIco[i]).toggle(
		  function(e){tmp.scheda.rem(e.target);},
		  function (e) {tmp.scheda.add(e.target);}
		);
	  } else {
		$(bnIco[i]).toggle(
		  function(e){tmp.scheda.add(e.target);},
		  function (e) {tmp.scheda.rem(e.target);}
		);
	  }
	}
  }

}


function BnEmptyClick() { //svuota il block notes
  $('a.svuotaBn').click(function() {
	var tmp = new BnInterface('empty');
	tmp.empty.empty();
  });
}

function BnTooltipInit() { //finestrella nel block notes
  $('#bn_elenco div.blocknotes').hover(
	function(e){
	  var tmp = new Tooltip();
	  tmp.create(e.target);
	},
	function(){}
  );
}

function BnConfrontaInit() { //nella pagina del confronto hotel
  var bnConf = $('#modulo_disponibilita').find('.rem_bn');
  for (var i=0;i<bnConf.length;i++) {
	$(bnConf[i]).click(function(e){
	  var tmp = new BnInterface('confronto');
	  tmp.confronto.rem(e.target);
	});
  }
}

/**************************** init.js  - fine ****************************************************************************/


/**************************** bocknotes.js  - inizio ***********************************************************************/
function BnInterface(tipo) {
  function Scheda(){
	this.getCode= function(targ) {
	   return $(targ).parent().parent().attr("id");
	};

	this.switchIco= function(targ) { 
	   if ($(targ).attr('src')==undefined) var obj = $(targ).parents('div:first').find('img');
	   else obj = targ;
	   var tmp = $(obj).attr('src');
	   if (tmp.match('_meno\.png$')=='_meno.png$' || tmp.match('_meno_on\.png$')=='_meno_on.png') {
		 if (tmp.match('_meno_on\.png')=='_meno_on.png') $(obj).attr('src','http://www.hotel-cattolica.eu/html/img/blocknotes_elenco_piu_on.png');
		 else $(obj).attr('src','http://www.hotel-cattolica.eu/html/img/blocknotes_elenco_piu.png');
	   }else {
		 if (tmp.match('_piu_on\.png$')=='_piu_on.png') $(obj).attr('src','http://www.hotel-cattolica.eu/html/img/blocknotes_elenco_meno_on.png');
		 else $(obj).attr('src','http://www.hotel-cattolica.eu/html/img/blocknotes_elenco_meno.png');
	   }
	}

	this.getImg = function(targ) {
	   return $(targ).parent().parent().find('img').attr('src');
	}

	this.add = function(targ) {
	  this.switchIco(targ);
	  code = this.getCode(targ);
	  if ($("#bn_elenco img[alt='"+code+"']").length==0){
		img = this.getImg(targ);
		//$.post('http://www.adrias-web.com/lavori/caterina/hotelcattolica/blocknotes.php',{op:'add',hotel:code});
		$.post('http://www.hotel-cattolica.eu/blocknotes.php',{op:'add',hotel:code});
		var block = $('#bn_elenco div.blocknotes');
		var i = 0;
		while ($(block[i]).children('img.bn_img').length) i++;
		$(block[i]).append('<img class="bn_img" src="'+img+'" alt="'+code+'" />');
		this.sync(code);
	  } else return false
	}

	this.rem = function(targ) {
	  this.switchIco(targ);
	  code = this.getCode(targ);
	  if ($("#bn_elenco img[alt='"+code+"']").length>0){
		$.post('http://www.hotel-cattolica.eu/blocknotes.php',{op:'rem',hotel:code});
		//$.post('http://www.adrias-web.com/lavori/caterina/hotelcattolica//blocknotes.php',{op:'rem',hotel:code});
		$("#bn_elenco img[alt='"+code+"']").remove();
		this.sync(code);
	  } else return false;
	}

	this.sync = function (code) {
	   if ($('#content #'+code).length>0) $('#content #'+code+' .maniglia_hotel').trigger('click');
	}
  };

  function Pulsante(){ //funziona
	this.getCode = function (targ) {
	   return $(targ).parents("div[id]:first").attr("id");
	 }

	this.switchIco = function (targ) {
	  if ($(targ).find('a').length>0) targ = $(targ).find('a');
	  if ($(targ).hasClass('bn_add')) {$(targ).removeClass('bn_add'); $(targ).addClass('bn_remove');}
	  else {$(targ).removeClass('bn_remove'); $(targ).addClass('bn_add');}
	}

	this.getImg = function (targ) {
	   return $(targ).parents("div[id]:first").find('img:first').attr('src');
	   return $(targ).prev().attr('src');
	}

	this.add = function(targ) {
	  this.switchIco(targ);
	  code = this.getCode(targ);
	  if ($("#bn_elenco img[alt='"+code+"']").length==0){
		img = this.getImg(targ);
		$.post('http://www.hotel-cattolica.eu/blocknotes.php',{op:'add',hotel:code});
		//$.post('http://www.adrias-web.com/lavori/caterina/hotelcattolica/blocknotes.php',{op:'add',hotel:code});
		var block = $('#bn_elenco div.blocknotes');
		var i = 0;
		while ($(block[i]).children('img.bn_img').length) i++;
		$(block[i]).append('<img class="bn_img" src="'+img+'" alt="'+code+'" />');
		this.sync(code);
	  } else return false;
	}

	this.rem = function(targ) {
	  this.switchIco(targ);
	  code = this.getCode(targ);
	  if ($("#bn_elenco img[alt='"+code+"']").length>0){
		$.post('http://www.hotel-cattolica.eu/blocknotes.php',{op:'rem',hotel:code});
		//$.post('http://www.adrias-web.com/lavori/caterina/hotelcattolica/blocknotes.php',{op:'rem',hotel:code});
		$("#bn_elenco img[alt='"+code+"']").remove();
		this.sync(code);
	  } else return false;
	}

	this.sync = function (code) {
	  bottone=$('#menu').find('div#'+code);
	  if (bottone.find('.addIcoLast:first').length>0) bottone.find('.addIcoLast:first').trigger('click');
	  if (bottone.find('.addIcoOff:first').length>0) bottone.find('.addIcoOff:first').trigger('click');
	}
  }

  function Empty(){
	
	this.empty = function(){
	  var hotels = $('#bn_elenco .blocknotes .bn_img');
	  $.post('http://www.hotel-cattolica.eu/blocknotes.php',{op:'empty'},function(){
	  //$.post('http://www.adrias-web.com/lavori/caterina/hotelcattolica/blocknotes.php',{op:'empty'},function(){
		$.post('http://www.hotel-cattolica.eu/blocknotes.php',{op:'empty'},function(){
		//$.post('http://www.adrias-web.com/lavori/caterina/hotelcattolica/blocknotes.php',{op:'empty'},function(){
		  $.post('http://www.hotel-cattolica.eu/blocknotes.php',{op:'redraw'},function(data){
		  //$.post('http://www.adrias-web.com/lavori/caterina/hotelcattolica/blocknotes.php',{op:'redraw'},function(data){
			$('#bn_elenco').empty().append(data);
		  },'html');
		});
	  });
	  this.sync(hotels);
	}

	this.partial = function(){
	  var obj = $('#notifica span.nosottolineato');
	  obj.each(function() {
		var clas = $(this).attr('class');
		var code = clas.substr(15);
		$("#bn_elenco img[alt='"+code+"']").remove();
		$("#blocknotes_confronta input[value='"+code+"']").parents('tr:first').remove();
		$('#notifica_close').trigger('click');
		if ($("#blocknotes_confronta .mailHotel a[alt='"+code+"']").length>0)
			$("#blocknotes_confronta .mailHotel a[alt='"+code+"']").parents('.mailHotel:first').remove(); 
	  });
	}
	
	this.sync = function (hotels){
	  hotels.each(function() {
		code = $(this).attr('alt');
		if ($('#content #'+code).length>0) $('#content #'+code+' .maniglia_hotel').trigger('click'); 

		if ($("#"+code+" .maniglia_hotel a[class='bn_remove']").length>0){
			$("#"+code+" .maniglia_hotel a[class='bn_remove']").removeClass('bn_remove');
			$("#"+code+" .maniglia_hotel a[class='']").addClass('bn_add');
		}

		if ($("#blocknotes_confronta .mailHotel a[alt='"+code+"']").length>0){
			$("#blocknotes_confronta .mailHotel a[alt='"+code+"']").parents('.mailHotel:first').remove();
		}

	  });
	}
  }

  function Info(){
	this.getCode = function(targ) {
	  return $('#info img:first').attr('alt');
	}
	
	this.sync = function (code) {
	  bottone=$('#menu').find('div#'+code);
	  if (bottone.find('.addIcoLast:first').length>0) $('#menu').find('.addIcoLast:first').trigger('click');
	  if (bottone.find('.addIcoOff:first').length>0) $('#menu').find('.addIcoOff:first').trigger('click');

	   if ($('#content #'+code).length>0) $('#content #'+code+' .maniglia_hotel').trigger('click');
	   if ($("#blocknotes_confronta .mailHotel img[alt='"+code+"']").length>0){
		   $("#blocknotes_confronta .mailHotel img[alt='"+code+"']").parents('.mailHotel:first').remove();
	   }
	   if ($("#"+code+" .maniglia_hotel a[class='bn_remove']").length>0){
		$("#"+code+" .maniglia_hotel a[class='bn_remove']").removeClass('bn_remove');
		$("#"+code+" .maniglia_hotel a[class='bn_remove']").addClass('bn_add');
	  }
	}
	
	this.rem = function(targ) {
	  code = this.getCode(targ);
	  if ($("#bn_elenco img[alt='"+code+"']").length>0){
		$.post('http://www.hotel-cattolica.eu/blocknotes.php',{op:'rem',hotel:code});
		//$.post('http://www.adrias-web.com/lavori/caterina/hotelcattolica/blocknotes.php',{op:'rem',hotel:code});
		$("#bn_elenco img[alt='"+code+"']").remove();
		this.sync(code);
	  } else return false;
	  return false;
	}
  }
  
  function Confronto(){
	this.getCode = function(targ) {
	   return $(targ).attr("alt");
	}
	this.rem = function(targ) {
	  code = this.getCode(targ);
	  $.post('http://www.hotel-cattolica.eu/blocknotes.php',{op:'rem',hotel:code});
	  //$.post('http://www.adrias-web.com/lavori/caterina/hotelcattolica/blocknotes.php',{op:'rem',hotel:code});
	  $(targ).parents('li.mailHotel').remove();
	  $("#bn_elenco img[alt='"+code+"']").remove();
	  return false;
    }
  }

  if (tipo=='scheda') this.scheda = new Scheda();
  else if (tipo=='pulsante') this.pulsante = new Pulsante();
  else if (tipo=='empty') this.empty = new Empty();
  else if (tipo=='info') this.info = new Info();
  else this.confronto = new Confronto();
}

function Tooltip() { //funziona
   this.create = function(targ){
	 $('#info').remove();
	 if ($(targ).find('img').length>0) var img = $(targ).find('img').clone();
	 else var img = $(targ).clone();
	 $(img).attr('style','');
	 var info = document.createElement('div');
	 $(info).attr('id','info');
	 code = $(img).attr('alt');
	 if (code==undefined) code = $(targ).attr('alt');
	 if (code!=undefined) {
	   $.post('http://www.hotel-cattolica.eu/getHotelTooltip.php',{idHotel:code},function(data){
	   //$.post('http://www.adrias-web.com/lavori/caterina/hotelcattolica/getHotelTooltip.php',{idHotel:code},function(data){
		 $(img).appendTo($(info));
		 $(data).appendTo($(info));
		 //pos è l'id delle div degli hotel nel box_blocknotes.inc
		 var pos = $(targ).attr('id');
		 if (pos==undefined || pos=='') pos = $(targ).parent('div:first').attr('id');
		 var template = 1;
		 var elevation = 0;
		 if (pos>=6) elevation=1;
		 if (pos<=2) {
		   var shift=36*pos;
		   var ieshift=parseInt(shift)-288;
		 }else if (pos<=5){
		   var shift = (288-(36*(7-pos)))-108;
		   var ieshift = parseInt(shift)-288;
		   var template=2;
		 }else if( (pos>=6) && (pos<=8) ){
		   var shift=36*(pos-6);
		  //6 è il numero di hotel che ci stanno in una riga
		   var ieshift=parseInt(shift)-288;
		 }else{
		   var shift = (288-(36*(8-(pos-5))))-108;
		   var ieshift = parseInt(shift)-288;
		   var template=2;
		 }
		 if (pos>=10) pos-=10;
		 if (template==1){
		   $(info).children('img').css({float:'left'});
		   $(info).children('#tooltip_blocknotes').css({float:'right'});
		 } else {
		   $(info).children('img').css({float:'right'})
		   $(info).children('#tooltip_blocknotes').css({float:'left'});
		 }
		 if (elevation==1) $(info).find('img:first').css({margin:'33px 0 0 0'});
		 $(info).css('cssText',"margin-top:0px; background:#999; position:absolute; top:0px; left:"+shift+"px!important; left:"+ieshift+'px; border:2px solid #999');
		if (isIE7()) $(info).css('left',shift);
		 $(info).css('width','98px');
		 $(info).css('height','59px');
		 $('#bn_elenco').append(info);
		 $(info).find('a.drem').click(function (e){
		   var tmp = new BnInterface('info');
		   tmp.info.rem(e.target);
		 });
//	   $('#info').animate({width:'138px', height:'66px', opacity:0.9},150);
		 $(info).hover(function(){},function(){$('#info').remove();});
	   },'html');
	 }
   }
   this.remove = function(){
	 $('#info').remove();
   }
}
/**************************** bocknotes.js  - fine ***********************************************************************/

