function ValidateSolicitud(theForm)
{
	var i;
  var dato;
  var indicetipoconsulta;
	for(i=7;i<19;){
		if(!theForm.elements[i+1].value){
    	dato = theForm.elements[i].value;
	  	alert("Debe ingresar su " + dato);
  	  theForm.elements[i+1].focus();
    	return false;
  	}
    i = i + 2;
  }
  
  indicetipoconsulta = theForm.elements[20].selectedIndex;
  if(!indicetipoconsulta)
  {
  	alert("Debe elegir su Comuna");
    theForm.elements[20].focus();
    return false;
  }
	for(i=21;i<27;){
		if(!Trim(theForm.elements[i+1].value)){
    	dato = theForm.elements[i].value;
	  	alert("Debe ingresar su " + dato);
  	  theForm.elements[i+1].focus();
    	return false;
  	}
    i = i + 2;
  }
  
  if (!checkRut(theForm,'elements[14]','Rut de usuario invalido',true)){
		return false;
	}
  
  if (!isPositiveInteger(theForm.elements[18].value)){
		alert("Su número de teléfono debe ser un campo numérico.");
    theForm.elements[18].focus();
    return false;
	}
			
	if (!isEmail(theForm.elements[26].value)){
		alert("La dirección de e-mail no es válida.");
    theForm.elements[26].focus();
    return false;
	}
}

function validateClave(form){

  if(form.clave_sat.value == ''){
  	alert("Debe ingresar clave actual");
    form.clave_sat.focus();
    return false;
  }
  if(form.clave_nueva1.value == ''){
  	alert("Debe ingresar nueva clave");
    form.clave_nueva1.focus();
    return false;
  }
  if(form.clave_nueva2.value == ''){
  	alert("Debe volver a escribir su nueva clave");
    form.clave_nueva2.focus();
    return false;
  }


  form.page.value="preguntas_respuestas";
  form.doAction.value ="updateClaveAfiliado";
  form.submit();

  return false;
}
/*
function validatePreguntas(theform,action){
	if(theform.pregunta1.value == ""){
		alert("Debe ingresar pregunta");
		theform.pregunta1.focus();
		return false;
	} 
	if(theform.respuesta1.value == ""){
		alert("Debe ingresar respuesta");
		theform.respuesta1.focus();
		return false;
	}
  
	if(theform.pregunta2.value == ""){
		alert("Debe ingresar pregunta");
		theform.pregunta2.focus();
		return false;
	} 
	if(theform.respuesta2.value == ""){
		alert("Debe ingresar respuesta");
		theform.respuesta2.focus();
		return false;
	}
 theform.doAction.value = action;
  theform.submit();

  return false;
}*/

function validatePreguntas(theform,action){
	var i = 0;
  
	for(i=0;i<theform.respuesta.length;i++){
    if(theform.pregunta[i].value == ""){
    	alert("Debe ingresar pregunta");
      theform.pregunta[i].focus();
      return false;
      break;
    } 
  	if(theform.respuesta[i].value == ""){
    	alert("Debe ingresar respuesta");
      theform.respuesta[i].focus();
      return false;
      break;
    }
  
  }
  theform.doAction.value = action;
  theform.submit();

  return false;
}

function validatePreguntasRespuestas(theform,action){
	var i = 0;
  
	for(i=0;i<theform.respuesta.length;i++){
  	
    if(theform.pregunta[i].value == ""){
    	alert("Debe ingresar pregunta");
      theform.pregunta[i].focus();
      return false;
      break;
    } 
  	if(theform.respuesta[i].value == ""){
    	alert("Debe ingresar respuesta");
      theform.respuesta[i].focus();
      return false;
      break;
    }
  
  }
  
  theform.doAction.value = action;
  theform.submit();

  return false;
}

function validateOlvidoClave(){
  var i;
  var form1 = document.getElementById('clave_temporal');
  if(checkRut2(form1.rut_completo,'Rut Invalido',true)){
	var rut = form1.rut.value; 
	var dig = form1.digito_verificador.value; 
	var rut_completo = form1.rut_completo.value;
	rut  = rut_completo.substr(0,rut_completo.indexOf("."));
	rut_completo = rut_completo.substr(rut_completo.indexOf(".")+1,rut_completo.length);
	rut += rut_completo.substr(0,rut_completo.indexOf("."));
	rut_completo = rut_completo.substr(rut_completo.indexOf(".")+1,rut_completo.length);	
	rut += rut_completo.substr(0,rut_completo.indexOf("-"));
  dig = rut_completo.substr(rut_completo.indexOf("-")+1,rut_completo.length);

	form1.rut.value = rut;
	form1.digito_verificador.value = dig;


 	form1.submit();
	
  }
  return false;
}

function validateRespuesta(){
	var i = 0;
	var form1 = window.document.getElementsByName("clave_temporal");	
        var wvarObjRespuesta=window.document.getElementsByName("respuesta");

	for(i=0;i<wvarObjRespuesta.length;i++){
  	if(wvarObjRespuesta[i].value == ""){
    	alert("Debe ingresar respuesta");
        wvarObjRespuesta[i].focus();
      return false;
      break;
    }
  }
  form1[0].submit();

  return false;
}
function validate_confirma_email(theForm) {
	var dispongo = theForm.d_email[0];
	if (dispongo.value == "SI" && dispongo.checked) {
		theForm.email.value = Trim(theForm.email.value);
		if (theForm.email.value == ""){
			alert("Por favor, ingrese su email.");
			theForm.email.focus();
			return false;
		}else	if (!isEmail(theForm.email.value)) {
			alert("El E-mail no es correcto. Por favor, ingreselo nuevamente.");
			theForm.email.focus();
			return false;
		}
	
		theForm.email2.value = Trim(theForm.email2.value);
		if (theForm.email2.value == ""){
			alert("Por favor, ingrese la confimacion de email.");
			theForm.email2.focus();
			return false;
		}else	if (!isEmail(theForm.email2.value)) {
			alert("El E-mail de confirmación no es correcto. Por favor, ingreselo nuevamente.");
			theForm.email2.focus();
			return false;
		}
		
		if (theForm.email.value != theForm.email2.value) {
			alert("Las direcciones de E-mail no coinciden.");
			theForm.email2.focus();
			return false;
		}
	} 
	
	return true;
}