// Funciones de validacion del formulario
vacio='';
var indiceSeleccion=1;

function crearray(n){
     this.lenght=n;
     for (var j=1;j<=n;j++){
              this[j]=0;
   }
}
function esVacio(s) 
{ 
    for(var i = 0; i < s.length; i++) { 
        var c = s.charAt(i); 
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false; 
    } 
    return true; 
} 
 
function tieneComilla(s) 
{ 
    for(var i = 0; i < s.length; i++) { 
        var c = s.charAt(i); 
        if (c == '\'') return true; 
    } 
    return false; 
} 
function sinEspacio (a) {
        var numero;
        numero = a.length;
        var variable =' ';
        var  i=0;
        var bandera =0;
        for (i=0;i<=numero;i++){
                if (a.charAt(i) == variable ){
                        bandera=1;
                        i=numero+1;
                }
        }
        if (bandera==1){
                return false;
        }else{
                return true;
        }
}
function sinNumeros (a) {
  var numero;
  numero = a.length;
  var i;
  var bandera =0;
  for (i=0;i<=numero;i++){
                if (isNaN(a.charAt(i))){
                        bandera=1;
                        i=numero+1;
                }
        }
        if (bandera==1){
                return false;
        }else{
                return true;
        }
}

function sinLetras (a) {
   var numero;
   var variable =' ';
  numero = a.length;
  var i;
  var bandera =0;
  if (numero!=0){
    for (i=0;i<numero;i++){
                if ((a.charAt(i)!=variable) && (!isNaN(a.charAt(i)))) {
                        bandera=1;
                          break;
                  }
          }
  }
        if (bandera==1){
                return true;
        }else{
                return false;
        }
}

function esCategoriaValida(){
	var marcado = "no";
	with (document.nominaciones){
		for ( var i = 0; i < categoria.length; i++ ) {
			if ( categoria[i].checked ) {
				return true;
			}
		}
		if ( marcado == "no" ){
			window.alert("You must select a Category") ;
		}
	}
}

function esInstitucionValida(){
	var marcado = "no";
	with (document.nominaciones){
		for ( var i = 0; i < institucion.length; i++ ) {
			if ( institucion[i].checked ) {
				return true;
			}
		}
		if ( marcado == "no" ){
			return false;
		}
	}
}

function codigoValido(){
	if (document.nominaciones.codValidacion.value!="")
		document.nominaciones.submit();
	else {
		alert("You must enter the characters you see in the image");
		return false;
	}
}

function inicializaFormularioNom() 
{ 
	with (document.nominaciones) {
	    nombreinst.opcional=false; 
	    nombreinst.label="Name of Institution";
	    web.opcional=true; 
	    web.label="Website";
	    nombre.opcional=true; 
	    nombre.label="Name";    
	    apellido.opcional=false; 
	    apellido.label="Surname";    
	    posicion.opcional=false; 
	    posicion.label="Position";    
	    direccion.opcional=false; 
	    direccion.label="Addres";	
	    cp.opcional=false; 
	    cp.label="Zip/Postal Code";  
	    ciudad.opcional=false; 
	    ciudad.label="City";
	    pais.opcional=false;
	    pais.label="Country"; 
	    email.opcional=false; 
	    email.label="Email";
	    telefono.opcional=false; 
	    telefono.label="Telephone";  
	    fax.opcional=true; 
	    fax.label="Fax";  
	    carta_nominador.opcional=false; 
	    carta_nominador.label="Nomination Letter";  
		
		//Pongo a null los label del institución, para que la validación no pase por estos campos		
	    nombre_inst_candidatoI.label=null;	    
	    web_candidatoI.label=null;	    
	    legalform_candidatoI.label=null;
	    representative_candidatoI.label=null;
	    posicion_candidatoI.label=null;	  	    
	    direccion_candidatoI.label=null;
	    cp_candidatoI.label=null;
	    ciudad_candidatoI.label=null;
	    pais_candidatoI.label=null;
	    email_candidatoI.label=null;
	    telefono_candidatoI.label=null;
	    movil_candidatoI.label=null;		
	    fax_candidatoI.label=null;		
		ciencia_candidatoI.label = null;
		meritos_candidatoI.label = null;		
		
		//Pongo a null los label del candidato individuo		
		nombre_candidatoP.label=null;
		apellidos_candidatoP.label=null;
		institucion_candidatoP.label=null;
		posicion_candidatoP.label=null;
		direccion_candidatoP.label=null;
		cp_candidatoP.label=null;
		ciudad_candidatoP.label=null;
		pais_candidatoP.label=null;
		email_candidatoP.label=null;
		telefono_candidatoP.label=null;
		movil_candidatoP.label=null;
		fax_candidatoP.label=null;
		sexo_candidatoP.label = null;
		nacionalidad_candidatoP.label = null;	
		ciencia_candidatoP.label = null;
		meritos_candidatoP.label = null;		
		
		if (document.getElementById('carta_candidatoI['+indiceSeleccion+']')) document.getElementById('carta_candidatoI['+indiceSeleccion+']').label=null;
		if (document.getElementById('cv_candidatoI['+indiceSeleccion+']')) document.getElementById('cv_candidatoI['+indiceSeleccion+']').label=null;
		if (document.getElementById('carta_candidatoP['+indiceSeleccion+']')) document.getElementById('carta_candidatoP['+indiceSeleccion+']').label=null;
		if (document.getElementById('cv_candidatoP['+indiceSeleccion+']')) document.getElementById('cv_candidatoP['+indiceSeleccion+']').label=null;
		
	}
}

