$(document).ready(function() {

	// Label the Inputs
	$("#quick-form input").each(	
		function() {
		$(this).inputLabel(false, {color:"#222222"});	
		}
	);
	
	// Remove Procedure Links
	//var replace = '<a href="http://www.sabbahgynecology.com/procedures/" title="Procedures">Procedures</a>';
	$("a:contains('Procedures')").replaceWith("<h4>Procedures & Services</h4>");
	
	$("a[href='http://www.sabbahgynecology.com/fr/montreal/']").replaceWith("<h4>Proc&#233;dures</h4>");
	
	// Label the Textarea
	$("#quick-form textarea").inputLabel(false, {color:"#222222"});

	// Hover the Submit
	$("#submit").hover(function() {
		$(this).css({backgroundColor: "#BF5F70", color: "#ffffff"});
	}, function() {
		$(this).css({backgroundColor: "#F7D0D5", color: "#222222"});
	});			
	
	function beforeSubmit() {
		$("#loader").fadeIn(600);
	}
	
	function processJson(data) {	
		var status = data.status;
		
		
		//alert(status);
		//return false;
		// Check the status codes
		if(status == 1) {
			$("#output").hide().empty().append("<p>You must fill in all required fields.</p>").fadeIn(500);
		}else if(status == 2) {
			$("#output").hide().empty().append("<p>Your name must be between 3 and 30 characters.</p>").fadeIn(500);
		}else if(status == 3) {
			$("#output").hide().empty().append("<p>Spam alert...</p>").fadeIn(500);
		}else if(status == 4) {
			$("#output").hide().empty().append("<p>Your email address is invalid.</p>").fadeIn(500);
		}else if(status == 5) {
			
			$("#quick-form form").slideUp({
				duration: 1000,
				easing: 'easeInBack',
				complete: function() {
					$("#output").hide().empty().append("<h4>Thanks!</h4><p>Your message has been sent.</p>").slideDown({
						duration: 200,
					easing: 'easeOutBack'
					});
				}			
			});
													
			}else{
			$("#output").hide().empty().append("<p>There was an error sending the form, please contact us directly.</p>").fadeIn(500);
		}
				
		$("#loader").fadeOut(150);
		return false;
	
	}
	
	// Intercept the form submission
	$("form").submit(function() {			
	
		// Verify that information has been entered
		var missingField = "<p>You must fill in the required information.</p>";	
		
		// Check the inputs ->> CHANGE FOR FRENCH
		if($("#name").val() == 'Name:' || $("#email").val() == 'Email:' || $("#message").val() == 'Message:') {
			$("#output").hide().empty().append(missingField).fadeIn(500);
			return false;
		}
			
		// Submit the form
		if($("#phone").val() == 'Phone:') {
			$("#phone").val("NA");
		}	
		
		var name = $("#name").val();
		var email = $("#email").val();
		var phone = $("#phone").val();
		var message = $("#message").val();
		
		//$("#loader").fadeIn(500);
				
		$.post("http://www.sabbahgynecology.com/wp-content/themes/sabba/submit-form.php", {name: name, email: email, phone: phone, message: message}, processJson, "json");
		
		
		//$("#quick-form form").ajaxSubmit(options);
		return false;
	});
					
});
