function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}



var menu_state = new Array();
	
function treeNode(expand, caption, link, target, number, level) {
	// Node properties
	this.expand  = expand;
	this.caption = caption;
	this.link    = link;
	this.target  = target;
	this.number  = number;
	this.level   = level;
	this.next    = null;
	this.subtree = null;
	// Node methods
	this.AddChild   = treeAddChild;
	this.AddSibling = treeAddSibling;
	this.Display	= treeDisplay;
}

var buildProgress = 0;

function addToTree(arr) {
	var start = buildProgress;
	var m = new treeNode(menu_state[start]=='1',arr[start][1],arr[start][2],arr[start][3], start, arr[start][0]);
	buildProgress++;

	var done = (buildProgress >= arr.length);
	var s = m;

	while (!done) {
		if (arr[start][0] == arr[buildProgress][0]) {
			j = buildProgress;
			s = s.AddSibling(menu_state[j]=='1',arr[j][1],arr[j][2],arr[j][3], j, arr[j][0]);
			buildProgress++;
		} else
		if (arr[start][0] < arr[buildProgress][0]) {
			s.subtree = addToTree(arr);
		} else
		if (arr[start][0] > arr[buildProgress][0]) {
			done = true;
		}
		done = done || (buildProgress >= arr.length);
	}
	return m;
}

function treeExpand(n) {
	menu_state[n] = '1';
	setCookie('TREEMENU_STATE', menu_state.join('|'));
	history.go(0);
}

function treeCollapse(n) {
	menu_state[n] = '0';
	setCookie('TREEMENU_STATE', menu_state.join('|'));
	history.go(0);
}

function treeCollapseLink(n,link) {
	menu_state[n] = '0';
	setCookie('TREEMENU_STATE', menu_state.join('|'));
	irA(link);

}

function miExpand(n){

	var anterior = 0;
	anterior = getCookie("anterior");
	var anteriorViejo = anterior;
	
	menu_state[n] = '1';
	
	setCookie('TREEMENU_STATE', menu_state.join('|'));
   
	setCookie("anterior",n,"","","","");	

	if ((anteriorViejo != null) && (anteriorViejo != n))		
		treeCollapse(anteriorViejo);
	else 
		history.go(0);
		
}
function irA(link){
	if (navigator.appName.indexOf('Netscape') != -1)
		window.location.href =  link;
	else{
		var url = "http://"+ document.location.hostname + "/pls/portal30/" + link;
		window.location.href =  url;
	}

}

function miExpandLink(n,link){

	var anterior = 0;
	anterior = getCookie("anterior");
	var anteriorViejo = anterior;
	
	menu_state[n] = '1';
	
	setCookie('TREEMENU_STATE', menu_state.join('|'));
   
	setCookie("anterior",n,"","","","");	

	if ((anteriorViejo != null) && (anteriorViejo != n))		
		treeCollapseLink(anteriorViejo,link);
	else 
		irA(link); 
	
}

function collapseLink(link,target,n){		
	var anterior = 0;
	anterior = getCookie("anterior");
	setCookie("anterior",n);
	if (anterior != null)		
		treeCollapseLink(anterior,link);
	else 
		irA(link); 
}
		



function buildMenu(arr) {
	var menu_state_cookie = getCookie('TREEMENU_STATE');
	if (menu_state_cookie != null) {
		menu_state = menu_state_cookie.split('|');
	}
	buildProgress = 0;
	return addToTree(arr, 0);
}


function treeAddSibling(expand,caption,link,target, number, level) {
	s = this;
	while (s.next != null) {
		s = s.next;	
	}
	s.next = new treeNode(expand,caption,link,target, number, level);
	return s.next;
}

function treeAddChild(expand, caption, link, target, number, level) {
	var n;
	if (this.subtree == null) {
		n = new treeNode(expand,caption,link,target, number, level);
		this.subtree = n;
	} else {
		n = this.subtree.AddSibling(expand,caption,link,target,number, level);
	}
	return n;
}


function indent(level) {

	if (level >0) {
	document.write('<TABLE width="100%" border=0 cellpadding=2 cellspacing=0 bgcolor = "#faf3dc"><TR><TD align = left>');
	}

	for (i=0; i<level; i++) 
		document.write('<img src="/images/pj1784.bmp" align=middle>');

	if (level >0) {
	  document.write('</TD><TD width="100%" border=0 cellpadding=0 cellspacing=0 align = left>');
	}

}


