
		var startDate;
		var endDate;

		function resetDates() {
			startDate = endDate = null;
		}

		function filterDates1(cal) {
			startDate = new Date(cal.date)
			startDate.setHours(0,0,0,0)	// used for compares without TIME
			/* If they haven't chosen an 
			end date before we'll set it to the same date as the start date This
			way if the user scrolls in the start date 5 months forward, they don't
			need to do it again for the end date.
			*/

			if (endDate == null) { 
				Zapatec.Calendar.setup({
					showOthers        : true,
					inputField     :    "f_salida",
					button         :    "f_salida",  // What will trigger the popup of the calendar
					ifFormat       :    "%d/%m/%Y",
					showsTime      :     false,          //no time
					dateStatusFunc		:    disallowDateBefore, //the function to call
					onUpdate       :    filterDates2,
					firstDay          : 1,
       				weekNumbers       : false,
					numberMonths   :     2
				});
			}
		}

		function filterDates2(cal) {
			var date = cal.date;
			endDate = new Date(cal.date)
			endDate.setHours(0,0,0,0)	// used for compares without TIME
		}

		/*
		* This functions return true to disallow a date
		* and false to allow it.
		*/


		/* 
		* Check-Out calendar allowed dates
		* Check-Out date can not be BEFORE Check-In date
		* Check-Out date can not be before today
		*/
		function disallowDateBefore(dateCheckOut) {
			dateCheckOut.setHours(0,0,0,0)
			if ((startDate != null) && startDate > dateCheckOut)
				// startDate is defined, make sure cal date is NOT before start date
				return true; 
			
			var now = new Date()
			now.setHours(0,0,0,0)
			if (dateCheckOut < now) 
				// check out date can not be befor today if startDate NOT defined
				return true;

			return false;
		}

		/* 
		* Check-In date checking
		* Check-In date can not be AFTER Check-Out date
		* Check-In date can not be before today
		*/
		function disallowDateAfter(dateCheckIn) {
			dateCheckIn.setHours(0,0,0,0)
			if ((endDate != null) && dateCheckIn > endDate)
				// endDate defined, calendar date can NOT be after endDate
				return true;

			var now = new Date()
			now.setHours(0,0,0,0)

			if (dateCheckIn < now)
				// endDate NOT defined, calendar date can not be before today
				return true;

			return false;
		}

		// end hiding contents from old browsers  -->
	
		var cal = new Zapatec.Calendar.setup({
		showOthers        : true,
         inputField     :    "f_entrada",   // id of the input field
         button         :    "b_entrada",  // What will trigger the popup of the calendar
         ifFormat       :    "%d/%m/%Y",       // format of the input field: Mar 18, 2005
         showsTime      :     false,          //no time
         dateStatusFunc    :    disallowDateAfter, //the function to call
         onUpdate       :    filterDates1,
         numberMonths   :     2,
         firstDay          : 1,
         weekNumbers       : false

		});
		
      Zapatec.Calendar.setup({
      	showOthers        : true,
         inputField     :    "f_salida",
         button         :    "b_salida",  // What will trigger the popup of the calendar
         ifFormat       :    "%d/%m/%Y",       // format of the input field: Mar 18, 2005
         showsTime      :     false,          //no time
         dateStatusFunc    :    disallowDateBefore, //the function to call
         numberMonths   :     2,
         firstDay          : 1,
         weekNumbers       : false
         //onUpdate       :    filterDates2
      });
      
	  
	var aFinMes = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

	function finMes(nMes, nAno){
	return aFinMes[nMes - 1] + (((nMes == 2) && (nAno % 4) == 0)? 1: 0);
	}
	  
      function inicia_fechas() {
      	
      	var numero_noches = document.form_destino.noches.value;
      	var f_entrada = document.form_destino.f_entrada.value;
      	var f_salida = document.form_destino.f_salida.value;
      		
      	if (f_entrada=="" && f_salida=="") {
      		var hoy = new Date;
      		var manana = new Date;
      		
			var meshoy = (hoy.getMonth()+1);
			if (meshoy < 10){ meshoy = '0'+(hoy.getMonth()+1)};
			
			var mesmanana = (manana.getMonth()+1);
						
			nDia = (manana.getDate() + 1);//dia de hoy mas uno.
			nAno = manana.getFullYear();
			if (nDia > finMes(mesmanana, nAno)){
				nDia = 1;
				mesmanana += 1;
				}
			if (mesmanana == 13){
				mesmanana = 1;
				nAno += 1;
				}
			if (mesmanana < 10){ mesmanana = '0'+mesmanana};
			if (nDia <10){nDia = '0'+nDia};
			diahoy = hoy.getDate();
			if (diahoy < 10){diahoy = '0'+diahoy};
			
      		document.form_destino.f_entrada.value = diahoy + "/"+meshoy+"/" + hoy.getFullYear();
      		document.form_destino.f_salida.value =  nDia + "/"+mesmanana+"/" + nAno;
      	}
      	
      	
      	
      }
      
     function num_noches() {
     	
     	
      
     	//si modificamos el número de noches, cogemos la fecha de entrada y le sumamos el número de noches
      	
      //si no hay ninguna noche o es 0, le damos el valor de 1
      		if (document.form_destino.noches.value!="") {
      			
      	var f_entrada = document.form_destino.f_entrada.value;
      	var f_salida = document.form_destino.f_salida.value;
      	
      	
      	//Date.parse("dd/MM/yyyy");
      	datos = f_entrada.split("/");
      	dia = datos[0];
      	mes = datos[1] - 1;
      	ano = datos[2];
      	
      
      	
      	
      	var fecha = {day: parseFloat(dia), month: parseFloat(mes), year: parseFloat(ano)};

a = document.form_destino.noches.value;
a = parseFloat(a);

document.form_destino.f_salida.value = Date.today().set(fecha).add(a).days().toString("dd/MM/yyyy");// Set date and time with a config object.

//Date.today().add(a).days().toString("dd/MM/yyyy");

}
else {
	
	//document.form_destino.noches.value = 1;
}

     }
      
      function cambia_f_entrada(f_entrada) {
      		
      	
      	
      	
      	
      	datos = f_entrada.split("/");
      	dia = datos[0];
      	mes = datos[1] - 1;
      	ano = datos[2];
      	
      
      
      	
      	//establecemos la fecha de f_entrada
      	var fecha = {day: parseFloat(dia), month: parseFloat(mes), year: parseFloat(ano)};

a = document.form_destino.noches.value;
a = parseFloat(a);

document.form_destino.f_salida.value = Date.today().set(fecha).add(a).days().toString("dd/MM/yyyy");// Set date and time with a config object.

      	
      }
      
      function cambia_f_salida(f_entrada,f_salida) {
      	
      	//aqui obtenemos el número de noches
      	
      	datos = f_entrada.split("/");
      	dia_e = datos[0];
      	mes_e = datos[1] - 1;
      	ano_e = datos[2];
      
      var fecha1 = new Date(ano_e,mes_e,dia_e);
      fecha1.getTime();
      
      
      	datos1 = f_salida.split("/");
      	dia_s = datos1[0];
      	mes_s = datos1[1] - 1;
      	ano_s = datos1[2];
      
      var fecha2 = new Date(ano_s,mes_s,dia_s);
      fecha2.getTime();
      
      dias_d = restarFechas(fecha1,fecha2);
      
      //alert(dias_d);
      
      if (dias_d>30) {
      	alert('El número máximo de noches es 30');
      	//ponemos la fecha de entrada más 30
      	var fecha = {day: parseFloat(dia_e), month: parseFloat(mes_e), year: parseFloat(ano_e)};
		document.form_destino.f_salida.value = Date.today().set(fecha).add(30).days().toString("dd/MM/yyyy");// Set date and time with a config object.
	document.form_destino.noches.value = 30;
      }
    
   else if (dias_d==0) {
   	alert('El número mínimo de noches es 1');
   	document.form_destino.noches.value = 1;
   	var fecha = {day: parseFloat(dia_e), month: parseFloat(mes_e), year: parseFloat(ano_e)};
		document.form_destino.f_salida.value = Date.today().set(fecha).add(1).days().toString("dd/MM/yyyy");
   }
   else {
   	document.form_destino.noches.value = dias_d;
   	
   	
   }
      
      	
      }
      
      
      