function esNomValido() 
{ 
with (document.nominaciones) {

    var msg; 
    var empty_fields = ""; 
    var errors = ""; 
    var vacio= "";
    // Inicializa los valores del formulario 
    inicializaFormularioNom(); 
 
    // Validacion 
    for(var i = 0; i < length; i++) { 
        var e = elements[i];
        if ( ((e.type == "text") || (e.type == "textarea") ||(e.type == "password")) && (e.label!=null) ) { 
            // primero chequea que no este vacio 
            if ((((e.value == null) ||(e.value == "") || esVacio(e.value)) && !e.opcional)) { 
                empty_fields += "\n          " + e.label; 
                continue; 
            } 
 
            // Chequea que los campos text no tenga comilla simple 
            if (tieneComilla(e.value)) { 
                e.value = e.value.replace(/'/g,'´');
                continue; 
            }        
        }
    }
                // array con los campos de solo letras
    arrayletras = new crearray(4);
    arrayletras[1]="nombre";
    arrayletras[2]="apellido";
	arrayletras[3]="ciudad";
	arrayletras[4]="pais";
    var contador;
    for (contador=1;contador<=4;contador++){
       var a = eval(arrayletras[contador] + ".value");
       if (sinLetras(a)){
          var etiqueta = eval (arrayletras[contador] + ".label");
          errors += "\n          " + etiqueta;
       }
    }
     // array con los campos de solo numeros
    arraynumeros = new crearray(1);
    arraynumeros[1]="telefono";
    
    var contador;    
    for (contador=1;contador<=1;contador++){
       var a = eval(arraynumeros[contador] + ".value");         
          if (!sinNumeros(a)){
            var etiqueta = eval (arraynumeros[contador] + ".label");
            errors += "\n          " + etiqueta +" (this must be numeric)";
          }
     }
    
    //Validación de email       
    if (email.value!=''){
                valor= email.value;
                if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor))){
                                errors += "\n          E-mail";
                        }
        }       

	//validacion de select	
	if (pais.options[pais.selectedIndex].value==''){
		empty_fields += "\n          Country";
	}
    
    //Validación de fichero       
	extension = (carta_nominador.value.substring(carta_nominador.value.lastIndexOf("."))).toLowerCase();
	if (extension =="")
		empty_fields += "\n          Nomination Letter";
    else if (extension !='.pdf'){
        errors += "\n          Nomination Letter";
    }       
    
    var contador;

		if (!esInstitucionValida())
		errors += "\n          Organization"
        if (!empty_fields && !errors && !vacio) {   
                return true;  
        }
        
    msg  = "______________________________________________________\n\n" 
    msg += "Form not submitted due to one or more errors.\n"; 
    msg += "Please correct data and try again.\n"; 
    msg += "______________________________________________________\n\n" 
    if (empty_fields) { 
        msg += "- The following compulsory fields have not been completed:"  
                + empty_fields + "\n"; 
    } 
    if (errors) { 
        msg += "- The following fields have incorrect data:"+ errors + "\n"; 
    }
    if (vacio) {
        msg += vacio;
    }
    alert(msg); 
    return false;
}
}

function inicializaFormularioCandidato() 
{ 
	with (document.nominaciones) {
	    nombre_candidatoP.opcional=false; 
	    nombre_candidatoP.label="Name of Candidate";
	    apellidos_candidatoP.opcional=false; 
	    apellidos_candidatoP.label="Surname(s)";
	    institucion_candidatoP.opcional=true; 
	    institucion_candidatoP.label="Organization";   
	    posicion_candidatoP.opcional=false; 
	    posicion_candidatoP.label="Position";    
	    direccion_candidatoP.opcional=false; 
	    direccion_candidatoP.label="Addres";	
	    cp_candidatoP.opcional=false; 
	    cp_candidatoP.label="Zip/Postal Code";  
	    ciudad_candidatoP.opcional=false; 
	    ciudad_candidatoP.label="City";
	    pais_candidatoP.opcional=false;
	    pais_candidatoP.label="Country"; 
	    email_candidatoP.opcional=false; 
	    email_candidatoP.label="Email";
	    telefono_candidatoP.opcional=false; 
	    telefono_candidatoP.label="Telephone";  
	    movil_candidatoP.opcional=true; 
	    movil_candidatoP.label="Cell Phone";
	    fax_candidatoP.opcional=true; 
	    fax_candidatoP.label="Fax";
		sexo_candidatoP.opcional = false;
		sexo_candidatoP.label = "Sex of candidate";
		nacionalidad_candidatoP.opcional = false;
		nacionalidad_candidatoP.label = "Current nationality(ies)";	
		ciencia_candidatoP.opcional = false;
		ciencia_candidatoP.label = "Scientific area";
		meritos_candidatoP.opcional = false;
		meritos_candidatoP.label = "Nominated for";
		
		//Pongo a null los label del institución, para que la validación no pase por estos campos		
	    nombre_inst_candidatoI.label=null;	    
	    web_candidatoI.label=null;	    
	    legalform_candidatoI.label=null;
	    representative_candidatoI.label=null;
	    posicion_candidatoI.label=null;	  	    
	    direccion_candidatoI.label=null;
	    cp_candidatoI.label=null;
	    ciudad_candidatoI.label=null;
	    pais_candidatoI.label=null;
	    email_candidatoI.label=null;
	    telefono_candidatoI.label=null;
	    movil_candidatoI.label=null;
	    fax_candidatoI.label=null;
		ciencia_candidatoI.label = null;
		meritos_candidatoI.label = null;
		
		
		if (document.getElementById('carta_candidatoP['+indiceSeleccion+']')){
			document.getElementById('carta_candidatoP['+indiceSeleccion+']').opcional=false; 
			document.getElementById('carta_candidatoP['+indiceSeleccion+']').label="Candidate's main contributions";  
		}
	    if (document.getElementById('cv_candidatoP['+indiceSeleccion+']')){
			document.getElementById('cv_candidatoP['+indiceSeleccion+']').opcional=false; 
			document.getElementById('cv_candidatoP['+indiceSeleccion+']').label="Candidate CV";  
		}
		
		if (document.getElementById('carta_candidatoI['+indiceSeleccion+']')) document.getElementById('carta_candidatoI['+indiceSeleccion+']').label=null;
		if (document.getElementById('cv_candidatoI['+indiceSeleccion+']')) document.getElementById('cv_candidatoI['+indiceSeleccion+']').label=null;
		
	}
}