function treeDisplay() {

	var colorLetraPadre = "#FFFFFF";
	var colorLetraHijo = "#000000";
	var colorLetraPadreSinExt = "#455A74"
	var colorLetra;
	var texto = "";


	if (navigator.appName.indexOf('Netscape') != -1)
		texto = "<span class = \'superiorNetscape\'>"
	else 
		texto = "<span class = \'superior\'>"

	texto += this.caption;
	texto += '</span>'; 

	indent(this.level);
	if (this.subtree == null){
		colorLetra = colorLetraHijo;
	}
	else 
		if (this.level ==0)
			if (this.link == '')
			{
				if (this.expand){
					colorLetra = colorLetraPadre;			
					document.write('<TABLE width="100%" border = 0 cellpadding= 2 cellspacing= 0 bgcolor = "#314053" >');
					document.write('<TR><TD align = left  ><a href="javascript: treeCollapse('+this.number+')"><img src="/images/pj1800.gif"  align=middle border=no></A>');
					document.write('</TD><TD width="100%"   align = left>');
					document.write('<a href="javascript: treeCollapse('+this.number+')"><FONT color = "'+colorLetra+'">' +texto+'</FONT></a></TD></TR></TABLE>');
				}
				else {
					document.write('<TABLE width="100%" border=0 cellpadding=0 cellspacing=2 bgcolor = "#FFFFFF"><TR><TD align = left>');
					document.write('<a href="javascript: miExpand('+this.number+')"><img src="/images/pj1783.gif" align=middle border=no></a>');
					document.write('</TD><TD width="100%" align = left>');
					document.writeln(' <a href="javascript: miExpand('+this.number+')">' +texto+'</A></TD></TR></TABLE>');		
			
				}
			} // this.link != ''
			else{
				if (this.expand){
					colorLetra = colorLetraPadre;			
					document.write('<TABLE width="100%" border = 0 cellpadding=2 cellspacing=0 bgcolor = "#314053" >');
					document.write('<TR><TD align = left><a href="javascript: treeCollapse('+this.number+')"><img src="/images/pj1800.gif"  align=middle border=no></A>');
					document.write('</TD><TD width="100%" border=0 cellpadding=0  align = left>');
					document.write('<a href="javascript: treeCollapse('+this.number+')"><FONT color = "'+colorLetra+'">' +texto+'</FONT></a></TD></TR></TABLE>');
				}
				else {
					document.write('<TABLE width="100%" border=0 cellpadding=0 cellspacing=2 bgcolor = "#FFFFFF"><TR><TD align = left>');
					document.write('<a href="javascript: miExpand('+this.number+')"><img src="/images/pj1783.gif" align=middle border=no></a>');
					document.write('</TD><TD width="100%" border=0 cellpadding=0  align = left>');
					document.writeln(' <a href="javascript: miExpandLink('+ this.number + ', \'' + this.link + '\')">' +texto+'</A></TD></TR></TABLE>');		
				}
			}

	if ((this.link != '') && (this.level == 0) && (this.subtree == null)){
		var ant = getCookie("anterior");
		if (this.number == ant){
			document.write('<TABLE width="100%" border=0 cellpadding=2 cellspacing=0  bgcolor = "#314053"><TR><TD align = left>');
			document.write('<a href = "javascript: collapseLink(\''+this.link+'\',\''+this.target+'\','+this.number+')"><img src="/images/pj1800.gif" align=middle border=no></a>');
			document.write('</TD><TD width="100%" border=0 cellpadding=0  align = left>');
			document.writeln(' <a href = "javascript: collapseLink(\''+this.link+'\',\''+this.target+'\','+this.number+')"><FONT COLOR = #FFFFFF>' +texto+'</FONT></A></TD></TR></TABLE>');
		
		}
		else{
			document.write('<TABLE width="100%" border=0 cellpadding=0 cellspacing=2  bgcolor = "#FFFFFF"><TR><TD align = left>');
			document.write('<a href = "javascript: collapseLink(\''+this.link+'\',\''+this.target+'\','+this.number+')"><img src="/images/pj1783.gif" align=middle border=no></a>');
			document.write('</TD><TD width="100%" border=0 cellpadding=0  align = left>');
			document.writeln(' <a href = "javascript: collapseLink(\''+this.link+'\',\''+this.target+'\','+this.number+')">' +texto+'</A></TD></TR></TABLE>');
		}
	}

	if ((this.link != '') && (this.level > 0)) {
		document.writeln(' <a href="'+this.link+'" target="'+this.target+'" >'+this.caption+'</a></TD></TR></TABLE>');
	} 


		

	if (this.subtree!=null && this.expand) {
		this.subtree.Display();
	}
	if (this.next != null) 
		this.next.Display();
	return ;
	
}

	var menuitems = new Array();
	var Loc = document.location;
	var Re  = document.referrer;

	menuitems[0] = [0,"Sistema de Justicia","url/folder/pjudicial/sj",""];
	menuitems[1] = [1,"Evolución Histórica","url/folder/pjudicial/sj/SJ01",""];
	menuitems[2] = [1,"Poder Judicial en el Contexto del Estado","url/folder/pjudicial/sj/SJ02",""];
	menuitems[3] = [1,"Artículos Constitucionales y Leyes Relacionadas","url/folder/pjudicial/sj/SJ03",""];
	menuitems[4] = [0,"Organización","url/folder/pjudicial/or"];
	menuitems[5] = [1,"Organos Jurisdiccionales","url/folder/pjudicial/or/oroj",""];
	menuitems[6] = [1,"Servicios de Administración","url/folder/pjudicial/or/orea",""];
	menuitems[7] = [1,"Servicios de Apoyo Técnico","url/folder/pjudicial/or/OREADGDIAT",""];
        menuitems[8] = [1,"Guía de Sedes y Autoridades","url/folder/pjudicial/or/ORGU1",""];
        menuitems[9] = [1,"Estructura Escalafonaria y Salarial","url/folder/pjudicial/or/oree01",""];

