var _Metadatos_js1_ = true;
var max_largo_titulo = 80;

// Tipos de versiones
var ORIGINAL = '0';
var INTERMEDIO = '1';
var ACTUALIZADO = '2';
var UNICA = '3';
var VIGENCIA_DIFERIDA_EVENTO = '7';
var VIGENCIA_DIFERIDA_FECHA = '8';
var eventos_propios = [1, 2, 4, 5, 6, 8, 9, 10];

function mesToStr(mes) {
    try {
        mes = parseInt(mes);
        mes = mes -1; 
        var mesesAnio = new Array();
        
        mesesAnio.push('ENE');
        mesesAnio.push('FEB');
        mesesAnio.push('MAR');
        mesesAnio.push('ABR');
        mesesAnio.push('MAY');
        mesesAnio.push('JUN');
        mesesAnio.push('JUL');
        mesesAnio.push('AGO');
        mesesAnio.push('SEP');
        mesesAnio.push('OCT');
        mesesAnio.push('NOV');
        mesesAnio.push('DIC');
    }
    catch(e) {
        return '';
    }
    return mesesAnio[mes];
}


function getFechaObj(f) {
	try {
    	var listfecha = f.split('-');
    	var anio = listfecha[0];
    	var mes = listfecha[1];
    	var dia = listfecha[2];
    }
    catch(e) {
    	return null;
    }
    
    var d=new Date();
    d.setFullYear(anio,mes-1,dia);
    return d;
 }


function esMenorIgual(fecha1, fecha2) {
    var fecha1 = getFechaObj(fecha1);
    var fecha2 = getFechaObj(fecha2);
    return fecha1 <= fecha2;
}
function esMayorIgual(fecha1, fecha2) {
    var fecha1 = getFechaObj(fecha1);
    var fecha2 = getFechaObj(fecha2);
    return fecha1 >= fecha2;
}

function ObtenerFechaVersionMovidoA(movido_a, id_parte){
	for (var i=0;i<_totalNodosNavegar_;i++){
		var arr 	= arregloPartes[i];
		var metas 	= arr[2];
		
		if(arr[3] == movido_a && metas.movido_de() == id_parte){
			return new Array(metas.vigente_desde(),metas.getEventoInicio("informado"));
		}
	}
	return new Array("","");
}

function ObtenerFechaVersionMovidoDe(movido_de, id_parte){
	for (var i = 0; i < _totalNodosNavegar_; i++) {
		var arr = arregloPartes[i];
		var metas = arr[2];
		
		if (arr[3] == movido_de && metas.movido_a() == id_parte) {
			return new Array(metas.vigente_desde(),metas.getEventoInicio("informado"));
		}
	}
	return new Array("","");
}

var configAlertas = {
	'DEROGADO' 	: {'texto':'Derogado', 			'css':'alerta-derogado', 	'link':true, 	'nombre_antiguo':'FECHA DEROGACION'},
	'REFUNDE_A'	: {'texto':'Texto refunde a', 		'css':'alerta-refunde', 	'link':false, 	'nombre_antiguo':'REFUNDE_A'},
	'OTRAS_VERS'	: {'texto':'Tiene Otras Versiones', 	'css':'alerta-actualizado',	'link':true, 	'nombre_antiguo':'TEXTO_ACTUALIZADO'},
	'TEXTO_DIFE'	: {'texto':'Tiene Texto diferido', 	'css':'alerta-diferido', 	'link':false, 	'nombre_antiguo':'DEROGACION_DIFERIDA'},
	'EN_PROCESO'	: {'texto':'En Proceso', 		'css':'alerta-proceso', 	'link':false, 	'nombre_antiguo':'OTRO_ESTADO'},
	'TEXTO_REFU'	: {'texto':'Tiene Texto Refundido',	'css':'alerta-refundido', 	'link':true, 	'nombre_antiguo':'REFUNDIDO_POR'},
	'DOBLE_ARTI'	: {'texto':'Tiene Doble Articulado', 	'css':'alerta-articulado',	'link':false, 	'nombre_antiguo':'DOBLE_ARTICULADO'}
};

var posicionAlertas = ["DEROGADO","REFUNDE_A","OTRAS_VERS","TEXTO_DIFE","EN_PROCESO","TEXTO_REFU","DOBLE_ARTI"];

var __alerta_diff__ = null;
function alertasHTML(arrayAlertas){
	var html = '<table class="alertasEncabezado">';
	html 	+= '<tr> ';
	html 	+= '	<td>';
	html 	+= '		<table class="alertasAncho">';
	html 	+= '			<tr>';
	var i;
	__alerta_diff__ = null;
	for (i=0; i < posicionAlertas.length; i++){
		var nombre = posicionAlertas[i];
		var alerta = null;
		for (var j = 0;j < arrayAlertas.length; j++){
			alerta = arrayAlertas[j];
			if(alerta.nombre == nombre){
				break;	
			}
		}
		
		if (!alerta){
			alert("No encontro la alerta... no debiese estar bien esto");
			continue;
		}
		if(!alerta.valor){
			continue;
		}
		
		var idNorma 	= $F('idNorma');
		var idParte 	= $F('idParte');
		var idVersion 	= $F('idVersion');
	

		var configAlerta = configAlertas[nombre];
		if (configAlerta.link){
			if (nombre == 'OTRAS_VERS') {
				html += '<td><span class="' + configAlerta['css'] + '" id="' + nombre + '_Nnorma" onmouseOver="mostrarAlerta(this,\'0\',\'' + alerta.valor + '\');return false;" onclick="javascript:window.parent.NavegarNorma(\'' + idNorma + '\',\'' + idParte + '\',\'\',buscar);" onMouseOut="ocultarAlerta(0);"><a href="javascript:void(0);">' + configAlerta.texto + '</a></span></td>';
			}else if(nombre == 'TEXTO_DIFE'){
				if (alerta.versiones_sigtes){
					__alerta_diff__ = alerta;
					html += '<td><span class="' + configAlerta['css'] + '" id="' + nombre + '_Nnorma" onmouseOver="mostrarAlerta(this,\'0\',\'' + alerta.valor + '\');return false;" onclick="javascript:verOpcionesDifferidoMultiple(__alerta_diff__, this);" onMouseOut="ocultarAlerta(0);"><a href="javascript:void(0);">' + configAlerta.texto + '</a></span></td>';
				}else{
					html += '<td><span class="' + configAlerta['css'] + '" id="' + nombre + '_Nnorma" onmouseOver="mostrarAlerta(this,\'0\',\'' + alerta.valor + '\');return false;" onclick="javascript:window.parent.NavegarNorma(\'' + idNorma + '\',\'' + idParte + '\',\'' + alerta.idversion + '\',buscar,\'\',\'\',undefined,true,\'' + alerta.valor + '\');" onMouseOut="ocultarAlerta(0);"><a href="javascript:void(0);">' + configAlerta.texto + '</a></span></td>';
				}
			}else{
				html += '<td><span class="' + configAlerta['css'] + '" id="' + nombre + '_Nnorma" onmouseOver="mostrarAlerta(this,\'0\',\'' + alerta.valor + '\');return false;" onclick="javascript:window.parent.NavegarAlertas(\'' + idNorma + '\',\'' + idVersion + '\',\'' + idParte + '\',\''+configAlerta.nombre_antiguo+'\',\'\',this);" onMouseOut="ocultarAlerta(0);"><a href="javascript:void(0);">' + configAlerta.texto + '</a></span></td>';
			}
		}else{
			html += '<td><span class="'+configAlerta['css']+'" id="'+nombre+'_Nnorma" onmouseOver="mostrarAlerta(this,\'0\',\''+alerta.valor+'\');return false;" onMouseOut="ocultarAlerta(0);"><a href="javascript:void(0);">'+configAlerta.texto+'</a></span></td>';
		}
	}
	
	html 	+= '				</tr>'
	html 	+= '			</table>'
	html 	+= '		</td>'
	html 	+= '	</tr>'
	html 	+= '	<tr>'
	html 	+= '	<td>'
	
	html 	+= '<p id="span_exp_norma_pdf"><a id="bot_exp_norma_pdf" href="javascript:exportarNorma(\'pdf\');"><img title="Descargue el documento PDF para imprimir" src="'+urlStatic+'/imagenes_Navegar/botones/descargar_pdf.gif" border="0" /></a></p>';
	html 	+= '	</td>'
	html 	+= '	</tr>'
	html 	+= '</table>';
	return html;
}
function verOpcionesDifferidoMultiple(alerta, objRef){
	var listaOpciones = alerta.versiones_sigtes;
	var msg = "Esta norma presenta más de una entrada en vigencia diferida, favor seleccione la que desea navegar";
	var html = '<ul>';
	var id =  $F('idNorma');
	var parte = $F('idParte');
	for(var i=0; i < listaOpciones.length; i++){
		var fecha = listaOpciones[i].desde;
		var evento = listaOpciones[i]['desdeStr'];
		var metas = arregloPartes[0][2];
		if (fecha == '2222-02-02'){
			var vigencia = " ("+evento+")";
		}else{
			var vigencia = " (vigente al "+darFormatoFechaTools(fecha,'dd-mm-aaa')+")";
		}
		var tn = metas.getTituloArbol();
		var org = metas.getOrganismos()[0];
		var strInfo =  tn + " de " + org + ", publicada el " + fechaLegis(metas.getFechaPublicacion()) + vigencia;
		var link = 'javascript:NavegarNorma('+id+',\''+parte+'\',\''+fecha+'\')';
		link = '<li><a href="'+link+'">'+strInfo+'</a></li>';
		html += link + "<br />";
	}
	html += '</ul>';
	var div = $('divOpcionesNavegarAlertas');
	if (!div){
		div = document.createElement('div');
		div.setAttribute('id','divOpcionesNavegarAlertas');
		div.setAttribute('class','divNormasGrandes');
		div.innerHTML  = '<div style="width:100%;text-align:right"><a href="javascript:void(0)" onclick="cleanObject(\'divOpcionesNavegarAlertas\')">Cerrar</a></div><div id="divMsgOpcionesNavAlerta"></div><br /><div id="divContenidoOpcionesNavAlerta"></div>';
		document.body.appendChild(div);
	}
	div.style.display = '';
	$('divMsgOpcionesNavAlerta').innerHTML = msg;
	$('divContenidoOpcionesNavAlerta').innerHTML = html;
	SetPositionObjectByOtherObject(div,objRef,0,0);
	
}
var __alerta_diff_niv_parte__ = null;

function alertasHTMLNivelParte(arrayAlertas){
	var html = '';
	__alerta_diff_niv_parte__ = null;
	for (var i=0; i < posicionAlertas.length; i++){
		var nombre = posicionAlertas[i];
		var alerta = null;
		for (var j = 0;j < arrayAlertas.length; j++){
			alerta = arrayAlertas[j];
			if(alerta.nombre == nombre){
				break;	
			}
		}
		
		if (!alerta){
			alert("No encontro la alerta... no debiese estar bien esto");
			continue;
		}
		if(!alerta.valor){
			continue;
		}
		
		var idNorma 	= $F('idNorma');
		var idParte 	= $F('idParte_interna');
		var idVersion 	= $F('idVersion_interna');
	

		var configAlerta = configAlertas[nombre];
		if (configAlerta.link){
			if (nombre == 'OTRAS_VERS') {
				html += '<label class="' + configAlerta['css'] + '" id="' + nombre + '_Nnorma" onmouseOver="mostrarAlerta(this,\'0\',\'' + alerta.valor + '\');return false;" onclick="javascript:window.parent.NavegarNorma(\'' + idNorma + '\',\'' + idParte + '\',\'\',buscar);" onMouseOut="ocultarAlerta(0);"><a href="javascript:void(0);">' + configAlerta.texto + '</a></label>\n';
			}else if(nombre == 'TEXTO_DIFE'){
				if(alerta.id_parte){
					var idParteTDIF = alerta.id_parte;
				}else{
					var idParteTDIF = idParte;
				}
				if (alerta.versiones_sigtes){
					__alerta_diff_niv_parte__ = alerta;
					html += '<label class="' + configAlerta['css'] + '" id="' + nombre + '_Nnorma" onmouseOver="mostrarAlerta(this,\'0\',\'' + alerta.valor + '\');return false;" onclick="javascript:verOpcionesDifferidoMultiple(__alerta_diff_niv_parte__, this);" onMouseOut="ocultarAlerta(0);"><a href="javascript:void(0);">' + configAlerta.texto + '</a></label>\n';
				}else{
					html += '<label class="' + configAlerta['css'] + '" id="' + nombre + '_Nnorma" onmouseOver="mostrarAlerta(this,\'0\',\'' + alerta.valor + '\');return false;" onclick="javascript:window.parent.NavegarNorma(\'' + idNorma + '\',\'' + idParteTDIF + '\',\'' + alerta.idversion + '\',buscar,\'\',\'\',undefined,true,\'' + alerta.valor + '\');" onMouseOut="ocultarAlerta(0);"><a href="javascript:void(0);">' + configAlerta.texto + '</a></label>\n';
				}
			}else{
				html += '<label class="' + configAlerta['css'] + '" id="' + nombre + '_Nnorma" onmouseOver="mostrarAlerta(this,\'0\',\'' + alerta.valor + '\');return false;" onclick="javascript:window.parent.NavegarAlertas(\'' + idNorma + '\',\'' + idVersion + '\',\'' + idParte + '\',\''+configAlerta.nombre_antiguo+'\',\'\',this);" onMouseOut="ocultarAlerta(0);"><a href="javascript:void(0);">' + configAlerta.texto + '</a></label>\n';
			}
		}else{
			html += '<label class="'+configAlerta['css']+'" id="'+nombre+'_Nnorma" onmouseOver="mostrarAlerta(this,\'0\',\''+alerta.valor+'\');return false;" onMouseOut="ocultarAlerta(0);"><a href="javascript:void(0);">'+configAlerta.texto+'</a></label>\n';
		}
	}
	return html;
}


