// 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';
	}
}