function esCandidatoValido() 
{ 
with (document.nominaciones) {
    var msg; 
    var empty_fields = ""; 
    var errors = ""; 
    var vacio= "";
    // Inicializa los valores del formulario 
    inicializaFormularioCandidato(); 
 
    // Validacion 
    for(var i = 0; i < length; i++) { 
        var e = elements[i];
        if ( ((e.type == "text")|| (e.type == "select") || (e.type == "textarea") ||(e.type == "password")) && (e.label!=null) ){ 
            // primero chequea que no este vacio 
            if ((((e.value == null) ||(e.value == "") || esVacio(e.value)) && !e.opcional)) { 
                empty_fields += "\n          " + e.label; 
                continue; 
            } 
 
            // Chequea que los campos text no tenga comilla simple 
            if (tieneComilla(e.value)) { 
                 e.value = e.value.replace(/'/g,'´');
                continue; 
            }        
        }
    }
                // array con los campos de solo letras
    arrayletras = new crearray(4);
    arrayletras[1]="nombre_candidatoP";
    arrayletras[2]="apellidos_candidatoP";
	arrayletras[3]="ciudad_candidatoP";
	arrayletras[4]="pais_candidatoP";
    var contador;
    for (contador=1;contador<=4;contador++){
       var a = eval(arrayletras[contador] + ".value");
       if (sinLetras(a)){
          var etiqueta = eval (arrayletras[contador] + ".label");
          errors += "\n          " + etiqueta;
       }
    }
     // array con los campos de solo numeros
    arraynumeros = new crearray(1);
    arraynumeros[1]="telefono_candidatoP";
    
    var contador;    
    for (contador=1;contador<=1;contador++){
       var a = eval(arraynumeros[contador] + ".value");         
          if (!sinNumeros(a)){
            var etiqueta = eval (arraynumeros[contador] + ".label");
            errors += "\n          " + etiqueta + " (this must be numeric)";
          }
     }
    	
    //Validación de email       
    if (email_candidatoP.value!=''){
                valor= email_candidatoP.value;
                if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor))){
                                errors += "\n          E-mail";
                        }
        }	
	//validacion de select	
	if (pais_candidatoP.options[pais_candidatoP.selectedIndex].value==''){
		empty_fields += "\n          Country";
	}	
	
	if (sexo_candidatoP.options[sexo_candidatoP.selectedIndex].value==''){
		empty_fields += "\n          Sex of candidate:";
	}

	if (nacionalidad_candidatoP.selectedIndex==-1){
		empty_fields += "\n          Current nationality(ies):";
	}	
	oCarta=document.getElementById('carta_candidatoP['+indiceSeleccion+']');
	oCv=document.getElementById('cv_candidatoP['+indiceSeleccion+']');	
    //Validación de ficheros       
	extension = (oCarta.value.substring(oCarta.value.lastIndexOf("."))).toLowerCase();
	if (extension =="")
		empty_fields += "\n          Candidate's main contributions";
    else if (extension !='.pdf'){
        errors += "\n          Candidate's main contributions";
    }  
	extension = (oCv.value.substring(oCv.value.lastIndexOf("."))).toLowerCase();
	if (extension =="")
		empty_fields += "\n          Candidate CV";
    else if (extension !='.pdf'){
        errors += "\n          Candidate CV";
    }  		
    
    var contador;

        if (!empty_fields && !errors && !vacio) {  
                return true;  
        }
        
    msg  = "______________________________________________________\n\n" 
    msg += "Form not submitted due to one or more errors.\n"; 
    msg += "Please correct data and try again.\n"; 
    msg += "______________________________________________________\n\n" 
    if (empty_fields) { 
        msg += "- The following compulsory fields have not been completed:"  
                + empty_fields + "\n"; 
    } 
    if (errors) { 
        msg += "- These fields have incorrect data:"+ errors + "\n"; 
    }
    if (vacio) {
        msg += vacio;
    }
    alert(msg); 
    return false;
}

}
function inicializaFormularioCandidatoI() 
{ 
	with (document.nominaciones) {
	    nombre_inst_candidatoI.opcional=false; 
	    nombre_inst_candidatoI.label="Candidate Organization";
	    web_candidatoI.opcional=true; 
	    web_candidatoI.label="Website";
	    legalform_candidatoI.opcional=true; 
	    legalform_candidatoI.label="Legal form";   
	    representative_candidatoI.opcional=false; 
	    representative_candidatoI.label="Representative/Office holder";    
	    posicion_candidatoI.opcional=false; 
	    posicion_candidatoI.label="Position";	  
	    direccion_candidatoI.opcional=false; 
	    direccion_candidatoI.label="Addres";	
	    cp_candidatoI.opcional=false; 
	    cp_candidatoI.label="Zip/Postal Code";  
	    ciudad_candidatoI.opcional=false; 
	    ciudad_candidatoI.label="City";
	    pais_candidatoI.opcional=false;
	    pais_candidatoI.label="Country"; 
	    email_candidatoI.opcional=false; 
	    email_candidatoI.label="Email";
	    telefono_candidatoI.opcional=false; 
	    telefono_candidatoI.label="Telephone";  
	    movil_candidatoI.opcional=true; 
	    movil_candidatoI.label="Cell Phone";
	    fax_candidatoI.opcional=true; 
	    fax_candidatoI.label="Fax";
		ciencia_candidatoI.opcional = false;
		ciencia_candidatoI.label = "Scientific area";
		meritos_candidatoI.opcional = false;
		meritos_candidatoI.label = "Nominated for";
	    	    
		
		//Pongo a null los label del candidato individuo		
	    nombre_candidatoP.label=null;
	    apellidos_candidatoP.label=null;
	    institucion_candidatoP.label=null;
	    posicion_candidatoP.label=null;
	    direccion_candidatoP.label=null;
	    cp_candidatoP.label=null;
	    ciudad_candidatoP.label=null;
	    pais_candidatoP.label=null;
	    email_candidatoP.label=null;
	    telefono_candidatoP.label=null;
	    movil_candidatoP.label=null;   
	    fax_candidatoP.label=null;   
		ciencia_candidatoP.label = null;
		meritos_candidatoP.label = null;
		
		if (document.getElementById('carta_candidatoI['+indiceSeleccion+']')){
			document.getElementById('carta_candidatoI['+indiceSeleccion+']').opcional=false; 
			document.getElementById('carta_candidatoI['+indiceSeleccion+']').label="Candidate's main contributions";  
		}	    
		
		if (document.getElementById('carta_candidatoP['+indiceSeleccion+']')) document.getElementById('carta_candidatoP['+indiceSeleccion+']').label=null;
		if (document.getElementById('cv_candidatoP['+indiceSeleccion+']')) document.getElementById('cv_candidatoP['+indiceSeleccion+']').label=null;
	}
}

