function trim(stringValue){
	return stringValue.replace(/(^\s*|\s*$)/g, "");
}

function sendMessage(){

	var form_name=document.getElementById('form_name').value;
	form_name=escape(form_name);
	
	var form_email=document.getElementById('form_email').value;
	form_email=escape(form_email);
	
	var form_regarding=document.getElementById('form_regarding').value;
	form_regarding=escape(form_regarding);
	
	var form_message=document.getElementById('form_message').value;
	form_message=escape(form_message);
	
	var params="form_name="+form_name+"&form_email="+form_email+"&form_regarding="+form_regarding+"&form_message="+form_message;
	
	var handlerFunc=function(t){
		var theResponse=trim(t.responseText);
		if(theResponse=="mailsent"){
			document.getElementById('sendMessage').style.display="none";
			document.getElementById('afterSend').innerHTML="<br><br>Thank you, your message has been sent!";
			document.getElementById('afterSend').style.display="block";
		
		}else{
			alert(theResponse);
		}
	};
	
	if(form_name==""||form_message==""){
		alert('Please fill in all the fields.')
	} else if (form_regarding==""){
		alert('Please choose the nature of your email.')
	}else{
		new Ajax.Request('mailfunctions.php?task=sendMessage&'+params,{onSuccess:handlerFunc,asynchronous:true})
	}
}