/***********************************************************************************************/
/*  Disable html control 																	   */
/***********************************************************************************************/

/* use .disabled(true) or .disabled(false) */
jQuery.fn.extend({
				 
	filterDisabled: function() {
		return this.filter(function() {
			return (typeof(this.disabled) != undefined)
		})
	},
	
	disabled: function(h) {
		if (h != undefined) return this.filterDisabled().each(function() {
			this.disabled = h
		});
		this.filterDisabled().each(function() {
			h = ((h || this.disabled) && this.disabled)
		});
		return h;
	},
	
	toggleDisabled: function() {
		return this.filterDisabled().each(function() {
			this.disabled =! this.disabled
		});
	}
	
});

/***********************************************************************************************/
/*  Clearing form data																		   */
/***********************************************************************************************/

/* use .clearForm() */
$.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" || type == "file" || tag == "textarea")
			this.value = "";
		else if (type == "checkbox" || type == "radio")
			this.checked = false;
		else if (tag == "select")
			this.selectedIndex = -1;
			
	});
	
};

/***********************************************************************************************/
/*  Wipe out the default text of a form input when it receives focus						   */
/***********************************************************************************************/

/* use .toggleVal() */
jQuery.fn.toggleVal = function(focusClass) {
	
	this.each(function() {
					   
		$(this).focus(function() {
							   
			/* clear value if current value is the default */
			if($(this).val() == this.defaultValue) {
				$(this).val("");
			}

			/* if focusClass is set, add the class */
			if(focusClass) {
				$(this).addClass(focusClass);
			}
			
		}).blur(function() {
			
			/* restore to the default value if current value is empty */
			if($(this).val() == "") {
				$(this).val(this.defaultValue);
			}

			/* if focusClass is set, remove class */
			if(focusClass) {
				$(this).removeClass(focusClass);
			}
			
		});
		
	});
	
}

/***********************************************************************************************/
