$(function() {
  $('input.text').focus(function() { $(this).select(); })
	$('form').submit(handleForm);
});

function handleForm(e) {
	$this = $(this);
	e.preventDefault();
	$this.find('.error').hide();
	$.ajax({
		url : $this.attr('action'),
		dataType : 'json',
		data : $this.serialize(),
		type : $this.attr('method'),
		success : function(data) {
			if(data.success == true) {
				
				$this.replaceWith('<p>'+data.message+'</p>');
				
			} else {
				$this.find('.error').text(data.message).show();
			}
 		}
	});
}