
msg1_es = 'Por favor verifique las fechas introducidas';
msg2_es = 'La estancia mínima para este apartamento es de [noches]: ';
msg3_es = 'Debe completar todos los campos, Nombre, País, Teléfono, Email y Fechas';
msg1_en = 'The dates are incorrect, please to verify';
msg2_en = 'The stay for this apartments is [nights]: ';
msg3_en = 'You must to fill all fields, Name, Country, Telpehone, Email and Dates';
msg1_de = 'The dates are incorrect, please to verify';
msg2_de = 'The stay for this apartments is [nights]: ';
msg3_de = 'Debe completar todos los campos, Nombre, País, Teléfono, Email y Fechas';
msg1_fr = 'Merci de vérifier vos dates';
msg2_fr = 'Le séjour minimum pour cet appartement est de [nuits]: ';
msg3_fr = 'Vous devez remplir tous les champs : Nom, Pays, Téléphone, Email et Dates';

function checkFastBooking(idioma){
	var error = 0;
	if (document.fastbooking.Nombre.value == "")	{
		error = 1;	
	}
	if (document.fastbooking.Pais.value == "")	{
		error = 1;
	}
	if (document.fastbooking.Telefono.value == "")	{
		error = 1;
	}
	if (document.fastbooking.Email.value == "")	{
		error = 1;
	}
	if (document.fastbooking.Fechas_Comentarios.value == "")	{
		error = 1;
	}
	if ( error == 1 ){
		if (idioma=="es"){
			alert(msg3_es);
		}
		if (idioma=="fr"){
			alert(msg3_fr);
		}
		if (idioma=="en"){
			alert(msg3_en);
		}
		if (idioma=="de"){
			alert(msg3_de);
		}
		
		return false;
	}
	return true;
}

function Abrir_popups (pagina, ancho, alto, selObj) {

	var opciones='toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,width='+ancho+', height='+alto+',top=85,left=140';

	if (selObj != ""){

		window.open(pagina+selObj.options[selObj.selectedIndex].value,'',opciones);

	}

	else{

		window.open(pagina,'',opciones);

	}

}

function ponerAction(){
	var tipoAloja;
	tipoAloja = document.forma.R1.value;
	
	if(tipoAloja=='V1'){
		//if selected aparts
		document.forma.action = "newresultados.php";
	}
	else{
		document.forma.action = "buscohot.php";
	}
}

var ventanaCalendario=false

function muestraCalendario(raiz,formulario_destino,campo_destino,mes_destino,ano_destino){
	//funcion para abrir una ventana con un calendario.
	//Se deben indicar los datos del formulario y campos que se desean editar con el calendario, es decir, los campos donde va la fecha.
	if (typeof ventanaCalendario.document == "object") {
		ventanaCalendario.close()
	}
	ventanaCalendario = window.open("/calendario/index.php?formulario=" + formulario_destino + "&nomcampo=" + campo_destino,"calendario","width=200,height=205,left=500,top=400,scrollbars=no,menubars=no,statusbar=NO,status=NO,resizable=YES,location=NO")
}

function muestraCalendario2(raiz,formulario_destino,campo_destinoDia,campo_destinoMesYear){
	//funcion para abrir una ventana con un calendario.
	//Se deben indicar los datos del formulario y campos que se desean editar con el calendario, es decir, los campos donde va la fecha.
	if (typeof ventanaCalendario.document == "object") {
		ventanaCalendario.close()
	}
	ventanaCalendario = window.open("/calendario/index2.php?formulario=" + formulario_destino + "&nomcampoDia=" + campo_destinoDia + "&nomcampoMesYear=" + campo_destinoMesYear + "&valueCampoMesYear=" + document.getElementById(campo_destinoMesYear).value,"calendario","width=200,height=205,left=500,top=400,scrollbars=no,menubars=no,statusbar=NO,status=NO,resizable=YES,location=NO")
}

var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

