function setfocus() 
	{
        document.form1.nombre.focus();
        return;
	}

function clear(Campo)
	{
        //Campo.value="";  // Valor del campo a 0
        Campo.focus();   // El campo vuelve a coger el foco
 	    Campo.select();  // Seleccionar el contenido del campo
	}
	
function validate()
{
	var digits="0123456789-/"
	var temp
	var mail="@."
//****************************************************************** NOMBRE
	if (document.form1.nombre.value=="") 
	{
		alert("Debe ingresar NOMBRE")
		document.form1.nombre.focus();
		return false
	}

//****************************************************************** EMAIL

var emailStr=document.form1.mail.value
var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
var matchArray=emailStr.match(emailPat)
if (matchArray==null){
	alert("Su dirección de E-MAIL es incorrecta (chequee @ y .)")
	document.form1.mail.focus();
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

if (user.match(userPat)==null) {
    alert("El nombre de usuario de su mail es incorrecto.")
	document.form1.mail.focus();
    return false
}
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("El DOMINIO de su dirección de e-mail es incorrecta")
			document.form1.mail.focus();
		return false
	    }
    }
    return true
}
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("El DOMINIO de su dirección de e-mail es incorrecta")
	document.form1.mail.focus();
    return false
}
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   alert("La direccion de correo debe acabar en 3 letras de dominio o 2 de un pais.")
   document.form1.mail.focus();
   return false
}
if (len<2) {
   var errStr="Esta dirección es desconocida"
   alert(errStr)
   document.form1.mail.focus();
   return false
}


//******************************************************************CODIGO
	len=document.form1.codigo.value.length
	if ((len<1)||(len>3)) 
	{
		alert("Código de Area no válido!")
		clear(document.form1.codigo)
		document.form1.codigo.focus();
		return false
	}
	else
		for (var i=0;i<len;i++)
		{
			temp=document.form1.codigo.value.substring(i,i+1)
			if (digits.indexOf(temp)==-1)
			{
				alert("Ingrese sólo números para código de área")
				clear(document.form1.codigo)
				document.form1.codigo.focus();
				return false
			}
		}



//******************************************************************TELEFONO
	len=document.form1.telefono.value.length
	if ((len<3)||(len>9)) 
	{
		alert("Teléfono no válido!")
		clear(document.form1.telefono)
		document.form1.telefono.focus();
		return false
	}
	else
		for (var i=0;i<len;i++)
		{
			temp=document.form1.telefono.value.substring(i,i+1)
			if (digits.indexOf(temp)==-1)
			{
				alert("Ingrese sólo números para teléfono")
				clear(document.form1.telefono)
				document.form1.telefono.focus();
				return false
			}
		}


//****************************************************************** MENSAJE
	if (document.form1.mensaje.value=="") 
	{
		alert("No ha ingresado MENSAJE")
		document.form1.mensaje.focus();
		return false
	}
//******************************************************************
	
	return true
}

