function busqueda_avanzada_submit(barrios_max_cant,categorias_max_cant){


	// Veo si hay algun barrio

	var barrios_in="";
	document.getElementById("txt_busqueda_barrios_in").value=" ";
	for (var i=0;i<barrios_max_cant;i++) {

		if (document.getElementById("busqueda_barrios_" + i) != undefined ) {
			if (document.getElementById("busqueda_barrios_" + i).checked) {
				if (barrios_in != "") barrios_in+=",";
				barrios_in+=document.getElementById("busqueda_barrios_" + i).value;
			}
		}
	}
	document.getElementById("txt_busqueda_barrios_in").value=barrios_in;



	// Veo si hay alguna categoria

	var categorias_in="";
	document.getElementById("txt_busqueda_categorias_in").value=" ";
	for (var i=0;i<categorias_max_cant;i++) {
		if (document.getElementById("busqueda_categorias_" + i) != undefined ) {
			if (document.getElementById("busqueda_categorias_" + i).checked) {
				if (categorias_in != "") categorias_in+=",";
				categorias_in+=document.getElementById("busqueda_categorias_" + i).value;
			}

		}
	}
	document.getElementById("txt_busqueda_categorias_in").value=categorias_in;


	// Controlo fechas
	var valida =true;
	if ((document.getElementById("busqueda_checkin_2").value.length == 10) && (document.getElementById("busqueda_checkout_2").value.length == 10)) {

		if (!fechas_comparar(document.getElementById("busqueda_checkout_2").value,document.getElementById("busqueda_checkin_2").value)){
			alert("Dates error / Error en las fechas seleccionadas");
			valida = false;
		}
	}

	if (valida ) {
		document.busqueda_avanzada_form.submit();
	}

}

function busqueda_avanzada_todos_check(total_checks){

	// Veo si hay algun check tildado
	var checkeados=0;
	for (var i=0;i<total_checks;i++) {
		if (document.getElementById("busqueda_barrios_" + i).checked) checkeados++;
	}

	if (checkeados == 0) {
		document.getElementById("busqueda_barrio_id").checked = true;
	}else{
		document.getElementById("busqueda_barrio_id_NO_BARRIO").checked = true;
	}
}

