$(document).ready(function() {
	$("li.punven").live("click", function() {
		var idt = $(this).attr("idt");
		var idz = $(this).attr("idz");
		var t = $("li.punven_tituloseccion[idt='"+idt+"']").html();
		var z = $("li.punven[idt='"+idt+"'][idz='"+idz+"']").html();
		$("#punven_tipozona").attr("t", t);
		$("#punven_tipozona").attr("z", z);
		punven_cargarZonas(idt, idz);

		punven_seleccionarTipoZona(idt, idz, t, z);
	});
	
	$("li.libr_itpro").live("click", function() {
		var idt = $("#punven_tipozona").attr("idt");
		var idz = $("#punven_tipozona").attr("idz");
		var idp = $(this).attr("idp");
		var pro = $(this).html();
		punven_cargarRegiones(idt, idz, idp, pro);

		punven_seleccionarRegion(idp, pro);
	});
	
	$("li.libr_itpob").live("click", function() {
		var idt = $("#punven_tipozona").attr("idt");
		var idz = $("#punven_tipozona").attr("idz");
		var idp = $("#punven_region").attr("idp");
		var pro = $("#punven_region").attr("pro");
		var pob = $(this).html();
		punven_cargarPoblaciones(idt, idz, idp, pro, pob);
		
		punven_seleccionarPoblacion(pob);
	});

	$("a[rel='especificacionespapel']").live("click", function(e) {
		e.preventDefault();
		var a = ".punven_especificacionespapel[rel='"+$("#punven_revista").attr("revista")+"']";
		var titulo = $(a + " h1").html() + " - " + $(a + " h2").html();
		$("#punven_docs div").fadeOut();
		$(a).fadeIn();
		$("#punven_apartado").html(" > <span>" + titulo + "</span>");
		$("#punven_revista span").addClass("href");
	});

	$("a[rel='tarifaspapel']").live("click", function(e) {
		e.preventDefault();
		var a = ".punven_tarifaspapel[rel='"+$("#punven_revista").attr("revista")+"']";
		var titulo = $(a + " h1").html() + " - " + $(a + " h2").html();
		$("#punven_docs div").fadeOut();
		$(a).fadeIn();
		$("#punven_apartado").html(" > <span>" + titulo + "</span>");
		$("#punven_revista span").addClass("href");
	});

	$("a[rel='especificacionesbanners']").live("click", function(e) {
		e.preventDefault();
		var a = "#especificacionesbanners";
		var titulo = $(a + " h1").html() + " - " + $(a + " h2").html();
		$("#punven_docs div").fadeOut();
		$(a).fadeIn();
		$("#punven_apartado").html(" > <span>" + titulo + "</span>");
		$("#punven_revista span").addClass("href");
	});

	$("a[rel='tarifasbanners']").live("click", function(e) {
		e.preventDefault();
		var a = "#tarifasbanners";
		var titulo = $(a + " h1").html() + " - " + $(a + " h2").html();
		$("#punven_docs div").fadeOut();
		$(a).fadeIn();
		$("#punven_apartado").html(" > <span>" + titulo + "</span>");
		$("#punven_revista span").addClass("href");
	});

	$("#punven_raiz").live("click", function() {
		$("#punven_puntos").fadeOut();
		$("#punven_tipos").fadeIn();
		$("#punven_poblacion span").removeClass("href");
		$("#punven_poblacion").html("");
		$("#punven_region span").removeClass("href");
		$("#punven_region").html("");
		$("#punven_pais span").removeClass("href");
		$("#punven_pais").html("");
		$("#punven_tipozona span").removeClass("href");
		$("#punven_tipozona").html("");
	});

	$("#punven_tipozona").live("click", function() {
		$("#punven_puntos").fadeOut();
		$("#punven_poblacion span").removeClass("href");
		$("#punven_poblacion").html("");
		$("#punven_region span").removeClass("href");
		$("#punven_region").html("");
		$("#punven_pais span").removeClass("href");
		$("#punven_pais").html("");
		$("#punven_tipozona span").removeClass("href");
		
		var idt = $("#punven_tipozona").attr("idt");
		var idz = $("#punven_tipozona").attr("idz");
		var t = $("#punven_tipozona").attr("t");
		var z = $("#punven_tipozona").attr("z");
		punven_cargarZonas(idt, idz);
	});

	$("#punven_region").live("click", function() {
		$("#punven_puntos").fadeOut();
		$("#punven_poblacion span").removeClass("href");
		$("#punven_poblacion").html("");
		$("#punven_pais span").removeClass("href");
		$("#punven_pais").html("");
		$("#punven_region span").removeClass("href");
		
		var idt = $("#punven_tipozona").attr("idt");
		var idz = $("#punven_tipozona").attr("idz");
		var idp = $("#punven_region").attr("idp");
		var pro = $("#punven_region").attr("pro");
		punven_cargarRegiones(idt, idz, idp, pro);
	});

	$("#punven_revista").live("click", function() {
		$("#punven_apartado").html("");
		$("#punven_revista span").removeClass("href");
		$("#punven_docs div").fadeOut();
		var r = $("#punven_revista").attr("revista");
		var t = $("#punven_revista span").html();
		punven_seleccionarRevista(r, t);
	});

});

function punven_seleccionarTipoZona(idt, idz, t, z) {
	$("#punven_tipozona").attr("idt", idt);
	$("#punven_tipozona").attr("idz", idz);
	$("#punven_tipozona").attr("t", t);
	$("#punven_tipozona").attr("z", z);
	$("#punven_tipozona").html(" > <span>" + t + " - " + z + "</span>");
	$("#punven_raiz").addClass("href");
}

function punven_seleccionarRegion(idp, pro) {
	$("#punven_region").attr("idp", idp);
	$("#punven_region").attr("pro", pro);
	$("#punven_region").html(" > <span>" + pro + "</span>");
	$("#punven_tipozona span").addClass("href");
}

function punven_seleccionarPoblacion(pob) {
	$("#punven_poblacion").attr("pob", pob);
	$("#punven_poblacion").html(" > <span>" + pob + "</span>");
	$("#punven_region span").addClass("href");
}

function punven_cargarZonas(idt, idz) {
	//alert(idt+"|"+ t + "|"+ idz + "|"+ z)
	$("#punven_tipos").fadeOut();
	$.post("/modulo.php?mop="+idt, "idz="+idz, function(h) {
		$("#punven_puntos").html(h);
		//alert(h);
		$("#punven_puntos").fadeIn();
	});
}

function punven_cargarRegiones(idt, idz, idp, pro) {
	//alert(idt+"|"+ idz + "|"+ idp + "|"+ pro)
	$("#punven_tipos").fadeOut();
	$.post("/modulo.php?mop="+idt, "idz="+idz+"&idp="+idp+"&pro="+pro, function(h) {
		$("#punven_puntos").html(h);
		//alert(h);
		$("#punven_puntos").fadeIn();
	});
}

function punven_cargarPoblaciones(idt, idz, idp, pro, pob) {
	//alert(idt+"|"+ idz + "|"+ idp + "|"+ pro + "|"+ pob)
	$("#punven_tipos").fadeOut();
	$.post("/modulo.php?mop="+idt, "idz="+idz+"&idp="+idp+"&pro="+pro+"&pob="+pob, function(h) {
		$("#punven_puntos").html(h);
		//alert(h);
		$("#punven_puntos").fadeIn();
	});
}

