function removeSpaces(item) {
  var tmp = "";
  var item_length = item.value.length;
  var item_length_minus_1 = item.value.length - 1;
  for (index = 0; index < item_length; index++) {
    if (item.value.charAt(index) != ' ') {
      tmp += item.value.charAt(index);
    }else{
      if (tmp.length > 0) {
        if (item.value.charAt(index+1) != ' ' && index != item_length_minus_1) {
          tmp += item.value.charAt(index);
        }
      }
    }
  }
  item.value = tmp;
}

var maximalwords=450;

// Do not edit the script below
if (document.layers) {netscapecorrector=1;maximalwords+=1}
if (document.all) {netscapecorrector=0}

function countwords() {
	var words="";
	var content="";
	var corrector=0;
	var text=document.inscripcion.Justificacion.value;
	words=text.split(" ");
	if (words[words.length-1]=="") {corrector=1;}
	document.inscripcion.countbox.value=(words.length)-corrector;
	if (words.length-1>=maximalwords) {
		for (i=0;i<maximalwords-netscapecorrector;i++) {
			content+=words[i]+" "
			document.inscripcion.Justificacion.value=content;
		}
	}
	var timer=setTimeout("countwords()",100);
}

function validaForm() {

  var validation = 0;

  function blankTxtField(tmpFielf,alertTxt){
    if(tmpFielf.value == '') {
	  tmpFielf.focus();
	  alert(alertTxt);
      return true;
	}
  }  
  objFrm = document.inscripcion;
  for(i = 0; i < objFrm.length; i++) {  
    if(objFrm.elements[i].type == "text" || objFrm.elements[i].type == "textarea")
	  removeSpaces(objFrm.elements[i]);
  }
  //Área de portulación
  if(objFrm.Area_postulacion[0].checked == false 
      && objFrm.Area_postulacion[1].checked == false) {
	alert("Debe seleccionar AREA DE LA POSTULACION \n (Punto I)");
	validation = 1;
    return false;
  }
  //Candidato
  if(objFrm.Apellidos.value == '' && objFrm.Nombres.value == '' &&
      objFrm.Institucion_razon_social.value == '') {
	alert("Debe ingresar un candidato ya sea PERSONA NATURAL  o \n EMPRESA o INSTITUCION");
	validation = 2;
    return false;
  }
  //Posible cadidato PERSONA NATURAL
  if(objFrm.Apellidos.value != '' || objFrm.Nombres.value != '') {
    if(objFrm.Apellidos.value == '' || objFrm.Nombres.value == '') {
	  alert("Debe ingresar NOMBRES y APELLIDOS del candidato \n (Punto II)");
	  validation = 3;
      return false;
	}	
 
 
   if(objFrm.Lugar_nacimiento_c.value == '' || objFrm.Lugar_nacimiento_p.value == '' || objFrm.Lugar_nacimiento_pa.value == '') {
	  alert("Debe ingresar ciudad, region y pais de nacimiento del candidato \n (Punto II)");
	  validation = 3;
      return false;
	}	
 
   if(objFrm.Especialidad.value == '' || objFrm.Estudios.value == '' || objFrm.Centro_estudios.value == '' || objFrm.Ciudad_centro_estudios.value == '') {
	  alert("Debe completar los datos academicos del candidato \n (Punto II)");
	  validation = 3;
      return false;
	}	
 
    //Candidato
  	  if(objFrm.Trabajo.value == '' || objFrm.Trabajo_direccion.value == '' || objFrm.Trabajo_distrito.value == '' || objFrm.Trabajo_provincia.value == '' || objFrm.Trabajo_departamento.value == '' || objFrm.Telefono_trabajo.value == '') {
	alert("Falta completar algunos campos del CENTRO DE TRABAJO 1 del candidato");
	validation = 3;
    return false;
  }
 
  }
  
   //Candidato
  if( objFrm.Institucion_razon_social.value != '') {
  	  if(objFrm.Lugar_creacion_c.value == '' || objFrm.Lugar_creacion_p.value == '' || objFrm.Lugar_creacion_pa.value == '') {
	alert("Debe ingresar ciudad, region y pais de creacion de la EMPRESA o INSTITUCION");
	validation = 4;
    return false;
  }
    //Candidato
  	  if(objFrm.Institucion_direccion.value == '' || objFrm.Institucion_distrito.value == '' || objFrm.Institucion_provincia.value == '' || objFrm.Institucion_departamento.value == '') {
	alert("Falta completar algunos campos de la DIRECCION ACTUAL de la EMPRESA o INSTITUCION");
	validation = 4;
    return false;
  }
   	  if(objFrm.Responsable_institucion.value == '') {
	alert("Debe ingresar el NOMBRE y CARGO de la persona responsable de la Institucion");
	validation = 4;
    return false;
  }
  }  
//    if(blankTxtField(objFrm.Responsable_institucion,"Debe ingresar el NOMBRE y CARGO de la persona responsable de la Institucion \n (Punto II)"))
//    validation=5;
if(blankTxtField(objFrm.Actividad,"Debe describir la ACTIVIDAD del candidato"))
    validation=6;

//  else if(blankTxtField(objFrm.Descripcion,"Debe ingresar una DESCRIPCION"))
//    validation=7;
  else if(blankTxtField(objFrm.Poblacion_beneficiada,"Debe ingresar la POBLACION BENEFICIADA por el candidato"))
    validation=8;
  else if(blankTxtField(objFrm.Justificacion,"Debe ingresar una JUSTIFICACION por la candidatura \n (Punto III)"))
    validation=9;
  else if(blankTxtField(objFrm.Proponente,"Debe ingresar sus datos completos como PROPONENTE \n (Punto IV)"))
    validation=10;
  else if(blankTxtField(objFrm.Proponente_direccion,"Debe ingresar sus datos completos como PROPONENTE \n (Punto IV)"))
    validation=11;
  else if(blankTxtField(objFrm.Proponente_distrito,"Debe ingresar sus datos completos como PROPONENTE \n (Punto IV)"))
    validation=12;
  else if(blankTxtField(objFrm.Proponente_provincia,"Debe ingresar sus datos completos como PROPONENTE \n (Punto IV)"))
    validation=13;
  else if(blankTxtField(objFrm.Proponente_departamento,"Debe ingresar sus datos completos como PROPONENTE \n (Punto IV)"))
    validation=14;
  else if(blankTxtField(objFrm.Proponente_telefono,"Debe ingresar sus datos completos como PROPONENTE \n (Punto IV)"))
    validation=15;
  else if(blankTxtField(objFrm.Proponente_email,"Debe ingresar sus datos completos como PROPONENTE \n (Punto IV)"))
    validation=16;
  else if(blankTxtField(objFrm.Relacion_candidato,"Debe ingresar sus datos completos como PROPONENTE \n (Punto IV)"))
    validation=17;
  else if(blankTxtField(objFrm.Contacto_proponente,"Debe ingresar sus datos completos como PROPONENTE \n (Punto IV)"))
    validation=18;
  else if(blankTxtField(objFrm.Referencia_1,"Debe ingresar los datos completos de al menos una REFERENCIA \n (Punto V)"))
    validation=19;
    else if(blankTxtField(objFrm.Referencia_1_organizacion_cargo,"Debe ingresar los datos completos de al menos una REFERENCIA \n (Punto V)"))
    validation=19;
  else if(blankTxtField(objFrm.Referencia_1_direccion,"Debe ingresar los datos completos de al menos una REFERENCIA \n (Punto V)"))
    validation=20;
  else if(blankTxtField(objFrm.Referencia_1_distrito,"Debe ingresar los datos completos de al menos una REFERENCIA \n (Punto V)"))
    validation=21;
  else if(blankTxtField(objFrm.Referencia_1_provincia,"Debe ingresar los datos completos de al menos una REFERENCIA \n (Punto V)"))
    validation=22;
  else if(blankTxtField(objFrm.Referencia_1_departamento,"Debe ingresar los datos completos de al menos una REFERENCIA \n (Punto V)"))
    validation=23;
  else if(blankTxtField(objFrm.Referencia_1_telefono,"Debe ingresar los datos completos de al menos una REFERENCIA \n (Punto V)"))
    validation=24;
  else if(blankTxtField(objFrm.Referencia_1_email,"Debe ingresar los datos completos de al menos una REFERENCIA \n (Punto V)"))
    validation=25;
  
  //Proceder con el envio
  else if(validation == 0) return true;
  //Por defecto no se envia el formulario hasta pasar las validaciones
  return false;
}