/*
 * Clase Alerta
*/
Alerta = function(nodo) {
	this.nodo = nodo;
	this.inicio_vigencia = $F('idVersion');
	
	this.derogado = function() {
		var obj = new Object();
		obj.nombre = 'DEROGADO';
		obj.valor  = this.nodo.getAttribute('fecha_derogacion')?fechaLegis(this.nodo.getAttribute('fecha_derogacion')):'';
		return obj;
	};
	
    this.refunde_a = function() {
		var obj = new Object();
		obj.nombre = 'REFUNDE_A';

        var r = this.nodo.selectSingleNode("./@refunde_a");
        if (r && r.nodeValue != "") {
			obj.valor = r.nodeValue;
		}else{
			obj.valor = "";
		}
		return obj;
    };
    
    this.refundido_por = function() {
		var obj = new Object();
		obj.nombre = 'TEXTO_REFU';

        var r = this.nodo.selectSingleNode("./@refundido_por");
        if (r && r.nodeValue != "") {
			obj.valor = r.nodeValue;
		}else{
			obj.valor = "";
		}
		return obj;
    };
    
    this.no_vigente = function() {
        // Si es No vigente entonces el tipo de version debe ser distinta de 
        // Actualizada o Unica
        
		var obj = new Object();
		obj.nombre = 'OTRAS_VERS';
		var version = this.encuentraVigencia(this.inicio_vigencia);
        if (version) {
		
		
			var tipo = version.selectSingleNode('./@tipo_version');
			tipo = tipo ? tipo.nodeValue : '';
			if (tipo != UNICA && tipo != ACTUALIZADO) {
				obj.valor = this.buscaVersionVigente();
			}
			else {
				obj.valor = "";
			}
		}else{
			obj.valor = "";
		}
		return obj;
    };
    
    this.getInfoNoVigente = function() {
        return this.buscaVersionVigente();
    };
    
    this.buscaVersionVigente = function(){
		// Obtiene el inicio de vigencia de la ultima version vigente
		var fecha = "";
		var vigencias = this.nodo.selectNodes('./VIGENCIAS/VERSION');
		for (i = 0; i < vigencias.length; i++) {
			var tipo = vigencias[i].selectSingleNode('./@tipo_version');
			tipo = tipo ? tipo.nodeValue : '';
			if (tipo == UNICA || tipo == ACTUALIZADO) {
				var inicio_vigencia = vigencias[i].selectSingleNode('./@desde');
				fecha = inicio_vigencia ? inicio_vigencia.nodeValue : '';
				break;
			}
		}
		return fecha ? fechaLegis(fecha) : '';
	};
    

    this.doble_articulado = function() {
		var obj 	= new Object();
		obj.nombre 	= 'DOBLE_ARTI';
        var art = this.nodo.selectSingleNode("./@doble_articulado");
        art = art ? art.nodeValue : '';
        if (art == "con doble articulado") {
			obj.valor = art;
		}else {
			obj.valor = "";
		}
		return obj;
    };

   	this.textoDiferido = function(){
		var obj 	= new Object();
		obj.nombre 	= 'TEXTO_DIFE';
		
		var evento_pendiente = this.nodo.selectSingleNode("@evento_pendiente");
		if (!evento_pendiente || evento_pendiente.nodeValue <= 0) {
			return obj;
		}
		var version = this.encuentraVigencia(this.inicio_vigencia);

		if(!version){
			obj;
		}

		var tipo_version = version.selectSingleNode("@tipo_version");
		if(!tipo_version){
			return obj;
		}
		
		if(tipo_version.nodeValue in oc([ORIGINAL ,INTERMEDIO])){
			return obj;
		}
		
		
		//Buscar en las siguientes versiones (que debiesen ser diferidas) y mostrar el tipo de Version
		//además del evento(s) o fecha de inicio de la version diferida
		//Si hay una sola version diferida, la alerta debe ser navegable, caso contrario no.-
		var texto = ""
		
		var versiones_sigtes = this.encuentraVersionesSiguientes(this.inicio_vigencia, tipo_version.nodeValue);
		for (var i = 0; i < versiones_sigtes.length; i++) {
			var version = versiones_sigtes[i];
			if (evento_pendiente.nodeValue in oc(eventos_propios)) {
				texto += "<b>" + version.tipoVersionStr + ":</b><br/><li>" + version.desdeStr + "</li><br/>";
			}else if(i == 0){
				texto += "<b>Modificación Diferida:</b><br/><li>" + version.desdeStr + "</li><br/>";
			}else{
				texto += version.desdeStr + "<br/>";
			}
			if (version.movido) {
				obj.idversion = version.fechaMovido;
				obj.id_parte  = version.id_parte;
			}
			else {
				obj.idversion = version.desde;
			}
		}
		
		configAlertas[obj.nombre].link = true;
		if (versiones_sigtes.length == 1){
			obj.versiones_sigtes = null;
		}else{
			obj.versiones_sigtes = versiones_sigtes;
		}
		/*if (versiones_sigtes.length == 1){
			configAlertas[obj.nombre].link = true;
		}else{
			configAlertas[obj.nombre].link = false;
			obj.idversion  = "";
		}*/
		obj.valor = texto;
		
		return obj;
	}

    this.otroEstado = function() {
		var obj 	= new Object();
		obj.nombre 	= 'EN_PROCESO';
        var estado 	= this.nodo.selectSingleNode("./@estado_produccion");
        if (estado && estado.nodeValue != '0') {
			obj.valor = "En Proceso";
		}else{
			obj.valor = "";
		}
		return obj;
    };
	
    this.encuentraVigencia = function(inicio_vigencia) {
        var vigencias = this.nodo.selectNodes('./VIGENCIAS/VERSION');
        var version = null;
        for(var v=0; v<vigencias.length; v++) {
            var vigencia_version = vigencias[v].selectSingleNode('./@desde');
            vigencia_version = vigencia_version ? vigencia_version.nodeValue : '';
            if(esMenorIgual(vigencia_version, inicio_vigencia)) 
            {
                version = vigencias[v];
            }
        }
        return version;
    };
    this.encuentraVersionesSiguientes = function(inicio_vigencia, tipo_version){
		var vigenciasArray = vigencias(this.nodo, inicio_vigencia)
		var versiones_sgtes = new Array();
		for (var v = 0; v < vigenciasArray.length; v++) {
			var vigencia_version = vigenciasArray[v].desde;
			if (!esMenorIgual(vigencia_version, inicio_vigencia)) {
				versiones_sgtes.push(vigenciasArray[v]);
			}
			else {
				if (!(tipo_version in oc([ACTUALIZADO, UNICA])) && vigencia_version == inicio_vigencia) {
					versiones_sgtes.unshift(vigenciasArray[v]);
				}
			}
		}
        
		try {
			var arrParte = arregloPartes[id_parte_cargada];
			var metadatos = arrParte[2];
			var movido_a = metadatos.movido_a();
			var idParte  = metadatos.getID();
			if (movido_a) {
				var datosMovidoA = ObtenerFechaVersionMovidoA(movido_a, idParte);
				if (!datosMovidoA[1]){
					datosMovidoA[1] = fechaLegis(datosMovidoA[0]);
				}
				var vig = {
					'desde': 'movido_a',
					'hasta': '',
					'id_parte': movido_a,
					'tipoVersionStr': 'Movido a',
					'misma_version': false,
					'movido': true,
					'fechaMovido': datosMovidoA[0],
					'desdeStr': datosMovidoA[1],
					'hastaStr': ''
				};
				versiones_sgtes.push(vig);
			}
		} 
		catch (e) {
		}
		versiones_sgtes.reverse();
		return versiones_sgtes;
	};
	
	this.encuentraVigenciaReal = function (){
		
	};
	this.getAlertas = function() {
        
		var alertas = new Array();
        
		alertas.push(this.derogado());//[0]
		alertas.push(this.no_vigente());//[1]
		alertas.push(this.refunde_a());//[2]
		alertas.push(this.refundido_por());//[3]
		alertas.push(this.textoDiferido());//[4]
		alertas.push(this.doble_articulado());//[5]
		alertas.push(this.otroEstado());//[6]
		return alertas;
	};
}

function tabla_metadatos(metadatosArr) {
	var strMetas = '<table style="font-size:11px;max-height:270px">';
	for(var i=0; i<metadatosArr.length; i++) {
		strMetas += "<tr><td>"+ metadatosArr[i][0]+ "</td><td>"+ metadatosArr[i][1]+ "</td></tr>";
	}
	strMetas += "</table>";
	return strMetas;
}


function fechaLegis(fecha) {
    var arrFecha = fecha.split('-');
	if (arrFecha.length == 3) {
		var dia = arrFecha[2];
		var mes = arrFecha[1];
		var anio = arrFecha[0];
        
		if (mes!="" && mes.charAt(0)=='0') {
			mes = mes.charAt(1);
		}
		fecha = dia + "-" + mesToStr(mes)+ "-" + anio;
	}
	return fecha;
}

function cortaPalabra(titulo) {
	if (titulo.length > max_largo_titulo) {
		// Buscar el ultimo espacio en blanco o salto de linea
		for(var i=max_largo_titulo; i>=0; i--) {
			if (titulo[i]=='\n' || titulo[i]==' ') {
				titulo = titulo.substring(0, i) + "...";
				return titulo
			}
		}
	}
	return titulo;
}

function getEnlacesHL(nodo){
	/** El caso de Historia de la Ley debo estudiarlo más 
	 *  Para los ws masivos. 
	 */
	// Listado de Enlaces a Historia de la Ley
	var filtro_rels_hl = new Array();	
	var rels_hl = new Array();
	
	// Listado de enlaces hacia "La Historia de la Ley"
	var clase = '1'; // Historia de la Ley
	
	var xpathExp = ".//RELACIONES/RELACION";
	var rels = nodo.selectNodes(xpathExp);

	var total = rels.length+"";
	var p_id_parte = "-1";
	var count_parte = 1000;
	
	for(var j=0;j<rels.length;j++) {
		var attrs  = rels[j].attributes;
		
		var clase_attr = attrs.getNamedItem("clase");
		if (clase_attr && clase_attr.nodeValue == clase)
		{
			var tipo_hipervinculo = rels[j].selectSingleNode('./HIPERVINCULO/@tipo');
			if (tipo_hipervinculo && tipo_hipervinculo.nodeValue == "0") {//Vinculo HTTP
				var parent = rels[j].parentNode;
				var id_parte   = parent.selectSingleNode('./@id_parte');
				var id_norma   = parent.selectSingleNode('./@id_norma');
				var tmpJ = "";
				while(parent && (!id_parte && !id_norma)){
					parent = parent.parentNode;
					id_parte = parent.selectSingleNode('./@id_parte');
					id_norma = parent.selectSingleNode('./@id_norma');
				}
				if(id_parte && id_parte.nodeValue){
					t_id_parte = id_parte.nodeValue;
					if(t_id_parte != p_id_parte){
						count_parte ++;
					}
					tmpJ  = count_parte+"";
					p_id_parte = t_id_parte;
				
				}else if(id_norma && id_norma.nodeValue){
					tmpJ  = "0";
				}
				filtro_rels_hl.push(new Array(rels[j], tmpJ));
			}
		}
	}

	rels = filtro_rels_hl.sort(my_sortfunction_relaciones_HL);

	for(var i=0;i<rels.length;i++) {
		var attrs = rels[i][0].attributes;
		var clase_attr = attrs.getNamedItem("clase");
		if (clase_attr && clase_attr.nodeValue == clase)
		{
			var tipo_hipervinculo = rels[i][0].selectSingleNode('./HIPERVINCULO/@tipo');
			if(tipo_hipervinculo && tipo_hipervinculo.nodeValue == "0") {//Vinculo HTTP
				var enlace = rels[i][0].selectSingleNode('./HIPERVINCULO/ENLACE/text()');
				var informacion = rels[i][0].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="informacion"]/text()');
				var categoria 	= rels[i][0].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="categoria"]/text()');

				if (enlace) {
					var enlaceValue = enlace.nodeValue;
					
					if(enlaceValue.indexOf("http://recursoslegales.bcn.cl/") == 0){
						   try {
							lista = enlaceValue.split('/');
							host = lista[2].split('.')[0];
							enlaceValue = urlServidor+'/../Navegar/scripts/obtienearchivo?id=' + host + '/' + lista[5] + '/' + lista[6] + '/' + lista[7] + '/' + lista[8];
						   } catch (e) {
							enlaceValue = '';
						   }
	  
					}
					
					if (enlaceValue.indexOf(__GATO__) == 0) {
						enlaceValue = enlaceValue.substring(__GATO__.length);
					}
					var txtAMostrar = enlaceValue;
					if (informacion){	
						txtAMostrar = informacion.nodeValue;
						if (txtAMostrar.indexOf(__GATO__) > -1) {
							txtAMostrar = replace(txtAMostrar,__GATO__,"");
						}
					}

					if (categoria) {
						categoria = categoria.nodeValue;
					}else{
						categoria = "";
					}
					var textToTraza = replace(replace(enlaceValue,'\n',''),' ','');
					rels_hl.push(new Array('<a onclick="TrazarClickEnlace(\'52\',\''+textToTraza+'\');" target="_blank" href="'+enlaceValue+'">'+txtAMostrar+'</a>', categoria));
				}
			}
		}
	}

	var prev = "";
	if (rels_hl.length > 0){
		prev = rels_hl[0][1];
	}
	var enlaces_hl = new Array();
	var tmp = "<b>"+prev.capitalize()+"</b><br /><br />";
	var entra = false;
	for (var i = 0; i < rels_hl.length; i++) {
		entra = true;
		if(prev == rels_hl[i][1]){
			tmp += "<li>"+rels_hl[i][0]+"</li>";
		}else{
			enlaces_hl.push(tmp);
			tmp = "<b>"+rels_hl[i][1].capitalize()+"</b><br /><br />";
			tmp += "<li>"+rels_hl[i][0]+"</li>";
		}
		prev = rels_hl[i][1];
	}
	if(entra){
		enlaces_hl.push(tmp);
	}
	return enlaces_hl;

}

function getEnlacesOSSinOrden(nodo){
	// Listado de Enlaces a Otros Sistemas
	var rels_hl = new Array();
	
	// Listado de enlaces hacia "Otros Sistemas"
	var clase = '2'; // Otros sistemas
	var rels = nodo.selectNodes("./RELACIONES/RELACION");
	
	for(var i=0;i<rels.length;i++) {
		var attrs = rels[i].attributes;
		var clase_attr = attrs.getNamedItem("clase");
		if (clase_attr && clase_attr.nodeValue == clase)
		{
			var tipo_hipervinculo = rels[i].selectSingleNode('./HIPERVINCULO/@tipo');
			if(tipo_hipervinculo && tipo_hipervinculo.nodeValue == "0") {//Vinculo HTTP
				var enlace = rels[i].selectSingleNode('./HIPERVINCULO/ENLACE/text()');
				var informacion = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="informacion"]/text()');
				var categoria = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="categoria"]/text()');
				var sub_categoria = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="sub_categoria"]/text()');				
				if (enlace) {
					if (enlace.nodeValue.indexOf(__GATO__) == 0) {
						enlace.nodeValue = enlace.nodeValue.substring(__GATO__.length);
					}
					var txtAMostrar = enlace.nodeValue;
					if (informacion){
						txtAMostrar = informacion.nodeValue;
						if (txtAMostrar.indexOf(__GATO__) > -1) {
							txtAMostrar = replace(txtAMostrar,__GATO__,"");
						}
					}

					if (categoria) {
						categoria = categoria.nodeValue;
					}else{
						categoria = "";
					}
					
					if (sub_categoria){
						sub_categoria = sub_categoria.nodeValue;
					}else{
						sub_categoria = "";
					}
					var textToTraza = replace(replace(enlace.nodeValue,'\n',''),' ','');
					rels_hl.push(new Array('<a target="_blank" onclick="TrazarClickEnlace(\'51\',\'' + textToTraza + '\');" href="' + enlace.nodeValue + '">' + txtAMostrar + '</a>', categoria, sub_categoria));					

				}
			}
		}
	}
	return rels_hl;	
}
function getEnlacesOS(nodo){
	var rels_hl = getEnlacesOSSinOrden(nodo);
	rels_hl = rels_hl.sort(my_sortfunction_categorias);
	
	var suma = '';
	for (var i = 0; i < rels_hl.length; i++) {
		suma += rels_hl[i][1] + '-' + rels_hl[i][2] + '\n';
	}
	
	
	var prev = "";
	var prev_sub = "";
	if (rels_hl.length > 0) {
		prev = rels_hl[0][1];
		prev_sub = rels_hl[0][2];
	}
	var enlaces_doct = new Array();
	var tmp = '';
	if (prev != '') {
		tmp += "<b>" + prev.capitalize() + "</b><br /> <UL>";
	}
	if (prev_sub != '') {
		tmp += "<b>"+prev_sub.capitalize() + "</b><br /><br />";
	}
	if (prev == '' && prev_sub == '') {
		tmp += "<b>Otros sistemas</b><br /><br />";
	}
	var entra = false;
	for (var i = 0; i < rels_hl.length; i++) {
		entra = true;
		if (prev == rels_hl[i][1] && prev_sub == rels_hl[i][2]) {
			tmp += "<li>" + rels_hl[i][0] + "</li>";
		}
		else 
			if (prev == rels_hl[i][1] && prev_sub != rels_hl[i][2]) {
				tmp += "</UL><br> <UL><b>" + rels_hl[i][2].capitalize() + "</b><br /><br /><li>" + rels_hl[i][0] + "</li>";
			}
			else {
				tmp += "</UL>";
				enlaces_doct.push(tmp);
				
				tmp = "<b>" + rels_hl[i][1].capitalize() + "</b><br /> <UL><b>" + rels_hl[i][2].capitalize() + "</b><br /><br />";
				tmp += "<li>" + rels_hl[i][0] + "</li>";
			}
		prev = rels_hl[i][1];
		prev_sub = rels_hl[i][2];
	}
	if (entra) {
		tmp += "</UL>";
		enlaces_doct.push(tmp);
	}
	return enlaces_doct;
}

