$( function(){
  $('form .error').hide();
  $('form').submit( function(){ return validarForm(this); });
});

function validarForm(form){
  $('form .error').hide();
  var error='';
  var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
  $(form).find('.validar').each(function(){
    if( $.trim( $(this).val() ).length==0 ) {
      $('[name=error-'+$(this).attr('name')+']').show(); error+= 'n';
    } else {
      if( ($(this).attr('name') == 'email') &&  (!$.trim($(this).val()).match(re)) ) { $('[name=error-formato-email]').show(); error+='n';} 
    }
  });
  if(error) {return false;} else { return true; }
}
