$(function() {
	$('#imaging').submit(function(e) {
  		e.preventDefault();
  		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){
			$data = $(thiz_id).serialize()+ '&form_id=' + form_id;
			$(thiz_id).find('.submit_btn').append('<img src="../wp-content/themes/twentyeleven/images/loading.gif" alt="Loading…" height="15" width="15" />');
			$.post("../wp-content/themes/twentyeleven/send.php", $data, function(result){		
					$(thiz_id).find('.submit_btn').remove();
					$(thiz_id).append('<div class="thanks first"><p>Thank you for your interest in <strong>Baptist Health Breast Center</strong>.<br /> A representative will contact you within one business day.</p></div>');
		    });
		}
	}); 
});