function getEnlacesProyectosSinOrden(nodo){
	// Listado de Enlaces a Proyectos
	var rels_hl = new Array();
	
	// Listado de enlaces hacia "Proyectos"
	var clase = '0'; // Proyectos
	var rels = nodo.selectNodes(".//RELACIONES/RELACION");
	
	for (var i = 0; i < rels.length; i++) {
		var attrs = rels[i].attributes;
		var clase_attr = attrs.getNamedItem("clase");
		if (clase_attr && clase_attr.nodeValue == clase) {
			var tipo_hipervinculo = rels[i].selectSingleNode('./HIPERVINCULO/@tipo');
			if (tipo_hipervinculo && tipo_hipervinculo.nodeValue == "0") {//Vinculo HTTP
				var enlace = rels[i].selectSingleNode('./HIPERVINCULO/ENLACE/text()');
				var informacion = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="informacion"]/text()');
				var nroBoletin = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="nroBoletin"]/text()');
				var categoria = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="categoria"]/text()');
				if (enlace) {
					if (enlace.nodeValue.indexOf(__GATO__) == 0) {
						enlace.nodeValue = enlace.nodeValue.substring(__GATO__.length);
					}
					if (enlace.nodeValue.indexOf('sil.senado.cl') > -1){
						enlace.nodeValue = enlace.nodeValue.replace('http://sil.senado.cl/cgi-bin/index_eleg.pl?','http://www.senado.cl/appsenado/templates/tramitacion/index.php?boletin_ini=')
						enlace.nodeValue = enlace.nodeValue.replace('http://sil.senado.cl/cgi-bin/sil_proyectos.pl?','http://www.senado.cl/appsenado/templates/tramitacion/index.php?boletin_ini=')
					}
					var txtAMostrar = enlace.nodeValue;
					
					if (informacion) {
						txtAMostrar = informacion.nodeValue;
						if (txtAMostrar.indexOf(__GATO__) > -1) {
							txtAMostrar = replace(txtAMostrar, __GATO__, "");
						}
					}

					if (nroBoletin) {
						var nroBoletinValue = nroBoletin.nodeValue;
						txtAMostrar += " (Boletín N° " + nroBoletin.nodeValue + ")";
						if (txtAMostrar.indexOf(__GATO__) > -1) {
							txtAMostrar = replace(txtAMostrar, __GATO__, "");
						}
					}else{
						var nroBoletinValue = "";
					}
					
					if (categoria) {
						categoria = categoria.nodeValue;
					}else{
						categoria = "";
					}
					var textToTraza = replace(replace(enlace.nodeValue,'\n',''),' ','');
					rels_hl.push(new Array('<a target="_blank" onclick="TrazarClickEnlace(\'53\',\'' + textToTraza + '\');" href="' + enlace.nodeValue + '">' + txtAMostrar + '</a>', categoria, nroBoletinValue, ''));
				}
			}
		}
	}
	return rels_hl;	
}
function getEnlacesProyectosOrdenados(rels_hl){
	rels_hl = rels_hl.sort(my_sortfunction_p_ley);
	var prev = "";
	if (rels_hl.length > 0){
		prev = rels_hl[0][1];
	}
	var enlaces_pry = new Array();
	var tmp = "<b>"+prev.capitalize()+"</b><br/><br/>";
	var entra = false;
	for (var i = 0; i < rels_hl.length; i++) {
		entra = true;
		if(prev == rels_hl[i][1]){
			tmp += "<li>"+rels_hl[i][0]+"</li>";
		}else{
			enlaces_pry.push(tmp);
			tmp = "<b>"+rels_hl[i][1].capitalize()+"</b><br/><br/>";
			tmp += "<li>"+rels_hl[i][0]+"</li>";
		}
		prev = rels_hl[i][1];
	}
	if(entra){
		enlaces_pry.push(tmp);
	}
	return enlaces_pry;
}
function getEnlacesProyectos(nodo){
	var rels_hl = getEnlacesProyectosSinOrden(nodo);
	return getEnlacesProyectosOrdenados(rels_hl);
}

function getEnlacesJurisprudenciaSinOrden(nodo){
	// Listado de Enlaces a Jurisprudencia
	var rels_hl = new Array();
	
	// Listado de enlaces hacia "Jurisprudencia"
	var clase = '5'; // Jurisprudencia
	var rels = nodo.selectNodes(".//RELACIONES/RELACION");
	
	for (var i = 0; i < rels.length; i++) {
		var attrs = rels[i].attributes;
		var clase_attr = attrs.getNamedItem("clase");
		if (clase_attr && clase_attr.nodeValue == clase) {
			var tipo_hipervinculo = rels[i].selectSingleNode('./HIPERVINCULO/@tipo');
			if (tipo_hipervinculo && tipo_hipervinculo.nodeValue == "0") {//Vinculo HTTP
				var enlace = rels[i].selectSingleNode('./HIPERVINCULO/ENLACE/text()');
				var informacion = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="informacion"]/text()');
				var nroBoletin = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="nroBoletin"]/text()');
				var categoria = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="categoria"]/text()');
				var sub_categoria = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="sub_categoria"]/text()');
				var rol  = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="rol"]/text()');
				var fecha  = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="fecha"]/text()');
				if (enlace) {
					if (enlace.nodeValue.indexOf(__GATO__) == 0) {
						enlace.nodeValue = enlace.nodeValue.substring(__GATO__.length);
					}
					var txtAMostrar = enlace.nodeValue;
					
					if (informacion) {
						txtAMostrar = informacion.nodeValue;
						if (txtAMostrar.indexOf(__GATO__) > -1) {
							txtAMostrar = replace(txtAMostrar, __GATO__, "");
						}
					}

					if (nroBoletin && nroBoletin.nodeValue) {
						txtAMostrar += ", " + nroBoletin.nodeValue;
						if (txtAMostrar.indexOf(__GATO__) > -1) {
							txtAMostrar = replace(txtAMostrar, __GATO__, "");
						}
					}

					if (rol) {
						txtAMostrar += "/Rol:" + rol.nodeValue;
						if (txtAMostrar.indexOf(__GATO__) > -1) {
							txtAMostrar = replace(txtAMostrar, __GATO__, "");
						}
					}
					var orden_fecha = 0;
					if (fecha && fecha.nodeValue) {//En formato AAAAMMDD
						var fecha_anio 	= fecha.nodeValue.substr(0,4);
						var fecha_mes 	= fecha.nodeValue.substr(4,2);
						var fecha_dia 	= fecha.nodeValue.substr(6,2);
						txtAMostrar += "/Fecha:" + fecha_dia+"."+fecha_mes+"."+fecha_anio;
						if (txtAMostrar.indexOf(__GATO__) > -1) {
							txtAMostrar = replace(txtAMostrar, __GATO__, "");
						}
						try {
							orden_fecha = parseInt(fecha.nodeValue);
						} 
						catch (e) {
							orden_fecha = fecha.nodeValue;
						}
					}
					
					if (categoria) {
						categoria = categoria.nodeValue;
					}else{
						categoria = "";
					}
					
					if (sub_categoria){
						sub_categoria = sub_categoria.nodeValue;
					}else{
						sub_categoria = "";
					}
					var textToTraza = replace(replace(enlace.nodeValue,'\n',''),' ','');
					rels_hl.push(new Array('<a target="_blank" onclick="TrazarClickEnlace(\'56\',\'' + textToTraza + '\');" href="' + enlace.nodeValue + '">' + txtAMostrar + '</a>', categoria, sub_categoria, '', orden_fecha, txtAMostrar));
				}
			}
			if (tipo_hipervinculo && tipo_hipervinculo.nodeValue == "1") {//Vinculo WEB SERVICE
				var enlace = rels[i].selectSingleNode('./HIPERVINCULO/ENLACE/text()');
				var informacion = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="informacion"]/text()');
				var nroBoletin = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="nroBoletin"]/text()');
				var categoria = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="categoria"]/text()');
				var sub_categoria = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="sub_categoria"]/text()');
				var parametros = rels[i].selectNodes('./HIPERVINCULO/PARAMETROS/PARAMETRO');

				if (enlace) {
					if (enlace.nodeValue.indexOf(__GATO__) == 0) {
						enlace.nodeValue = enlace.nodeValue.substring(__GATO__.length);
					}
					var txtAMostrar = enlace.nodeValue;
					
					if (informacion) {
						txtAMostrar = informacion.nodeValue;
						if (txtAMostrar.indexOf(__GATO__) > -1) {
							txtAMostrar = replace(txtAMostrar, __GATO__, "");
						}
					}
					
					if (nroBoletin && nroBoletin.nodeValue) {
						txtAMostrar += ", " + nroBoletin.nodeValue;
						if (txtAMostrar.indexOf(__GATO__) > -1) {
							txtAMostrar = replace(txtAMostrar, __GATO__, "");
						}
					}
					
					if (categoria) {
						categoria = categoria.nodeValue;
					}
					else {
						categoria = "";
					}
					
					if (sub_categoria) {
						sub_categoria = sub_categoria.nodeValue;
					}
					else {
						sub_categoria = "";
					}
					if (parametros) {
						var params = ''
						for (var n = 0; n < parametros.length; n++) {
							var pnom = parametros[n].getAttribute('nombre');
							var pval = parametros[n].firstChild.nodeValue;
							params = params + pnom + '=' + pval + '&';
						}
						params = enlace.nodeValue + '?' + params
					}
					else {
						alert('no vienen');
					}
					var textToTraza = replace(replace(enlace.nodeValue,'\n',''),' ','');
					rels_hl.push(new Array('<a onclick="TrazarClickEnlace(\'56\',\'' + textToTraza + '\'); muestraWS(\'' + txtAMostrar + '\', \'' + params + '\');" style="cursor:pointer;">' + txtAMostrar + '</a><input id="input_' + txtAMostrar + '" type="hidden" value=""/><div id="' + txtAMostrar + '" style="display:none;">Cargando...<img src="'+urlStatic+'/imagenes_Navegar/cargando.gif"/></div>', categoria, sub_categoria,params,'', txtAMostrar));
				}
			}								
		}
	}
	return 	rels_hl;
}

function unirEnlacesWSSimilares(rels_hl){
	var new_rels = [];
	var claves_existentes = {};
	for (var i = 0; i < rels_hl.length; i++) {
		var clave = rels_hl[i][1]+rels_hl[i][2]+rels_hl[i][5];
		if(!(clave in claves_existentes)){
			claves_existentes[clave] = rels_hl[i];
		}else{
			relacion_existente = claves_existentes[clave];
			if (typeof relacion_existente[3] == typeof ""){
				if (relacion_existente[3] && rels_hl[i][3]){
					relacion_existente[3] = new Array(relacion_existente[3],rels_hl[i][3]);
				}
			}else{
				relacion_existente[3].push(rels_hl[i][3]);
			}
			claves_existentes[clave] = relacion_existente; 
		}
	}
	for(c in claves_existentes){
		new_rels.push(claves_existentes[c]);
	}
	return new_rels;
}

function getEnlacesJurisprudenciaOrdenados(rels_hl){
	rels_hl = unirEnlacesWSSimilares(rels_hl);
	rels_hl = rels_hl.sort(my_sortfunctionJuri);
	
	var prev 	 = "";
	var prev_sub = "";
	if (rels_hl.length > 0){
		prev 	 = rels_hl[0][1];
		prev_sub = rels_hl[0][2];
	}
	var enlaces_jur = new Array();
	var tmp = "<b>"+prev.capitalize()+"</b><br /> <UL><b> "+prev_sub+"</b><br/><br/>";
	var entra = false;
	for (var i = 0; i < rels_hl.length; i++) {
		entra = true;
		if (prev == rels_hl[i][1] && prev_sub == rels_hl[i][2]) {
			if (typeof rels_hl[i][3] == typeof "") {
				tmp += "<li>" + rels_hl[i][0] + "</li>";
			}else{
				tmp += "<li>" + rels_hl[i][0].replace(rels_hl[i][3][0],rels_hl[i][3].join(',')) + "</li>";
			}
		}
		else 
			if (prev == rels_hl[i][1] && prev_sub != rels_hl[i][2]) {
				if (typeof rels_hl[i][3] == typeof ""){
					tmp += "</UL><br> <UL><b>"+rels_hl[i][2]+"</b><br /><br /><li>" + rels_hl[i][0] + "</li>";
				}else{
					tmp += "</UL><br> <UL><b>"+rels_hl[i][2]+"</b><br /><br /><li>" + rels_hl[i][0].replace(rels_hl[i][3][0],rels_hl[i][3].join(',')) + "</li>";
				}
			}
			else {
				tmp += "</UL>";
				enlaces_jur.push(tmp);
				
				tmp = "<b>"+rels_hl[i][1].capitalize() + "</b><br /> <UL><b> " + rels_hl[i][2].capitalize()+"</b><br /><br />";
				if (typeof rels_hl[i][3] == typeof "") {
					tmp += "<li>" + rels_hl[i][0] + "</li>";
				}else{
					tmp += "<li>" + rels_hl[i][0].replace(rels_hl[i][3][0],rels_hl[i][3].join(',')) + "</li>";
				}
			}
		prev = rels_hl[i][1];
		prev_sub = rels_hl[i][2];
	}
	if(entra){
		tmp += "</UL>";
		enlaces_jur.push(tmp);
	}
	return enlaces_jur;

}
function getEnlacesJurisprudencia(nodo){
	var rels_hl = getEnlacesJurisprudenciaSinOrden(nodo);
	return getEnlacesJurisprudenciaOrdenados(rels_hl);
}

