$(document).ready(function(){
	$('#contactForm').submit(function(){
 		$('#contactForm #loading').show();
		var action = $(this).attr('action');
 		$("#feedback").slideUp(750,function() {
		$('#feedback').hide();
		$('#submit').attr('disabled','disabled');
 
		$.post(action, { 
			name: $('#name').val(),
			email: $('#email').val(),
			phone: $('#phone').val(),
			referrer: $('#referrer').val(),
			appointment: $('#appointment').val(),
			visitDate: $('#visitDate').val(),
			message: $('#message').val()
		},
			function(data){
				$('#submit').removeAttr('disabled');
				document.getElementById('feedback').innerHTML = data;
				$('#feedback').slideDown('slow');
				$('#contactForm #loading').hide();
				if(data.indexOf('Thanks') > 0) $('#contactForm').clearForm();
			}
		);

		});
		return false;
 
	});
	$("a[href^='http:']:not([href*='" + window.location.host + "'][target='_blank'])").live('click', function(){$(this).attr('target','_blank');});
});

$.fn.clearForm = function() {
  return this.each(function() {
 var type = this.type, tag = this.tagName.toLowerCase();
 if (tag == 'form')
   return $(':input',this).clearForm();
 if (type == 'text' || type == 'password' || tag == 'textarea')
   this.value = '';
 else if (type == 'checkbox' || type == 'radio')
   this.checked = false;
 else if (tag == 'select')
   this.selectedIndex = -1;
  });
};