<!--
//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/number/fmt-money [rev. #2]
// usage: 
// Number.formatMoney([floatPoint: Integer = 2], [decimalSep: String = ","], [thousandsSep: String = "."]): String 
// Returns the number into the monetary format. 
// floatPoint amount of decimal places 
// decimalSep string that will be used as decimal separator 
// thousandsSep string that will be used as thousands separator 
// example: number.formatMoney(2, "*", "#") = 123#456*79
Number.prototype.formatMoney = function(c, d, t){
    var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "",
    i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t)
    + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};

function showPopup(divId)
{
    //set the last popup invisible
	if (popup != null)
	{
		popup.style.visibility = "hidden";
		popup.style.display = "none";
		
		if (popup2 != null)
		{
			popup2.style.visibility = "hidden";
			popup2.style.display = "none";
		}
		if (popup3 != null)
		{
			popup3.style.visibility = "hidden";
			popup3.style.display = "none";
		}
	}
    popup = document.getElementById(divId);
    if (popup != null)
	{	
		popup.setAttribute("scrolling","no");
		popup.setAttribute("frameborder","0");
		popup.style.display = "block";
		popup.style.visibility = "visible";
		popup.style.zindex = "2";
		
		var globalnavlbar = $("div.globalnav_lbar");
		var colRight = $("div.columnRight");
		if(null != globalnavlbar && null != colRight)
		{
			globalnavlbar.addClass("globalNavBarColOnBottom");
			colRight.addClass("rightColOnTop");
		}
	}
}

function setCurrentBundleState(currentRb, currentIs, itemInnerPriceLblId, itemInnerOriginalPriceLblId, 
                               sumInnerPriceLblId, sumInnerOriginalPriceLblId,
                               sumPriceLblId, sumOriginalPriceLblId, 
                               hfLeftPriceId, hfRightPriceId, 
                               hfLeftOriginalPriceId, hfRightOriginalPriceId, 
                               hfSelectedDiscountLeftId, hfSelectedDiscountRightId,
                               itemPriceNum, itemOriginalPriceNum, hfieldVariantID, name, discount,
                               decPlaces, decSeparator, thousendSep, currencyPattern )
{
    var innerPriceLbl = $("#"+itemInnerPriceLblId);
    if(innerPriceLbl != null)
    {
        innerPriceLbl.text(currencyPattern.replace(/000/g, (itemPriceNum).formatMoney(decPlaces,decSeparator,thousendSep)));
        if(discount == true)
        {
            if(innerPriceLbl.hasClass("price_normal"))
            {
                innerPriceLbl.removeClass("price_normal");
            }
            innerPriceLbl.addClass("price_discount");
        }
        else
        {
            if(innerPriceLbl.hasClass("price_discount"))
            {
                innerPriceLbl.removeClass("price_discount");
            }
            innerPriceLbl.addClass("price_normal");
        }
    }
    
    var innerOriginalPriceLbl = $("#"+itemInnerOriginalPriceLblId);
    if(innerOriginalPriceLbl != null)
    {
        innerOriginalPriceLbl.text(currencyPattern.replace(/000/g, (itemOriginalPriceNum).formatMoney(decPlaces,decSeparator,thousendSep)));
        if(discount == true)
        {
            if(innerOriginalPriceLbl.hasClass("orig_price_hidden"))
            {
                innerOriginalPriceLbl.removeClass("orig_price_hidden");
            }
        }
        else
        {
            if(!innerOriginalPriceLbl.hasClass("orig_price_hidden"))
            {
                innerOriginalPriceLbl.addClass("orig_price_hidden");
            }
        }
    }

    var leftPriceHf = $("#"+hfLeftPriceId);
    var rightPriceHf = $("#"+hfRightPriceId);
    var leftOriginalPriceHf = $("#"+hfLeftOriginalPriceId);
    var rightOriginalPriceHf = $("#"+hfRightOriginalPriceId);
    var hfSelectedDiscountLeft = $("#"+hfSelectedDiscountLeftId);
    var hfSelectedDiscountRight = $("#"+hfSelectedDiscountRightId);

    if(currentIs == "left")
    {
        leftPriceHf.val(itemPriceNum);
        leftOriginalPriceHf.val(itemOriginalPriceNum);
        hfSelectedDiscountLeft.val(discount);
    }
    else if(currentIs == "right")
    {
        rightPriceHf.val(itemPriceNum);
        rightOriginalPriceHf.val(itemOriginalPriceNum);
        hfSelectedDiscountRight.val(discount);
    }

    var leftPriceNum = leftPriceHf.val() * 1.0;
    var rightPriceNum = rightPriceHf.val() * 1.0;
    var leftOriginalPriceNum = leftOriginalPriceHf.val() * 1.0;
    var rightOriginalPriceNum = rightOriginalPriceHf.val() * 1.0; 
    
    //set Sum Price
    var sumPrice = leftPriceNum + rightPriceNum;
    var sumOriginalPrice = leftOriginalPriceNum + rightOriginalPriceNum;
    
    var sumInnerPriceLbl = $("#"+sumInnerPriceLblId);
    var sumInnerOriginalPriceLbl = $("#"+sumInnerOriginalPriceLblId);
    var sumPriceLbl = $("#"+sumPriceLblId);
    var sumOriginalPriceLbl = $("#"+sumOriginalPriceLblId);

    sumInnerPriceLbl.text(currencyPattern.replace(/000/g, (sumPrice).formatMoney(decPlaces,decSeparator,thousendSep)));
    sumPriceLbl.text(currencyPattern.replace(/000/g, (sumPrice).formatMoney(decPlaces,decSeparator,thousendSep)));
    
    sumInnerOriginalPriceLbl.text(currencyPattern.replace(/000/g, (sumOriginalPrice).formatMoney(decPlaces,decSeparator,thousendSep)));
    sumOriginalPriceLbl.text(currencyPattern.replace(/000/g, (sumOriginalPrice).formatMoney(decPlaces,decSeparator,thousendSep)));
	
    if(hfSelectedDiscountLeft.val() == "true" || hfSelectedDiscountRight.val() == "true")
    {
        if(sumInnerPriceLbl.hasClass("price_normal"))
        {
            sumInnerPriceLbl.removeClass("price_normal");
        }
        sumInnerPriceLbl.addClass("price_discount");
    
        if(sumPriceLbl.hasClass("price_normal"))
        {
            sumPriceLbl.removeClass("price_normal");
        }
        sumPriceLbl.addClass("price_discount");
    
        sumInnerOriginalPriceLbl.removeClass("orig_price_hidden");
        sumOriginalPriceLbl.removeClass("orig_price_hidden");
    }
    else
    {
        if(sumInnerPriceLbl.hasClass("price_discount"))
        {
            sumInnerPriceLbl.removeClass("price_discount");
        }
        sumInnerPriceLbl.addClass("price_normal");
    
        if(sumPriceLbl.hasClass("price_discount"))
        {
            sumPriceLbl.removeClass("price_discount");
        }
        sumPriceLbl.addClass("price_normal");
    
        sumInnerOriginalPriceLbl.addClass("orig_price_hidden");
        sumOriginalPriceLbl.addClass("orig_price_hidden");
    }

    //SetVariantID to Hidden Field
    var hf = $("#"+hfieldVariantID);
    hf.val(currentRb.value);
}


