var colorBoton = "#4A3402";

$(function(){
	$("#MOSTRARprecios").hide();
	$(".botonContinuar").click(function(){
		buscarPreciosIrFormulario();
	}).css("cursor","pointer");
	$("#TBfechasSeleccionadas").click(function(){
		$("#MOSTRARprecios").hide();
		mostrarFechas(iraHotel);
	}).css("cursor","pointer");
	
	if (fechaSalida != '') {
		buscarPrecios();
		$("#MOSTRARprecios").show();
		$("#TBbotonesElijaFecha").hide();
		$("#TBfechasSeleccionadas").show();
		completarPrecios();
	}	
	
	
});


function mostrarFechas(hotel) {
	iraHotel=hotel;
	$("#TBbotonesElijaFecha").hide();
	$("#TBfechasSeleccionadas").show();
	$("#DIVcalendario").datepicker(calendario);
	$("#DIVdias").slider({
		range: "max",
		min: 1,
		max: 20,
		value: diasEstadia,
		slide: function(event, ui) {
			$("#SLBLdias").html(ui.value );
			diasEstadia = ui.value;
			mostrarSalida();
		},
		stop: function(){
			$("#DIVfechaHora .ui-widget-content").removeClass("ui-bordeON");
			$(".DIVsliders2").addClass("ui-bordeON");
			$(".DIVsliders .ui-slider-handle").css("background",colorBoton);
			$(".DIVsliders2 .ui-slider-handle").css("background","red url(img/formulario/manitoBlink.gif) no-repeat");

		},
		start: function(){
			$("#DIVfechaHora .ui-widget-content").removeClass("ui-bordeON");
			$(".DIVsliders").addClass("ui-bordeON");
			$(".DIVsliders2 .ui-slider-handle").css("background",colorBoton);
			$(".DIVsliders .ui-slider-handle").css("background","red url(img/formulario/manitoBlink.gif) no-repeat");

		}

	});
	mostrarLlegada();
	mostrarSalida();
	$("#DIVfechaHora").show();
}

function selectLlegada(dateText, inst){
	//$("#DIVfLlegada").hide();
	fechaLlegada = dateText;
	mostrarLlegada();
	mostrarSalida();
	$("#DIVfechaHora .ui-widget-content").removeClass("ui-bordeON");
	$(".DIVsliders").addClass("ui-bordeON");
	$(".DIVsliders .ui-slider-handle").css("background","red url(img/formulario/manitoBlink.gif) no-repeat");
	$(".DIVsliders2 .ui-slider-handle").css("background",colorBoton);
}
function mostrarSalida(){
	fechaSalida = sumarDias(fechaLlegada, diasEstadia);
	$("#SLBLdias").html('<span class="fontSeleccion3 ">'+diasEstadia+"</span>");
	$("#SLBLdeparture").html(queFecha(fechaSalida));
	completarPrecios() ;
}

function completarPrecios() {
//	$("#DIVdatosFechas").css("background","url(img/home/contenedor-datos.gif) no-repeat");
	$("#DIVdatosFechas").html("<b>"+LBLfechaLlegada+":</b> "+fechaLlegada+"&nbsp;&nbsp;-&nbsp;&nbsp;<b>"+LBLfechaSalida+":</b> "+queFecha(fechaSalida)+"&nbsp;&nbsp;-&nbsp;&nbsp;<b>"+LBLdiasEstadia+":</b> "+diasEstadia+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
}


function mostrarLlegada(){
	$("#LBLfechaLlegada").html('<span class="fontSeleccion2">'+queDia(fechaLlegada)+"/"+queMes(fechaLlegada)+"/"+queAnio(fechaLlegada)+"</span>");
}

function buscarPreciosIrFormulario(){
	fechaSalida = sumarDias(fechaLlegada, diasEstadia);
	var args = JSON.encode([fechaLlegada,queFecha(fechaSalida)]);
	$.getJSON("preciosCalendario.php",{accion: "buscarPrecios", method: "GET", args: args},
		function (data){
			if (data.OK) {
				if (iraHotel=='B') {
					document.location.href = opcionMenu[ 5 ]  + 'barcelona';
				}else {
					document.location.href = opcionMenu[ 5 ]  + 'palacete';
				}
			}
		}
	);
}

function buscarPrecios(){
	fechaSalida = sumarDias(fechaLlegada, diasEstadia);
	var args = JSON.encode([fechaLlegada,queFecha(fechaSalida)]);
	$.getJSON("preciosCalendario.php",{accion: "buscarPrecios", method: "GET", args: args},
		function (data){
			if (data.OK) {
				for(var x in data.preciosBarcelona) {
					$("#PH"+x+"B").html("&euro; " + data.preciosBarcelona[x]);	
					$("#PH"+x+"P").html("&euro; " + data.preciosPalacete[x]);
					$("#DIVfechaHora").hide();
					$("#MOSTRARprecios").show();
				}	
			}
		}
	);
}
