
function CargarOJTipos(){

	var abc = $("#valor_materia>#cbMaterias").val();//$("#cuadro_mando>input#abc").val();
	var valor = 0;
	
	if(abc == "0"){
		//$("#b_materias>#b_materias_contenido .lnkMaterias").each(function(){
		//	valor = bigint_plus(valor, this.rel);
		$("#valor_materia>#cbMaterias>option").each(function(){
			valor = bigint_plus(valor, this.value);
		});
		abc = valor;
	}

	$.ajax({
		async:		true,
		type:		"GET",		
		url:		"/buscador/ajax_organos.asp?tipo=tipo&abc=" + abc,
		beforeSend: function(){
			$("#organos_tipos").html("<img src='/comunes/imagenes/spinner.gif'/>&nbsp;Cargando...");
		},
		success:	function(html){
			$("#organos_tipos").html(html);
			$("#organos_tipos>select").change(function(){
				if(this.value != ""){
					CargarOJSedes(this.value);					
					$("#cont_criterio_tribunal>#organos>#organo_valor").val(this.value);
					$("#cont_criterio_tribunal>#organos>#organo_etiqueta").val($("#organo_tipo option:selected").text());
				}
			});
			$("#organos_sedes").empty();
			$("#organos_salas").empty();
		},
		error:		function(){
			$("#organos_tipos").empty();
			alert("Error cargando órganos jurisdiccionales.");
		}
	});
}

function CargarOJSedes(Tipo){

	var abc = $("#cuadro_mando>input#abc").val();

	$.ajax({
		async:		true,
		type:		"GET",		
		url:		"/buscador/ajax_organos.asp?tipo=sede&funcion=" + Tipo + "&abc=" + abc,
		beforeSend: function(){
			$("#organos_sedes").html("<img src='/comunes/imagenes/spinner.gif'/>&nbsp;Cargando...");
		},
		success:	function(html){
			$("#organos_sedes").html(html);
			$("#organos_sedes>select").change(function(){
				if(this.value != ""){
					CargarOJSalas(this.value);
					$("#cont_criterio_tribunal>#organos>#organo_valor").val(this.value);
					$("#cont_criterio_tribunal>#organos>#organo_etiqueta").val($("#organo_tipo option:selected").text() + " " + $("#organo_sede option:selected").text());
				}
			});
			$("#organos_salas").empty();
		},
		error:		function(){
			$("#organos_sedes").empty();
			alert("Error cargando órganos jurisdiccionales.");
		}
	});
}

function CargarOJSalas(Sede){

	var abc = $("#cuadro_mando>input#abc").val();

	$.ajax({
		async:		true,
		type:		"GET",		
		url:		"/buscador/ajax_organos.asp?tipo=sala&funcion=" + Sede + "&abc=" + abc,
		beforeSend: function(){
			$("#organos_salas").html("<img src='/comunes/imagenes/spinner.gif'/>&nbsp;Cargando...");
		},
		success:	function(html){
			$("#organos_salas").html(html);
			$("#organos_salas>select").change(function(){
				if(this.value != ""){
					$("#cont_criterio_tribunal>#organos>#organo_valor").val(this.value);
					$("#cont_criterio_tribunal>#organos>#organo_etiqueta").val($("#organo_tipo option:selected").text() + " " + $("#organo_sede option:selected").text() + " " + $("#organo_sala option:selected").text());
				}
			});
		},
		error:		function(){
			$("#organos_salas").empty();
			alert("Error cargando órganos jurisdiccionales.");
		}
	});
}