function clearText(thefield){
	if (thefield.defaultValue==thefield.value) thefield.value = "";
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
	if (init==true) with (navigator) {
		if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
			document.MM_pgW=innerWidth;
			document.MM_pgH=innerHeight;
			onresize=MM_reloadPage;
		}
	}else if(innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH){
		location.reload();
	}
}
function poner_fecha(idioma){
	var mydate=new Date()
	var theYear=mydate.getFullYear()
	var day=mydate.getDay()
	var month=mydate.getMonth()
	var daym=mydate.getDate()
	if (daym<10)
	daym="0"+daym;
	var dayarray = new Array('EN','ES');
	dayarray['EN']=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	dayarray['ES']=new Array("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado");
	var montharray = new Array('EN','ES');
	montharray['EN']=new Array("Jan","Feb","Mar","Apr","May","June","July","Aug","Sep","Oct","Nov","Dec");
	montharray['ES']=new Array("Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic");
	if(idioma == 'EN'){
		document.write(dayarray[idioma][day]+", "+montharray[idioma][month]+" "+daym+" "+theYear);
	}else{
		document.write(dayarray[idioma][day]+" " +daym+" de " +montharray[idioma][month]+" de "+theYear);
	}
}
function cambiar_idioma(){
	$.get('cambiar_idioma.php', function(data) {
			window.location.reload();
		});
}
function alquiler_ver_imagen(ruta){
		$("#imagen_actual").attr({src: ruta});
}
function alquiler_mostrar_video(){
	//document.getElementById('separador_medios').style.backgroundColor='#5394ED';
	document.getElementById('contenido_fotos').style.visibility = 'hidden';
	document.getElementById('contenido_video').style.visibility = 'visible';

}
function alquiler_mostrar_fotos(){
	//document.getElementById('separador_medios').style.backgroundColor='#f4821f';
	document.getElementById('contenido_video').style.visibility = 'hidden';
	document.getElementById('contenido_fotos').style.visibility = 'visible';

}
function agregar_a_favoritos(url,titulo){
	if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)) {
		window.external.AddFavorite(url,titulo);
	}else{
		if(navigator.appName == "Netscape")
		alert ("Presione Crtl+D para agregar a este sitio en sus Bookmarks");  //Puedes personalizar este mensaje
	}
}
function alquiler_filtro_categoria(id){
	document.busqueda.busqueda_categoria_id.value = id;
	document.busqueda.submit();
}
function ir_a_pagina(pagina){
	document.busqueda.busqueda_pagina.value = pagina;
	document.busqueda.submit();
}
function consultar_disponibilidad(){
	if(document.busqueda.busqueda_checkin.value.indexOf('/') != -1 && document.busqueda.busqueda_checkout.value.indexOf('/') != -1){
		document.busqueda.submit();
	}else{
		alert('Debe especificar las fechas de ingreso y salida.');
		return(false);
	}
}
function booking_disponibilidad(prop_id, idioma, mes, anio,meses_a_mostrar){
	$.get('ver_disponibilidad.php?prop_id=' + prop_id + '&idioma=' + idioma + '&mes=' + mes + '&anio=' + anio + '&meses_cant='+meses_a_mostrar, function(data) {
		document.getElementById('disponibilidad').innerHTML =data;
		});
}
function enviar_contacto(){
	var error_str="";
	if (document.form_contacto.contacto_nombre.value.length == 0) {
	       error_str+="Debe ingresar su nombre \n";
	} // del If
	if (document.form_contacto.contacto_email.value.length == 0) {
	       error_str+="Debe ingresar su mail \n";
	} // del If
	if (document.form_contacto.contacto_telefono.value.length == 0) {
	       error_str+="Debe ingresar su telefono \n";
	} // del If
	if (parseInt(document.form_contacto.contacto_sobre.selectedIndex) == 0) {
	       error_str+="Debe seleccionar el motivo de su contacto \n";
	} // del If
	if (error_str == '') {
		return(true);
	}else{
		alert(error_str);
		return(false);
	}//del if
}
function enviar_contacto_venta(){
	var error_str="";
	if (document.form_contacto.contacto_nombre.value.length == 0) {
	       error_str+="Debe ingresar su nombre \n";
	} // del If
	if (document.form_contacto.contacto_email.value.length == 0) {
	       error_str+="Debe ingresar su mail \n";
	} // del If
	if (document.form_contacto.contacto_telefono.value.length == 0) {
	       error_str+="Debe ingresar su telefono \n";
	} // del If
	if (parseInt(document.form_contacto.contacto_nacionalidad.selectedIndex) == 0) {
	       error_str+="Debe seleccionar su nacionalidad \n";
	} // del If
	if (error_str == '') {
		return(true);
	}else{
		alert(error_str);
		return(false);
	}//del if
}
function enviar_visita(){
	var error_str="";
	if (document.form_contacto.contacto_nombre.value.length == 0) {
	       error_str+="Debe ingresar su nombre \n";
	} // del If
	if (document.form_contacto.contacto_email.value.length == 0) {
	       error_str+="Debe ingresar su mail \n";
	} // del If
	if (document.form_contacto.contacto_telefono.value.length == 0) {
	       error_str+="Debe ingresar su telefono \n";
	} // del If
	if (document.form_contacto.contacto_dia.selectedIndex == 0) {
	       error_str+="Debe seleccionar el dia para la visita \n";
	} // del If
	if (document.form_contacto.contacto_mes.selectedIndex == 0) {
	       error_str+="Debe seleccionar el mes para la visita \n";
	} // del If
	if (document.form_contacto.contacto_anio.selectedIndex == 0) {
	       error_str+="Debe seleccionar el año para la visita \n";
	} // del If
	if (parseInt(document.form_contacto.contacto_nacionalidad.selectedIndex) <= 0) {
	       error_str+="Debe seleccionar su nacionalidad \n";
	} // del If

	if (error_str == '') {
		return(true);
	}else{
		alert(error_str);
		return(false);
	}//del if
}
function enviar_reserva_tour(){
	var error_str="";
	if (document.reserva_tour.nombre.value.length == 0) {
	       error_str+="Debe ingresar su nombre \n";
	} // del If
	if (document.reserva_tour.email.value.length == 0) {
	       error_str+="Debe ingresar su mail \n";
	} // del If
	if (document.reserva_tour.email.value != document.reserva_tour.email2.value) {
	       error_str+="Debe confirmar su mail \n";
	} // del If
	if (document.reserva_tour.telefono.value.length == 0) {
	       error_str+="Debe ingresar su telefono \n";
	} // del If
	if (parseInt(document.reserva_tour.nacionalidad.selectedIndex) == 0) {
	       error_str+="Debe seleccionar su nacionalidad \n";
	} // del If
	if (document.reserva_tour.date.value.length == 0) {
	       error_str+="Debe ingresar una fecha estimada \n";
	} // del If
	if (error_str == '') {
		return(true);
	}else{
		alert(error_str);
		return(false);
	}//del if
}
function enviar_reserva_deportes(){
	var error_str="";
	if (document.form_reserva.reserva_nombre.value.length == 0) {
	       error_str+="Debe ingresar su nombre \n";
	} // del If

	if (document.form_reserva.reserva_email.value.length == 0) {
	       error_str+="Debe ingresar su mail \n";
	} // del If

	if (document.form_reserva.reserva_email.value != document.form_reserva.reserva_emailc.value) {
	       error_str+="Debe confirmar su email \n";
	} // del If
	if (parseInt(document.form_reserva.reserva_nacionalidad.selectedIndex) == 0) {
	       error_str+="Debe seleccionar su pais \n";
	} // del If
	if (document.form_reserva.reserva_telefono.value.length == 0) {
	       error_str+="Debe ingresar su numero de telefono \n";
	} // del If
	if (document.form_reserva.reserva_partido.value.length == 0) {
	       error_str+="Debe ingresar el codigo del partido \n";
	} // del If
	if (document.form_reserva.reserva_personas.value.length == 0) {
	       error_str+="Debe ingresar la cantidad de personas \n";
	} // del If

	if (error_str == '') {
		return(true);
	}else{
		alert(error_str);
		return(false);
	}//del if
}
function enviar_reserva_celular(){
	var error_str="";
	if (document.form_reserva.reserva_nombre.value.length == 0) {
	       error_str+="Debe ingresar su nombre \n";
	} // del If
	if (document.form_reserva.reserva_email.value.length == 0) {
	       error_str+="Debe ingresar su mail \n";
	} // del If
	if (document.form_reserva.reserva_email.value != document.form_reserva.reserva_emailc.value) {
	       error_str+="Debe confirmar su email \n";
	} // del If
	if (document.form_reserva.reserva_telefono.value.length == 0) {
	       error_str+="Debe ingresar su numero de telefono \n";
	} // del If
	if (parseInt(document.form_reserva.reserva_nacionalidad.selectedIndex) == 0) {
	       error_str+="Debe seleccionar su nacionalidad \n";
	} // del If
	if (parseInt(document.form_reserva.reserva_residencia.selectedIndex) == 0) {
	       error_str+="Debe seleccionar su pais de residencia \n";
	} // del If
/*	if (document.form_reserva.reserva_pasaporte.value.length == 0) {
	       error_str+="Debe ingresar su numero de pasaporte \n";
	} // del If
*/
	if (document.form_reserva.reserva_fecha_desde.value.length == 0) {
	       error_str+="Debe ingresar la fecha de inicio \n";
	} // del If
	if (document.form_reserva.reserva_fecha_hasta.value.length == 0) {
	       error_str+="Debe ingresar la fecha de finalizacion \n";
	} // del If

	if (error_str == '') {
		return(true);
	}else{
		alert(error_str);
		return(false);
	}//del if
}
function enviar_reserva_transporte(){
	var error_str="";
	if (document.form_reserva.reserva_nombre.value.length == 0) {
	       error_str+="Debe ingresar su nombre \n";
	} // del If
	if (document.form_reserva.reserva_email.value.length == 0) {
	       error_str+="Debe ingresar su mail \n";
	} // del If
	if (document.form_reserva.reserva_email.value != document.form_reserva.reserva_emailc.value) {
	       error_str+="Debe confirmar su email \n";
	} // del If
	if (document.form_reserva.reserva_personas.value.length == 0) {
	       error_str+="Debe ingresar la cantidad de personas \n";
	} // del If
	if (document.form_reserva.reserva_fecha.value.length == 0) {
	       error_str+="Debe ingresar la fecha \n";
	} // del If

	if (error_str == '') {
		return(true);
	}else{
		alert(error_str);
		return(false);
	}//del if
}
function enviar_tasacion(){
	var error_str="";
	if (document.form_tasacion.name.value.length == 0) {
	       error_str+="Debe ingresar su nombre \n";
	} // del If
	if (document.form_tasacion.email.value.length == 0) {
	       error_str+="Debe ingresar su mail \n";
	} // del If
	if (document.form_tasacion.tel.value.length == 0) {
	       error_str+="Debe ingresar su telefono \n";
	} // del If
	if (parseInt(document.form_tasacion.tipo.selectedIndex) == 0) {
	       error_str+="Debe seleccionar el tipo de propiedad \n";
	} // del If
	if (document.form_tasacion.location.value.length == 0) {
	       error_str+="Debe ingresar la ubicacion de su propiedad \n";
	} // del If
	if (document.form_tasacion.desc.value.length == 0) {
	       error_str+="Debe ingresar una breve descripcion de su propiedad \n";
	} // del If

	if (error_str == '') {
		return(true);
	}else{
		alert(error_str);
		return(false);
	}//del if
}
function buscar_para_eventos(barrio_id,desde,hasta,capacidad,barrio_2){
	document.filtros_eventos.busqueda_barrio_id.value=barrio_id;
	document.filtros_eventos.busqueda_barrio_id_2.value=barrio_2;
	document.filtros_eventos.busqueda_checkin.value=desde;
	document.filtros_eventos.busqueda_checkout.value=hasta;
	document.filtros_eventos.busqueda_capacidad_avanzada.value=capacidad;
	document.filtros_eventos.submit();
}