function esCandidatoInstitucionValido() 
{ 
with (document.nominaciones) {
    var msg; 
    var empty_fields = ""; 
    var errors = ""; 
    var vacio= "";
    // Inicializa los valores del formulario 
    inicializaFormularioCandidatoI(); 
 
    // Validacion 
    for(var i = 0; i < length; i++) { 
        var e = elements[i];
        if ( ((e.type == "text") || (e.type == "select") || (e.type == "textarea") ||(e.type == "password")) && (e.label!=null) ) { 
            // primero chequea que no este vacio 
            if ((((e.value == null) ||(e.value == "") || esVacio(e.value)) && !e.opcional)) { 
                empty_fields += "\n          " + e.label; 
                continue; 
            } 
 
            // Chequea que los campos text no tenga comilla simple 
            if (tieneComilla(e.value)) { 
                e.value = e.value.replace(/'/g,'´');
                continue; 
            }        
        }
    }
                // array con los campos de solo letras
    arrayletras = new crearray(4);
    arrayletras[1]="nombre_inst_candidatoI";
    arrayletras[2]="representative_candidatoI";
	arrayletras[3]="ciudad_candidatoI";
	arrayletras[4]="pais_candidatoI";
    var contador;
    for (contador=1;contador<=4;contador++){
       var a = eval(arrayletras[contador] + ".value");
       if (sinLetras(a)){
          var etiqueta = eval (arrayletras[contador] + ".label");
          errors += "\n          " + etiqueta;
       }
    }
     // array con los campos de solo numeros
    arraynumeros = new crearray(1);
    arraynumeros[1]="telefono_candidatoI";
    
    var contador;    
    for (contador=1;contador<=1;contador++){
       var a = eval(arraynumeros[contador] + ".value");         
          if (!sinNumeros(a)){
            var etiqueta = eval (arraynumeros[contador] + ".label");
            errors += "\n          " + etiqueta + "(this must be numeric)";
          }
     }
    
    //Validación de email       
    if (email_candidatoI.value!=''){
                valor= email_candidatoI.value;
                if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor))){
                                errors += "\n          E-mail";
                        }
        }

	//validacion de select	
	if (pais_candidatoI.options[pais_candidatoI.selectedIndex].value==''){
		empty_fields += "\n          Country";
	}		
		
    //Validación de ficheros       
	oCarta=document.getElementById('carta_candidatoI['+indiceSeleccion+']');
	extension = (oCarta.value.substring(oCarta.value.lastIndexOf("."))).toLowerCase();
	if (extension =="")
		empty_fields += "\n          Candidate's main contributions";
    else if (extension !='.pdf'){
        errors += "\n          Candidate's main contributions";
    }  
	    
    var contador;

        if (!empty_fields && !errors && !vacio) {   
                return true;  
        }
        
    msg  = "______________________________________________________\n\n" 
    msg += "Form not submitted due to one or more errors.\n"; 
    msg += "Please correct data and try again.\n"; 
    msg += "______________________________________________________\n\n" 
    if (empty_fields) { 
        msg += "- The following compulsory fields have not been completed:"  
                + empty_fields + "\n"; 
    } 
    if (errors) { 
        msg += "- These fields have incorrect data:"+ errors + "\n"; 
    }
    if (vacio) {
        msg += vacio;
    }
    alert(msg); 
    return false;
}
}

function esCandValido() {
	for (i=0;i<document.nominaciones.tipocandidato.length;i++){ 
       if (document.nominaciones.tipocandidato[i].checked) 
          break; 
    } 
	aux=document.nominaciones.tipocandidato[i].value;
	if (aux=="persona")
		return esCandidatoValido();
	else return esCandidatoInstitucionValido();
}

//Validación de Fechas
function esDigito(sChr){
        var sCod = sChr.charCodeAt(0);
        return ((sCod > 47) && (sCod < 58));
}

function valSep(oTxt){
        var bOk = false;
        bOk = bOk || ((oTxt.value.charAt(2) == "-") && (oTxt.value.charAt(5) == "-"));
        bOk = bOk || ((oTxt.value.charAt(2) == "/") && (oTxt.value.charAt(5) == "/"));
        return bOk;
}

function finMes(oTxt){
        var nMes = parseInt(oTxt.value.substr(3, 2), 10);
        var nRes = 0;
        switch (nMes){
                case 1: nRes = 31; break;
                case 2: nRes = 29; break;
                case 3: nRes = 31; break;
                case 4: nRes = 30; break;
                case 5: nRes = 31; break;
                case 6: nRes = 30; break;
                case 7: nRes = 31; break;
                case 8: nRes = 31; break;
                case 9: nRes = 30; break;
                case 10: nRes = 31; break;
                case 11: nRes = 30; break;
                case 12: nRes = 31; break;
        }
        return nRes;
}

function valDia(oTxt){
        var bOk = false;
        var nDia = parseInt(oTxt.value.substr(0, 2), 10);
        bOk = bOk || ((nDia >= 1) && (nDia <= finMes(oTxt)));
        return bOk;
}

function valMes(oTxt){
        var bOk = false;
        var nMes = parseInt(oTxt.value.substr(3, 2), 10);
        bOk = bOk || ((nMes >= 1) && (nMes <= 12));
        return bOk;
}

function valAno(oTxt){
        var bOk = true;
        var nAno = oTxt.value.substr(6);
        bOk = bOk && ((nAno.length == 2) || (nAno.length == 4));
        if (bOk){
                for (var i = 0; i < nAno.length; i++){
                        bOk = bOk && esDigito(nAno.charAt(i));
                }
        }
        return bOk;
}

function valFecha(oTxt){
        var bOk = true;
        if (oTxt.value != ""){
                bOk = bOk && (valAno(oTxt));
                bOk = bOk && (valMes(oTxt));
                bOk = bOk && (valDia(oTxt));
                bOk = bOk && (valSep(oTxt));
                if (!bOk){
                        alert("Fecha invalida");
                        oTxt.value = "";
                        oTxt.focus();
                }
        }
}

function validarNumeros(event){
	var key=window.event.keyCode;//codigo de tecla. 
		if (key < 48 || key > 57){//si no es numero  
		window.event.keyCode=0;//anula la entrada de texto. 
	}
}
//FUNCIONES DE NAVEGACION POR EL FORMULARIO

function limpiar(archivo)	{
//LIMPIA UN INPUT FILE
	f = document.getElementById(archivo);
	nuevoFile = document.createElement("input");
	nuevoFile.id = f.id;
	nuevoFile.type = "file";
	nuevoFile.name = archivo;
	nuevoFile.value = "";
	nuevoFile.onchange = f.onchange;
	nodoPadre = f.parentNode;
	nodoSiguiente = f.nextSibling;
	nodoPadre.removeChild(f);
	(nodoSiguiente == null) ? nodoPadre.appendChild(nuevoFile):
		nodoPadre.insertBefore(nuevoFile, nodoSiguiente);
} 
/*
function cargar(archivo, fichero)	{
//CARGA UN INPUT FILE
	f = document.getElementById(archivo);
	nuevoFile = document.createElement("input");
	nuevoFile.id = f.id;
	nuevoFile.type = "file";
	nuevoFile.name = archivo;
	nuevoFile.value = fichero;
	nuevoFile.onchange = f.onchange;
	nodoPadre = f.parentNode;
	nodoSiguiente = f.nextSibling;
	nodoPadre.removeChild(f);
	(nodoSiguiente == null) ? nodoPadre.appendChild(nuevoFile):
		nodoPadre.insertBefore(nuevoFile, nodoSiguiente);
} */

