
$(document).ready(function(){$('#id_fecha_entrada').datepicker({dateFormat:'dd/mm/yy',minDate:new Date,firstDay:1,numberOfMonths:2,onSelect:function(dateText,inst){dateText=dateText.split('/');var nueva_fecha=new Date(dateText[2],(dateText[1]-1),dateText[0]);var manana=sumar_noches(nueva_fecha,1);$('#id_fecha_salida').val(formatear_fecha(manana));$('#id_fecha_salida').datepicker('option','minDate',nueva_fecha);}});$('#id_fecha_salida').datepicker({dateFormat:'dd/mm/yy',firstDay:1,numberOfMonths:2,minDate:sumar_noches(new Date,1)});formulario_dispo.init();});function sumar_noches(fecha,noches){var cont=1;while((noches>=cont)&&(cont<365))
{fecha.setTime(fecha.getTime()+(86400000));if(fecha.getHours()==1)fecha.setTime(fecha.getTime()-3600000);else if(fecha.getHours()==23)fecha.setTime(fecha.getTime()+3600000);cont++;}
return fecha;}
function formatear_fecha(fecha){return zero_delante(fecha.getDate())+'/'+zero_delante((fecha.getMonth()+1))+'/'+fecha.getFullYear()}
function zero_delante(valor){var cadena=new String(valor);if(cadena.length==1){return'0'+cadena;}else{return cadena;}}
function busca_dispo_hotel(id_hotel,fecha_entrada,noches)
{$('#id_hotel').val(id_hotel);$('#id_fecha_entrada').val(fecha_entrada);fecha_entrada=fecha_entrada.split('/');var nueva_fecha=new Date(fecha_entrada[2],(fecha_entrada[1]-1),fecha_entrada[0]);nueva_fecha=sumar_noches(nueva_fecha,noches);$('#id_fecha_salida').val(formatear_fecha(nueva_fecha));$('#formulario_dispo_horizontal').submit();}
function obligar_seleccion_hotel(texto){if($('ul li #id_hotel').val()==''){alert(texto);return false;}else{return true;}}
var formulario_dispo=new function(){this.init=function(){}
this.selecciona_opcion=function(codigo_producto,texto_producto){$('#id_hotel').val(codigo_producto);$('#id_hotel_label').val(texto_producto);$("#id_hotel_opciones").fadeOut();}
this.mostrar_capa_opciones=function(){$("#id_hotel_opciones").fadeToggle(function(){if($(this).is(':visible')){$('body').one("click",function(){$("#id_hotel_opciones").fadeOut();});}});}
this.mostar_capa_buscando=function(){$('body').append('<div id="capa_buscando_dispo"><img src="/es/bookcore_engine/images/disponibilidad/cargando_grande.gif" class="cargando"/></div>');$("#capa_buscando_dispo").fadeToggle();return true;}
this.buscar_omitiendo_restricciones=function(){var action=$('#formulario_dispo_horizontal').attr('action')+'?omrest=';$('#formulario_dispo_horizontal').attr('action',action).submit();}}