function fechas_comparar (fecha_desde, fecha_hasta){

	fecha1 = fecha_desde.split("/");
	fecha2 = fecha_hasta.split("/");


	//devuelve true si la fecha1 es mayor que la fecha 2
	if (fecha1[2] > fecha2[2]){
		return (true);
	} else if (fecha1[2] < fecha2[2]){
		return (false);
	}else{ // mismo año

		// Controlo mes
		if (fecha1[1] > fecha2[1]){
			return(true);
		}else if (fecha1[1] < fecha2[1]){
			return(false);
		}else{
			// mismo mes

			if (fecha1[0] > fecha2[0]){
				return(true);
			}else if (fecha1[0] <= fecha2[0]){
				return(false);
			}
		}


	}


}
function AlternarRevision(idioma){
	var revision = document.getElementById('detalle_revision_expandido');
	var link = document.getElementById('link_mostrar_reviews');
	var general = document.getElementById('revision_resumen');


    if (revision.style.display=='none'){
    	revision.style.display='inline'
    	if(idioma == 'ES'){
    		link.innerHTML = '[Ocultar todas las opiniones]'
    	}else{
    		link.innerHTML = '[Hide all reviews]'
    	}

    	general.style.backgroundColor='#D8D8D8';
	}else{
		revision.style.display='none'
    	if(idioma == 'ES'){
    		link.innerHTML = '[Ver todas las opiniones]'
    	}else{
    		link.innerHTML = '[Show all reviews]'
    	}

		general.style.backgroundColor='#FFFFFF';
	}
}