//Elementos para el select1
var sel1=new Array("POR TIPO DE INSTITUCION","POR TIPO DE ESTABLECIMIENTO") //2006
var sel2=new Array("POR TIPO DE INSTITUCION","POR TIPO DE ESTABLECIMIENTO") //2007
var sel3=new Array("POR TIPO DE INSTITUCION","POR TIPO DE ESTABLECIMIENTO") //2008
var sel4=new Array("POR TIPO DE INSTITUCION","POR TIPO DE ESTABLECIMIENTO") //2009
var sel5=new Array("POR TIPO DE INSTITUCION","POR TIPO DE ESTABLECIMIENTO") //2010





function Seleccionar()
{

	if (document.getElementById ("frame"))
	{
			nodoTabla = document.getElementById ("frame");
			nodoTabla.removeChild(nodoTabla.lastChild);
			nodoGeneral = document.getElementById ("tabla");
			nodoGeneral.removeChild(nodoTabla);
	}

		if (document.getElementById ("valor1"))
		{
			nodoTabla = document.getElementById ("valor1");
			nodoTabla.removeChild(nodoTabla.lastChild);
			nodoGeneral = document.getElementById ("tabla");
			nodoGeneral.removeChild(nodoTabla);
			Num = 0;
			
			Agregar(0);
		}
		else
		{
			Agregar(0);
		}
}

//esta función es para hacer la actualización del segundo combobox
function selectAsociado(){

province1 = document.form1.province1[document.form1.province1.selectedIndex].value
    if (province1 != 0) {
        mis_subsecc=eval("secc_sub" + province1)
        num_seccisub = mis_subsecc.length
        document.form1.city1.length = num_seccisub
        
        mis_subseccVls=eval("secc_subVls" + province1)
        num_seccisubVls = mis_subseccVls.length
        document.form1.city1.length = num_seccisubVls
    
        for(i=0;i<num_seccisub;i++){
            document.form1.city1.options[i].value=mis_subseccVls[i] 
            document.form1.city1.options[i].text=mis_subsecc[i]
        }
    }else{
    document.form1.city1.length = 1
    document.form1.city1.options[0].value = "0"
    document.form1.city1.options[0].text = "-"
    }
    document.form1.city1.options[0].selected = true
}

//textos de las ciudades
var secc_sub1= new Array('Seleccione', 'PROCESO DE ASIGNACION 2006','QUINTIL DE INGRESO PER CAPITA','NIVEL DE ESTUDIO','GENERO','BENEFICIOS DE ARANCEL DEL MINEDUC','TITULO DE CARRERA','JORNADA','REGION','BENEFICIARIOS Y MONTOS SOLICITADOS','BANCO ADMINISTRADOR','INSTITUCION ACREEDORA')
var secc_sub2= new Array('Seleccione', 'INSTITUCION DE EDUCACION SUPERIOR', 'QUINTIL DE INGRESO PER CAPITA')

//valores de las ciudades
var secc_subVls1= new Array('0', '1', '2', '3', '4','5','6','7','8','9','10','11')
var secc_subVls2= new Array('0', '12', '13')

//esta función es la que crea los combobox dinamicamente

function Agregar(Num){
		Num = 0;
        obj=document.getElementById('tabla');
        f=document.getElementById('fila');
        Num++;
                
        elTr=document.createElement('tr');
        elTr.id='valor'+Num;
        elTd=document.createElement('td');

        selectf=document.createElement('select');
        selectf.name='province'+Num;
        selectf.onchange=selectAsociado;       
        
        soption0 = document.createElement('option');
        soption0.value = "0";
        soption0.text = "Seleccione >>";
        selectf.appendChild(soption0);
    soption1 = document.createElement('option');
        soption1.value = "1";
    soption1.text = "Por tipo de INSTITUCION";
        selectf.appendChild(soption1);
    soption2 = document.createElement('option');
        soption2.value = "2";
    soption2.text = "Por tipo de ESTABLECIMIENTO";
    selectf.appendChild(soption2);     
        

        selectf1=document.createElement('select');
		selectf1.name='city'+Num;
		selectf1.onchange=resultados;
         

       
        elTd.appendChild(selectf);


        elTr.appendChild(elTd);
        obj.insertBefore(elTr,f)
        

        elTd.appendChild(selectf1);
		
        return Num;
}

