// JavaScript Document
function showservizio(id_div) {
		document.getElementById(id_div).style.display='block';
}
function hiddenservizio(id_div) {
		document.getElementById(id_div).style.display='none';
}
function change_mese(num_mese, id_apartment, incr_decr) {
	document.getElementById('mese'+num_mese+id_apartment).style.display='none';
	if(incr_decr == 'incr') {
		mese = Number(num_mese)+1;
		id_freccia = 'freccia'+mese+''+id_apartment;
		document.getElementById(id_freccia).style.display='block';	
		if(mese==11) {
			id_freccia2 = 'freccia2'+mese+''+id_apartment;
			document.getElementById(id_freccia2).style.display='none';
		}
	} else if(incr_decr == 'decr')
		mese = Number(num_mese)-1;	
	idmese = 'mese'+''+mese+''+id_apartment;
	document.getElementById(idmese).style.display='block';
	
}
function show(image, id_ap, dominio) {
var a = document.getElementById(image);

/*var f = new Array()
for(i=1;i<=num_foto;i++) {
	f[i] = "foto/apartments/"+id_ap+"/apartment"+i+".jpg";
}
f[1] = "foto/apartments/1/1.jpg";
f[2] = "/images/image2.jpg";
f[3] = "/images/image3.jpg";
f[4] = "/images/image4.jpg";
f[5] = "/images/image5.jpg";
f[6] = "/images/image6.jpg";
f[7] = "/images/image7.jpg";
f[8] = "/images/image8.jpg";
f[9] = "/images/image9.jpg";
f[10] = "/images/image10.jpg";
f[11] = "/images/image11.jpg";
f[12] = "/images/image12.jpg";
f[13] = "/images/image13.jpg";
f[14] = "/images/image14.jpg";
f[15] = "/images/image15.jpg";
f[16] = "/images/image16.jpg";
f[17] = "/images/image17.jpg";
f[18] = "/images/image18.jpg";*/

//var url = f[image];
var url = dominio+"/foto/apartments/"+id_ap+"/"+image;
a.setAttribute('href', url);
myLightbox.start(a);
}

