// Validador campos

// Por: Rodrigo Alfaro, Mayo 2009

//-> Funciones de campo

function contacto_valida(contacto) {

if (contacto.nombre.value.length < 1) {

    alert("ALERTA:\nEl campo NOMBRE debe estar completo");

    contacto.nombre.focus();

    return (false);

  }	

if (contacto.direccion.value.length < 1) {

    alert("ALERTA:\nEl campo DIRECCION debe estar completo");

    contacto.direccion.focus();

    return (false);

  }

if (contacto.comuna.value.length < 1) {

    alert("ALERTA:\nEl campo COMUNA / CIUDAD debe estar completo");

    contacto.comuna.focus();

    return (false);

  }  

if (contacto.region.selectedIndex==0){

      alert("ALERTA:\nDebe elegir una REGION")

      contacto.region.focus()

      return (false);

   }

if (contacto.cod_fono.value.length < 1) {

    alert("ALERTA:\nEl campo CODIGO DE AREA debe estar completo");

    contacto.cod_fono.focus();

    return (false);

  }

if (isNaN(contacto.cod_fono.value)) {

	alert("ERROR:\nEste campo debe TENER SOLO NUMEROS.");

	contacto.cod_fono.focus();

	return (false);

  }

if (contacto.fono.value.length < 6) {

    alert("ALERTA:\nEl campo TELEFONO debe tener un mínimo de 6 caracteres");

    contacto.fono.focus();

    return (false);

  }  

if (isNaN(contacto.fono.value)) {

	alert("ERROR:\nEste campo debe TENER SOLO NUMEROS.");

	contacto.fono.focus();

	return (false);

  }

if (contacto.cod_cel.selectedIndex==0){

     alert("ALERTA:\nDebe elegir un CODIGO DE CELULAR")

     contacto.cod_cel.focus()

     return (false);

  }

if (contacto.celular.value.length < 6) {

    alert("ALERTA:\nEl campo CELULAR debe tener un mínimo de 6 caracteres");

    contacto.celular.focus();

    return (false);

  }

if (isNaN(contacto.celular.value)) {

	alert("ERROR:\nEste campo debe TENER SOLO NUMEROS.");

	contacto.celular.focus();

	return (false);

  }

if (contacto.correo.value.length < 1) {

    alert("ALERTA:\nEl campo E-MAIL debe estar completo");

    contacto.correo.focus();

    return (false);

  }  

  //-> Valido el Mail  

  if (contacto.correo.value){

	var s = contacto.correo.value;

	var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;

	if (s.length == 0 ) return true;

	if (filter.test(s))

	return true;

	else

	alert("ERROR:\n Debe ingresar un E-MAIL VALIDO");

	contacto.correo.focus();

	return false;

  }

//-> Valido que un checkbox deba ser clickeado

//  if (!contacto.cargo_1.checked) {

//    alert("Please mark the checkbox");

//    contacto.cargo_1.focus();

//    return (false);

//  }

if (contacto.comentarios.length < 1) {

    alert("ALERTA:\nEl campo COMENTARIOS debe estar completo");

    contacto.comentarios.focus();

    return (false);

  }  

  return (true);

}
