$(function() {
			$('.contact_form').submit(function(e) {
  		
  		var thiz = $(this).attr("id");
  		var thiz_id = '#'+thiz;
  		var form_id=thiz;
  		var hasError = false;
  		$(thiz_id).find('.requiredField').each(function() {
  			if(jQuery.trim($(this).val()) == '') {
    		$(this).addClass('invalid')
		   	 	   .focus();
    		hasError = true;
			return false;
   			}else if($(this).hasClass('email')) {
    			var emailReg = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
    			if(!emailReg.test(jQuery.trim($(this).val()))) {
     				$(this).addClass('invalid')
		   			   	   .focus();
    				hasError = true;
					return false;
    			}else{
   					$(this).removeClass('invalid');
   				}
   			}else{
   			$(this).removeClass('invalid');
   			}
 		});
    if(!hasError){return true;}
    else{return false;}
  		/*if(!hasError){
			$data = $(thiz_id).serialize()+ '&form_id=' + form_id;

			$(thiz_id).find('.submit_btn').append('<img src="../wp-content/themes/imagery/images/loading.gif" alt="Loading…" height="15" width="15" />');
			
			$.post("../wp-content/themes/imagery/send.php", $data, function(result){
					console.log(result);
				if(result=='sent'){			
					$('.form-container').remove();
					$('.right-sidebar').append('<div class="thanks first "><h3 class="widget-title">Thanks!</h3><p>Your email was successfully sent. <br />We will be in touch soon.</p></div>');
				}
				else{
					$(thiz_id).append('<div class="error first "><h3 class="widget-title">Error</h3><p>Sorry but an error occured, please try again</p></div>');
				}
		    });
		}*/
	});   

});
