/**
 * @author jon.merchant
 */
tinyMCE.init({
    mode : "textareas",
    theme : "simple",
    editor_selector : "contact"
});
function contact_form() {
	name = $("#contact-name").val();
	email = $("#contact-email").val();
	phone = $("#contact-phone").val();
	subject = $("#contact-subject").val();
	message = tinyMCE.activeEditor.getContent();

        //console.log(email);
	
	name_check = /^([a-zA-Z\s]{1,25})$/;
	email_check = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	phone_check = /^\(?[\d]{3}\)?[\s-]?[\d]{3}[\s-]?[\d]{4}$/;

        reason = "";
        reason += validateNames("cotact-name","Name",75);
        reason += validateEmail("contact-email");
        reason += validatePhone("contact-phone","Phone");
        reason += validateEmpty("contact-subject","Subject");
	
//	error = false;
//	if (!name || !name_check.test(name)) {
//		alert("There seems to be a problem with the name field, please correct and try again.\nThe field allows letters and spaces.");
//		$("#contact-name").css({"border":"1px solid #880000","background":"#FFDDDD"});
//		error = true;
//	} else {
//		$("#contact-name").css({"border":"1px solid #c1c1c1","background":"#fff"});
//		error = false;
//	}
//	if (!email || !email_check.test(email)) {
//		alert("There seems to be a problem with the email field, please correct and try again.\nThe field allows any properly formatted email address.");
//		$("#contact-email").css({"border":"1px solid #880000","background":"#FFDDDD"});
//		error = true;
//	} else {
//		$("#contact-email").css({"border":"1px solid #c1c1c1","background":"#fff"});
//		error = false;
//	}
//	if (!phone || !phone_check.test(phone)) {
//		alert("There seems to be a problem with the phone field, please correct and try again.\nThe field allow any properly formatted US phone number like 800-555-555 or (800)555-555");
//		$("#contact-phone").css({"border":"1px solid #880000","background":"#FFDDDD"});
//		error = true;
//	} else {
//		$("#contact-phone").css({"border":"1px solid #c1c1c1","background":"#fff"});
//		error = false;
//	}
//	if (!subject) {
//		alert("The subject line can not be blank, please correct and try again.");
//		$("#contact-subject").css({"border":"1px solid #880000","background":"#FFDDDD"});
//		error = true;
//	} else {
//		$("contact-subject").css({"border":"1px solid #c1c1c1","background":"#fff"});
//		error = false;
//	}
//	 if (!message) {
//	 	alert("Please fill in the message box so that we might know what you want to discuss with us, thank you.");
//		error = true;
//	 } else {
//	 	error = false;
//	 }
	
	params = $("form").serialize();
	params = params+"&message="+message;
	
	if (reason.length == 0) {
		$.post("/site_core/libs/ajax_send_contact.php",params,function(data){
			if (data.sent == "good") {
				alert("Your message has been sent, someone will contact you as soon as possible in regards to your email.\nThank You!");
				location.href = "http://"+location.host;
			} else {
				alert("There was a problem sending your message, please try again.");
				return false;
			}
		},"json");
	} else {
            alert(reason);
        }
	return false;
}
