function verifydigit(texto)
{
  largo = texto.length;
  for (i=0; i < largo ; i++ )
    {
   if ( texto.charAt(i) != "0" && 
        texto.charAt(i) != "1" && texto.charAt(i) != "2" && 
        texto.charAt(i) != "3" && texto.charAt(i) != "4" && 
        texto.charAt(i)!= "5" && texto.charAt(i) != "6" && 
        texto.charAt(i) != "7" && texto.charAt(i)!= "8" && 
        texto.charAt(i) != "9" ) 
        {
          return false;
        }
    }
    return true;
}
function verifyrut(rut, dv)
{
  var dvr = '0'
  var midv= dv.toUpperCase()
  suma = 0
  mul  = 2
 for (i= rut.length-1; i >= 0; i--)
    {
      suma = suma + parseInt(rut.charAt(i)) * mul
        if (mul == 7)
          mul = 2
        else
          mul++
   }
  res = suma % 11
  if (res==1)
  dvr = 'k'
  else if (res==0)
    dvr = '0'
 else
    {
      dvi = 11-res
      dvr = dvi + ""
    }
  if ( dvr != midv.toLowerCase() )
    { return false; }
  else
    { return true }
}
function validate(emailad) {
var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
var check=/@[\w\-]+\./;
var checkend=/\.[a-zA-Z]{2,3}$/;
	if(((emailad.search(exclude) != -1)||(emailad.search(check)) == -1)||(emailad.search(checkend) == -1))
{
 return true
  }
 else  return false
}
function checkall( forma )
{
  if ( forma.nombre.value == "") {
     alert("Ingrese su Nombre")
     forma.nombre.focus();
     return false
   }
      if ( forma.apellidos.value == "") {
     alert("Ingrese su apellido")
     forma.apellidos.focus();
     return false
   }
   if ( forma.rut.value == "") {
         alert("El RUT es incorrecto")
      forma.rut.focus();
      return false
   }
   
   if ( forma.rut.value != "") {
      if (!verifyrut(forma.rut.value, forma.dv.value)) {
      alert("El RUT es incorrecto")
      forma.rut.focus();
      return false
   }
   } 
   if ( forma.telefono.value != "") {
      if (!verifydigit(forma.telefono.value)) {
      alert("El telefono debe contener numeros solamente.")
	  forma.telefono.focus();
      return false
   }
   }
   if ( forma.direccion.value == "") {
     alert("Ingrese Dirección")
      forma.direccion.focus();
      return false
   }
 if ( forma.comuna.value == "") {
      alert("Ingrese Comuna")
      forma.comuna.focus();
      return false
   }
 if ( forma.email.value == "") {
      alert("Ingrese email")
      forma.email.focus();
      return false
   }
 if (validate(forma.email.value)) {
      alert("Debe contener email valido.")
	  forma.email.focus();
     return false
  }
    if ( forma.referencia.options[forma.referencia.selectedIndex].value == 0 ) {
        alert("Seleccione Referencia")
		forma.referencia.focus();
        return false
  }
  
  
 if ( forma.mensaje.value == "") {
      alert("Ingrese mensaje")
      forma.mensaje.focus();
      return false
   }

   return true
}


