$.fn.submitOnEnter = function(func)
{
	this.find(":text, :password").keydown(function(e){
		if (e.which == 13)
		{
			if (func)
				func()
			else if (this.form.next)
				this.form.next(e)
		}
	})
}

$.fn.toggleCheckbox = function(selector)
{
	if (!this.attr('initToggleCheckbox'))
	{
		this.attr('initToggleCheckbox', 1).click(function(){ $(selector).attr("checked", this.checked); })
		var cb = this[0]
   	$(selector).click(function() { cb.checked = 0; })
	}
}

$.fn.defVal = function()
{
	this.find(":text, textarea").each(function(){
		var defval = $(this).attr("default_value")

		if (defval)
			$(this)
				.bind("focus", function() { if (defval == this.value) this.value = "" })
				.bind("blur",  function() { if (!this.value) this.value = defval })
				.val(defval)
	})

	return this
}

$.fn.clearDefVal = function()
{
	this.find(":text, textarea").each(function(){
		if (this.value && this.value == $(this).attr("default_value"))
			this.value = ""
	})
}