function restarFechas(fechaInicio,fechaFin)
{
	var diferencia = fechaFin.getTime() - fechaInicio.getTime();
	var dias = Math.round(diferencia / (1000 * 60 * 60 * 24))
	return dias;
}

function estilo_bhotel() {
	
	document.getElementById('pestana2').className="pestana_activa_bh";
	document.getElementById('pestana1').className="pes_normal";
	document.getElementById('tabcontent1').className="panel_2";
	
	var newForm = 'Hotel: <input type="text" id="hotel" onkeyup="ajax_showOptions(this,\'esp\',event)" autocomplete="off" name="hotel" class="text_busc sz_418" style="margin-left: 16px;" />';
	document.getElementById('campo_destino').innerHTML = newForm;
}

function estilo_bdestino() {
	
	document.getElementById('pestana2').className="pes_normal";
	document.getElementById('pestana1').className="pestana_activa_bd";
	document.getElementById('tabcontent1').className="panel_1";
	
		var newForm = 'Destino: <input type="text" id="destino" onkeyup="ajax_showOptions(this,\'esp\',event)" autocomplete="off" name="destino" class="text_busc sz_418" />';
	document.getElementById('campo_destino').innerHTML = newForm;
	
	
}

var x;
x=$(document);
x.ready(inicializarEventosTipo);

