function IsValidEmail(email) {
  var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
  return filter.test(email);
}

$(document).ready(function() {
  $('#hirlevelform').submit(function() {
  	$('#hiba').html('');
    if($('#nev').val().length == 0) {
      $('#hiba').append('<p>A név nincs kitöltve.</p>');
    } else if($('#nev').val().length < 3) {
      $('#hiba').append('<p>A név túl rövid.</p>');
    }
    if($('#cim').val().length == 0) {
      $('#hiba').append('<p>Az email cím nincs kitöltve.</p>');
    } else if(!IsValidEmail($('#cim').val())) {
      $('#hiba').append('<p>Az email cím nem valós.</p>');  
    }
    if($('#hiba').html().length == 0) {
      window.open('', 'formpopup', 'menubar=0,resizable=0,width=600,height=125,scrollbars=0');
      this.target = 'formpopup';  
    } else {
      return false;
    }
  });
});