function setCurrentState(currentRb, innerpriceLblId, inneroriginalpriceLblId, outerpriceLblId, outeroriginalpriceLblId, 
                         price, originalprice, hfield, name, discount, discountMessageLblId){
//price_discount" : "price_normal
    //Set PriceLabels
    var priceLblInner = $("#"+innerpriceLblId);
    if(priceLblInner != null) 
    { 
        priceLblInner.text(price);
        if(discount == true)
        {
            if(priceLblInner.hasClass("price_normal"))
            {
                priceLblInner.removeClass("price_normal");
            }
            priceLblInner.addClass("price_discount");
        }
        else
        {
            if(priceLblInner.hasClass("price_discount"))
            {
                priceLblInner.removeClass("price_discount");
            }
            priceLblInner.addClass("price_normal");
        }
    }
    
    var origpriceLblInner = $("#"+inneroriginalpriceLblId);
    if(origpriceLblInner != null) 
    { 
        origpriceLblInner.text(originalprice);
        if(discount == true)
        {
            if(origpriceLblInner.hasClass("orig_price_hidden"))
            {
                origpriceLblInner.removeClass("orig_price_hidden");
            }
        }
        else
        {
            if(!origpriceLblInner.hasClass("orig_price_hidden"))
            {
                origpriceLblInner.addClass("orig_price_hidden");
            }
        }
    };
    
    var priceLblOuter = $("#"+outerpriceLblId);
    if(priceLblOuter != null)
    {
        priceLblOuter.text(price);
        if(discount == true)
        {
            if(priceLblOuter.hasClass("price_normal"))
            {
                priceLblOuter.removeClass("price_normal");
            }
            priceLblOuter.addClass("price_discount");
        }
        else
        {
            if(priceLblOuter.hasClass("price_discount"))
            {
                priceLblOuter.removeClass("price_discount");
            }
            priceLblOuter.addClass("price_normal");
        }
    }
        
    var origpriceLblOuter = $("#"+outeroriginalpriceLblId);
    if(origpriceLblOuter != null)
    {
        origpriceLblOuter.text(originalprice);
        if(discount == true)
        {
            if(origpriceLblOuter.hasClass("orig_price_hidden"))
            {
                origpriceLblOuter.removeClass("orig_price_hidden");
            }
        }
        else
        {
            if(!origpriceLblOuter.hasClass("orig_price_hidden"))
            {
                origpriceLblOuter.addClass("orig_price_hidden");
            }
        }
    }

    var discountMessageLbl = $("#"+discountMessageLblId);
    if(discountMessageLbl != null)
    {
        if(discount == true)
        {
            if(discountMessageLbl.hasClass("orig_price_hidden"))
            {
                discountMessageLbl.removeClass("orig_price_hidden");
            }
        }
        else
        {
            if(!discountMessageLbl.hasClass("orig_price_hidden"))
            {
                discountMessageLbl.addClass("orig_price_hidden");
            }
        }
    }

    //SetVariantID to Hidden Field
    var hf = $("#"+hfield);
    if(hf != null && currentRb != null)
    {
        hf.val(currentRb.value);
    }
}


function hidePopup(divId, divId2, divId3)
{
    if (popup != null)
	{
        popup.style.display = "none";
        popup.style.visibility = "hidden";
        popup = null;
        
        if (popup2 != null){
        popup2.style.display = "none";
        popup2.style.visibility = "hidden";
        popup2 = null;
		}
		if (popup3 != null){
        popup3.style.display = "none";
        popup3.style.visibility = "hidden";
        popup3 = null;
		}
		
		hideCurrentMediaSelector();
    }
}

//-->