/* Copyright Jamis Charles 2008 */

/* Dynamic behavior for the contact form */
/* -------------------------------------*/

//not needed for new form?
$(document).ready(function () {//on dom ready...
	
	//name value pairs of default values of form fields 
	var formValues = {
		contactName: "name",
		contactEmail: "email",
		contactWebsite: "website (optional)",
		contactMessage: ""
	}
	
	function checkFieldValues(e){
		//on click and focus, 
		if (e.type == "click" && this.value == formValues[this.id] || e.type == "focus" && this.value == formValues[this.id]){
			this.value = "";
			
		}else if(e.type == "blur" && this.value == ""){
			this.value = formValues[this.id];
		
		}else if(e.type == "load"){//add value to contactMessage textarea on pageload because the value alone doesn't populate on load
			$("#contactMessage")[0].value = formValues["contactMessage"];
		}
	
	}
	
	//attach eventlisteners: checkFieldsValues callback fn to .contactField
	$(".contactField").click(checkFieldValues);
	$(".contactField").focus(checkFieldValues);
	$(".contactField").blur(checkFieldValues);
	
	
	//onload, run checkFieldValues to populate the textarea
	(function(){
		var e = {};
		e.type = "load";
		checkFieldValues(e);
	}());
});



/* Ajax functionality for contact form */
/* ------------------------------------------*/
$(document).ready(function () {//on dom ready... 
	

	//add submit listener to contact form 
	$("#contactForm").submit(sendFormAjax);
	//on submit, supress default behavior
	$("form").bind( "submit", function(event) {
		event.preventDefault();
 	});

	
	function sendFormAjax(){
		//serialize form 
		var formStr = $(".commentField").serialize();
	
		formStr += "&ajax=true";
	
		//ajax form post fn
		$.post("includes/sendmail.php", formStr, showSuccessMsg, "text");
		
		//callback fn for successful form submit
		function showSuccessMsg(data, textStatus) {
			//alert('message sent');
			$("#contactSuccessMsg").css({'display': 'block'});
			
			
		}
	
	}

	
	

});


//for validation and submission of form, use ajax to submit, and show hidden confirmation layer.
// use hidden layers for 