function limpiarPaso3(tipo){
//PARA BORRAR TODOS LOS DATOS DE UN CANDIDATO
	if (tipo=="persona"){
		with (document.nominaciones) {
			nombre_candidatoP.value="";
			apellidos_candidatoP.value="";
			institucion_candidatoP.value="";
			posicion_candidatoP.value="";
			direccion_candidatoP.value="";
			cp_candidatoP.value="";
			ciudad_candidatoP.value="";
			pais_candidatoP.value="";
			email_candidatoP.value="";
			telefono_candidatoP.value="";
			movil_candidatoP.value="";
			fax_candidatoP.value="";
			ciencia_candidatoP.value = "";
			meritos_candidatoP.value = "";
		}
//		limpiar("carta_candidatoP");
//		limpiar("cv_candidatoP");
	} else if (tipo=="institucion"){
		with (document.nominaciones) {
			nombre_inst_candidatoI.value="";
			web_candidatoI.value="";
			legalform_candidatoI.value="";
			representative_candidatoI.value="";
			posicion_candidatoI.value="";
			direccion_candidatoI.value="";
			cp_candidatoI.value="";
			ciudad_candidatoI.value="";
			pais_candidatoI.value="";
			email_candidatoI.value="";
			telefono_candidatoI.value="";
			movil_candidatoI.value="";
			fax_candidatoI.value="";
			ciencia_candidatoI.value = "";
			meritos_candidatoI.value = "";
		}
//		limpiar("carta_candidatoI");
//		limpiar("cv_candidatoI");
	}
}

function cargarPaso3(indice){
//PARA CARGAR TODOS LOS DATOS DE UN CANDIDATO
	ref="candidatos"+indice;
	aux=document.getElementById(ref);
	document.getElementById('listaCandidatos').selectedIndex=indice-1;
	//Oculto todos los div de los files, para luego solo mostrar los del candidato seleccioando
	for (i=1;i<=document.getElementById('listaCandidatos').length;i++){ 
		document.getElementById('dcarta_candidatoP'+i).style.display="none";
		document.getElementById('dcv_candidatoP'+i).style.display="none";
		document.getElementById('dcarta_candidatoI'+i).style.display="none";
	}
	
	if (aux!=null){
		if (aux.value!=""){ 
			cand=aux.value.split("&$&");
			aux_cat=cand[0];
			if (aux_cat=="persona"){
				with (document.nominaciones) {
					nombre_candidatoP.value=cand[1];
					apellidos_candidatoP.value=cand[2];
					institucion_candidatoP.value=cand[3];
					posicion_candidatoP.value=cand[4];
					direccion_candidatoP.value=cand[5];
					cp_candidatoP.value=cand[6];
					ciudad_candidatoP.value=cand[7];
					pais_candidatoP.value=cand[8];
					email_candidatoP.value=cand[9];
					telefono_candidatoP.value=cand[10];
					movil_candidatoP.value=cand[11];
					fax_candidatoP.value=cand[12];
					sexo_candidatoP.value = cand[13];
					nacionalidad_candidatoP.value = cand[14];
					ciencia_candidatoP.value = cand[15];
					meritos_candidatoP.value = cand[16];
					document.getElementById('tipocandidatop').checked=true;					
				}					
				cambiarPersona(indice);				
			} else if (aux_cat=="institucion"){
				with (document.nominaciones) {
					nombre_inst_candidatoI.value=cand[1];
					web_candidatoI.value=cand[2];
					legalform_candidatoI.value=cand[3];
					representative_candidatoI.value=cand[4];
					posicion_candidatoI.value=cand[5];
					direccion_candidatoI.value=cand[6];
					cp_candidatoI.value=cand[7];
					ciudad_candidatoI.value=cand[8];
					pais_candidatoI.value=cand[9];
					email_candidatoI.value=cand[10];
					telefono_candidatoI.value=cand[11];
					movil_candidatoI.value=cand[12];
					fax_candidatoI.value=cand[13];
					ciencia_candidatoI.value = cand[14];
					meritos_candidatoI.value = cand[15];
					document.getElementById('tipocandidatoi').checked=true;
				}
				document.getElementById('dcarta_candidatoI'+indice).style.display="block";
				cambiarInstitucion(indice);
			}
		}
	}else{
		limpiarPaso3 ('persona');
		document.getElementById('dcarta_candidatoP'+indice).style.display="block";
		document.getElementById('dcv_candidatoP'+indice).style.display="block";
	}
	
	if (indice==1){
		//Oculto los botones de eliminar.
		document.getElementById('deleteP').style.display="none";
		document.getElementById('deleteI').style.display="none";	
	}else{
		document.getElementById('deleteP').style.display="block";
		document.getElementById('deleteI').style.display="block";
	}
	indiceSeleccion=indice;
}

//FUNCIONES DE NAVEGACION POR LOS CANDIDATOS
function cambiarPersona(indice){
	//limpiarPaso3("institucion");
	document.getElementById('paso3Institucion').style.display="none";
	document.getElementById('paso3Persona').style.display="block";
	if (indice){
		document.getElementById('dcarta_candidatoP'+indice).style.display="block";
		document.getElementById('dcv_candidatoP'+indice).style.display="block";
	}else{
		document.getElementById('dcarta_candidatoP'+indiceSeleccion).style.display="block";
		document.getElementById('dcv_candidatoP'+indiceSeleccion).style.display="block";	
	}
}
function cambiarInstitucion(indice){
	//limpiarPaso3("persona");
	document.getElementById('paso3Persona').style.display="none";
	document.getElementById('paso3Institucion').style.display="block";
	if (indice){
		document.getElementById('dcarta_candidatoI'+indice).style.display="block";		
	}else{
		document.getElementById('dcarta_candidatoI'+indiceSeleccion).style.display="block";		
	}
}
//FIN FUNCIONES DE NAVEGACION POR LOS CANDIDATOS


function procesarCandidato() {
//CARGA EL SELECT PERSONA-INSTITUCION SI PROCEDE
	document.getElementById('controlPaso3').style.display="block";
	for (i=0;i<document.nominaciones.categoria.length;i++){ 
       if (document.nominaciones.categoria[i].checked) 
          break; 
    } 
	categoria=document.nominaciones.categoria[i].value;
	if ((categoria=="CC") || (categoria=="CD") || (categoria=="MU"))
		document.getElementById("paso3Selector").style.display="block";
	else document.getElementById("paso3Selector").style.display="none";
}

