/* Form Used for General Contact Form */
function sendForm(){
	var name             = escape(document.getElementById("form_name").value);
	var email            = escape(document.getElementById("form_email").value);
	var phone1           = escape(document.getElementById("form_phone1").value);
	var phone2           = escape(document.getElementById("form_phone2").value);
	var phone3           = escape(document.getElementById("form_phone3").value);
	var boat             = escape(document.getElementById("form_boat").value);
	var reason           = escape(document.getElementById("form_reason").value);
	var comments         = escape(document.getElementById("form_comments").value);


	var dataString = 'email=' + email +
	'&name=' + name +
	'&phone1=' + phone1 + 
	'&phone2=' + phone2 + 
	'&phone3=' + phone3 +
	'&boat=' + boat +  
	'&reason=' + reason +
	'&comments=' + comments;
	$.ajax({  
		type: "POST",  
		url: "/public/ajax/server_form_contact.php",  
		data: dataString,  
		success: function() {
			$("#form_msg_container").fadeOut();
			$("#form_container").fadeOut();
			$('#btn_request').fadeOut('', function() {
		        $("#form_msg_container_l").fadeIn();
		     });
			setTimeout(function() { $('#form_msg_container_l').hide();}, 4000);
			setTimeout(function() {$("#form_msg_container_f").fadeIn();},4000);
		}
	});
	return false; 
};

/* Clear the comments Box */
$('#form_comments').live('click', function (){
	$(this).attr('value', '');
});

/* Send Form Action */
$('#btn_request').live('click', function (){
	var noerrors = true;
	 	$('.required').each(function () {
		 if($(this).val() == ''){
		 	$('#form_msg_container').html('Sorry, you missed something we need.');
			$(this).addClass('error');
			noerrors = false;
		 }else{
		 	$(this).removeClass('error');
		 }
 	});
 	if(noerrors == true){
		sendForm();
	}
});
/* Move thru the phone number fields */
$().ready(function() {

	/* Make the Form Nice and Easy */
	$('#form_phone1').keyup(function() {
	    if ($('#form_phone1').val().length > 2) {
	        $('#form_phone2').focus();
	    }
	});
	$('#form_phone2').keyup(function() {
	    if ($('#form_phone2').val().length > 2) {
	        $('#form_phone3').focus();
	    }
	});
	$('#form_phone3').keyup(function() {
	    if ($('#form_phone3').val().length > 3) {
	        $('#form_boat').focus();
	    }
	});
});