function countup(yr_in, m_in, d_in, yr_out, m_out, d_out){
	var checkintring=montharray[m_in-1]+" "+d_in+", "+yr_in;
	var checkouttring=montharray[m_out-1]+" "+d_out+", "+yr_out;
	var difference=(Math.round((Date.parse(checkouttring)-Date.parse(checkintring))/(24*60*60*1000))*1);
	return difference;
}

function checkDates(nomFormu, campoinDay, campoinMonthYear, campooutDay, campooutMonthYear, estanciaMin, idioma){
	
	var checkin,checkout,checkinDay,checkinMonth,checkinYear,checkoutDay,checkoutMonth,checkoutYear,year,month,day;
	
	checkinDay = document.getElementById(campoinDay).value;
	checkinMonth = document.getElementById(campoinMonthYear).value.substr(0,2);
	checkinYear = document.getElementById(campoinMonthYear).value.substr(3,4);	
	checkoutDay = document.getElementById(campooutDay).value;
	checkoutMonth = document.getElementById(campooutMonthYear).value.substr(0,2);
	checkoutYear = document.getElementById(campooutMonthYear).value.substr(3,4);	
	
	var today = new Date();
	
	year = today.getFullYear();
	month = today.getMonth();
	day = today.getDate();

	if ( (Date.UTC(checkinYear,checkinMonth-1,checkinDay,0,0,0,0) >= Date.UTC(checkoutYear,checkoutMonth-1,checkoutDay,0,0,0,0)) || 
		 ( Date.UTC(checkinYear,checkinMonth-1,checkinDay,0,0,0,0) < Date.UTC(year,month,day,0,0,0,0) )){
		
		switch (idioma){
			case "es":
				alert(msg1_es);
				break;
			case "en":
				alert(msg1_en);
				break;
			case "fr":
				alert(msg1_fr);
				break;
			case "de":
				alert(msg1_de);
				break;
		}
				
		return false;
	}
	var numNoches = countup(checkinYear,checkinMonth,checkinDay, checkoutYear, checkoutMonth, checkoutDay);
	
	if ( estanciaMin > 0 ){
		if ( numNoches < estanciaMin) {
			switch (idioma){
				case "es":
					alert(msg2_es + " " + estanciaMin);
					break;
				case "en":
					alert(msg2_en + " " + estanciaMin);
					break;
				case "fr":
					alert(msg2_fr + " " + estanciaMin);
					break;
				case "de":
					alert(msg2_de + " " + estanciaMin);
					break;
			}
			return false;
		}
	}
	return true;	
}

function updateCheckout(nomFormu, campoinDay, campoinMonthYear, campooutDay, campooutMonthYear){
	var checkin,checkout,checkinDay,checkinMonth,checkinYear,checkoutDay,checkoutMonth,checkoutYear,year,month,day;
	
	checkinDay = document.getElementById(campoinDay).value;
	checkinMonth = document.getElementById(campoinMonthYear).value.substr(0,2);
	checkinYear = document.getElementById(campoinMonthYear).value.substr(3,4);	
	checkoutDay = document.getElementById(campooutDay).value;
	checkoutMonth = document.getElementById(campooutMonthYear).value.substr(0,2);
	checkoutYear = document.getElementById(campooutMonthYear).value.substr(3,4);	
	
	var numNoches = countup(checkinYear,checkinMonth,checkinDay, checkoutYear, checkoutMonth, checkoutDay);
	
	if ( numNoches < 0) {
		if ( ( checkoutMonth < checkinMonth ) && ( checkoutYear == checkinYear ) || ( checkinYear > checkoutYear ) )
		{
			document.getElementById(campooutMonthYear).options.selectedIndex = document.getElementById(campoinMonthYear).options.selectedIndex;
			document.getElementById(campooutDay).options.selectedIndex = document.getElementById(campoinDay).options.selectedIndex;
		}
		else if ( ( checkoutDay < checkinDay ) && ( checkoutMonth == checkinMonth ) )
		{
			document.getElementById(campooutDay).options.selectedIndex = document.getElementById(campoinDay).options.selectedIndex;
		}
	}
}

