function abreVentana(url){window.open(url);
};

function abrirVentanaOnClick (e,url){
	var key=e.charCode?e.charCode:e.keyCode?e.keyCode:0;
	if(key!= 9){window.open(url);return false;}
}
var appVarsFN = {
	rounded : ["bloque","tit_round","ayuda","tit_round_int","round"],
	ocultarCapas : ["ocultajsmasinfo"],
	init : function(){
		appVarsFN.PNGFix();
		$("." + appVarsFN.ocultarCapas).each(function(){
			$(this).hide();
			$(this).after('<p><a href="#" class="enlacevineta" onclick="$(this).parent().prev().show();return false;">M\u00E1s informaci\u00f3n</a>.</p>');
		});	
		$.each(appVarsFN.rounded,function(){
				$("." + this).each(function(){
					$(this).corner("round 10px")
				});				
		});		
		$(".btnimprimir").each(function(i){
				$(this).html('<a href="#" onclick="self.print();return false"><img src="../../images/ico_print.gif" alt="" />Imprimir</a>');
			})
	},
	initDocumentos: function(){
		appVarsFN.initListaDocumentos();
		$("#estilo_mostrar_documentos").html('<p>Mostrar resultados en: <strong>Lista</strong> | <a href="#" title="">Todo</a></p>');
		$("#estilo_mostrar_documentos").toggle(
			function() { 
				$(this).html('<p>Mostrar resultados en: <a href="#" title="">Lista</a> | <strong>Todo</strong></p>');
				appVarsFN.initTodosDocumentos();
			},
			function() { 
				$(this).html('<p>Mostrar resultados en: <strong>Lista</strong> | <a href="#" title="">Todo</a></p>');				
				appVarsFN.initListaDocumentos();
			}			
		);	
	},
	initListaDocumentos: function(){
		$("#buscador_r.documentos * span.toogle_doc").each(function(z){
			var ind =(z/2);
			$(this).addClass("cerrado");
			$(this).html('<a href="#" onclick="appVarsFN.toogleDocs(this,\''+$(this).attr("id")+'\');return false"><img src="./css/img/flecha_down.gif" alt="" />Mostrar unidades documentales</a>');
			$("#tabla_toggle_"+(ind)).hide();
			$("#toggle_bottom_"+(ind)).hide();
		})
	},
	initTodosDocumentos: function(){
		$("#buscador_r.documentos * span.toogle_doc").each(function(z){
			var ind =(z/2);
			$(this).removeClass("cerrado");
			$(this).html('<a href="#" onclick="appVarsFN.toogleDocs(this,\''+$(this).attr("id")+'\');return false"><img src="./css/img/flecha_up.gif" alt="" />Cerrar unidades documentales</a>');
			$("#tabla_toggle_"+(ind)).show();
			$("#toggle_bottom_"+(ind)).show();
		})
	},
	toogleDocs: function (obj,id){
		try {
			var num = id.split('_');
			num = num[num.length-1];
			if ($("#toggle_"+ num).hasClass("cerrado")){				
				$("#toggle_"+ num +" > a").html('<img src="./css/img/flecha_up.gif" alt="" />Cerrar unidades documentales');
				$("#toggle_bottom_"+ num +" > a").html('<img src="./css/img/flecha_up.gif" alt="" />Cerrar unidades documentales');
				$("#toggle_bottom_"+ num ).show();
				$("#toggle_"+ num).removeClass("cerrado");
			}else  {
				$("#toggle_"+ num +" > a").html('<img src="./css/img/flecha_down.gif" alt="" />Mostrar unidades documentales');
				$("#toggle_bottom_"+ num).hide();				
				$("#toggle_"+ num).addClass("cerrado");
			}
			$("#tabla_toggle_"+ num).toggle();			
			
		 }catch(exe){
			//console.error(exe.message);
		}	
	},
	PNGFix: function (){
			var arVersion = navigator.appVersion.split("MSIE")
			var version = parseFloat(arVersion[1])
			var logo = document.getElementById('img_logo');
			
			if ( ($.browser.msie) &&  ($.browser.version < 7)) {
				var img = logo;
				var imgName = img.src.toUpperCase()
				
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText 
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
				img.outerHTML = strNewHTML
				
			}
	},
	rowspanTable: function(idtable) {
		var titulo='', tituloAntiguo=$("#listadoMunicipales tbody tr td"), indexAntiguo=0, contador=1, claseTr="even";
		$("#"+idtable+" tbody tr").each(function(index){
			$(this).attr("class", claseTr);
			titulo = $(this).find("td").eq(0).find("a").text();
			if (titulo != tituloAntiguo) {
				if (claseTr == "odd") claseTr = "even"; else claseTr = "odd";
				$(this).attr("class", claseTr);
				$("#"+idtable+" tbody tr:eq("+indexAntiguo+") td:first-child").attr("rowspan", contador);
				indexAntiguo=index;
				tituloAntiguo=titulo;
				contador=1;
			} else {
				$(this).find("td").eq(0).remove();
				contador++;
			}
		});
		// Para que la última fila se agrupe 
		if (claseTr == "odd") claseTr = "even"; else claseTr = "odd";
		$(this).attr("class", claseTr);
		$("#"+idtable+" tbody tr:eq("+indexAntiguo+") td:first-child").attr("rowspan", contador);
	}
}
	

$(document).ready(appVarsFN.init);
