$(function() {  
	$("#form_error").hide();
	$("#send_message").click(function() {
		$("#form_error").hide();
		var arrForm = ["clientname", "email", "phone", "message"];
		var blnContinue = true;
		
		$.each(
			arrForm,
			function(intIndex, objValue){
				if ($("#"+objValue).val() == "") {
					$("#label_"+objValue).addClass("form_notify");
					blnContinue = false;
				} else {
					$("#label_"+objValue).removeClass("form_notify");
					$("#send_message").val('Processing').attr('disabled', 'disabled');
				}
			}
			
		);
		
		if (!blnContinue) {
			$("#form_error").show();
			return false;
		}
		
		$.ajax({
      		type: "POST",
      		url: "scripts/process_emailforms.php",
      		data:$("#contactusfrm").serialize(),
			success: function(data) {
				
				
				if (data.result == 'success') {
					$('#contactbucket').html("<div id='message_response'></div>");
					$('#message_response').html('<h5>Thank You!</h5>')
					.append('<p>'+data.msg+'</p>')
					.hide()
					.fadeIn(1500);
				} else {
					$("#form_error").show();
					$("#form_error_msg").html(data.msg);
					
					//alert(data.errors);
					
					 $.each(data.errors, function() {
					 	$("#"+this).addClass("form_notify");
					 });
					 $("#send_message").val('Processing').attr('disabled', 'disabled');
					 
				}
					
			},
			dataType: "json"
				
     	});
     	
	 
	 
	 });
	

});
