jQuery(function($) {
    actualizaDesdeHistorial();	
    $(window).history(function(e, hash) {
    	actualizaDesdeHistorial(hash);
    });
	$(".ocultar").hide();
	$("#mostrar_ocultar").click(function() {
		$("#frmOcupacion .ocultar").show();
		$("#mostrar_ocultar").hide();
	});
	$("#cambiarVisibilidad").click(function() {
		$("#generalCondition").slideToggle();
	});
	$("#establecimiento input[type=radio]").change(function(e) {
		if ($(this).attr("checked")) {
			$("tr", $(this).parents("table")).css({'background-color': '#AABCEE'});
			$(this).parent().parent().css({'background-color': '#E3E6EE'});
		} 
	});
	$("#barco input[type=radio]").change(function(e) {
		if ($(this).attr("checked")) {
			$("tr", $(this).parents("table")).css({'background-color': '#AABCEE'});
			$(this).parent().parent().css({'background-color': '#E3E6EE'});
		} 
	});
	$("a").click(function() {
		if (this.href) {
			if (this.href.indexOf(location.hostname) == -1 || $(this).attr("rel")=="external") {
				abreVentana(this.href);
				return false;
			}
		}
	});
	$("input[type='checkbox'][name='seguro']").change(function() {
		var nvalor = parseFloat($("#sinSeguroAsistencia").attr("value"));
		var href = $("#presupuesto").attr("href");
		if ($(this).attr("checked")==true) {
			nvalor += parseFloat($("#seguroAsistencia").attr("value"));
			href = href.replace("seguro=0", "seguro=1");
		} else {
			href = href.replace("seguro=1", "seguro=0");
		}
		$("#presupuesto").attr("href", href);
		nvalor = nvalor.toFixed(2);
		nvalor = nvalor.replace(".", ",");
		$("#pTotal").html(nvalor+"€");
	});
	$("#enlOferta").click(function(e){
		$("#ulOfertas").slideToggle();
	});
})

function abreVentana(direccion) {
	if (!(window.open(direccion))) {
		alert("No se ha podido abrir la nueva ventana. Por favor, habilite la apertura de ventanas emergentes en su navegador e inténtelo nuevamente.");
	}
	return false;
}

function actualizaDesdeHistorial(hash) {
	if (hash) {
		var param = hash.split(",");
		for (var i=0; i<param.length; i++) {
			var d = param[i].split("=");
			switch (d[0]) {
				case "tr":
					cambiaTipo(d[1], false);
					break;
			}
		}
	} else if (window.location.hash) {
		actualizaDesdeHistorial(window.location.hash.substring(1));
	}
}


