function checkEmail(inputvalue) {  
  var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
  if (pattern.test(inputvalue)) {         
    return true;
  }  
  return false; 
}

$(document).ready(function() {
  $('form#contactForm').submit(function() {
    var hasError = false;
    $('.requiredField').each(function() {
      if(jQuery.trim($(this).val()) == '' || jQuery.trim($(this).val()) == 'e-naslov' || jQuery.trim($(this).val()) == 'ime in priimek') {
        $('#errReport').replaceWith('<label id="errReport">Obe polji sta obvezni!</label>');
        hasError = true;
      } else if ($(this).hasClass('email')) {
        checkEmail($(this).val());
        if (!checkEmail($(this).val())) {
          $('#errReport').replaceWith('<label id="errReport">Neveljaven e-naslov!</label>');
          hasError = true;
        }
      }
    });

    if (!hasError) {
      var formInput = $(this).serialize();
      $.post($(this).attr('action'),formInput, function(data){
        $('div#formWrap').slideUp("fast", function() {       
          $(this).before('<p class="thanks">Priklopili smo te na energijo Tanergije.<br\>Hvala za tvojo vibracijo!</p>');
        });
      });
    }
    return false;
  });
});