var popupscheda = null;
function checklogin(id_ap, arearis) {
	var w = 700;
	var h = 550;
	var pw = Math.floor((screen.width - w) / 2);
	var ph = Math.floor((screen.height - h) / 2);
	// Crea il popup solo se non è già stato aperto
	//if (!popupscheda || popupscheda.closed) 
		popupscheda = window.open("arearis.php?id_ap="+id_ap, "mywin", "scrollbars=yes, toolbar=no, width=" + w + ",height=" + h + ",top=" + ph + ",left=" + pw);
	// Attiva il popup (portalo in primo piano)
	if (popupscheda) popupscheda.focus();
}
function resetdate() {
	document.getElementById('data_arrivo').value='';
	document.getElementById('data_partenza').value='';
	document.getElementById('data_partenza').style.border='1px solid #ffffff';
	document.getElementById('data_partenza').style.background='#ffffff';
}
function checkform(lingua, minimum_period) {
	var msg_err = "Please,\n";
	var dataarrivo = document.getElementById('data_arrivo');
	var datapartenza = document.getElementById('data_partenza');
	if(dataarrivo.value.length==0 || datapartenza.value.length==0) {
		if(lingua == 'ita')
			msg_err += " - Inserisci il giorno di arrivo e il giorno di partenza\n";
		else if(lingua == 'eng')
			msg_err += " - enter check-in date and check-out date\n";
		else if(lingua == 'esp')
			msg_err += " - Selecciona la fecha de llegada y la fecha de partida\n";			
		dataarrivo.focus();
	} else {
		gg_mm_aa_arr = dataarrivo.value.split('/');
		gg_mm_aa_par = datapartenza.value.split('/');
		dataarrivo_ = new Date(gg_mm_aa_arr[2],gg_mm_aa_arr[1],gg_mm_aa_arr[0]);
		datapartenza_ = new Date(gg_mm_aa_par[2],gg_mm_aa_par[1],gg_mm_aa_par[0]);
		dataarrivoMillisec = dataarrivo_.getTime();
		datapartenzaMillisec = datapartenza_.getTime();
		if(datapartenzaMillisec<=dataarrivoMillisec){
			if(lingua == 'ita')
				msg_err += " - Il giorno di partenza non è corretto perché antecedente o uguale al giorno di arrivo\n";
			else if(lingua == 'eng')
				msg_err += " - the check-in date must be before the check-out date\n";
			else if(lingua == 'esp')
				msg_err += " - La fecha de llegada tiene que ser anterior a la fecha de partida\n";
			datapartenza.focus();
		} else if(minimum_period>0 && (datapartenzaMillisec - dataarrivoMillisec)<(1000*60*60*24*minimum_period)) {
			if(lingua == 'ita')
				msg_err += " - Il periodo minimo di soggiorno è di "+minimum_period+" giorni\n";
			else if(lingua == 'eng')
				msg_err += " - minimum period must be "+minimum_period+" days \n";
			else if(lingua == 'esp')
				msg_err += " - El periodo mìnimo de estancia es de "+minimum_period+" dìas\n";
			datapartenza.focus();
		}
	}
	if(document.getElementById('nome').value.length==0) {
		if(lingua == 'ita')
			msg_err += " - Cognome e nome sono obbligatori\n";
		else if(lingua == 'eng')
			msg_err += " - enter the name and surname\n";
		else if(lingua == 'esp')
			msg_err += " - Escribe nombre y apellido\n";		
		document.getElementById('nome').focus();
	}
	if(document.getElementById('email').value.length==0) {
		if(lingua == 'ita')
			msg_err += " - L'e-mail è obbligatoria\n";
		else if(lingua == 'eng')
			msg_err += " - enter the e-mail\n";
		else if(lingua == 'esp')
			msg_err += " - Escribe el e-mail\n";
		document.getElementById('email').focus();
	}
	if(document.getElementById('telefono').value.length==0) {
		if(lingua == 'ita')
			msg_err += " - Il telefono è obbligatorio\n";
		else if(lingua == 'eng')
			msg_err += " - enter the phone number\n";
		else if(lingua == 'esp')
			msg_err += " - Escribe el telefono\n";		
		document.getElementById('telefono').focus();
	}
	if(!document.getElementById('autorizzo').checked) {
		if(lingua == 'ita')
			msg_err += " - Dai l'autorizzazione al trattamento dei dati\n";
		else if(lingua == 'eng')
			msg_err += " - you must consent the treatment of your personal data\n";
		else if(lingua == 'esp')
			msg_err += " - Da la autorizociòn al tratamiento de datos\n";		
	}
	if(msg_err.length>8) {
		alert(msg_err);
		return false;
	} else
		return true;
}

function aggiorna_giorno_arrivo(gg,mm,aa) {
	if(document.getElementById('data_arrivo').value.length==0) {
		document.getElementById('data_arrivo').value=gg+"/"+mm+"/"+aa;
		document.getElementById('data_arrivo').style.border='1px solid #ff0000';
		document.getElementById('data_partenza').style.border='1px solid #ff0000';
		document.getElementById('data_partenza').style.background='#ffffff';
		document.getElementById('data_arrivo').style.border='1px solid #ffffff';
	} else {
		document.getElementById('data_partenza').value=gg+"/"+mm+"/"+aa;
		document.getElementById('data_partenza').style.border='1px solid #ffffff';
		document.getElementById('data_partenza').style.background='#ffffff';
	}
}

function load2() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map2"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(43.7687324, 11.2569013), 14);
map.setMapType(G_HYBRID_MAP);
/*if(home1==2) 
	pagexml = "creaxml.php";
else*/
	pagexml = "creaxml.php";	
GDownloadUrl(pagexml, function(data) {
	var xml = GXml.parse(data);
	var markers = xml.documentElement.getElementsByTagName("marker");
	for (var i = 0; i < markers.length; i++) {
		var denom = markers[i].getAttribute("denom");
		var indirizzo = markers[i].getAttribute("indirizzo");
		var id_apart = markers[i].getAttribute("id_apart");
		var cap = markers[i].getAttribute("cap");
		var letti = markers[i].getAttribute("letti");
		var tipo = markers[i].getAttribute("tipo");
		var area = markers[i].getAttribute("area");
		var lat = markers[i].getAttribute("lat");
		var long = markers[i].getAttribute("long");
		var	point = new GLatLng(parseFloat(lat), parseFloat(long), 9);
		var marker = createMarker(point, denom, indirizzo, cap, id_apart, letti, tipo, area, lat, long, 'map2');
		map.addOverlay(marker);
	}
});
}
}
function loadbb() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map2"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(43.7687324, 11.2569013), 13);
map.setMapType(G_HYBRID_MAP);
/*if(home1==2) 
	pagexml = "creaxml.php";
else*/
	pagexml = "creaxmlbb.php";	
