// JavaScript Document
function change_foto(nome) {
	document.getElementById('foto').src='bilocale/'+nome;
}
function change_quadrim(type) {
	var div1 = document.getElementById("quadrimestre1");
	var div2 = document.getElementById("quadrimestre2");
	var div3 = document.getElementById("quadrimestre3");
	if(type == "r1") {
		div1.style.display='none';
		div2.style.display='block';
		div3.style.display='none';
	}
	if(type == "r2") {
		div1.style.display='none';
		div2.style.display='none';		
		div3.style.display='block';
	}
	if(type == "l1") {
		div1.style.display='block';
		div2.style.display='none';		
		div3.style.display='none';
	}	
	if(type == "l2") {
		div1.style.display='block';
		div2.style.display='none';		
		div3.style.display='none';
	}
}
function change_quadrim2(type) {
	if(type == "r1") {
		document.getElementById("q1").style.display='none';
		document.getElementById("q2").style.display='block';
		document.getElementById("q3").style.display='none';
	}
	if(type == "r2") {
		document.getElementById("q1").style.display='none';
		document.getElementById("q2").style.display='none';		
		document.getElementById("q3").style.display='block';
	}
	if(type == "l1") {
		document.getElementById("q1").style.display='block';
		document.getElementById("q2").style.display='none';		
		document.getElementById("q3").style.display='none';
	}	
	if(type == "l2") {
		document.getElementById("q1").style.display='block';
		document.getElementById("q2").style.display='none';		
		document.getElementById("q3").style.display='none';
	}
}
function aggiorna_giorno_arrivo(gg,mm,aa) {
	if(document.prenota.data_arrivo.value.length==0) {
		document.prenota.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='#F3B59C';
		document.getElementById('data_arrivo').style.border='1px solid #ffffff';
	} else {
		document.prenota.data_partenza.value=gg+"/"+mm+"/"+aa;
		document.getElementById('data_partenza').style.border='1px solid #ffffff';
		document.getElementById('data_partenza').style.background='#FFDACB';
	}
}
function resetdate() {
	document.prenota.data_arrivo.value='';
	document.prenota.data_partenza.value='';
	document.getElementById('data_partenza').style.border='1px solid #ffffff';
	document.getElementById('data_partenza').style.background='#FFDACB';
}
function checkform(lingua) {
	var msg_err = "";
	var dataarrivo = document.prenota.data_arrivo.value;
	var datapartenza = document.prenota.data_partenza.value;

	
	if(dataarrivo.length==0 || datapartenza.length==0) {
		if(lingua == 'ita')
			msg_err += " - Inserisci il giorno di arrivo e il giorno di partenza\n";
		else if(lingua == 'eng')
			msg_err += " - Please, 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";			
		document.prenota.data_arrivo.focus();
	} else {
		gg_mm_aa_arr = dataarrivo.split('/');
		gg_mm_aa_par = datapartenza.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";				
			document.prenota.data_partenza.focus();
			} 
			/*else 	if(Math.ceil((datapartenzaMillisec - dataarrivoMillisec)/(1000*60*60*24))<3){
			if(lingua == 'ita')
				msg_err += " - Il periodo minimo di soggiorno è di tre giorni\n";
			else if(lingua == 'eng')
				msg_err += " - Minimum period must be three days \n";
			else if(lingua == 'esp')
				msg_err += " - El periodo mìnimo de estancia es de tres dìas\n";
				document.prenota.data_partenza.focus();
			}*/
	}
	if(document.prenota.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.prenota.nome.focus();
	}
	if(document.prenota.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.prenota.nome.focus();
	}
	if(document.prenota.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.prenota.telefono.focus();
	}
	if(!document.prenota.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>0) {
		alert(msg_err);
		return false;
	} else
		return true;
}
function checkforminfo(lingua) {
	var msg_err = "";	
	var nome = document.info.nome;
	var email = document.info.email;
	if(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";		
		nome.focus();
	}	
	if(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";
		email.focus();
	}	
	if(msg_err.length>0) {
		alert(msg_err);
		return false;
	} else
		return true;	
}
function showfoto(nome,id_offerta) {
	thumb = 'http://www.residenzarondinelli.it/';
	if(id_offerta==1)
		thumb += 'appartamento1/'+nome+'.jpg';
	if(id_offerta==2)
		thumb += 'appartamento2/'+nome+'.jpg';
	document.getElementById('foto').src=thumb;
	document.getElementById('showfoto').style.display='block';
}
function hiddenfoto() {
	document.getElementById('showfoto').style.display='none'
}
function show(image, id_ap, dominio) {
var a = document.getElementById(image);
var url = dominio+"/foto/apartments/"+id_ap+"/"+image;
a.setAttribute('href', url);
myLightbox.start(a);
}