function cargaDatos(){
	for (i=0;i<document.nominaciones.categoria.length;i++){ 
       if (document.nominaciones.categoria[i].checked) 
          break; 
    } 
	document.getElementById('rcategoria').innerHTML=document.nominaciones.categoria[i].alt;
	
	for (i=0;i<document.nominaciones.institucion.length;i++){ 
       if (document.nominaciones.institucion[i].checked) 
          break; 
    } 
	document.getElementById('rninstitucion').innerHTML=document.nominaciones.institucion[i].alt;
	document.getElementById('rnnombreinst').innerHTML=document.nominaciones.nombreinst.value;
	document.getElementById('rnweb').innerHTML="<a href='"+document.nominaciones.web.value+"' target='_blank'>"+document.nominaciones.web.value+"</a>";
	document.getElementById('rnnombre').innerHTML=document.nominaciones.nombre.value;
	document.getElementById('rnapellidos').innerHTML=document.nominaciones.apellido.value;
	document.getElementById('rnposicion').innerHTML=document.nominaciones.posicion.value;
	document.getElementById('rndireccion').innerHTML=document.nominaciones.direccion.value;
	document.getElementById('rncp').innerHTML=document.nominaciones.cp.value;
	document.getElementById('rnciudad').innerHTML=document.nominaciones.ciudad.value;
	document.getElementById('rnpais').innerHTML=document.nominaciones.pais.value;
	document.getElementById('rnemail').innerHTML="<a href='mailto:"+document.nominaciones.email.value+"'>"+document.nominaciones.email.value+"</a>";
	document.getElementById('rntelefono').innerHTML=document.nominaciones.telefono.value;
	document.getElementById('rnfax').innerHTML=document.nominaciones.fax.value;
	document.getElementById('rncarta').innerHTML=document.nominaciones.carta_nominador.value;
	
	oCandidatos=document.getElementById('rcandidatos');
	for (i=1;i<=document.getElementById('listaCandidatos').length;i++){ 
		ref="candidatos"+i;
		aux=document.getElementById(ref);
		if (aux.value!=""){ 
			cand=aux.value.split("&$&");
			aux_cat=cand[0];
			sNacion = "";
			if(cand[14].value!=""){
				aux_nacion = cand[14].split("-");
				for(j=0;j<(aux_nacion.length);j++){
					if(j==(aux_nacion.length-2)){
						sNacion += aux_nacion[j];
					}else{
						if (aux_nacion[j]!="")
							sNacion += aux_nacion[j]+",";
					}
				}	
			}

			if (aux_cat=="persona")
			oCandidatos.innerHTML+="<div class='subtitulo'><strong>CANDIDATE "+i+"</strong></div><div class='confirmar_form_content'><div style='width: 98%;'><div style='width: 15%;'><strong>Name of candidate</strong>:</div> <div class='caja_derecha'>"+cand[1]+"</div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Surname(s)</strong>:</div> <div class='caja_derecha'>"+cand[2]+"</div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Institution</strong>:</div> <div class='caja_derecha'>"+cand[3]+"</div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Position</strong>:</div><div class='caja_derecha'> "+cand[4]+"</div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Address</strong>:</div><div class='caja_derecha'> "+cand[5]+"</div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Zip / Postal code</strong>:</div> <div class='caja_derecha'>"+cand[6]+"</div></div><div style='width: 98%;'><div style='width: 15%;'><strong>City</strong>:</div> <div class='caja_derecha'>"+cand[7]+"</div></div> <div style='width: 98%;'><div style='width: 15%;'><strong>Country</strong>: </div><div class='caja_derecha'>"+cand[8]+" </div></div><div style='width: 98%;'><div style='width: 15%;'><strong>E-mail</strong>:</div><div class='caja_derecha'> <a href='"+cand[9]+"'>"+cand[9]+"</a></div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Tel.</strong>:</div> <div class='caja_derecha'>"+cand[10]+"</div></div> <div style='width: 98%;'><div style='width: 15%;'><strong>Cell Phone</strong>:</div><div class='caja_derecha'> "+cand[11]+"</div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Fax</strong>:</div><div class='caja_derecha'> "+cand[12]+"</div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Sex of candidate</strong>:</div><div class='caja_derecha'>"+cand[13]+"</div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Current nationality(ies)</strong>:</div><div class='caja_derecha'>"+sNacion+"</div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Scientific area</strong>:</div><div class='caja_derecha'>"+cand[15]+"</div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Description</strong>:</div><div class='caja_derecha'>"+cand[17]+" </div></div> <div style='width: 98%;'><div style='width: 15%;'><strong>Candidate CV</strong>:</div><div class='caja_derecha'>"+cand[18]+"</div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Nominated for</strong>:</div><div class='caja_derecha_multilinea'>"+cand[16]+"</div></div></div> "; 
			else if (aux_cat=="institucion")
			oCandidatos.innerHTML+="<div class='subtitulo'><strong>CANDIDATE "+i+"</strong></div><div class='confirmar_form_content'><div style='width: 98%;'><div style='width: 15%;'><strong>Candidate institution</strong>: </div> <div class='caja_derecha'>"+cand[1]+"</div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Website</strong>: </div> <div class='caja_derecha'><a href='"+cand[2]+"' target='_blank'>"+cand[2]+"</a></div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Legal form</strong>: </div> <div class='caja_derecha'>"+cand[3]+" </div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Representative / Office holder</strong>: </div> <div class='caja_derecha'>"+cand[4]+"</div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Position</strong>: </div> <div class='caja_derecha'>"+cand[5]+"</div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Address</strong>: </div> <div class='caja_derecha'>"+cand[6]+"</div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Zip / Postal code</strong>: </div> <div class='caja_derecha'>"+cand[7]+"</div></div><div style='width: 98%;'><div style='width: 15%;'><strong>City</strong>: </div> <div class='caja_derecha'>"+cand[8]+" </div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Country</strong>: </div> <div class='caja_derecha'>"+cand[9]+" </div></div><div style='width: 98%;'><div style='width: 15%;'><strong>E-mail</strong>: </div> <div class='caja_derecha'><a href='"+cand[10]+"'>"+cand[10]+"</a></div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Tel.</strong>: </div> <div class='caja_derecha'>"+cand[11]+" </div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Cell Phone</strong>: </div> <div class='caja_derecha'>"+cand[12]+"</div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Fax</strong>: </div> <div class='caja_derecha'>"+cand[13]+"</div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Description</strong>:</div> <div class='caja_derecha'>"+cand[16]+" </div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Scientific area</strong>:</div><div class='caja_derecha'>"+cand[14]+"</div></div><div style='width: 98%;'><div style='width: 15%;'><strong>Nominated for</strong>:</div><div class='caja_derecha_multilinea'>"+cand[15]+"</div></div></div> ";
		}
    } 
	return true;
	
}
function iCandidatos() {
return (document.getElementById('listaCandidatos').length);
}
//NAVEGACION GENERAL DEL FORMULARIO
function avanzarAPaso (id){
	oldid=id-1;
	document.getElementById('tit_paso'+oldid).className='solapaoff';
	document.getElementById('paso'+oldid).style.display='none';
	document.getElementById('paso'+oldid).height='0px';
	document.getElementById('paso'+oldid).style.overflow='hidden';
	document.getElementById('tit_paso'+id).className='solapa';
	document.getElementById('paso'+id).style.display='block';
	if (id==3) procesarCandidato();			
	if (oldid==3) document.getElementById('controlPaso3').style.display="none";
	if (id==4) {
		volcarPaso3(document.getElementById('listaCandidatos').selectedIndex+1);
		cargaDatos();
	}
}
function retroAPaso (id){
	oldid=id+1;
	document.getElementById('tit_paso'+oldid).className='solapaoff';
	document.getElementById('paso'+oldid).style.display='none';
	document.getElementById('paso'+oldid).height='0px';
	document.getElementById('paso'+oldid).style.overflow='hidden';
	document.getElementById('tit_paso'+id).className='solapa';
	document.getElementById('paso'+id).style.display='block';
	if (id==3) document.getElementById('controlPaso3').style.display="block";
	if (oldid==3) document.getElementById('controlPaso3').style.display="none";
	if (oldid==4) document.getElementById('rcandidatos').innerHTML="";
}
//FIN NAVEGACION GENERAL DEL FORMULARIO