GDownloadUrl(pagexml, function(data) {
	var xml = GXml.parse(data);
	var markers = xml.documentElement.getElementsByTagName("marker");
	for (var i = 0; i < markers.length; i++) {
		var denom = markers[i].getAttribute("denom");
		var indirizzo = markers[i].getAttribute("indirizzo");
		var id_bed = markers[i].getAttribute("id_apart");
		var cap = markers[i].getAttribute("cap");
		var area = markers[i].getAttribute("area");
		var lat = markers[i].getAttribute("lat");
		var long = markers[i].getAttribute("long");
		var	point = new GLatLng(parseFloat(lat), parseFloat(long), 9);
		var marker = createMarkerbb(point, denom, indirizzo, cap, id_bed, area, lat, long, 'map2');
		map.addOverlay(marker);
	}
});
}
}
function createMarkerbb(point, denom, indirizzo, cap, id_apart, area, lat, long, map) {
	var icon = new GIcon();
	icon.image = "http://www.firenze-maps.it/marker/marker_appartamento.png";
	icon.iconSize = new GSize(25, 28);
	icon.shadow = "http://www.firenze-maps.it/marker/ombra.png";
	icon.shadowSize = new GSize(40, 28);
	icon.iconAnchor = new GPoint(0, 20);
	icon.infoWindowAnchor = new GPoint(12, 0);		
	var marker = new GMarker(point,icon);
	var html = "<img src=\"http://www.firenze-maps.it/foto/"+id_apart+"/bedandbreakfast0.jpg\" alt=\"\" width=\"100\" height=\"77\" align=\"left\" style=\"margin-right:3px;border:1px solid #3461bf;\"><a href=\"http://www.firenze-maps.it/appartamento_firenze.php/id_ap="+id_apart+"\" style=\"color:#3461bf;\">" + denom + "</a> <br/>" + indirizzo + "<br />" + cap +" "+area+"<br /><a href=\"javascript:streetview('"+lat+"','"+long+"','"+map+"')\" style=\"font-weight:bold;\">Street view</a>";
	GEvent.addListener(marker, 'mouseover', function() {
		marker.openInfoWindowHtml(html);
	});
return marker;
}
function createMarker(point, denom, indirizzo, cap, id_apart, letti, tipo, area, lat, long, map) {
	var icon = new GIcon();
	icon.image = "http://www.firenze-maps.it/marker/marker_appartamento.png";
	icon.iconSize = new GSize(25, 28);
	icon.shadow = "http://www.firenze-maps.it/marker/ombra.png";
	icon.shadowSize = new GSize(40, 28);
	icon.iconAnchor = new GPoint(0, 20);
	icon.infoWindowAnchor = new GPoint(12, 0);		
	var marker = new GMarker(point,icon);
	var html = "<img src=\"http://www.rentflorenceapartment.com/foto/apartments/"+id_apart+"/apartment1.jpg\" alt=\"\" width=\"100\" height=\"77\" align=\"left\" style=\"margin-right:3px;border:1px solid #3461bf;\"><a href=\"http://www.firenze-maps.it/appartamento_firenze.php/id_ap="+id_apart+"\" style=\"color:#3461bf;\">" + denom + "</a> <br/>" + indirizzo + "<br />" + cap +" "+area+"<br />"+tipo+", "+letti+" letti<br /><a href=\"javascript:streetview('"+lat+"','"+long+"','"+map+"')\" style=\"font-weight:bold;\">Street view</a>";
	GEvent.addListener(marker, 'mouseover', function() {
		marker.openInfoWindowHtml(html);
	});
return marker;
}

var myPano;
function streetview(lat,long, map) {
  var fenwayPark = new GLatLng(lat, long);
  panoramaOptions = { latlng:fenwayPark };
  myPano = new GStreetviewPanorama(document.getElementById(map), panoramaOptions);
  GEvent.addListener(myPano, "error", handleNoFlash);
//  var div_tasto_map = document.getElementById("return_map");
//  div_tasto_map.style.display='block';
}
function handleNoFlash(errorCode) {
  if (errorCode == "FLASH_UNAVAILABLE") {
	alert("Errore: Flash doesn't appear to be supported by your browser");
	return;
  }
}