jQuery(document).ready(function(){
	jQuery("#cf_form_1281940215338").submit(function(){
		var email = jQuery("#email").val();
		var phone = jQuery("#phone").val();
		var code = jQuery("#captcha").val();
		var msg = jQuery("#msg").val();
		var check_at = email.indexOf('@');
		var check_dot = email.indexOf('.');
	 	captcha = jQuery.ajax({
	 	 	url: '/wp-content/themes/the-hearing-clinic/images/image.php?check=' + code,
	 	 	async: false,
	 	 	type: "GET"
	 	}).responseText;	
		if (email.length == 0) {
			jQuery("#email").animate({ backgroundColor: 'yellow' },1000).animate({ backgroundColor: 'white' }, 1200);
			alert('Please enter a email address!');
			return false;
		} 
		else if (phone.length == 0) {
			jQuery("#phone").animate({ backgroundColor: 'yellow' },1000).animate({ backgroundColor: 'white' }, 1200);
			alert('Please enter a phone nomber!');
			return false;
		}
		else if (check_at < 1 || check_dot < 2) {
			jQuery("#email").animate({ backgroundColor: 'yellow' },1000).animate({ backgroundColor: 'white' }, 1200);
			alert('Please enter a valid email address!');	
			return false;
		}
		else if (msg == '') {
			jQuery("#msg").animate({ backgroundColor: 'yellow' },1000).animate({ backgroundColor: 'white'}, 1200);
			alert('Put your message!')
			return false;
		}
	else if (captcha != "ok") {
			jQuery("#captcha").animate({ backgroundColor: 'yellow' },1000).animate({ backgroundColor: 'white'}, 1200);	
			alert('Validate Captcha code!');	
			return false;	
		}		
	});
});
