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});}
});

jQuery(document).ready(function(){
		$j(".gridTable input[type='text']").bind("click", function(event) {
			stopEvent(event);			
		});
	});



$j.fn.onEnterMenu = function () {
		return this.each(
			function() {
				
				var subID = $j(this).attr("subId");	
				currentMenuActive = subID;
				
				/*
				var s = $j("#logsStatus").html();
				s = s + ' ' + subID + ' ';
				$j("#logsStatus").html(s);
				*/
				
				$j("#secondLineMenu ul[subid!="+subID+"]").hide();
				$j("#topLineMenu li[subid!="+subID+"]").removeClass("mod_active");
				
				menuInTimerID = 0;
				
				$j("#subm_" + subID).fadeIn('fast');
				$j("#mainM_" + subID).addClass("mod_active");
				
				
				/*
				if(menuInTimerID && menuInTimerID != subID) {
					$j("#subm_" + menuInTimerID).hide();
					$j("#mainM_" + menuInTimerID).removeClass("mod_active");
				}
				
				
				if(currentMenuActive && subID != currentMenuActive) {
				
					$j("#subm_" + currentMenuActive).hide();
					$j("#mainM_" + currentMenuActive).removeClass("mod_active");
				}*/
				
			}
		);
}

function timerOutMenu(subID) {
	if(currentMenuActive > 0) return false;
	if(currentMenuActive > 0 && currentMenuActive == subID ) return false;
	if(currentMenuActive == 0 && selectedSection == subID) return false;
	
	$j("#subm_" + subID).hide();
	$j("#mainM_" + subID).removeClass("mod_active");
	
	/*
	var s = $j("#logsStatus").html();
	s = s + ' out:' + subID + ' ';
	$j("#logsStatus").html(s);
	*/
	
	if(currentMenuActive == 0) {
		currentMenuActive = selectedSection;
		$j("#secondLineMenu ul[subid!="+selectedSection+"]").hide();
		$j("#topLineMenu li[subid!="+selectedSection+"]").removeClass("mod_active");
		
		$j("#subm_" + selectedSection).fadeIn('fast');
		$j("#mainM_" + selectedSection).addClass("mod_active");
		
		/*
			var s = $j("#logsStatus").html();
			s = s + ' a:' + selectedSection + ' ';
			$j("#logsStatus").html(s);
		*/
	}
}

$j.fn.onOutMenu = function () {
		return this.each(
			function() {
				currentMenuActive = 0;
				var subID = $j(this).attr("subId");
				menuInTimerID = subID;
				setTimeout("timerOutMenu("+subID+")", 500);
			}
		);
}


$j.fn.hoverMenu = function () {
	currentMenuActive = selectedSection;
	menuInTimerID = 0;
	return this.each(
		function(){
			var subID = $j(this).attr("subId");
			if( !$j("#subm_" + subID) ) {
				subID = 0;								
			}
			if(subID) {
				$j(this).hover(
					function() { $j("#subm_" + subID).onEnterMenu(); },
					function() { $j("#subm_" + subID).onOutMenu(); }
				);
				
				$j("#subm_" + subID).hover(
					function() { $j(this).onEnterMenu(); },
					function() { $j(this).onOutMenu(); }
				);
			}
		}
	);
}



function redirect(url) {
	location.href = url
}

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
	//return (((sign)?'':'-') + num + '.' + cents);
	
}

function updateCartBox(qty, price, productID, prodQty) {	
	$("topBarCartQty").innerHTML = qty;
	$("hoverProdNo").innerHTML = qty;
	currentTotal = parseInt($("hoverTotal").innerHTML);
	//$("hoverTotal").innerHTML = currentTotal + price;
	$("hoverTotal").innerHTML = formatCurrency(price);
	
	if($("qty_prod_" + productID)) {
		var newQty = $("qty_prod_" + productID).innerHTML;
		newQty = parseInt(newQty);
		newQty -= prodQty;
		$("qty_prod_" + productID).innerHTML = newQty;
	}
}


function stopEvent(e) {
	var e = e || window.event;
		
	if(e.stopPropagation)
		e.stopPropagation();
	//if (e.cancelBubble)
     e.cancelBubble = true;
      
	//if (e.preventDefault) e.preventDefault(); 
	//else
	//e.returnValue = false;               
}

function staticPageLink(link) {
	if(window.isPopup && window.opener) {
		window.opener.location = link;
		window.close()
	}
	else window.location = link;
}