//	Requires jquery.blockUI.js and jquery.form.js.

//	Removes all white space from a string and returns the new string.
function white_space(data){
	return (data).replace(/^\s*|\s*$/g,'');
}

$(function(){
	//	Processes the Contact.
	
		//	pre-submit callback
		function preSubmit(formData, jqForm, options){
			var contactName = $("#contact_name").val();
			var contactEmail = $("#contact_email").val();
			var message = $("#contact_message").val();
			var errorMsg = '';
			
			if(contactName == ''){
				errorMsg = errorMsg + "Please enter your Name.\n";
			}
			
			if(contactEmail == ''){
				errorMsg = errorMsg + "Please enter your Email.\n";
			}
			
			if(message == ''){
				errorMsg = errorMsg + "Please enter a Message.\n";
			}
			
			if(errorMsg != ''){
				alert(errorMsg);
				return false;
			}
			$.blockUI({ css: { 
	            border: 'none', 
	            padding: '15px', 
	            backgroundColor: '#000', 
	            '-webkit-border-radius': '10px', 
	            '-moz-border-radius': '10px', 
	            opacity: '.5', 
	            color: '#fff' 
	        } }); 
			return true;
		}
		//	post-submit callback
		function postSubmit(responseText, statusText){
			$.unblockUI();
			$('#frmContact').resetForm();
			alert(white_space(responseText));;
		}
		$("#frmContact").ajaxForm({beforeSubmit:preSubmit, success:postSubmit, url:"proc.sendContact.php", type:"post"});
});