$.fn.clearForm = function() {
	return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
		if (tag == 'form')
			return $(':input',this).clearForm();
		if (type == 'text' || type == 'password' || tag == 'textarea')
			this.value = '';
		else if (type == 'checkbox' || type == 'radio')
			this.checked = false;
		else if (tag == 'select')
			this.selectedIndex = -1;
	});
};

$.fn.lockForm = function(lock) {
	return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
		if (tag == 'form')
			return $(':input',this).lockForm(lock);
		if (
				type == 'text' || 
				type == 'password' || 
				tag == 'textarea' || 
				type == 'checkbox' || 
				type == 'radio' || 
				type == 'submit' ||
				type == 'reset' ||
				type == 'image' ||
				type == 'button' || 
				tag == 'select'
			)
			this.disabled = lock;
	});
};

$(document).ready(function() {
	$("#send_btn").click(function (e){
		e.preventDefault();
		var url = '/submit.php?' + $('#post_msg').serialize();
		$('#post_msg').lockForm(true);
		
		$.get(url, function(data){
			if(data != "") alert(data);
			$('#post_msg').clearForm();
			$('#post_msg').lockForm(false);
		});
	});
});
