var base = ''; 
var array = new Array();
var posicion=0;
var nombres = new Array();

function navegacion()
{
  formatearMigas(); // acorta las migas en caso de que no quepan
  document.getElementById('cabecera_ruta').innerHTML = base;
}

function setBase(texto)
{
  base = base + texto;
}

function cargarNavegacionAnterior (nombre,enlace) {
  if (enlace== '') {
    base2 = '&nbsp;'+nombre;
  }
  else {
				 var nombre1=nombre.replace("new"," ");
			 	 base2 = '><a href="' + enlace + '" title="'+nombre1+'" >'+nombre1+'</a> ';		 
	}
  array[posicion]= base2;
  nombres[posicion] = nombre1;
  posicion++;
}

function escribirNavegacion () {
  for (i=posicion-1; i>=0; i--) {
    setBase (array[i]);
  }
  navegacion();
  reset ();
}

function reset () {
  for (i=posicion-1; i>=0; i--) {
    array[i]=null;
  }
  array= new Array ();
  posicion=0;
}
function ocultar(etiqueta)
{		
    for(r=0;r < n1;r++)
    {		
		
        if(codigo1[r]==etiqueta) 
        {
            for(s=0;s < n2;s++) 
            {
                document.getElementById(codigo2[s]).className="hueco";		
            };			
            for(r=0;r < n1;r++)
            {		
                if(codigo1[r] != etiqueta)
                {
                    document.getElementById(codigo1[r]).className="hueco";																					
                }		

            } 			
        }			
    };	

    for(s=0;s < n2;s++)
    {
        if(codigo2[s]==etiqueta) 
        {
            for(s=0;s < n2;s++)
            {		
                if(codigo2[s] != etiqueta)
                {
                    document.getElementById(codigo2[s]).className="hueco";																					
                }
            }	
        }		
    };
};
// La siguiente función se utiliza en el buscador de empleo.
    function validar(formulario){
        //Modalidades
        formulario.Modalidades.value = "";
        for(i=0;i < formulario.Modalidad.length;i++)
        {
            if(formulario.Modalidad.options[i].selected == true)
            {
                if(formulario.Modalidades.value == "")
                    formulario.Modalidades.value += formulario.Modalidad.options[i].value
                else
                    formulario.Modalidades.value += ","+ formulario.Modalidad.options[i].value; 
            }
        }
  
        //Grupos
        formulario.Grupos.value = "";
        for(i=0;i < formulario.Grupo.length;i++)
        {
            if(formulario.Grupo.options[i].selected == true)
            {
                if(formulario.Grupos.value == "")
                    formulario.Grupos.value += formulario.Grupo.options[i].value
                else
                    formulario.Grupos.value += ","+ formulario.Grupo.options[i].value; 
            }
        }
       
        return (false);
  }

/* JULIO : Funcion encargada de acortar las migas en caso de que excedan el tamaño del div */
function formatearMigas(){
        // LIMITE DE CARACTERES EN LAS MIGAS (MODIFICABLE) //
        var limite = 145;
        // establecemos los limites de las migas anteriores en los diferentes niveles
        var limite_n2 = 50;
        var limite_n3 = 30;
        var limite_n4 = 25;
	var nivel = (base.split("> ").length - 1);
        var sobrante;
        var acortada;
        var tam_2;
        var tam_3;
        var tam_4;
        // a veces hay un elemento en el array '&nbsp;', en ese caso, lo despreciamos
        var indice;
        if (array[0]=="&nbsp;")indice=1;
        else indice=0;
        switch (nivel){

            // NIVEL 1
            case 1:
                if (nombres[indice].length > limite-1){
                    acortada = nombres[indice].substr(0,limite-3)+"...";
                    base = base.replace(">"+nombres[indice],">"+acortada);
                }
                break;

            // NIVEL 2
            case 2:
                if (nombres[indice].length + nombres[indice+1].length > limite-2){ //solo si la suma excede el rango
                    if (nombres[indice+1].length > limite_n2){ // acortamos la primera
                        acortada = nombres[indice+1].substr(0,limite_n2-3)+"...";
                        base = base.replace(">"+nombres[indice+1],">"+acortada);
                        tam_2 = acortada.length;
                    }else tam_2 = nombres[indice+1].length;

                    if (nombres[indice].length + tam_2 > limite-2){ // acortamos la segunda
                        sobrante = (nombres[indice].length + tam_2) - limite;
                        acortada = nombres[indice].substr(0,nombres[indice].length-sobrante-4)+"...";
                        base = base.replace(">"+nombres[indice],">"+acortada);
                    }
                }
                break;

            // NIVEL 3
            case 3:
                if (nombres[indice].length + nombres[indice+1].length + nombres[indice+2].length > limite-3){//solo si la suma excede el rango
                    if (nombres[indice+1].length > limite_n3){ // acortamos la segunda
                        acortada = nombres[indice+1].substr(0,limite_n3-3)+"...";
                        base = base.replace(">"+nombres[indice+1],">"+acortada);
                        tam_2 = acortada.length;
                    }else tam_2 = nombres[indice+1].length;

                    if (nombres[indice+2].length > limite_n3){ // acortamos la primera
                        acortada = nombres[indice+2].substr(0,limite_n3-3)+"...";
                        base = base.replace(">"+nombres[indice+1],">"+acortada);
                        tam_3 = acortada.length;
                    }else tam_3 = nombres[indice+2].length;

                    if (nombres[indice].length + tam_2 + tam_3 > limite-3){//acortamos la tercera
                        sobrante = (nombres[indice].length + tam_2 + tam_3) - limite;
                        acortada = nombres[indice].substr(0,nombres[indice].length-sobrante-6)+"...";
                        base = base.replace(">"+nombres[indice],">"+acortada);
                    }
                }
                break;

            // NIVEL 4
            case 4:
                if (nombres[indice].length + nombres[indice+1].length + nombres[indice+2].length + nombres[indice+3].length > limite-4){//solo si la suma excede el rango
                    if (nombres[indice+1].length > limite_n4){ // acortamos la tercera
                        acortada = nombres[indice+1].substr(0,limite_n4-3)+"...";
                        base = base.replace(">"+nombres[indice+1],">"+acortada);
                        tam_2 = acortada.length;
                    }else tam_2 = nombres[indice+1].length;

                    if (nombres[indice+2].length > limite_n4){ // acortamos la segunda
                        acortada = nombres[indice+2].substr(0,limite_n4-3)+"...";
                        base = base.replace(">"+nombres[indice+2],">"+acortada);
                        tam_3 = acortada.length;
                    }else tam_3 = nombres[indice+2].length;

                    if (nombres[indice+3].length > limite_n4){ // acortamos la primera
                        acortada = nombres[indice+3].substr(0,limite_n4-3)+"...";
                        base = base.replace(">"+nombres[indice+3],">"+acortada);
                        tam_4 = acortada.length;
                    }else tam_4 = nombres[indice+3].length;

                    if (nombres[indice].length + tam_2 + tam_3 + tam_4 > limite-4){//acortamos la cuarta
                        sobrante = (nombres[indice].length + tam_2 + tam_3 + tam_4) - limite;
                        acortada = nombres[indice].substr(0,nombres[indice].length-sobrante-8)+"...";
                        base = base.replace(">"+nombres[indice],">"+acortada);
                    }
                }                        
                break;
        }
}