//CARGA DE CANDIDATOS EN ARRAY TEMPORAL 
function volcarPaso3(indice){
	for (i=0;i<document.nominaciones.tipocandidato.length;i++){ 
       if (document.nominaciones.tipocandidato[i].checked) 
          break; 
    } 
	tipocandidato=document.nominaciones.tipocandidato[i].value;
	
	var nacionalidadesCandidatoArray = new Array();
	var nacionalidadesCandidato = "";
	
	if(document.nominaciones.nacionalidad_candidatoP!=null){
		nacionalidadesCandidatoArray = document.nominaciones.nacionalidad_candidatoP;
		while (nacionalidadesCandidatoArray.selectedIndex!=-1){
			if (nacionalidadesCandidatoArray.selectedIndex!=0){
				nacionalidadesCandidato += nacionalidadesCandidatoArray.options[nacionalidadesCandidatoArray.selectedIndex].value +"-";
			}
			nacionalidadesCandidatoArray.options[nacionalidadesCandidatoArray.selectedIndex].selected = false;
		}
	}
	
	if (tipocandidato=="persona"){
		scarta=document.getElementById('carta_candidatoP['+indice+']').value;
		scv=document.getElementById('cv_candidatoP['+indice+']').value;
		with (document.nominaciones) {
			result="persona&$&"+nombre_candidatoP.value+"&$&"+apellidos_candidatoP.value+"&$&"+institucion_candidatoP.value+"&$&"+posicion_candidatoP.value+"&$&"+direccion_candidatoP.value+"&$&"+cp_candidatoP.value+"&$&"+ciudad_candidatoP.value+"&$&"+pais_candidatoP.value+"&$&"+email_candidatoP.value+"&$&"+telefono_candidatoP.value+"&$&"+movil_candidatoP.value+"&$&"+fax_candidatoP.value+"&$&"+sexo_candidatoP.value+"&$&"+nacionalidadesCandidato+"&$&"+ciencia_candidatoP.value+"&$&"+meritos_candidatoP.value+"&$&"+scarta+"&$&"+scv;
		}		
		if (document.getElementById('candidatos'+indice)){
			document.getElementById('candidatos'+indice).value=result;
		}else{
			document.getElementById('candidatos_arr').innerHTML+="<input type='hidden' name='candidatos"+indice+"' id='candidatos"+indice+"' value='' />";
			document.getElementById('candidatos'+indice).value = result;
		}
//		document.getElementById('candidatos_arr').innerHTML+="<input type='file' name='carta_candidatos"+indice+"' id='carta_candidatos"+indice+"' value='"+document.nominaciones.carta_candidatoP.value+"' />";
//		document.getElementById('candidatos_arr').innerHTML+="<input type='file' name='cv_candidatos"+indice+"' id='cv_candidatos"+indice+"' value='"+document.nominaciones.cv_candidatoP.value+"' />";
		limpiarPaso3("persona");
	} else if (tipocandidato=="institucion") {
		scarta=document.getElementById('carta_candidatoI['+indice+']').value;		
		with (document.nominaciones) {
			result="institucion&$&"+nombre_inst_candidatoI.value+"&$&"+web_candidatoI.value+"&$&"+legalform_candidatoI.value+"&$&"+representative_candidatoI.value+"&$&"+posicion_candidatoI.value+"&$&"+direccion_candidatoI.value+"&$&"+cp_candidatoI.value+"&$&"+ciudad_candidatoI.value+"&$&"+pais_candidatoI.value+"&$&"+email_candidatoI.value+"&$&"+telefono_candidatoI.value+"&$&"+movil_candidatoI.value+"&$&"+fax_candidatoI.value+"&$&"+ciencia_candidatoI.value+"&$&"+meritos_candidatoI.value+"&$&"+scarta;
		}
		
		if (document.getElementById('candidatos'+indice))
			document.getElementById('candidatos'+indice).value=result;
		else{
			document.getElementById('candidatos_arr').innerHTML+="<input type='hidden' name='candidatos"+indice+"' id='candidatos"+indice+"' value='"+result+"' />";
		}		
//		document.getElementById('candidatos_arr').innerHTML+="<input type='file' name='carta_candidatos"+indice+"' id='carta_candidatos"+indice+"' value='"+document.nominaciones.carta_candidatoI.value+"' />";
//		document.getElementById('candidatos_arr').innerHTML+="<input type='file' name='cv_candidatos"+indice+"' id='cv_candidatos"+indice+"' value='"+document.nominaciones.cv_candidatoI.value+"' />";
		limpiarPaso3("institucion");
	}
}
function addCandidato(){

	//Hago visibles los botones de eliminar.
	document.getElementById('deleteP').style.display="block";
	document.getElementById('deleteI').style.display="block";
	
	lista=document.getElementById('listaCandidatos');
	num=(lista.length+1);
	if (num>25){
		alert ('The system will only accept up to 25 candidates. Any further nominations should be made in writing to the BBVA Foundation at awards-info@fbbva.es. Thank you.');
		return false;
	}else {
		aux=document.createElement('option');
		aux.text="Candidate "+(num);
		aux.value=(num);
		try {
			lista.add(aux, null);
		} catch(ex) {
			lista.add(aux);
		}
		lista.selectedIndex=num-1;
		
		for (j=1;j<=lista.length-1;j++){ 
			document.getElementById('dcarta_candidatoP'+j).style.display="none";
			document.getElementById('dcv_candidatoP'+j).style.display="none";
			document.getElementById('dcarta_candidatoI'+j).style.display="none";
		}
		divPadre=document.getElementById('dcarta_candidatoP');
		
		nuevoDiv = document.createElement("div");
		nuevoDiv.id = 'dcarta_candidatoP'+num;		
		nuevoDiv.name = 'dcarta_candidatoP'+num;
		nuevoDiv.setAttribute('style','text-align:center; display:block;');
		nuevoDiv.innerHTML+='<input type="file" name="carta_candidatoP['+num+']" id="carta_candidatoP['+num+']" />';		
		
		divPadre.appendChild(nuevoDiv);
		
//		divPadre.appendChild(nuevoDiv);
		
		divPadre=document.getElementById('dcv_candidatoP');
		
		nuevoDiv = document.createElement("div");
		nuevoDiv.id = 'dcv_candidatoP'+num;		
		nuevoDiv.name = 'dcv_candidatoP'+num;
		nuevoDiv.setAttribute('style','text-align:center; display:block;');				
		nuevoDiv.innerHTML+='<input type="file" name="cv_candidatoP['+num+']" id="cv_candidatoP['+num+']" />';
		
		divPadre.appendChild(nuevoDiv);
		
		divPadre=document.getElementById('dcarta_candidatoI');
		
		nuevoDiv = document.createElement("div");
		nuevoDiv.id = 'dcarta_candidatoI'+num;		
		nuevoDiv.name = 'dcarta_candidatoI'+num;
		nuevoDiv.setAttribute('style','text-align:center; display:block;');							
		nuevoDiv.innerHTML+='<input type="file" name="carta_candidatoI['+num+']" id="carta_candidatoI['+num+']" />';
		
		divPadre.appendChild(nuevoDiv);		
		
		volcarPaso3(indiceSeleccion);
		indiceSeleccion=num;		
	}
}
//FIN CARGA DE CANDIDATOS EN ARRAY TEMPORAL