function getEnlacesDoctrinaSinOrden(nodo){
	// Listado de Enlaces a Doctrina
	var rels_hl = new Array();
	
	// Listado de enlaces hacia "Doctrina"
	var clase = '6'; // Doctrina
	var rels = nodo.selectNodes("./RELACIONES/RELACION");
	
	for (var i = 0; i < rels.length; i++) {
		var attrs = rels[i].attributes;
		var clase_attr = attrs.getNamedItem("clase");
		if (clase_attr && clase_attr.nodeValue == clase) {
			var tipo_hipervinculo = rels[i].selectSingleNode('./HIPERVINCULO/@tipo');
			if (tipo_hipervinculo && tipo_hipervinculo.nodeValue == "0") {//Vinculo HTTP
				var enlace = rels[i].selectSingleNode('./HIPERVINCULO/ENLACE/text()');
				var informacion = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="informacion"]/text()');
				var nroBoletin = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="nroBoletin"]/text()');
				var categoria = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="categoria"]/text()');
				var sub_categoria = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="sub_categoria"]/text()');
				if (enlace) {
					if (enlace.nodeValue.indexOf(__GATO__) == 0) {
						enlace.nodeValue = enlace.nodeValue.substring(__GATO__.length);
					}
					var txtAMostrar = enlace.nodeValue;
					
					if (informacion) {
						txtAMostrar = informacion.nodeValue;
						if (txtAMostrar.indexOf(__GATO__) > -1) {
							txtAMostrar = replace(txtAMostrar, __GATO__, "");
						}
					}

					if (nroBoletin && nroBoletin.nodeValue) {
						txtAMostrar += ", " + nroBoletin.nodeValue;
						if (txtAMostrar.indexOf(__GATO__) > -1) {
							txtAMostrar = replace(txtAMostrar, __GATO__, "");
						}
					}
					
					if (categoria) {
						categoria = categoria.nodeValue;
					}else{
						categoria = "";
					}
					
					if (sub_categoria){
						sub_categoria = sub_categoria.nodeValue;
					}else{
						sub_categoria = "";
					}
					var textToTraza = replace(replace(enlace.nodeValue,'\n',''),' ','');
					rels_hl.push(new Array('<a target="_blank" onclick="TrazarClickEnlace(\'57\',\'' + textToTraza + '\');" href="' + enlace.nodeValue + '">' + txtAMostrar + '</a>', categoria, sub_categoria,''));
				}
			}
			if (tipo_hipervinculo && tipo_hipervinculo.nodeValue == "1") {//Vinculo WEB SERVICE
				var enlace = rels[i].selectSingleNode('./HIPERVINCULO/ENLACE/text()');
				var informacion = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="informacion"]/text()');
				var nroBoletin = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="nroBoletin"]/text()');
				var categoria = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="categoria"]/text()');
				var sub_categoria = rels[i].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="sub_categoria"]/text()');
				var parametros = rels[i].selectNodes('./HIPERVINCULO/PARAMETROS/PARAMETRO');

				if (enlace) {
					if (enlace.nodeValue.indexOf(__GATO__) == 0) {
						enlace.nodeValue = enlace.nodeValue.substring(__GATO__.length);
					}
					var txtAMostrar = enlace.nodeValue;
					
					if (informacion) {
						txtAMostrar = informacion.nodeValue;
						if (txtAMostrar.indexOf(__GATO__) > -1) {
							txtAMostrar = replace(txtAMostrar, __GATO__, "");
						}
					}
					
					if (nroBoletin && nroBoletin.nodeValue) {
						txtAMostrar += ", " + nroBoletin.nodeValue;
						if (txtAMostrar.indexOf(__GATO__) > -1) {
							txtAMostrar = replace(txtAMostrar, __GATO__, "");
						}
					}
					
					if (categoria) {
						categoria = categoria.nodeValue;
					}
					else {
						categoria = "";
					}
					
					if (sub_categoria) {
						sub_categoria = sub_categoria.nodeValue;
					}
					else {
						sub_categoria = "";
					}
					if (parametros) {
						var params = ''
						for (var n = 0; n < parametros.length; n++) {
							var pnom = parametros[n].getAttribute('nombre');
							var pval = parametros[n].firstChild.nodeValue;
							params = params + pnom + '=' + pval + '&';
						}
						params = enlace.nodeValue + '?' + params
					}
					else {
						alert('no vienen');
					}
					var textToTraza = replace(replace(enlace.nodeValue,'\n',''),' ','');
					rels_hl.push(new Array('<a onclick="TrazarClickEnlace(\'56\',\'' + textToTraza + '\'); muestraWS(\'' + txtAMostrar + '\', \'' + params + '\');" style="cursor:pointer;">' + txtAMostrar + '</a><input id="input_' + txtAMostrar + '" type="hidden" value=""/><div id="' + txtAMostrar + '" style="display:none;">Cargando...<img src="'+urlStatic+'/imagenes_Navegar/cargando.gif"/></div>', categoria, sub_categoria, ''));
				}
			}											
		}
	}
	return rels_hl;
}
function getEnlacesDoctrinaOrdenados(rels_hl){
	rels_hl = rels_hl.sort(my_sortfunction);
	var prev 	 = "";
	var prev_sub = "";
	if (rels_hl.length > 0){
		prev 	 = rels_hl[0][1];
		prev_sub = rels_hl[0][2];
	}
	var enlaces_doct = new Array();
	var tmp = "<b>"+prev.capitalize()+"</b><br /> <UL>"+prev_sub.capitalize()+"<br /><br />";
	var entra = false;
	for (var i = 0; i < rels_hl.length; i++) {
		entra = true;
		if (prev == rels_hl[i][1] && prev_sub == rels_hl[i][2]) {
			tmp += "<li>" + rels_hl[i][0] + "</li>";
		}
		else 
			if (prev == rels_hl[i][1] && prev_sub != rels_hl[i][2]) {
				tmp += "</UL><br> <UL>"+rels_hl[i][2].capitalize()+"<br><li>" + rels_hl[i][0] + "</li>";
			}
			else {
				tmp += "</UL>";
				enlaces_doct.push(tmp);
				
				tmp = "<b>"+rels_hl[i][1].capitalize() + "</b><br /> <UL>" + rels_hl[i][2].capitalize()+"<br /><br />";
				tmp += "<li>" + rels_hl[i][0] + "</li>";
			}
		prev = rels_hl[i][1];
		prev_sub = rels_hl[i][2];
	}
	if(entra){
		tmp += "</UL>";
		enlaces_doct.push(tmp);
	}
	return enlaces_doct;
	
}
function getEnlacesDoctrina(nodo){
	var rels_hl = getEnlacesDoctrinaSinOrden(nodo);
	return getEnlacesDoctrinaOrdenados(rels_hl);
}

function my_sortfunctionJuri(a, b){
	if (a[1] > b[1]){
		return 1;
	}else if(a[1] < b[1]){
		return -1;
	}
	if (a[2] > b[2]){
		return 1;
	}else if(a[2] < b[2]){
		return -1;
	}
	if (a[4] < b[4]){
		return 1;
	}else if(a[4] > b[4]){
		return -1;
	}
	return 0;
}

function my_sortfunction(a, b){
	if (a[1] > b[1]){
		return 1;
	}else if(a[1] < b[1]){
		return -1;
	}
	return 0;
}

function my_sortfunction_p_ley(a, b){
	if (a[1] > b[1]) {
		return 1;
	}
	else 
		if (a[1] < b[1]) {
			return -1;
		}
		
	if (a[2] > b[2]) {
		return 1;
	}
	else {
		return -1;
	}
	return 0;
}

function my_sortfunction_categorias(a, b){
	if (a[1] == b[1]) {
	
		if (a[2] == b[2]) {
			return 0;
		}
		
		return (a[2] < b[2]) ? -1 : 1;
	}
	
	return (a[1] < b[1]) ? -1 : 1;
}

function my_sortfunction_relaciones_HL(a, b){
	// solo para Historia de la Ley
	var A_enlace = a[0].selectSingleNode('./HIPERVINCULO/ENLACE/text()');
	var A_informacion = a[0].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="informacion"]/text()');
	var A_categoria = a[0].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="categoria"]/text()');
	var B_enlace = b[0].selectSingleNode('./HIPERVINCULO/ENLACE/text()');
	var B_informacion = b[0].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="informacion"]/text()');
	var B_categoria = b[0].selectSingleNode('./HIPERVINCULO/GENERICOS/GENERICO[@tipo="categoria"]/text()');
	var A_pos = a[1];
	var B_pos = b[1];
	var A_txtAMostrar = "";
	var B_txtAMostrar = "";

	if (A_enlace && B_enlace) {
		if (A_enlace.nodeValue.indexOf(__GATO__) == 0) {
			A_enlace.nodeValue = A_enlace.nodeValue.substring(__GATO__.length);
		}
		if (B_enlace.nodeValue.indexOf(__GATO__) == 0) {
			B_enlace.nodeValue = B_enlace.nodeValue.substring(__GATO__.length);
		}
		var A_txtAMostrar = A_enlace.nodeValue;
		var B_txtAMostrar = B_enlace.nodeValue;
		if (A_informacion && B_informacion ) {
			A_txtAMostrar = A_informacion.nodeValue;
			B_txtAMostrar = B_informacion.nodeValue;
			if (A_txtAMostrar.indexOf(__GATO__) > -1) {
				A_txtAMostrar = replace(A_txtAMostrar, __GATO__, "");
			}
			if (B_txtAMostrar.indexOf(__GATO__) > -1) {
				B_txtAMostrar = replace(B_txtAMostrar, __GATO__, "");
			}
		}
	}	
	
	if (!A_categoria || !B_categoria){
		return 0;
	}
	var A_toCompare = A_categoria.nodeValue+"_"+A_pos+"_"+A_txtAMostrar;
	var B_toCompare = B_categoria.nodeValue+"_"+B_pos+"_"+B_txtAMostrar;

	if (A_toCompare && B_toCompare) {
		if (A_toCompare > B_toCompare) {
			return 1;
		}
		else 
			if (A_toCompare < B_toCompare) {
				return -1;
			}
	}
	return 0;
}

function toDocument(strXML) {
    var oDomDoc = Sarissa.getDomDocument();
    oDomDoc.async = false; 
    oDomDoc = (new DOMParser()).parseFromString(strXML, "text/xml");
    return oDomDoc;
}

function toXML(nodo) {
	var strXML = new XMLSerializer().serializeToString(nodo);
	return strXML;
}

function genericos(nodo) {
	var arrResultado = new Array();
    return arrResultado;
	var xpathExpr = "./METADATOS/GENERICOS/GENERICO";
	var nodos_genericos = nodo.selectNodes(xpathExpr);
	for(var i=0; i<nodos_genericos.length; i++) 
    {
		var tipo = nodos_genericos[i].selectSingleNode('./@tipo');
		tipo = tipo?tipo.nodeValue:null;
		for(var j=0; j < genericos_a_mostrar.length; j++) 
        {
			if(tipo == genericos_a_mostrar[j]) 
            {
				var valor = nodos_genericos[i].selectSingleNode('./text()');
				valor = valor?valor.nodeValue:'';
                
                var encontrado = false;
                for (var z=0; z<arrResultado.length; z++) 
                {
                    if (arrResultado[z][0] == tipo)
                    {
                        arrResultado[z][1] = arrResultado[z][1] + "; " + valor;
                        encontrado = true;
                    }
                }
                if (encontrado == false)                    
                {
                        var item = new Array(2);
                        item[0] = tipo;
                        item[1] = valor;
                        arrResultado.push(item);
                }
			}
		}
	}
    
    return arrResultado;
}


function getTipoVersion(nodo){
    var tipo = nodo.selectSingleNode("./@tipo_version");
    tipo = tipo ? tipo.nodeValue : '';
    if(tipo != "")
        tipo = tiposVersion.getItem(tipo);
	return tipo;
}


function selectMany(nodo, xpathExpr) {
	var elements = nodo.selectNodes(xpathExpr);
	var arrDatos = new Array();
	
	for(var i=0; i<elements.length; i++)
	{
		arrDatos.push(elements[i].nodeValue);
	}
	return arrDatos;
}
function preperaTexto(texto, html){
	if (html){
		texto = replace(texto,"  ","&nbsp;&nbsp;");
		texto = replace(texto,"\n","<br />");
	}
	texto = replace(texto,"|!|","");
	return texto;
}
function selectSingle(nodo, xpathExpr) {
	var element = nodo.selectSingleNode(xpathExpr);
	var dato = "";
	if (element)
	{
		dato = element.nodeValue;
	}
	return dato;
};


function vigencia(nodo) {
	
	var vigencia = new Array(4);
	var xpathExpr = "./VIGENCIA/@inicio_vigencia";
	var node_inicio_vigencia = nodo.selectSingleNode(xpathExpr);
	var valor = node_inicio_vigencia ? node_inicio_vigencia.nodeValue : "";
	//this.metadatos.setItem("inicio_vigencia", valor);	
	vigencia[0] = valor;
	
	xpathExpr = "./VIGENCIA/@fin_vigencia";
	var node_fin_vigencia = nodo.selectSingleNode(xpathExpr);
	valor = node_fin_vigencia ? node_fin_vigencia.nodeValue : "";
	//this.metadatos.setItem("fin_vigencia", valor);
	vigencia[1] = valor;
	
    xpathExpr = "./VIGENCIA/EVENTO_INICIO/text()";
    var node_evento_inicio = nodo.selectSingleNode(xpathExpr);
    valor = node_evento_inicio ? node_evento_inicio.nodeValue : "";
    //this.metadatos.setItem("fin_vigencia", valor);
    vigencia[2] = valor;
    
    xpathExpr = "./VIGENCIA/EVENTO_TERMINO/text()";
    var node_evento_fin = nodo.selectSingleNode(xpathExpr);
    valor = node_evento_fin ? node_evento_fin.nodeValue : "";
    //this.metadatos.setItem("fin_vigencia", valor);
    vigencia[3] = valor;
	
	return vigencia;
};

function cantidadesVinculaciones(nodo){
	var xpathExpr 		= "./CANTIDADES_VINCULACIONES/CANTIDAD";
	var cantidades 		= nodo.selectNodes(xpathExpr);
	var lista_cantidades= new Array();
	for(var i=0; i < cantidades.length;i++){
		var objCantidad = new Object();
		var tipo 	 = cantidades[i].selectSingleNode("@tipo");
		var cantidad = cantidades[i].selectSingleNode("./text()");

		objCantidad.tipo 	 = tipo?tipo.nodeValue:"";
		objCantidad.cantidad = cantidad?cantidad.nodeValue:"";
		objCantidad.cantidad = objCantidad.cantidad.replace("XX","");

		lista_cantidades.push(objCantidad);
	}
	return lista_cantidades;
}

function listaIdsVinc(nodo){
	var xpathExpr 		= ".//VINCULACION";
	var vinculaciones	= nodo.selectNodes(xpathExpr);
	var listaIds 		= new Array();
	var limiteVincs 	= 1000;
	
	for (var i = 0; i < vinculaciones.length && i < limiteVincs; i++) {
		listaIds.push(vinculaciones[i].selectSingleNode("./text()").nodeValue.replace("XX",""));
	}
	return listaIds;
}

function getMismaVersion(nodo,vigencias){
	var fecha_version = idVersion;
	var fecha = null;
	for(var i=0; i< vigencias.length; i++){
		var desde = vigencias[i].selectSingleNode("@desde");
		if (esMenorIgual(desde.nodeValue,fecha_version)){
			if (fecha != null){
				if (esMayorIgual(desde.nodeValue,fecha)){
					fecha  = desde.nodeValue;
				}
			}else{
				fecha = desde.nodeValue;
			}
		}
	}

	return fecha;
}

function vigencias(nodo,idVersion){
	var xpathExpr 		= "./VIGENCIAS/VERSION";
	var vigencias 		= nodo.selectNodes(xpathExpr);
	var lista_vigencias = new Array();
	var se_econtro_misma_version = false;
	var fechaMismaVersion = getMismaVersion(nodo,vigencias);
	
	for (var i = 0; i < vigencias.length; i++) {
		var vigencia = new Object();
		var desde = vigencias[i].selectSingleNode("@desde");
		var hasta = vigencias[i].selectSingleNode("@hasta");
		var tipo_version = vigencias[i].selectSingleNode("@tipo_version");
		
		vigencia.desde = desde ? desde.nodeValue : "";
		vigencia.hasta = hasta ? hasta.nodeValue : "";
		vigencia.tipo_version = tipo_version ? tipo_version.nodeValue : "";
		
		if (vigencia.desde == "2222-02-02") {
			var eventos = eventosInicio(nodo);
			if (eventos.length > 0) {
				vigencia.desdeStr = eventos.join("<br />");
			}
			else {
				vigencia.desdeStr = desde ? fechaLegis(vigencia.desde) : "";
			}
		}
		else {
			vigencia.desdeStr = desde ? fechaLegis(vigencia.desde) : "";
		}
		
		
		if (vigencia.hasta == '2222-02-01') {
			vigencia.hastaStr = '';
		}
		else {
			vigencia.hastaStr = hasta ? fechaLegis(vigencia.hasta) : "";
		}
		
		if (__TERMINO_AJAX_USUARIO_INTERMEDIA__) {
			if (!__USUARIO_PUEDE_VER_INTERMEDIAS__) {
				if (vigencia.tipo_version == INTERMEDIO) {
					continue;
				}
				else 
					if (vigencia.tipo_version == ORIGINAL) {
						vigencia.hastaStr = ""; //"<span id='_fecha_hasta_v_original_'>"+vigencia.hastaStr+"</span>";
					}
			}
		}
		
		vigencia.tipoVersionStr = tipo_version ? tiposVersion.getItem(vigencia.tipo_version) : "";
		
		if (fechaMismaVersion == vigencia.desde) {
			vigencia.misma_version = true;
			se_econtro_misma_version = true;
		}
		else {
			vigencia.misma_version = false;
		}
		lista_vigencias.push(vigencia);
	}
	if (!se_econtro_misma_version){
		lista_vigencias[lista_vigencias.length - 1].misma_version = true;
	}
	return lista_vigencias;
}
eventosInicio = function(nodo, estadoValue){
	if(typeof(estadoValue)=='undefined'){
		estadoValue = "pendiente";
	}
	var eventos = new Array();
	var eventos_inicio = nodo.selectNodes(".//EVENTO_INICIO");
	for (var j = 0; j < eventos_inicio.length; j++) {
		var evento_inicio = eventos_inicio[j];
		var estado = evento_inicio.selectSingleNode("@estado");
		if (estado && estado.nodeValue.indexOf(estadoValue) > -1) {
			if (evento_inicio.textContent && !(evento_inicio.textContent in oc(eventos))) {
				eventos.push(evento_inicio.textContent);
			}
		}
	}
	return eventos;
}
function resumenes(nodo) {
	var resumenes = new Array();
	var xpathExpr = "./METADATOS/RESUMENES/RESUMEN";
	var r = nodo.selectNodes(xpathExpr);
	for(var i=0; i<r.length; i++) {
		var texto = r[i].selectSingleNode('./text()');
		var idioma = r[i].getAttribute('idioma');
		texto = texto?texto.nodeValue:'';
		//idioma = tiposIdioma.getItem(idioma);
		resumenes.push(new Array(idioma, texto));
	}
	return resumenes;
};

