
$(document).ready(function() {
	$("form#contact_form").submit(function(e) {
		e.preventDefault();
		var first_name = $.trim($("input#first_name").val());
		var last_name = $.trim($("input#last_name").val());
		var email = $.trim($("input#email").val());
		var telephone = $.trim($("input#telephone").val());
		var questions = $.trim($("textarea#questions").val());

		hideCustomerInfo();		
		if(email == "") {
			setCustomerInfo("Please type your email address.", ERROR_MESSAGE_COLOR);
			return;
		}
		
		if(questions == "") {
			setCustomerInfo("Please write your message.", ERROR_MESSAGE_COLOR);
			return;
		}

		setBusy("input#submit_question_btn", true);
		var requestStr = {first_name: first_name, last_name: last_name, email: email, telephone: telephone, questions: questions};
		$.post("/actions/send_customer_support_email.php", requestStr, afterSubmit);
	});
});


function afterSubmit(data) {
	setBusy("input#submit_question_btn", false);
	switch(data) {
		case "success":
			setCustomerInfo("Thank you for contacting us! Our Customer Support team will make every effort to answer your questions and resolve any issue quickly and efficiently.", OK_MESSAGE_COLOR);
			break;
		default:
			setCustomerInfo("Please try again soon. We're experiencing some technical difficulties. We apologize for the inconvenience!", ERROR_MESSAGE_COLOR);
			break;
	}
}


function setCustomerInfo(message, color) {
	hideCustomerInfo();
	$("div#customer_info").html(message).fadeIn("fast").css("color", color);
}


function hideCustomerInfo() {
	$("div#customer_info").hide();
}