function inicializarEventosTipo(){
	var x;
	x=$("#destino");
	x.click(vaciar_destino);
	
	x=$("#boton_buscar");
	x.click(comprobar_form);
	
	
	x=$("#n_ninos");
	x.change(numero_ninos);
	//x.click(numero_ninos);
	
	}

function numero_ninos() {
	//alert('estoy con click');
	var n_habitaciones = document.form_destino.n_habitaciones.value;
	var n_ninos = document.form_destino.n_ninos.value;
	var der_o_izq = document.form_destino.der_o_izq.value;
	//alert (n_ninos);
	var total_ninos = n_habitaciones * n_ninos;
	
	if (total_ninos>=1) {
		if (der_o_izq == 'der'){
			var newForm = "<p>Edad Niños</p>";
		}else{
			var newForm = "<div style='float:left; width:300px;'><center><p class='p4'>Edad Niños</p></center></div>";
		}
		var punt = 0; //puntero para nombrar con numero cada uno de los niños 
		for (z=0;z<n_habitaciones;z++){
			if (der_o_izq == 'der'){
				newForm += "<div style='float:left; width:90px;'>";
			}else{
				newForm += "<div style='float:left; width:400px;'>";
			}
			
			if (der_o_izq == 'der'){
				newForm += "<p>Habitación "+(z+1)+"</p>";
			}else{
				newForm += "<p class='p4' style='padding-top:15px;'>Habitación "+(z+1)+"</p>";
			}
			
			for (i=0;i<n_ninos;i++) {
				punt = punt + 1;
				if (der_o_izq == 'der'){
					newForm += "<p>Niño "+ (i + 1) +"<select id='edad_nino"+(punt)+"' name='nino_"+(punt)+"' class='text_select sz_45 centro'><option selected value='-'>-</option><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option><option value='11'>11</option><option value='12'>12</option></select></p>";
				}else{
					newForm += "<p class='p1'>Niño "+ (i + 1) +"<select id='edad_nino"+(punt)+"' name='nino_"+(punt)+"' class='text_select sz_45 centro'><option selected value='-'>-</option><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option><option value='11'>11</option><option value='12'>12</option></select></p>";
				}
			}
			newForm += "</div>";
		}
		document.getElementById('div_4_busc').innerHTML = newForm;
	}else{
		document.getElementById("error_edad").style.display = "none";
		document.getElementById('div_4_busc').innerHTML = "";
	}
	
	return true;
}


function str_replace(cadena, cambia_esto, por_esto){
return cadena.split(cambia_esto).join(por_esto);
}

function comprobar_form(){
	var res = false;
	
	//alert('funciona el javascript de aux_calendar');
	//alert(document.form_destino.contador_busc.value);
	
	if (document.form_destino.destino.value == ''){
		alert('Debes indicar un destino para realizar la búsqueda.');
		document.getElementById("error_cond").style.display = "block";
		res = false;
	}else{
	//document.getElementById("error_cond").style.display = "none";
	
		if(document.getElementById("n_ninos").value != 0){
			var num_ninos = document.getElementById("n_ninos").value;
			
			for (i=0;i<num_ninos;i++){
				if (document.getElementById("edad_nino"+(i+1)+"").value == '-'){
					document.getElementById("error_edad").style.display = "block";
					res = false;
				}else{
					document.getElementById("error_edad").style.display = "none";
					res = true;
				}
			}
		}else{
			document.getElementById("error_edad").style.display = "none";
			res = true;
		}
	}
	
//buscador=&destino=Granada+Ciudad+%28Espa%F1a%29&id_localidad=ES_851_18_363&provincia=&busca_disp=&pagina=nuevaBusc&noches=2&f_entrada=20%2F11%2F2009&f_salida=22%2F11%2F2009&n_habitaciones=1&n_adultos=2&n_ninos=1&buscar_hotel.x=40&buscar_hotel.y=11&nino_1=2	

	es_provincia = /Provincia/
	if (es_provincia.test(document.form_destino.destino.value)){
	document.getElementById('provincia').value = 'provincia'; 
	}
	
	return res;	
	
}

function vaciar_destino(){
	document.form_destino.destino.value = '';
return true;
}

function setPage(SAction)
	{
		document.form_destino.pagina.value = SAction;
		document.form_destino.submit();
		//alert('setpage2 ha sido llamado por la pagina');
	}

	