function es_evento_inicio(nodo) {
    var v = vigencia(nodo);
    if (v[0]=='2222-02-02') {// Esta fecha de inicio de vigencia indica que es por evento 
        return true;
    }
    return false;
};
 

Nota = function(nodo){
	this.nodo = nodo;
	this.tipoNota = function (){
		var xpathExpr = "./@tipo_nota";
		var element = this.nodo.selectSingleNode(xpathExpr);
		var dato = "";
		if (element)
		{
			dato = element.nodeValue;
		}
		return dato;
	};
	this.texto = function(){
		var xpathExpr = "./text()";
		var element = this.nodo.selectSingleNode(xpathExpr);
		var dato = "";
		if (element)
		{
			dato = element.nodeValue;
		}
		return dato;
	};
};

ObjNotasMetas = function (nodo, path) {
	this.nodo = nodo;
	this.path  = path;
	this.__nodosNota = null;
	this._tipo_nota_bcn  = '0';
	this._tipo_nota_orig = '1';
	this.__getNodosNota= function (){
		if (this.__nodosNota != null){
			return this.__nodosNota;
		}
		var nodosNota = this.nodo.selectNodes(this.path+"ELEMENTOS_DEL_TEXTO//NOTA");
		this.__nodosNota = [];		
		for (var i=0; i < nodosNota.length; i++) {
			this.__nodosNota.push(new Nota(nodosNota[i]));
		}
		return this.__nodosNota;
	};
	this.getNotasBCN  = function (){
		var notas = this.__getNodosNota();
		var to_return = [];
		for (var i=0; i < notas.length; i++){
			if (notas[i].tipoNota() == this._tipo_nota_bcn){
				to_return.push(notas[i]);
			}
		}
		return to_return;
	};
	this.getNotasOriginales  = function (){
		var notas = this.__getNodosNota();
		var to_return = [];
		for (var i=0; i < notas.length; i++){
			if (notas[i].tipoNota() == this._tipo_nota_orig){
				to_return.push(notas[i]);
			}
		}
		return to_return;
	};
	this.getNotasPie  = function (){
	
	};
	
};

/*
 * Metadatos de la Norma
 *
 * TODO
 * Falta agregar el idioma que viene con los Resumenes
 * Falta Organizacion Tratado
*/

Norma = function(nodo) {
	this.nodo = nodo;
	this.Texto = function(html){
		if (typeof html == 'undefined'){
			html = true;		
		}
		var textos = selectMany(this.nodo,'.//TEXTO/text()');
		return preperaTexto(textos.join(""),html);
	}
    this.inicio_por_evento = es_evento_inicio(nodo);
    this.vigencia = null;
	
	// Agregado por David  (2007-01-07)
	// Obtiene el valor del atributo especificado
	// Si no existe, retorna vacio ("")
	this._getAttribute = function(attribute) {
		var xpathExpr = "./@"+attribute;
		var element = this.nodo.selectSingleNode(xpathExpr);
		var dato = "";
		if (element)
		{
			dato = element.nodeValue;
		}
		return dato
	};
	this.creaIdItemCache = function(){
		return this.getID_Norma()+"_0_"+this.vigente_desde();
	}
	this.vigente_desde = function (){
		return this._getAttribute("vigente_desde");
	};
	// esta funcion obtiene el id del tipo de parte del nodo
	this.getTipoParteID = function(){
		return 0;
	}
	this.nombreArchivoDescarga = function(){
		var tipos = this.getTiposNumeros();
		var nombre = "";
		for (var i = 0; i < tipos.length; i++) {
			if (nombre != "") {
				nombre += "; "+tipos[i][2] + "-" + tipos[i][1];
			}
			else {
				nombre += tipos[i][2] + "-" + tipos[i][1];
			}
		}
		nombre += "_"+fechaLegis(this.getFechaPublicacion());
		return nombre;
	}
	// esta funcion obtiene el id de la version del nodo
	this.getID_Version = function() {
		var xattribute = "id_version";
		return this._getAttribute(xattribute);
	};

	// esta funcion obtiene el id de la norma del nodo
	// sólo para este caso la funcion getID llama al Id de la Norma
	this.getID = function() {
		//var xattribute = "id_parte";
		var xattribute = "id_norma";
		return this._getAttribute(xattribute);
	};

	// esta funcion obtiene el id de la norma del nodo
	this.getID_Norma = function() {
		var xattribute = "id_norma";
		return this._getAttribute(xattribute);
	};
	
	/**
	 * esta funcion obtiene la fecha de Promulgacion de la norma
	 */
	this.getFechaPromulgacion = function (){
		var xattribute = "fecha_promulgacion";
		return this._getAttribute(xattribute);
	};
	/**
	 * esta funcion obtiene la fecha de inicio de vigencia de la norma
	 */
	this.getVigenteDesde = function (){
		var vigencia = this.getVigencia();
		return vigencia[0];
	};
	this.getEventoInicio = function (estadoValue){
		if (typeof(estadoValue) == 'undefined') {
			estadoValue = "pendiente";
		}
		var eventos = eventosInicio(this.nodo, estadoValue)
		return eventos.join("<br />");
	};
	this.getEventoTermino= function (){
		var vigencia = this.getVigencia();
		return vigencia[3];
	};
	this.getVigenteDesde = function (){
		var vigencia = this.getVigencia();
		return vigencia[0];
	};
	/**
	 * esta funcion obtiene la fecha de Fin de vigencia de la norma
	 */
	this.getVigenteHasta = function (){
		var vigencia = this.getVigencia();
		return vigencia[1];
	};

	this.getTituloArbol = function() {
		var tipos = "";
		var arrTipos = this.getTiposNumeros();
		for (var i=0; i<arrTipos.length; i++) {
			tipos += tiposNorma.getItem(arrTipos[i][0]) + " " + arrTipos[i][1];
		}
		return tipos;		
	};

	this.getAlertas = function() {
    	var a = new Alerta(this.nodo);
        return a.getAlertas();
    };
    
	this.getAlertasHTML = function (){
		return alertasHTML(this.getAlertas());
	}

	this.getAlertasHTMLNivelParte = function (){
		return alertasHTMLNivelParte(this.getAlertas());
	}
	
	
	this.buscaVersion = function(inicio_vigencia) {
        // Obtiene el tipo de version por el inicio de vigencia
        var tipo = "";
        var vigencias = this.nodo.selectNodes('./VIGENCIAS/VERSION');
        for(var i=0; i<vigencias.length; i++) 
        {
            var desde = vigencias[i].selectSingleNode('./@desde');
            desde = desde ? desde.nodeValue : '';
            if(desde == inicio_vigencia) 
            {
                tipo = vigencias[i].selectSingleNode('./@tipo_version');
                tipo = tipo ? tipo.nodeValue : '';
            }
        }
        return tipo;
    };

	this.getMetadatos = function() {
    	// Falta implementar
    };
    
	this.metadatosHtml = function() {
		metadatos = new Array();
		
		// Tipos Numeros
		/*var tipos = "";
		var arrTipos = this.getTiposNumeros();
		for (var i=0; i<arrTipos.length; i++) {
			tipos += tiposNorma.getItem(arrTipos[i][0]) + " " + arrTipos[i][1] + ";";
		}*/
		
		var atributos = this.getAtributos();
		
		//metadatos.push(new Array("<b>Tipo Numero:&nbsp;</b>", tipos));
		//metadatos.push(new Array("<b>Organismos:&nbsp;</b>", this.getOrganismos().join("; ")));
		//metadatos.push(new Array("<b>Fecha Publicacion:&nbsp;</b>", fechaLegis(this.getFechaPublicacion()) ));
		//metadatos.push(new Array("<b>Fecha Promulgacion:&nbsp;</b>", fechaLegis(atributos.getItem('fecha_promulgacion')) ));

		metadatos.push(new Array("<b>Titulo Norma:&nbsp;</b>", this.getTituloNorma(),									'tituloNorma', 			'atributosNorma'));
		metadatos.push(new Array("<b>Identificacion Fuente:&nbsp;</b>", this.getFuente(),								'identificacionFuente', 'atributosNorma'));
		metadatos.push(new Array("<b>Numero Fuente:&nbsp;</b>", atributos.getItem('numero_fuente'),						'identificacionFuente', 'atributosNorma'));

		metadatos.push(new Array("<b>Fecha Derogacion:&nbsp;</b>", fechaLegis(atributos.getItem('fecha_derogacion')) , 	'fechaDerogacion', 		'fechas'));

		metadatos.push(new Array("<b>Numero Bcn:&nbsp;</b>", atributos.getItem('numero_bcn'), 							'nroBcn', 				'identificadores'));
		// Resumenes
		var res = this.getResumenes();
		var htmlResumenes = "";
		for(var i=0; i<res.length; i++) {
			var idioma = res[i][0];
			var texto = res[i][1];
			
			htmlResumenes += '<table border="0" style="font-size:11px;">';
			htmlResumenes += '<tr><td valign="top">'+idioma+'-'+'</td><td>'+texto+'</td></tr>';
			htmlResumenes += '</table>';
		}
		metadatos.push(new Array("<b>Resumenes:&nbsp;</b>", htmlResumenes));
		metadatos.push(new Array("<b>Materias:&nbsp;</b>", this.getMaterias().join("; ")));
		metadatos.push(new Array("<b>Terminos Libres:&nbsp;</b>", this.getTerminosLibres().join("; ")));
		metadatos.push(new Array("<b>Categoria Norma:&nbsp;</b>", this.getCategoriasNormas().join("; ")));
		metadatos.push(new Array("<b>Nombre Uso Comun:&nbsp;</b>", this.getNombresUsoComun().join("; ")));
		metadatos.push(new Array("<b>Paises Tratados:&nbsp;</b>", this.getPaisesTratados().join("; ")));
		metadatos.push(new Array("<b>Observaciones:&nbsp;</b>", this.getObservaciones().join("; ")));
		metadatos.push(new Array("<b>Fecha Version:&nbsp;</b>", fechaLegis(atributos.getItem('fecha_version')) ));
        // Si el inicio de vigencia es por Evento la fecha inicio Vigencia queda vacio
        var fechaInicioVigencia = "";
        if (!this.inicio_por_evento) {
            fechaInicioVigencia = fechaLegis(this.getVigencia()[0]);
        } 
        else {
            // El inicio de Vigencia es por Evento
            fechaInicioVigencia = this.getVigencia()[2];
        }
		metadatos.push(new Array("<b>Inicio Vigencia:&nbsp;</b>", fechaInicioVigencia));
		metadatos.push(new Array("<b>Fin Vigencia:&nbsp;</b>", fechaLegis(this.getVigencia()[1])));
		metadatos.push(new Array("<b>Fecha ultima modificacion:&nbsp;</b>", fechaLegis(atributos.getItem('fecha_ultima_modificacion')) ));
		metadatos.push(new Array("<b>Derogado:&nbsp;</b>", atributos.getItem('derogado')));						
		//metadatos.push(new Array("<b>Refundido:&nbsp;</b>", atributos.getItem('refundido')));						
		metadatos.push(new Array("<b>id norma:&nbsp;</b>", this.getID()));		
		metadatos.push(new Array("<b>Organismos Tratados:&nbsp;</b>", this.getOrganismosTratados()));				
		metadatos.push(new Array("<b>Otra Fuente:&nbsp;</b>", this.getOtraFuente()));				
		metadatos.push(new Array("<b>Fecha Tratado:&nbsp;</b>", atributos.getItem('fecha_tratado')));				
		metadatos.push(new Array("<b>Estado Produccion:&nbsp;</b>", tiposEP.getItem(atributos.getItem('estado_produccion'))));				
		metadatos.push(new Array("<b>Refundido por:&nbsp;</b>", this.getRefundido_por()));				
		metadatos.push(new Array("<b>Refunde a:&nbsp;</b>", this.getRefunde_a()));				
    	metadatos.push(new Array("<b>Tipo Version:&nbsp;</b>", this.getTipoVersion()));				
        metadatos.push(new Array("<b>Evento Pendiente:&nbsp;</b>", this.tieneEventoPendiente()));             
		
		// Se agregan los Genericos
		var genericos = this.getGenericos();
		for (var i =0; i<genericos.length; i++) {
			metadatos.push(new Array("<b>"+genericos[i][0]+":&nbsp;</b>", genericos[i][1]));
		}
		var tabla = tabla_metadatos(metadatos);
		return tabla;
	};
    
	this.getTipoVersion = function() {
        return getTipoVersion(this.nodo);
    };
    
	this.getTipoVersionNum = function() {
        var tipo = this.nodo.selectSingleNode("./@tipo_version");
        tipo = tipo ? tipo.nodeValue : '';
        return tipo;
    };

	this.getEnlacesHL = function() {
		return getEnlacesHL(this.nodo);
	};

	this.getEnlacesOS = function() {
		return getEnlacesOS(this.nodo);
	};

	this.getEnlacesProyectos = function() {
		return getEnlacesProyectos(this.nodo);
	};

	this.getEnlacesJurisprudencia = function() {
		return getEnlacesJurisprudencia(this.nodo);
	};
	
	this.getEnlacesDoctrina = function() {
		return getEnlacesDoctrina(this.nodo);
	};
	
	this.getNombre = function(nodo) {
		return this.nodo.tagName;
	};
	
	this.getGenericos = function() {
		return genericos(this.nodo);
	};

	this.estaEliminada = function() {
    // Retorna True o False si esta eliminada
		var element = this.nodo.selectSingleNode('./@estado');
		if (element)
		{
			var eliminada = element.nodeValue;
			if (eliminada == '1')
				return true;
		}
		return false

    };
	
	this.estaMovida = function() {
    // Retorna True o False si esta movida
		var element = this.nodo.selectSingleNode('./@estado');
		if (element)
		{
			var movida = element.nodeValue;
			if (movida == '2')
				return true;
		}
		return false
    }   ;
	this.movido_de = function (){
		var element = this.nodo.selectSingleNode('./@movido_de');
		if (element)
		{
			var movido_de = element.nodeValue;
			return movido_de;
		}
		return "";
	};
	
	this.movido_a = function (){
		var element = this.nodo.selectSingleNode('./@movido_a');
		if (element)
		{
			var movido_a = element.nodeValue;
			return movido_a;
		}
		return "";
	};
	this.getAtributos = function() {
		// Tomar los atributos de la Norma
		
		var atributos = new Dict();
		
		var attrs = this.nodo.attributes;
		for(var i=0; i < attrs.length; i++) 
		{		
			var attr = attrs[i];
			switch (attr.name)
			{
				case "id_norma":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "fecha_promulgacion":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "identificacion_fuente":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "numero_bcn":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "numero_fuente":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "fecha_derogacion":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "fecha_version":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "fecha_ultima_modificacion":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "refundido":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "derogado":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "estado_produccion":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "fecha_tratado":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "tipo_version":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
			}			
		}
		return atributos;
	};

	this.getXML = function() {
		return toXML(this.nodo);
	};
	
	this.getDoc = function() {
		return toDocument(this.getXML());
	};

	this.getTiposNumeros = function() {
		// Tomar los TIPOS_NUMEROS
		var xpathExpr = "./IDENTIFICADOR/TIPOS_NUMEROS/TIPO_NUMERO";
		var tiposNumerosElements = this.nodo.selectNodes(xpathExpr);
		var arrTiposNumeros = new Array();
		
		for(var i=0; i < tiposNumerosElements.length; i++) 
		{
			var tipo 	= tiposNumerosElements[i].selectSingleNode('./TIPO/text()');
			var numero 	= tiposNumerosElements[i].selectSingleNode('./NUMERO/text()');
			var abbr 	= tiposNumerosElements[i].selectSingleNode('./ABREVIACION/text()');
			tipo 		= tipo ? tipo.nodeValue : '';
			numero 		= numero ? numero.nodeValue : '';
			abbr 		= abbr ? abbr.nodeValue : '';
			
			var tpArray = new Array(2);
			tpArray[0] = tipo;
			tpArray[1] = numero;
			tpArray[2] = abbr;
			
			arrTiposNumeros.push(tpArray);
		}
		return arrTiposNumeros;
	};

	this.getOrganismos = function() {
		var xpathExpr = "./IDENTIFICADOR/ORGANISMOS/ORGANISMO/text()";
		return selectMany(this.nodo, xpathExpr);
	};
	
	this.getRefunde_a = function() {
		var xpathExpr = "./@refunde_a";
		return selectSingle(this.nodo, xpathExpr);
	};
	
	this.getRefundido_por = function() {
		var xpathExpr = "./@refundido_por";
		return selectSingle(this.nodo, xpathExpr);
	};
	
	this.getOrganismosTratados = function() {
		var xpathExpr = "./METADATOS/ORGANISMOS_TRATADOS/ORGANISMO_TRATADO/text()";
		return selectMany(this.nodo, xpathExpr);
	};
	
	this.getFechaPublicacion = function() {
		var xpathExpr = "./IDENTIFICADOR/@fecha_publicacion";
		return selectSingle(this.nodo, xpathExpr);
	};

	this.getTituloNorma = function() {
		var xpathExpr = "./METADATOS/TITULO_NORMA/text()";
		return selectSingle(this.nodo, xpathExpr);
	};

	this.getOtraFuente = function() {
		var xpathExpr = "./METADATOS/OTRA_FUENTE/text()";
		return selectSingle(this.nodo, xpathExpr);
	};
    
	this.getFuente = function() {
        var xpathExpr = "./METADATOS/FUENTE/text()";
        return selectSingle(this.nodo, xpathExpr);
    };

	this.getResumenes = function() {
		return resumenes(this.nodo);
	};

	this.getMaterias = function() {
		var xpathExpr = "./METADATOS/MATERIAS/MATERIA/text()";
		return selectMany(this.nodo, xpathExpr);
	};

	this.getTerminosLibres = function() {
		var xpathExpr = "./METADATOS/TERMINOS_LIBRES/TERMINO_LIBRE/text()";
		return selectMany(this.nodo, xpathExpr);
	};

	this.getCategoriasNormas = function() {
		var xpathExpr = "./METADATOS/CATEGORIAS_NORMA/CATEGORIA_NORMA/text()";
		return selectMany(nodo, xpathExpr);
	};

	this.getNombresUsoComun = function() {
		var xpathExpr = "./METADATOS/NOMBRES_USO_COMUN/NOMBRE_USO_COMUN/text()";
		return selectMany(this.nodo, xpathExpr);
	};

	this.getFechaUltimaModificacion= function() {
        var fecha = this.nodo.getAttribute('fecha_ultima_modificacion');
        return fecha;
    };
    
	this.getPaisesTratados = function() {
		var xpathExpr = "./METADATOS/PAISES_TRATADOS/PAIS_TRATADO/text()";
		return selectMany(this.nodo, xpathExpr);
	};

	this.getObservaciones = function() {
		var xpathExpr = "./METADATOS/OBSERVACIONES/OBSERVACION/text()";
		return selectMany(this.nodo, xpathExpr);
	};

	this.getPoliticas = function() {
		var xpathExpr = "./POLITICAS/POLITICA/text()";
		return selectMany(this.nodo, xpathExpr);
	};

	this.getVigencia = function() {
		if(this.vigencia){
			return this.vigencia;
		}
		this.vigencia = vigencia(this.nodo);
		return this.vigencia;
	};
	
	this.getVigencias = function(idVersion) {
		return vigencias(this.nodo,idVersion);
	};
	
	this.getCantidadesVinculaciones = function(){
		return cantidadesVinculaciones(this.nodo);
	}
	
	this.getListaIdsVinc = function(){
		return listaIdsVinc(this.nodo);
	}
	this.getInicioVigencia = function (){
		var vigencia = this.getVigencia();
		return vigencia[0];
	};
	
	this.getTitulo = function() {
		var titulo = "";
		
		var xpathExpr = "./METADATOS/TITULO_NORMA/text()";
		var element = this.nodo.selectSingleNode(xpathExpr);
		var tituloParte = "";
		if (element)
		{
			tituloParte = element.nodeValue;
		}
		return tituloParte;
	};
    
	this.tieneEventoPendiente = function() {
        var xpathExpr = "./@evento_pendiente/text()";
        return selectSingle(this.nodo, xpathExpr);
    };

};