menuitems[10] = [1,"Acordadas y Circulares","url/folder/pjudicial/or/ORCA01",""];

      
  menuitems[11] = [0,"Planificación Estratégica","url/folder/pjudicial/pjpe",""];
        menuitems[12] = [1,"Planificación Presupuestal","url/folder/pjudicial/pjpe/pjpp",""];
	menuitems[13] = [1,"Elemento del Plan Operativo Anual","url/folder/pjudicial/pjpe/pjepoa",""];
	menuitems[14] = [0,"Modernización del Sistema de Justicia","url/folder/pjudicial/ms"];
	menuitems[15] = [1,"Programa de Fortalecimiento del Sistema Judicial Uruguayo","url/folder/pjudicial/ms/mspf",""];
	menuitems[16] = [0,"Estadísticas","url/folder/pjudicial/es",""];
        menuitems[17] = [1,"Estadísticas de Oficinas Jurisdiccionales","url/folder/pjudicial/es/esoj",""];
        menuitems[18] = [1,"Estadísticas de Oficinas de Apoyo Técnico y Administrativo","url/folder/pjudicial/es/esoa",""];
	menuitems[19] = [0,"Publicaciones","url/folder/pjudicial/pu"];
	menuitems[20] = [1,"Boletín Judicial","url/folder/pjudicial/pu/pubo",""];
	menuitems[21] = [1,"Boletín Informativo del Programa de Fortalecimiento ","url/folder/PJUDICIAL/MS/MSPF/MSPFBO",""];

      menuitems[22] = [0,"Licitaciones","url/folder/pjudicial/li",""];
	menuitems[23] = [1,"Llamados a Licitación","url/folder/pjudicial/li/lill",""];
	menuitems[24] = [1,"Licitaciones en Trámite","url/folder/pjudicial/li/litr",""];
	menuitems[25] = [1,"Histórico de Licitaciones","url/folder/pjudicial/li/lihi",""];
      menuitems[26] = [0,"Profesionales Suspendidos","url/folder/pjudicial/ps",""];
	menuitems[27] = [0,"Novedades","url/folder/pjudicial/no",""]; 
        menuitems[28] = [0,"Sugerencias","url/folder/pjudicial/su",""];
        menuitems[29] = [0,"Otros Enlaces","url/folder/pjudicial/ol",""];
	menuitems[30] = [0,"Identificación Única de Expedientes", "url/folder/pjudicial/IUE",""];
	menuitems[31] = [1,"Consulta por Número de Expediente Anterior", "url/folder/pjudicial/IUE/IUE01",""];
	menuitems[32] = [1,"Busqueda por IUE", "url/folder/pjudicial/IUE/IUE02",""];
	menuitems[33] = [1,"Listados para Descargar", "url/folder/pjudicial/IUE/listarjuzgados",""];


	var menu = buildMenu(menuitems);