function resultados()
{
	Slimbox.open("http://www.google.com", "&lt;a href=&quot;excel.html&quot;&gt;Descargar Excel&lt;/a&gt; - Proceso de Asignaci&oacute;n 2006: "+selectf1.value);
}


function changeSelect1(v){

    //compruebo q si se selecciono una opcion, si es 0 es pq no se selecciono nada
    if (v != 0) {
       //selecciono el array segun lo q se selecciono
       contenido_select1=eval("sel" + v)
       //calculo el numero de elementos del array seleccionado
       cantidad_select1 = contenido_select1.length
       //marco el n&uacute;mero de elementos en el select
       document.form1.select1.length = cantidad_select1
       //para cada elemento del array, lo introduzco en el select1
       for(i=0;i<cantidad_select1;i++){
          document.form1.select1.options[i].value=(i+1)
          document.form1.select1.options[i].text=contenido_select1[i]
       }
    }else{
       //si no hab&iacute;a provincia seleccionada, elimino las provincias del select
       document.form1.select1.length = 1
       //coloco el gui&oacute;n en la &uacute;nica opci&oacute;n
       document.form1.select1.options[0].value = "-"
       document.form1.select1.options[0].text = "-"
    }
    //marco como seleccionada la opci&oacute;n primera de provincia
    document.form1.select1.options[0].selected = true
}


//Elementos para el select2
var pro1=new Array("PROCESO DE ASIGNACION 2008","QUINTIL DE INGRESO PER CAPITA","NIVEL DE ESTUDIO")
var pro2=new Array("-","2_1","2_2","2_3","2_4","2_5")
var pro3=new Array("-","3_1","3_2","3_3","3_4")

function changeSelect2(){
    //tomo el valor del select1 de la opcion elegida
    var select1
    select1 = document.form1.select1[document.form1.select1.selectedIndex].value
    //compruebo q si se selecciono una opcion, si es 0 es pq no se selecciono nada
    if (select1 != 0) {
       //selecciono el array segun lo q se selecciono
       contenido_select2=eval("pro" + select1)
       //calculo el numero de elementos del array seleccionado
       cantidad_select2 = contenido_select2.length
       //marco el n&uacute;mero de elementos en el select
       document.form1.select2.length = cantidad_select2
       //para cada elemento del array, lo introduzco en el select2
       for(i=0;i<cantidad_select2;i++){
          document.form1.select2.options[i].value=contenido_select2[i]
          document.form1.select2.options[i].text=contenido_select2[i]
       }
    }else{
       //si no hab&iacute;a provincia seleccionada, elimino las provincias del select
       document.form1.select2.length = 1
       //coloco el gui&oacute;n en la &uacute;nica opci&oacute;n
       document.form1.select2.options[0].value = "-"
       document.form1.select2.options[0].text = "-"
    }
    //marco como seleccionada la opci&oacute;n primera de provincia
    document.form1.select2.options[0].selected = true
}

showTable=/**
 *
 * @access public
 * @return void
 **/
function showTable(){
	//alert("se selecciono la segunda opcion, se debe mostrar la tabla con lo seleccionado.")
	document.getElementById("div1").innerHTML="<table name='table1' id='table1'><tr><td>A&ntilde;o seleccionado: </td><td>"+document.form1.r.checked+"</td></tr><tr><td>Select1: "+document.form1.select1[document.form1.select1.selectedIndex].text+"</td><td>Select2: "+document.form1.select2.value+"</td></tr></table>"
}