/*
 * Metadatos del Encabezado
 * TODO
 * Falta 'otra numeracion' (de donde se saca?)
 * 
*/
Encabezado = function(nodo) {
	this.nodo = nodo;
	this.inicio_por_evento = es_evento_inicio(nodo);
	this.objNotas = null;
	this.__checkObjNotas = function(){
		if (this.objNotas == null){
			this.objNotas = new ObjNotasMetas(this.nodo, './TEXTO_ENCABEZADO/');
		}
	}
	this.getNotasBCN = function(){
		this.__checkObjNotas();
		return this.objNotas.getNotasBCN();
	}
	this.getNotasOriginales = function(){
		this.__checkObjNotas();
		return this.objNotas.getNotasOriginales();
	}
	this.getNotasPie = function(){
		this.__checkObjNotas();
		return this.objNotas.getNotasPie();
	}
	this.Texto = function(html){
		if (typeof html == 'undefined'){
			html = true;		
		}
		var textos = selectMany(this.nodo,'.//TEXTO/text()');
		return preperaTexto(textos.join(""),html);
	}
	// Agregado por David  (2007-01-07)
	// Obtiene el valor del atributo especificado
	// Si no existe, retorna vacio ("")
	this._getAttribute = function(attribute) {
		var xpathExpr = "./@"+attribute;
		var element = this.nodo.selectSingleNode(xpathExpr);
		var dato = "";
		if (element)
		{
			dato = element.nodeValue;
		}
		return dato
	}	;
	this.creaIdItemCache = function(){
		return this.getID_Norma()+"_"+this.getID()+"_"+this.vigente_desde();
	}
	this.vigente_desde = function (){
		return this._getAttribute("vigente_desde");
	};
	// esta funcion obtiene el id del tipo de parte del nodo
	this.getTipoParteID = function(){
		return 10;
	}
	
	// esta funcion obtiene el id de la version del nodo
	this.getID_Version = function() {
		var xattribute = "id_version";
		return this._getAttribute(xattribute);
	};

	// esta funcion obtiene el id de la parte del nodo
	this.getID = function() {
		var xattribute = "id_parte";
		return this._getAttribute(xattribute);
	};

	// esta funcion obtiene el id de la norma del nodo
	this.getID_Norma = function() {
		var xattribute = "id_norma";
		return this._getAttribute(xattribute);
	};
	
	this.getTituloArbol = function() {
		return this.getNombre();
	};
	
    this.getAlertas = function() {
    	a = new Alerta(this.nodo);
        return a.getAlertas();
    };
	this.getAlertasHTMLNivelParte = function (){
		return alertasHTMLNivelParte(this.getAlertas());
	}

	this.getMetadatos = function() {
	};
	
	this.metadatosHtml = function() {
		metadatos = new Array();
		var atributos = this.getAtributos();
		
		metadatos.push(new Array("<b>Tipo:&nbsp;</b>", 'Encabezado'));
		metadatos.push(new Array("<b>Fecha Version:&nbsp;</b>", fechaLegis(this.getAtributos().getItem('fecha_version')) ));
		metadatos.push(new Array("<b>Fecha Derogacion:&nbsp;</b>", fechaLegis(this.getAtributos().getItem('fecha_derogacion')) ));
        // Si el inicio de vigencia es por Evento la fecha inicio Vigencia queda vacio
        var fechaInicioVigencia = "";
        if (!this.inicio_por_evento) {
            fechaInicioVigencia = fechaLegis(this.getVigencia()[0]);
        } 
        else {
            // El inicio de Vigencia es por Evento
            fechaInicioVigencia = this.getVigencia()[2];
        }

		metadatos.push(new Array("<b>Inicio Vigencia:&nbsp;</b>", fechaInicioVigencia));
		metadatos.push(new Array("<b>Fin Vigencia:&nbsp;</b>", fechaLegis(this.getVigencia()[1])) );
		metadatos.push(new Array("<b>Observaciones:&nbsp;</b>", this.getObservaciones().join("; ")));
		//metadatos.push(new Array("<b>Secuencia:&nbsp;</b>", this.getAtributos().getItem('secuencia')));
		metadatos.push(new Array("<b>Id parte:&nbsp;</b>", this.getID()));						
		metadatos.push(new Array("<b>Fecha ultima modificacion:&nbsp;</b>", fechaLegis(atributos.getItem('fecha_ultima_modificacion')) ));
		metadatos.push(new Array("<b>Refundido por:&nbsp;</b>", this.getRefundido_por()));				
		metadatos.push(new Array("<b>Refunde a:&nbsp;</b>", this.getRefunde_a()));	
		metadatos.push(new Array("<b>Estado Produccion:&nbsp;</b>", tiposEP.getItem(atributos.getItem('estado_produccion'))));							
		metadatos.push(new Array("<b>Derogado:&nbsp;</b>", atributos.getItem('derogado')));						
    	metadatos.push(new Array("<b>Tipo Version:&nbsp;</b>", this.getTipoVersion()));		
        metadatos.push(new Array("<b>Evento Pendiente:&nbsp;</b>", this.tieneEventoPendiente()));		

		// Se agregan los Genericos
		var genericos = this.getGenericos();
		for (var i =0; i<genericos.length; i++) {
			metadatos.push(new Array("<b>"+genericos[i][0]+":&nbsp;</b>", genericos[i][1]));
		}
		var tabla = tabla_metadatos(metadatos);
		return tabla;
	};
	
	this.getEnlacesHL = function() {
		return getEnlacesHL(this.nodo);
	};

    this.getTipoVersion = function() {
        return getTipoVersion(this.nodo)
    };

	this.getEnlacesOS = function() {
		return getEnlacesOS(this.nodo);
	};
	this.getEnlacesProyectos = function() {
		return getEnlacesProyectos(this.nodo);
	};
	this.getEnlacesJurisprudencia = function() {
		return getEnlacesJurisprudencia(this.nodo);
	};
	
	this.getEnlacesDoctrina = function() {
		return getEnlacesDoctrina(this.nodo);
	};

	this.getNombre = function(nodo) {
		return this.nodo.tagName;
	};
	
    this.estaEliminada = function() {
    // Retorna True o False si esta eliminada
        if (this.getTipoVersion() == 'eliminada')
            return true;
        return false;
    };
	this.estaMovida = function() {
		return false
    }  ;
	this.movido_de = function (){
		var element = this.nodo.selectSingleNode('./@movido_de');
		if (element)
		{
			var movido_de = element.nodeValue;
			return movido_de;
		}
		return "";
	};
	
	this.movido_a = function (){
		var element = this.nodo.selectSingleNode('./@movido_a');
		if (element)
		{
			var movido_a = element.nodeValue;
			return movido_a;
		}
		return "";
	};

	this.getAtributos = function() {
		// Tomar los atributos de la Norma
		
		var attrs = this.nodo.attributes;
		var atributos = new Dict();
		
		for(var i=0; i < attrs.length; i++) 
		{		
			var attr = attrs[i];
			switch (attr.name)
			{
				case "id_parte":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "fecha_derogacion":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "fecha_version":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "secuencia":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "fecha_ultima_modificacion":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "estado_produccion":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "derogado":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "tipo_version":
					atributos.setItem(attr.name, attr.nodeValue);
					break;

			}			
		}
		return atributos;
	};


	this.getXML = function() {
		return toXML(this.nodo);
	};
	
	this.getDoc = function() {
		return toDocument(this.getXML());
	};

	this.getRefunde_a = function() {
		var xpathExpr = "./@refunde_a/text()";
		return selectSingle(this.nodo, xpathExpr);
	};
	
	this.getRefundido_por = function() {
		var xpathExpr = "./@refundido_por/text()";
		return selectSingle(this.nodo, xpathExpr);
	};

	this.getGenericos = function() {
		return genericos(this.nodo);
	};
	
	this.getObservaciones = function() {
		var xpathExpr = "./OBSERVACIONES/OBSERVACION/text()";
		return selectMany(this.nodo, xpathExpr);
	};

    this.getFechaUltimaModificacion= function() {
        var fecha = this.nodo.getAttribute('fecha_ultima_modificacion');
        return fecha;
    };

	this.getPoliticas = function() {
		var xpathExpr = "./POLITICAS/POLITICA/text()";
		return selectMany(this.nodo, xpathExpr);
	};

	this.getVigencia = function() {
		return vigencia(this.nodo);
	};

	this.getVigencias = function(idVersion) {
		return vigencias(this.nodo,idVersion);
	};
	this.getCantidadesVinculaciones = function(){
		return cantidadesVinculaciones(this.nodo);
	}
	this.getListaIdsVinc = function(){
		return listaIdsVinc(this.nodo);
	}

    this.getInicioVigencia = function (){
		var vigencia = this.getVigencia();
		return vigencia[0];
	};
    this.tieneEventoPendiente = function() {
        var xpathExpr = "./@evento_pendiente/text()";
        return selectSingle(this.nodo, xpathExpr);
    };


};


/*
 * Metadatos de la Estructura Funcional
 * TODO
 * 
 * 
*/

