//valida formulario ingreso en blanco

function no_vacio(elemento1, elemento2)
{ 
   var elto1=elemento1;
   var elto2=elemento2;
  
   if (trim(elto1.value).length == 0) {
         elto1.focus();
         return false;
    }     
    else if (trim(elto2.value).length == 0) {
         elto2.focus(); 
         return false;
    }    
    else
    	return true; 

}

//valida formulario de contacto
function validar(nombre,direccion,ciudad,email,telefono,message)
{ 
   var nombre=nombre;
   var correo=email;
   var msg=message;
    
    if (trim(nombre.value).length == 0) {
         alert('Debe ingresar un nombre');
         nombre.focus();
         return false;
    }
    else if (trim(direccion.value).length == 0) {
         alert('Debe ingresar una direccion');
         direccion.focus();
         return false;
    }
    else if (trim(ciudad.value).length == 0) {
         alert('Debe ingresar una ciudad');
         ciudad.focus();
         return false;
    }    
    else if(trim(correo.value).length == 0) {
         alert('Debe ingresar un email');
         correo.focus();
         return false;
    }
	else if (!esEmailValido(trim(correo.value))) {
         alert('Debe ingresar un email válido');
         correo.focus();
         return false;
    }
    else if (trim(telefono.value).length == 0) {
         alert('Debe ingresar un telefono');
         telefono.focus();
         return false;
    }     
    else if (trim(msg.value).length == 0) {
         alert('Debe ingresar un mensaje' );
         msg.focus();
         return false;
    }
    else {
     	 return true;
    }
}

//valida email
function esEmailValido(elemento)
{
	var s = elemento;

    var filter=s.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);


	if (s.length == 0 ) 
		return true;
	if (filter)
		return true;
	else
		return false;
}

// quita espacios en blanco al comienzo y al final
function trim( value ) 
{
	var txt=value;
	var re_der = /((\s*\S+)*)\s*/;
	var re_izq = /\s*((\S+\s*)*)/;
	
	txt=txt.replace(re_der, "$1");
	txt=txt.replace(re_izq, "$1");
	return txt;
	
}
