﻿	$(document).ready(function() {
		$("input").bind('click', function() {
			if($(this).attr("type")=="checkbox"){
		  	var id=$(this).attr("id");
		  	var inputs=0;
		  	if($(this).attr("checked")){
		  		$("#sublista_"+id+" input").attr({"checked":"checked"});
		  		var cont=1;
		  		inputs=id.split("_");
					if (inputs != 0){
		  			if (inputs.length > 1){
		  				$("#sublista_"+inputs[0]+"_"+inputs[1]+" input").each(function(){ if (! $(this).attr("checked")){ cont=0; }  });
		  				if (cont==1)
		  					$("#"+inputs[0]+"_"+inputs[1]).attr({"checked":"checked"});
		  			}
		  			$("#sublista_"+inputs[0]+" input").each(function(){ if (! $(this).attr("checked")){ cont=0; }  });
		  			if (cont==1)
		  					$("#"+inputs[0]).attr({"checked":"checked"});
		  		}
		  	}
		  	else{
		  		$("#sublista_"+id+" input").removeAttr("checked"); //desmarca los hijos
					inputs=id.split("_");
					if (inputs != 0){
						$("#"+inputs[0]).removeAttr("checked");
						$("#"+inputs[0]+"_"+inputs[1]).removeAttr("checked");
					}
		  	}
		  }
		});
		$("#fotos_container").css({'overflow':'hidden','float':'left','width':'415px','height':'76px'});
		$("#fotos").css({'border':'0px','margin-left':'0px'});
	});
		
	function select_all(lista){
		$("#"+lista+" input").attr({"checked":"checked"});
	}
	
	$(window).load(function () {
  	//$(".error").fadeOut(5000);
	});
	function keypress(e,siguiente){
		var keycode=e.keyCode;
		if (keycode==13){
			if (siguiente!="submit"){
				$('#'+siguiente).focus();
			}else{
				if (siguiente=="find"){
					$('#buscador').submit();
				}else{
					$('#login_form').submit();
				}
			}
		}
	}
	
	function buscarComunicado(pagina){
		$('#buscador').attr({'action' : $('#buscador').attr('action')+"/"+pagina});
		$('#buscador').submit();
	}
			
	function enviar(formulario,msg){
		var error=0;
		$(".comprobar").each(function(){
				if ($(this).val()=="" && !error){
					alert($("#"+msg).val()); 
					error++;
				}
			}
		);
		if (!error){
			$("#"+formulario).submit();
		}
	}
	
	function comprobar_registro(msg,pass,privacidad){
		var error=0;
		$(".comprobar").each(function(){
				if ($(this).val()=="" && !error){
					alert($("#"+msg).val()); 
					error++;
				}
			}
		);
		if (!error){
			if ($("#password").val()!=$("#password_confirm").val()){
				alert($("#"+pass).val());
			}else{
				if ($("#privacidad:checked").val()!=null){
					//alert($("#formRegistro").serialize());
					$("#formRegistro").submit();
				}else{
					alert($("#"+privacidad).val());
				}
			}
		}
	}
	
	function load_video(item){
		var video=$("#video"+item).html();
		var video_titulo=$("#video_titulo"+item).html();
		$("#video").html(video);
		$("#video_titulo").html("<strong>"+video_titulo+"</strong>");
	}
	
	function load_image(item,cod){
		var img=$(item).attr("src");
		var titulo="<strong>"+$("#foto_titulo"+cod).html()+"</strong>";
		$("#foto_ppal").attr({"src":img});
		$("#foto_titulo").html(titulo);
	}
	
	function cargar(layer,item){
		$.ajax({ 
						type: "POST", 
						url: "/adjs/",
						cache: false,
						data: "codigo="+item,
						dataType: "html" ,
						async:false,
						beforeSend: function(objeto){
						 	
       			},success: function(resp){
       				var txt=resp.split("##");
       					$("#"+layer+"_titulo").html(txt[0]);	
       					$("#"+layer).html(txt[1]);												
						} });
	}
	
	function next_foto(){
		var total=parseInt($("#fotos").css('width'));
		var margen=(parseInt($("#fotos").css("margin-left")));
		if ((margen-135) >= (405)-total){
			$("#fotos").css({'margin-left': (margen-135)+'px'});
		}
	}
	
	function prev_foto(){
		var total=parseInt($("#fotos").css('width'));
		var margen=(parseInt($("#fotos").css("margin-left")));
		if ((margen+135) <= 0){
			$("#fotos").css({'margin-left': (margen+135)+'px'});
		}
	}
	
	function next_video(){
		var total=parseInt($("#videos").css('width'));
		var margen=(parseInt($("#videos").css("margin-left")));
		if ((margen-135) >= (405)-total){
			$("#videos").css({'margin-left': (margen-135)+'px'});
		}
	}
	
	function prev_video(){
		var total=($(".imagen").length);
		var margen=(parseInt($("#videos").css("margin-left")));
		if ((margen+135) <= 0){
			$("#videos").css({'margin-left': (margen+135)+'px'});
		}
	}
	
	