EstructuraFuncional = function(nodo) {
	this.nodo = nodo;
	this.objNotas = null;
	this.__checkObjNotas = function(){
		if (this.objNotas == null){
			this.objNotas = new ObjNotasMetas(this.nodo, './TEXTO_PARTE/');
		}
	}
	this.getNotasBCN = function(){
		this.__checkObjNotas();
		return this.objNotas.getNotasBCN();
	}
	this.getNotasOriginales = function(){
		this.__checkObjNotas();
		return this.objNotas.getNotasOriginales();
	}
	this.getNotasPie = function(){
		this.__checkObjNotas();
		return this.objNotas.getNotasPie();
	}
	this.Texto = function(html){
		if (typeof html == 'undefined'){
			html = true;		
		}
		var textos = selectMany(this.nodo,'./TEXTO_PARTE/TEXTOS//TEXTO/text()');
		return preperaTexto(textos.join(""),html);
	}
	this.inicio_por_evento = es_evento_inicio(nodo);
	__tiene_estructuras_func__ = true;
	// Agregado por David  (2007-01-07)
	// Obtiene el valor del atributo especificado
	// Si no existe, retorna vacio ("")
	this._getAttribute = function(attribute) {
		var xpathExpr = "./@"+attribute;
		var element = this.nodo.selectSingleNode(xpathExpr);
		var dato = "";
		if (element)
		{
			dato = element.nodeValue;
		}
		return dato
	}	;
	this.creaIdItemCache = function(){
		return this.getID_Norma()+"_"+this.getID()+"_"+this.vigente_desde();
	}
	this.vigente_desde = function (){
		return this._getAttribute("vigente_desde");
	};
	// esta funcion obtiene el id del tipo de parte del nodo
	this.getTipoParteID = function(){
		return this._getAttribute("tipo_parte");
	}
	
	// esta funcion obtiene el id de la version del nodo
	this.getID_Version = function() {
		var xattribute = "id_version";
		return this._getAttribute(xattribute);
	};

	// esta funcion obtiene el id de la parte del nodo
	this.getID = function() {
		var xattribute = "id_parte";
		return this._getAttribute(xattribute);
	};

	// esta funcion obtiene el id de la norma del nodo
	this.getID_Norma = function() {
		var xattribute = "id_norma";
		return this._getAttribute(xattribute);
	};
	// esta funcion obtiene el atributo "transitorio" de la EF ("transitorio", "no transitorio")
	this.getTransitorio = function (){
		var xattribute = "transitorio";
		return this._getAttribute(xattribute);
	};
	
	this.getTituloArbol = function() {
		var tituloArbol = "";
		var titulo = this.getTitulo();
		var tipoParte = this.getTipoParte();
        var atributos = this.getAtributos();
        var numero_parte = atributos.getItem('numero_parte');
        var doble_articulado = atributos.getItem('doble_articulado');
		
		if ((doble_articulado || this.getTipoParte() != "Articulo") && titulo) { // El titulo se aplica solo para las partes distintas de articulo o que sean doble articulado
			tituloArbol = titulo.replace('\n', ' ');
		}
		else {
			//Concatenar   trim(concatenación(numero,” “,otra_numeracion))
			tituloArbol += tipoParte;
			tituloArbol += " " + numero_parte;
			var otraNum = this.getAtributos().getItem('otra_numeracion');
			tituloArbol += " " + otraNum;
			tituloArbol = trim(tituloArbol);
			//+ [Transitorio] para todos.
			//Cambio segun mail de solange, 10 de sept 2008
			//Solo para Articulo
			var transitorio = this.getTransitorio();
			if (transitorio == "transitorio"){
				tituloArbol += " " + "Transitorio";
			}			
		}

		return tituloArbol;
	};
	this.getAlertas = function() {
    	a = new Alerta(this.nodo);
        return a.getAlertas();
    };
	this.getAlertasHTMLNivelParte = function (){
		return alertasHTMLNivelParte(this.getAlertas());
	}
    
	this.getMetadatos = function() {
    };
	
	this.metadatosHtml = function() {
		var metadatos = new Array();
		var atributos = this.getAtributos();
		
		metadatos.push(new Array("<b>Tipo:&nbsp;</b>", this.getTipoParte()));
		metadatos.push(new Array("<b>Numero:&nbsp;</b>", atributos.getItem('numero_parte')));
		metadatos.push(new Array("<b>Titulo:&nbsp;</b>", this.getTitulo()));
		metadatos.push(new Array("<b>Fecha Version:&nbsp;</b>", fechaLegis(atributos.getItem('fecha_version')) ));
		metadatos.push(new Array("<b>Fecha Derogacion:&nbsp;</b>", fechaLegis(atributos.getItem('fecha_derogacion')) ));
        // Si el inicio de vigencia es por Evento la fecha inicio Vigencia queda vacio
        var fechaInicioVigencia = "";
        if (!this.inicio_por_evento) {
            fechaInicioVigencia = fechaLegis(this.getVigencia()[0]);
        } 
        else {
            // El inicio de Vigencia es por Evento
            fechaInicioVigencia = this.getVigencia()[2];
        }

		metadatos.push(new Array("<b>Inicio Vigencia:&nbsp;</b>", fechaInicioVigencia));
		metadatos.push(new Array("<b>Fin Vigencia:&nbsp;</b>", fechaLegis(this.getVigencia()[1])));
		metadatos.push(new Array("<b>Materias:&nbsp;</b>", this.getMaterias().join("; ")));
		metadatos.push(new Array("<b>Terminos Libres:&nbsp;</b>", this.getTerminosLibres().join("; ")));
		metadatos.push(new Array("<b>Nombre Uso Comun:&nbsp;</b>", this.getNombresUsoComun().join("; ")));
		metadatos.push(new Array("<b>Observaciones:&nbsp;</b>", this.getObservaciones().join("; ")));
		metadatos.push(new Array("<b>Secuencia:&nbsp;</b>", atributos.getItem('secuencia')));
		metadatos.push(new Array("<b>Id parte:&nbsp;</b>", this.getID()));
		metadatos.push(new Array("<b>Fecha ultima modificacion:&nbsp;</b>", fechaLegis(atributos.getItem('fecha_ultima_modificacion')) ));
		metadatos.push(new Array("<b>Otra Numeracion:&nbsp;</b>", fechaLegis(atributos.getItem('otra_numeracion')) ));
		metadatos.push(new Array("<b>Nombre Parte:&nbsp;</b>", this.getNombreParte()));
		metadatos.push(new Array("<b>Refundido por:&nbsp;</b>", this.getRefundido_por()));				
		metadatos.push(new Array("<b>Refunde a:&nbsp;</b>", this.getRefunde_a()));	
		metadatos.push(new Array("<b>Estado Produccion:&nbsp;</b>", tiposEP.getItem(atributos.getItem('estado_produccion'))));							
	    metadatos.push(new Array("<b>Transitorio:&nbsp;</b>", atributos.getItem('transitorio')));							
   	    metadatos.push(new Array("<b>Derogado:&nbsp;</b>", atributos.getItem('derogado')));							
   	    metadatos.push(new Array("<b>Tipo Version:&nbsp;</b>", this.getTipoVersion()));	
        metadatos.push(new Array("<b>Evento Pendiente:&nbsp;</b>", this.tieneEventoPendiente()));             						

		// Se agregan los Genericos
		var genericos = this.getGenericos();
		for (var i =0; i<genericos.length; i++) {
			metadatos.push(new Array("<b>"+genericos[i][0]+":&nbsp;</b>", genericos[i][1]));
		}							
		var tabla = tabla_metadatos(metadatos);
		return tabla;
	};

	this.getEnlacesHL = function() {
		return getEnlacesHL(this.nodo);
	};

	this.getTipoVersion = function() {
        return getTipoVersion(this.nodo)
    };

	this.getEnlacesOS = function() {
		return getEnlacesOS(this.nodo);
	};
	this.getEnlacesProyectos = function() {
		return getEnlacesProyectos(this.nodo);
	};
	this.getEnlacesJurisprudencia = function() {
		return getEnlacesJurisprudencia(this.nodo);
	};
	
	this.getEnlacesDoctrina = function() {
		return getEnlacesDoctrina(this.nodo);
	};
	this.getEventoInicio = function (estadoValue){
		if (typeof(estadoValue) == 'undefined') {
			estadoValue = "pendiente";
		}
		var eventos = eventosInicio(this.nodo, estadoValue)
		return eventos.join("<br />");
	};

	
	this.getAtributos = function() {
		var attrs = this.nodo.attributes;
		var atributos = new Dict();
		for(var i=0; i < attrs.length; i++) 
		{		
			var attr = attrs[i];
			switch (attr.name)
			{
				case "id_parte":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "fecha_derogacion":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "fecha_version":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "numero_parte":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "secuencia":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "otra_numeracion":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "nombre_parte":	
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "fecha_ultima_modificacion":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "estado_produccion":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "transitorio":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "derogado":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "tipo_version":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
                case "doble_articulado":
                    atributos.setItem(attr.name, attr.nodeValue);
                    break;
			}			
		}
		return atributos
	};

	this.getXML = function() {
		return toXML(this.nodo);
	};
	
	this.getDoc = function() {
		return toDocument(this.getXML());
	};

	this.estaEliminada = function() {
		var element = this.nodo.selectSingleNode('./@estado');
		//alert(element);
		if (element)
		{
			var eliminada = element.nodeValue;
			//alert("eliminada");
			if (eliminada == '1')
				return true;
		}
		return false    
	};
	
	this.estaMovida = function() {
    // Retorna True o False si esta movida
		var element = this.nodo.selectSingleNode('./@estado');

		if (element)
		{
			var movida = element.nodeValue;
			if (movida == '2') {
				return true;
			}
		}
		return false
    }   ;
	
	this.movido_de = function (){
		var element = this.nodo.selectSingleNode('./@movido_de');
		if (element)
		{
			var movido_de = element.nodeValue;
			return movido_de;
		}
		return "";
	};
	
	this.movido_a = function (){
		var element = this.nodo.selectSingleNode('./@movido_a');
		if (element)
		{
			var movido_a = element.nodeValue;
			return movido_a;
		}
		return "";
	};
	
	this.getNombreParte = function() {
		var xpathExpr = "./@nombre_parte";
		var element = this.nodo.selectSingleNode(xpathExpr);
		var dato = "";
		if (element)
		{
			dato = element.nodeValue;
		}
		return dato;
	};
	
	this.getNombre = function(nodo) {
		return this.nodo.tagName;
	};
	
	this.getRefunde_a = function() {
		var xpathExpr = "./@refunde_a/text()";
		return selectSingle(this.nodo, xpathExpr);
	};
	
	this.getRefundido_por = function() {
		var xpathExpr = "./@refundido_por/text()";
		return selectSingle(this.nodo, xpathExpr);
	};

	this.getTipoParte = function() {
		var xpathExpr = "./@tipo_parte";
		var element = this.nodo.selectSingleNode(xpathExpr);
		var dato = "";
		if (element)
		{
			dato = tiposEF.getItem(element.nodeValue)
		}
		return dato
	};
	
	this.getTipoParteNum  = function() {
        var xpathExpr = "./@tipo_parte";
        var element = this.nodo.selectSingleNode(xpathExpr);
        return element.nodeValue;
    
    };
    
	this.getTitulo = function() {
		var titulo = "";
		
		var xpathExpr = "./METADATOS/TITULO_PARTE/text()";
		var element = this.nodo.selectSingleNode(xpathExpr);
		var tituloParte = "";
		if (element)
		{
			tituloParte = element.nodeValue;
		}
		return tituloParte;
	};

	this.getObservaciones = function() {
		var xpathExpr = "./METADATOS/OBSERVACIONES/OBSERVACION/text()";
		return selectMany(this.nodo, xpathExpr);
	};

	this.getMaterias = function() {
		var xpathExpr = "./METADATOS/MATERIAS/MATERIA/text()";
		return selectMany(this.nodo, xpathExpr);
	};

	this.getTerminosLibres = function() {
		var xpathExpr = "./METADATOS/TERMINOS_LIBRES/TERMINO_LIBRE/text()";
		return selectMany(this.nodo, xpathExpr);
	};

	this.getFechaUltimaModificacion= function() {
        var fecha = this.nodo.getAttribute('fecha_ultima_modificacion');
        return fecha;
    };

	this.getNombresUsoComun = function() {
		var xpathExpr = "./METADATOS/NOMBRES_USO_COMUN/NOMBRE_USO_COMUN/text()";
		return selectMany(this.nodo, xpathExpr);
	};

	this.getPoliticas = function() {
		var xpathExpr = "./POLITICAS/POLITICA/text()";
		return selectMany(this.nodo, xpathExpr);
	};

	this.getVigencia = function() {
		return vigencia(this.nodo);
	};

	this.getVigencias = function(idVersion) {
		return vigencias(this.nodo,idVersion);
	};
	this.getCantidadesVinculaciones = function(){
		return cantidadesVinculaciones(this.nodo);
	}
	this.getListaIdsVinc = function(){
		return listaIdsVinc(this.nodo);
	}

	this.getInicioVigencia = function (){
		var vigencia = this.getVigencia();
		return vigencia[0];
	};
	this.getGenericos = function() {
		return genericos(this.nodo);
	};
    
	this.tieneEventoPendiente = function() {
        var xpathExpr = "./@evento_pendiente/text()";
        return selectSingle(this.nodo, xpathExpr);
    };

};

/*
 * Metadatos de la Promulgacion
 * TODO
 * 
 * 
*/