function cambioListaCandidatos(){
	if (esCandValido()){
		volcarPaso3(indiceSeleccion); 
		cargarPaso3((document.getElementById('listaCandidatos').selectedIndex)+1);
	}else{
		document.getElementById('listaCandidatos').selectedIndex=indiceSeleccion-1;
		return false;
	}
		
}


//Elimina al candidato seleccionado

function eliminarCandidato(){
	//No dejo que se elimine el primero, ya que al menos debe haber un candidato
	if (indiceSeleccion!=1){
		lista=document.getElementById('listaCandidatos');						
		ultimoOption=lista.length;
		
		//Si no es el último option, lo recorro para ir pasando los datos.
		if (ultimoOption!=indiceSeleccion){
			for (i=indiceSeleccion;i<(lista.length);i++){
				document.getElementById('candidatos'+(i)).value=document.getElementById('candidatos'+(i+1)).value;
				lista.options[i].value=i;
				lista.options[i].text="Candidate "+i;
									
				//Creo un objeto con el elemento que tengo que se va a elimianr
				aux_dcarta_candidatoP=document.getElementById("dcarta_candidatoP"+i);
				aux_dcv_candidatoP=document.getElementById("dcv_candidatoP"+i);
				aux_dcarta_candidatoI=document.getElementById("dcarta_candidatoI"+i);
				
				//Asigno al siguiente elemento, el nombre e id del que se va a  eliminar				
				document.getElementById("dcarta_candidatoP"+(i+1)).id="dcarta_candidatoP"+i;
				document.getElementById("dcv_candidatoP"+(i+1)).id="dcv_candidatoP"+i;
				document.getElementById("dcarta_candidatoI"+(i+1)).id="dcarta_candidatoI"+i;
				
				//Al elemento que se va a aeliminar, le pongo el id del siguiente.
				aux_dcarta_candidatoP.id="dcarta_candidatoP"+(i+1);
				aux_dcv_candidatoP.id="dcv_candidatoP"+(i+1);
				aux_dcarta_candidatoI.id="dcarta_candidatoI"+(i+1);
				
				//Hago lo mismo para el carta_candidatoP
				aux_carta_candidatoP=document.getElementById("carta_candidatoP["+i+"]");
				
				document.getElementById("carta_candidatoP["+(i+1)+"]").name="carta_candidatoP["+i+"]";
				document.getElementById("carta_candidatoP["+(i+1)+"]").id="carta_candidatoP["+i+"]";
				
				aux_carta_candidatoP.name="carta_candidatoP["+(i+1)+"]";
				aux_carta_candidatoP.id="carta_candidatoP["+(i+1)+"]";
				
				//Hago lo mismo para el cv_candidatoP
				aux_cv_candidatoP=document.getElementById("cv_candidatoP["+i+"]");
				
				document.getElementById("cv_candidatoP["+(i+1)+"]").name="cv_candidatoP["+i+"]";
				document.getElementById("cv_candidatoP["+(i+1)+"]").id="cv_candidatoP["+i+"]";
				
				aux_cv_candidatoP.name="cv_candidatoP["+(i+1)+"]";
				aux_cv_candidatoP.id="cv_candidatoP["+(i+1)+"]";
				
				//Hago lo mismo para el carta_candidatoI
				aux_carta_candidatoI=document.getElementById("carta_candidatoI["+i+"]");
				
				document.getElementById("carta_candidatoI["+(i+1)+"]").name="carta_candidatoI["+i+"]";
				document.getElementById("carta_candidatoI["+(i+1)+"]").id="carta_candidatoI["+i+"]";
				
				aux_carta_candidatoI.name="carta_candidatoI["+(i+1)+"]";
				aux_carta_candidatoI.id="carta_candidatoI["+(i+1)+"]";
			}			
		}
		
		if (document.getElementById("candidatos"+ultimoOption)){
			divPadre=document.getElementById('candidatos_arr');
			divPadre.removeChild(document.getElementById("candidatos"+ultimoOption));
		}
		
		divPadre=document.getElementById('dcarta_candidatoP');
		divPadre.removeChild (document.getElementById("dcarta_candidatoP"+ultimoOption));		
		divPadre=document.getElementById('dcv_candidatoP');
		divPadre.removeChild (document.getElementById("dcv_candidatoP"+ultimoOption));
		divPadre=document.getElementById('dcarta_candidatoI');
		divPadre.removeChild (document.getElementById("dcarta_candidatoI"+ultimoOption));
		
		lista.options[lista.selectedIndex]=null;
		indiceSeleccion--;
		lista.selectedIndex=indiceSeleccion-1;
		cargarPaso3(indiceSeleccion);
	}
}
