Utils.Functions=new Object();
Utils.Functions.ShowHide=function(element, isVisible, visibleType, hiddenType){
	if (typeof element == 'string'){
		try{
			element=$O(element);
		} catch(ex){
			return;
		}
	}
	if (typeof visibleType=='undefined'){
		visibleType='';
	}
	if (typeof hiddenType=='undefined'){
		hiddenType='none';
	}
	if (
		(typeof isVisible!='undefined' && !isVisible) ||
		(typeof isVisible=='undefined' && element.style.display!=hiddenType)
	){
		element.style.display=hiddenType;
	} else {
		element.style.display=visibleType;
	}
}

Utils.Functions.GetObjectPosition=function(element){
	if (typeof element!='object'){
		element=$O(element);
	}
	currLeft=0;
	currTop=0;
	do {
		currLeft+=element.offsetLeft;
		currTop+=element.offsetTop;
	} while (element = element.offsetParent);
	return {'objectLeft':currLeft, 'objectTop':currTop};
}

Utils.array=new Object();
Utils.array.getRandomElements=function(array,elementCnt){
	var items=new Array();
	if(elementCnt>array.length){
		elementCnt=array.length;
	}
	while(items.length!=elementCnt){
		var _continue=false;
		var item=array[Math.floor(Math.random()*array.length)];
		for(var i=0;i<items.length;i++){
			if(items[i]==item){
				_continue=true;
			}
		}
		if(_continue){
			continue;
		}
		items.push(item);
	}
	return items;
};

Utils.getElementsByClassName=function(ClassName){
	return Utils.getElementsByTagAndClassName('*', ClassName);
};

$j.fn.paste = function(fn) {
	if (typeof fn == 'undefined') {
		this.trigger('paste');
	} else {
		this.bind('paste', function(event) {
			var _this = this;
			setTimeout(function() {
				fn.apply(_this, [event]);
			}, 0);
		});
	}
}

$j.fn.textCounter = function(maxlimit) {
	this.bind('keyup keydown change', counter).paste(counter);
	function counter() {
		if ($j(this).val().length > maxlimit){
			$j(this).val($j(this).val().substring(0, maxlimit));
			$j(this).parent().find('.remaining-counter').val(0);
		}else{
			$j(this).parent().find('.remaining-counter').val(maxlimit - $j(this).val().length);
		}
	}
}

$j.fn.log = function (msg) {
	if (window.console && window.console.log) {
		if (msg) {
			window.console.log("%s: %o", msg, this);
		} else {
			window.console.log("%o", this);
		}
	}
	return this;
};