Promulgacion = function(nodo) {
	this.nodo = nodo;
	this.inicio_por_evento = es_evento_inicio(nodo);
	this.objNotas = null;
	this.__checkObjNotas = function(){
		if (this.objNotas == null){
			this.objNotas = new ObjNotasMetas(this.nodo, './TEXTO_PROMULGACION/');
		}
	}
	this.getNotasBCN = function(){
		this.__checkObjNotas();
		return this.objNotas.getNotasBCN();
	}
	this.getNotasOriginales = function(){
		this.__checkObjNotas();
		return this.objNotas.getNotasOriginales();
	}
	this.getNotasPie = function(){
		this.__checkObjNotas();
		return this.objNotas.getNotasPie();
	}
	this.Texto = function(html){
		if (typeof html == 'undefined'){
			html = true;		
		}
		var textos = selectMany(this.nodo,'.//TEXTO/text()');
		return preperaTexto(textos.join(""),html);
	}
    
	// Agregado por David  (2007-01-07)
	// Obtiene el valor del atributo especificado
	// Si no existe, retorna vacio ("")
	this._getAttribute = function(attribute) {
		var xpathExpr = "./@"+attribute;
		var element = this.nodo.selectSingleNode(xpathExpr);
		var dato = "";
		if (element)
		{
			dato = element.nodeValue;
		}
		return dato
	}	;
	this.creaIdItemCache = function(){
		return this.getID_Norma()+"_"+this.getID()+"_"+this.vigente_desde();
	}
	this.vigente_desde = function (){
		return this._getAttribute("vigente_desde");
	};
	// esta funcion obtiene el id del tipo de parte del nodo
	this.getTipoParteID = function(){
		return 11;
	}
	// esta funcion obtiene el id de la version del nodo
	this.getID_Version = function() {
		var xattribute = "id_version";
		return this._getAttribute(xattribute);
	};

	// esta funcion obtiene el id de la parte del nodo
	this.getID = function() {
		var xattribute = "id_parte";
		return this._getAttribute(xattribute);
	};

	// esta funcion obtiene el id de la norma del nodo
	this.getID_Norma = function() {
		var xattribute = "id_norma";
		return this._getAttribute(xattribute);
	};
	
	
	this.getTituloArbol = function() {
		return this.getNombre();
	} ;
	
	this.getAlertas = function() {
    	a = new Alerta(this.nodo);
        return a.getAlertas();
    };
	this.getAlertasHTMLNivelParte = function (){
		return alertasHTMLNivelParte(this.getAlertas());
	}

	this.getMetadatos = function() {
	};
	
	this.metadatosHtml = function() {
		var metadatos = new Array();
		var atributos = this.getAtributos();
		
		metadatos.push(new Array("<b>Tipo:&nbsp;</b>", this.getNombre()));
		metadatos.push(new Array("<b>Fecha Version:&nbsp;</b>", fechaLegis(atributos.getItem('fecha_version'))));
		metadatos.push(new Array("<b>Fecha Derogacion:&nbsp;</b>", fechaLegis(atributos.getItem('fecha_derogacion'))));
        // Si el inicio de vigencia es por Evento la fecha inicio Vigencia queda vacio
        var fechaInicioVigencia = "";
        if (!this.inicio_por_evento) {
            fechaInicioVigencia = fechaLegis(this.getVigencia()[0]);
        } 
        else {
            // El inicio de Vigencia es por Evento
            fechaInicioVigencia = this.getVigencia()[2];
        }

		metadatos.push(new Array("<b>Inicio Vigencia:&nbsp;</b>", fechaInicioVigencia));
		metadatos.push(new Array("<b>Fin Vigencia:&nbsp;</b>", fechaLegis(this.getVigencia()[1])));
		metadatos.push(new Array("<b>Observaciones:&nbsp;</b>", this.getObservaciones().join("; ")));
		metadatos.push(new Array("<b>Secuencia:&nbsp;</b>", atributos.getItem('secuencia')));
		metadatos.push(new Array("<b>Id parte:&nbsp;</b>", this.getID()));
		metadatos.push(new Array("<b>Fecha ultima modificacion:&nbsp;</b>", fechaLegis(atributos.getItem('fecha_ultima_modificacion')) ));
		metadatos.push(new Array("<b>Refundido por:&nbsp;</b>", this.getRefundido_por()));				
		metadatos.push(new Array("<b>Refunde a:&nbsp;</b>", this.getRefunde_a()));	
		metadatos.push(new Array("<b>Estado Produccion:&nbsp;</b>", tiposEP.getItem(atributos.getItem('estado_produccion'))));	
		metadatos.push(new Array("<b>Derogado:&nbsp;</b>", atributos.getItem('derogado')));	
		metadatos.push(new Array("<b>Tipo Version:&nbsp;</b>", this.getTipoVersion()));	
        metadatos.push(new Array("<b>Evento Pendiente:&nbsp;</b>", this.tieneEventoPendiente()));						

		// Se agregan los Genericos
		var genericos = this.getGenericos();
		for (var i =0; i<genericos.length; i++) {
			metadatos.push(new Array("<b>"+genericos[i][0]+":&nbsp;</b>", genericos[i][1]));
		}							
		var tabla = tabla_metadatos(metadatos);
		return tabla;
	};

	this.getEnlacesHL = function() {
		return getEnlacesHL(this.nodo);
	};

	this.getTipoVersion = function() {
        return getTipoVersion(this.nodo)
    };
    
	this.estaEliminada = function() {
    // Retorna True o False si esta eliminada
        if (this.getTipoVersion() == 'eliminada')
            return true;
        return false;
    };
	
	this.estaMovida = function() {
		return false
    }   ;
	
	this.movido_de = function (){
		var element = this.nodo.selectSingleNode('./@movido_de');
		if (element)
		{
			var movido_de = element.nodeValue;
			return movido_de;
		}
		return "";
	};
	
	this.movido_a = function (){
		var element = this.nodo.selectSingleNode('./@movido_a');
		if (element)
		{
			var movido_a = element.nodeValue;
			return movido_a;
		}
		return "";
	};

	this.getEnlacesOS = function() {
		return getEnlacesOS(this.nodo);
	};
	this.getEnlacesProyectos = function() {
		return getEnlacesProyectos(this.nodo);
	};
	this.getEnlacesJurisprudencia = function() {
		return getEnlacesJurisprudencia(this.nodo);
	};
	
	this.getEnlacesDoctrina = function() {
		return getEnlacesDoctrina(this.nodo);
	};

	this.getNombre = function() {
		return this.nodo.tagName;
	};
    
	this.getAtributos = function() {
		
		var attrs = this.nodo.attributes;
		var atributos = new Dict();
		
		for(var i=0; i < attrs.length; i++) 
		{		
			var attr = attrs[i];
			switch (attr.name)
			{
				case "id_parte":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "fecha_derogacion":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "fecha_version":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "secuencia":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "fecha_ultima_modificacion":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "estado_produccion":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "derogado":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "tipo_version":
					atributos.setItem(attr.name, attr.nodeValue);
					break;

			}			
		}
		return atributos;
	};

	this.getXML = function() {
		return toXML(this.nodo);
	};
	
	this.getDoc = function() {
		return toDocument(this.getXML());
	};

	this.getObservaciones = function() {
		var xpathExpr = "./OBSERVACIONES/OBSERVACION/text()";
		return selectMany(this.nodo, xpathExpr);
	};

	this.getPoliticas = function() {
		var xpathExpr = "./POLITICAS/POLITICA/text()";
		return selectMany(this.nodo, xpathExpr);
	};

	this.getFechaUltimaModificacion= function() {
        var fecha = this.nodo.getAttribute('fecha_ultima_modificacion');
        return fecha;
    };

	this.getVigencia = function() {
		return vigencia(this.nodo);
	};

	this.getVigencias = function(idVersion) {
		return vigencias(this.nodo,idVersion);
	};
	this.getCantidadesVinculaciones = function(){
		return cantidadesVinculaciones(this.nodo);
	}
	this.getListaIdsVinc = function(){
		return listaIdsVinc(this.nodo);
	}

	this.getInicioVigencia = function (){
		var vigencia = this.getVigencia();
		return vigencia[0];
	};
	this.getRefunde_a = function() {
		var xpathExpr = "./@refunde_a/text()";
		return selectSingle(this.nodo, xpathExpr);
	};
	
	this.getRefundido_por = function() {
		var xpathExpr = "./@refundido_por/text()";
		return selectSingle(this.nodo, xpathExpr);
	};

	this.getGenericos = function() {
		return genericos(this.nodo);
	};
    
	this.tieneEventoPendiente = function() {
        var xpathExpr = "./@evento_pendiente/text()";
        return selectSingle(this.nodo, xpathExpr);
    };
};

/*
 * Metadatos del Anexo
 * TODO
 * 
 * 
*/

Anexo = function(nodo) {
	this.nodo = nodo;
	this.objNotas = null;
	this.__checkObjNotas = function(){
		if (this.objNotas == null){
			this.objNotas = new ObjNotasMetas(this.nodo, './TEXTO_ANEXO/');
		}
	}
	this.getNotasBCN = function(){
		this.__checkObjNotas();
		return this.objNotas.getNotasBCN();
	}
	this.getNotasOriginales = function(){
		this.__checkObjNotas();
		return this.objNotas.getNotasOriginales();
	}
	this.getNotasPie = function(){
		this.__checkObjNotas();
		return this.objNotas.getNotasPie();
	}
	this.Texto = function(html){
		if (typeof html == 'undefined'){
			html = true;		
		}
		var textos = selectMany(this.nodo,'.//TEXTO/text()');
		return preperaTexto(textos.join(""),html);
	}
    this.inicio_por_evento = es_evento_inicio(nodo);

	// Agregado por David  (2007-01-07)
	// Obtiene el valor del atributo especificado
	// Si no existe, retorna vacio ("")
	this._getAttribute = function(attribute) {
		var xpathExpr = "./@"+attribute;
		var element = this.nodo.selectSingleNode(xpathExpr);
		var dato = "";
		if (element)
		{
			dato = element.nodeValue;
		}
		return dato
	}	;
	this.creaIdItemCache = function(){
		return this.getID_Norma()+"_"+this.getID()+"_"+this.vigente_desde();
	}
	this.vigente_desde = function (){
		return this._getAttribute("vigente_desde");
	};
	// esta funcion obtiene el id del tipo de parte del nodo
	this.getTipoParteID = function(){
		return 12;
	}
	
	// esta funcion obtiene el id de la version del nodo
	this.getID_Version = function() {
		var xattribute = "id_version";
		return this._getAttribute(xattribute);
	};

	// esta funcion obtiene el id de la parte del nodo
	this.getID = function() {
		var xattribute = "id_parte";
		return this._getAttribute(xattribute);
	};

	// esta funcion obtiene el id de la norma del nodo
	this.getID_Norma = function() {
		var xattribute = "id_norma";
		return this._getAttribute(xattribute);
	};



	this.getTituloArbol = function() {
		var titulo = this.getTitulo();
		var numero_parte = this.getAtributos().getItem('numero_parte');
		var tipoParte = this.getNombre();
		titulo = tipoParte + " " + titulo;
		if (titulo) {
			titulo = cortaPalabra(titulo);
		}
		else {
			titulo += tipoParte;
			if (numero_parte!="") 
			{
				titulo += " " + numero_parte;
			}
			else 
			{
				var nomParte = this.getNombreParte();
				if (nomParte != "") {
					titulo += " " + nomParte;
				}
				else {
					var otraNum = this.getAtributos().getItem('otra_numeracion');
					if (otraNum!="") {
						titulo += " " + otraNum;
					}
				}
			}
		}
		return titulo;
	};

	this.getAlertas = function() {
    	a = new Alerta(this.nodo);
        return a.getAlertas();
    };
	this.getAlertasHTMLNivelParte = function (){
		return alertasHTMLNivelParte(this.getAlertas());
	}

	this.getMetadatos = function() {
	};
	
	this.metadatosHtml = function() {
		var metadatos = new Array();
		var atributos = this.getAtributos();
		metadatos.push(new Array("<b>Tipo:&nbsp;</b>", "Anexo"));
		metadatos.push(new Array("<b>Numero:&nbsp;</b>", atributos.getItem('numero_parte')));
		metadatos.push(new Array("<b>Titulo:&nbsp;</b>", this.getTitulo()));
		metadatos.push(new Array("<b>Fecha Version:&nbsp;</b>", fechaLegis(atributos.getItem('fecha_version'))));
		metadatos.push(new Array("<b>Fecha Derogacion:&nbsp;</b>", fechaLegis(atributos.getItem('fecha_derogacion'))));				
        // Si el inicio de vigencia es por Evento la fecha inicio Vigencia queda vacio
        var fechaInicioVigencia = "";
        if (!this.inicio_por_evento) {
            fechaInicioVigencia = fechaLegis(this.getVigencia()[0]);
        } 
        else {
            // El inicio de Vigencia es por Evento
            fechaInicioVigencia = this.getVigencia()[2];
        }

		metadatos.push(new Array("<b>Inicio Vigencia:&nbsp;</b>", fechaInicioVigencia));
		metadatos.push(new Array("<b>Fin Vigencia:&nbsp;</b>", fechaLegis(this.getVigencia()[1])));				
		metadatos.push(new Array("<b>Materias:&nbsp;</b>", this.getMaterias().join("; ")));				
		metadatos.push(new Array("<b>Terminos Libres:&nbsp;</b>", this.getTerminosLibres().join("; ")));				
		metadatos.push(new Array("<b>Nombre Uso Comun:&nbsp;</b>", this.getNombresUsoComun().join("; ")));				
		metadatos.push(new Array("<b>Observaciones:&nbsp;</b>", this.getObservaciones().join("; ")));				
		metadatos.push(new Array("<b>Secuencia:&nbsp;</b>", atributos.getItem('secuencia')));
		metadatos.push(new Array("<b>Id parte:&nbsp;</b>", this.getID()));				
		metadatos.push(new Array("<b>Fecha ultima modificacion:&nbsp;</b>", fechaLegis(atributos.getItem('fecha_ultima_modificacion')) ));
		metadatos.push(new Array("<b>Refundido por:&nbsp;</b>", this.getRefundido_por()));				
		metadatos.push(new Array("<b>Refunde a:&nbsp;</b>", this.getRefunde_a()));	
		metadatos.push(new Array("<b>Estado Produccion:&nbsp;</b>", tiposEP.getItem(atributos.getItem('estado_produccion'))));	
		metadatos.push(new Array("<b>Derogado:&nbsp;</b>", atributos.getItem('derogado')));	
		metadatos.push(new Array("<b>Tipo Version:&nbsp;</b>", this.getTipoVersion()));							
		metadatos.push(new Array("<b>Transitorio:&nbsp;</b>", atributos.getItem('transitorio')));	
        metadatos.push(new Array("<b>Evento Pendiente:&nbsp;</b>", this.tieneEventoPendiente()));						

		// Se agregan los Genericos
		var genericos = this.getGenericos();
		for (var i =0; i<genericos.length; i++) {
			metadatos.push(new Array("<b>"+genericos[i][0]+":&nbsp;</b>", genericos[i][1]));
		}		
		var tabla = tabla_metadatos(metadatos);
		return tabla;		
	};
	
	this.getEnlacesHL = function() {
		return getEnlacesHL(this.nodo);
	};

	this.getTipoVersion = function() {
        return getTipoVersion(this.nodo)
    };
    
	this.estaEliminada = function() {
    // Retorna True o False si esta eliminada
        if (this.getTipoVersion() == 'eliminada')
            return true;
        return false;
    };
	this.estaMovida = function() {
		return false
    };
	this.movido_de = function (){
		var element = this.nodo.selectSingleNode('./@movido_de');
		if (element)
		{
			var movido_de = element.nodeValue;
			return movido_de;
		}
		return "";
	};
	
	this.movido_a = function (){
		var element = this.nodo.selectSingleNode('./@movido_a');
		if (element)
		{
			var movido_a = element.nodeValue;
			return movido_a;
		}
		return "";
	};

	this.getEnlacesOS = function() {
		return getEnlacesOS(this.nodo);
	};
	this.getEnlacesProyectos = function() {
		return getEnlacesProyectos(this.nodo);
	};
	this.getEnlacesJurisprudencia = function() {
		return getEnlacesJurisprudencia(this.nodo);
	};
	
	this.getEnlacesDoctrina = function() {
		return getEnlacesDoctrina(this.nodo);
	};

	this.getNombre = function() {
		return this.nodo.tagName;
	};

	this.getNombreParte = function() {
		var xpathExpr = "./@nombre_parte";
		var element = this.nodo.selectSingleNode(xpathExpr);
		var dato = "";
		if (element)
		{
			dato = element.nodeValue;
		}
		return dato
	};
	
	this.getTitulo = function() {
		var titulo = "";
		
		var xpathExpr = "./METADATOS/TITULO_PARTE/text()";
		var element = this.nodo.selectSingleNode(xpathExpr);
		var tituloParte = "";
		if (element)
		{
			tituloParte = element.nodeValue;
		}
		return tituloParte;
	};

	this.getAtributos = function() {
		// Tomar los atributos de la Norma
		
		var attrs = this.nodo.attributes;
		var atributos = new Dict();
		
		for(var i=0; i < attrs.length; i++) 
		{		
			var attr = attrs[i];
			switch (attr.name)
			{
				case "id_parte":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "fecha_derogacion":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "fecha_version":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "numero_parte":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "secuencia":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "otra_numeracion":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "fecha_ultima_modificacion":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "estado_produccion":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "derogado":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "transitorio":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
				case "tipo_version":
					atributos.setItem(attr.name, attr.nodeValue);
					break;
			}			
		}
		return atributos;
	};

	this.getXML = function() {
		return toXML(this.nodo);
	};
	
	this.getDoc = function() {
		return toDocument(this.getXML());
	};

	this.getObservaciones = function() {
		var xpathExpr = "./METADATOS/OBSERVACIONES/OBSERVACION/text()";
		return selectMany(this.nodo, xpathExpr);
	};

	this.getMaterias = function() {
		var xpathExpr = "./METADATOS/MATERIAS/MATERIA/text()";
		return selectMany(this.nodo, xpathExpr);
	};

	this.getTerminosLibres = function() {
		var xpathExpr = "./METADATOS/TERMINOS_LIBRES/TERMINO_LIBRE/text()";
		return selectMany(this.nodo, xpathExpr);
	};

	this.getNombresUsoComun = function() {
		var xpathExpr = "./METADATOS/NOMBRES_USO_COMUN/NOMBRE_USO_COMUN/text()";
		return selectMany(this.nodo, xpathExpr);
	};

	this.getTituloParte = function() {
		var xpathExpr = "./METADATOS/TITULO_PARTE/text()";
		return selectSingle(this.nodo, xpathExpr);
	};
    
	this.getFechaUltimaModificacion= function() {
        var fecha = this.nodo.getAttribute('fecha_ultima_modificacion');
        return fecha;
    };

	this.getPoliticas = function() {
		var xpathExpr = "./POLITICAS/POLITICA/text()";
		return selectMany(this.nodo, xpathExpr);
	};

	this.getVigencia = function() {
		return vigencia(this.nodo);
	};

	this.getVigencias = function(idVersion) {
		return vigencias(this.nodo,idVersion);
	};
	this.getCantidadesVinculaciones = function(){
		return cantidadesVinculaciones(this.nodo);
	}
	this.getListaIdsVinc = function(){
		return listaIdsVinc(this.nodo);
	}

	this.getInicioVigencia = function (){
		var vigencia = this.getVigencia();
		return vigencia[0];
	};
	this.getRefunde_a = function() {
		var xpathExpr = "./@refunde_a/text()";
		return selectSingle(this.nodo, xpathExpr);
	};
	
	this.getRefundido_por = function() {
		var xpathExpr = "./@refundido_por/text()";
		return selectSingle(this.nodo, xpathExpr);
	};

	this.getGenericos = function() {
		return genericos(this.nodo);
	};
    
	this.tieneEventoPendiente = function() {
        var xpathExpr = "./@evento_pendiente/text()";
        return selectSingle(this.nodo, xpathExpr);
    };

};

//EOF
