// on dom ready
$(function(){


});

window.trace = window.console ? console.log : alert;


/* disable/enable
*******************************************************************************/
$.fn.disable = function(not) {
	(not ? this.not(not) : this).map(function(){
		var t = $(this);
		switch (this.tagName.toLowerCase()) {
			case 'form':
				t.addClass('disabled').prepend(
					$('<div class="disabled-voile">').css('opacity', .5).width(t.width()).height(t.height())
				);
				//$(':input,label', this).attr('disabled', 'disabled').addClass('disabled');
				break;
			case 'input':
			case 'textarea':
			case 'select':
			case 'button':
				t.attr('disabled', 'disabled').addClass('disabled');
				break;
			default:
				t.addClass('disabled');
				break;
		}
	});
	return this;
};
$.fn.enable = function(not) {
	(not ? this.not(not) : this).map(function(){
		switch (this.tagName.toLowerCase()) {
			case 'form':
				$('.disabled-voile', $(this).removeClass('disabled')).remove();
				//$(':input,label', this).removeAttr('disabled').removeClass('disabled');
				break;
			case 'input':
			case 'textarea':
			case 'select':
			case 'button':
				$(this).removeAttr('disabled').removeClass('disabled');
				break;
			default:
				$(this).removeClass('disabled');
				break;
		}
	});
	return this;
};

/* field loading
*******************************************************************************/
$.fn.loading = function(is, bf) {
	return bf
		? (is ? this.disable().addClass('loading').blur() : this.enable().removeClass('loading').focus())
		: (is ? this.disable().addClass('loading') : this.enable().removeClass('loading'));
};