function newShowReviews(paneId, activeTab, sDiv, sReviewSelectID)
{
    UpdateTab.over(activeTab); 
    if (sDiv != null)
        showPaneAndMove(paneId, activeTab, sDiv);
    else
        showPane(paneId, activeTab);
    ResortReviews(sReviewSelectID);
    return false;    
}

function imagesAltSwap(altImageThumb)
{
    altImageThumb.blur();
    var swapSpot = document.getElementById('ProductImagesMain');
    if (swapSpot != null)
    {
        $$('#ProductImagesAlt img.CSf')[0].className = '';
        altImageThumb.getElementsByTagName("img")[0].className = 'CSf';
    }
}

function setDivHeightsProductNav() 
{
    var iLeftHeight = 0;
    var iRightHeight = 0;
    var oProductNavigationCats    = document.getElementById("ProductNavigationCats");
    var oProductNavigationSimilar = document.getElementById("ProductNavigationSimilar");
    if (oProductNavigationCats == null || oProductNavigationSimilar == null)
        return;
    
    iLeftHeight  = oProductNavigationCats.offsetHeight;
    iRightHeight = oProductNavigationSimilar.offsetHeight;

    if (iLeftHeight < iRightHeight) 
        oProductNavigationCats.style.height = (iRightHeight-1) + "px";
    else 
        oProductNavigationSimilar.style.height = iLeftHeight + "px";
}

var UpdateTab = function()
{
    var activeLeftC, activeRightC, rightC, leftC, nowActiveTab;
    var nonWhiteBackground = '';

    function out(a)
    {
        nowActiveTab = $$('ul.Tabs2 a.tab-active')[0];
        if(nowActiveTab != null && nowActiveTab != a){
            nowActiveTab.parentNode.style.background = activeLeftC;
            nowActiveTab.style.background = activeRightC;
            a.parentNode.style.background = leftC;
            a.style.background = rightC;
        }
    };
    function over(a)
    {
        nowActiveTab = $$('ul.Tabs2 a.tab-active')[0];
        if(nowActiveTab != null && a.className != 'tab-active'){
            nowActiveTab.style.background = rightC;
            nowActiveTab.parentNode.style.background = leftC;
            a.style.background = activeRightC;
            a.parentNode.style.background = activeLeftC;
        }
    };
    function init(backgroundColorChange)
    {
        if (backgroundColorChange != undefined)
            nonWhiteBackground = backgroundColorChange;
        activeLeftC  = '#fff url(/IVG2/Templates/Images/tab_left_corner'  + nonWhiteBackground + '_active.gif) no-repeat left top';
        activeRightC = '#fff url(/IVG2/Templates/Images/tab_right_corner' + nonWhiteBackground + '_active.gif) no-repeat right top';
        rightC       = '#fff url(/IVG2/Templates/Images/tab_right_corner' + nonWhiteBackground + '.jpg) no-repeat right top';
        leftC        = '#fff url(/IVG2/Templates/Images/tab_left_corner'  + nonWhiteBackground + '.jpg) no-repeat left top';
    }
    init();
    return { init:init, out:out, over:over }
}();

function newSelectOption(sHideDiv, sOptionSelect, sOptionID, nOffset, nIDProduct)
{
    var optionSelect = document.getElementById(sOptionSelect);
    var nCount;
    for (nCount = 0; nCount < optionSelect.length; nCount++)
    {
        if (optionSelect[nCount].value == sOptionID)
        {
            optionSelect.selectedIndex = nCount;
            $('ProductOptionImagesBottomID').remove();
            $('ProductOptionImagesTitleID').remove();
            checkForAddToOrder(nIDProduct)
            Effect.BlindUp(sHideDiv, { duration: 0.4, queue: "begin" });
            Effect.ScrollTo(sOptionSelect, { duration: 1.0, offset: nOffset, queue: "end" });
            return false;
        }
    }
    
}

function newHideDiv(sDiv)
{
    $('ProductOptionImagesBottomID').remove();
    $('ProductOptionImagesTitleID').remove();
    Effect.BlindUp(sDiv, { duration: 0.4, queue: "end" });
    return false;
}
 
function newShowDiv(sDiv,sHTML,nOffset)
{
    if (nOffset != null)
    {
        var oDiv = document.getElementById(sDiv);
        oDiv.style.display = "block";
        Effect.ScrollTo(sDiv, { duration: 1.0, offset: nOffset,  queue: "begin" });
        oDiv.style.display = "none";
    }
    
    if (sHTML != null)
        oDiv.innerHTML = sHTML;
   
   var pickerTitleP = oDiv.firstChild;
   var pickertitle = pickerTitleP.innerHTML;
   
   var pickertitlebar ='<div class=\"ProductOptionImagesTitle CSc\" id=\"ProductOptionImagesTitleID\"><h3 class=\"SectionTitle\">' + pickertitle + '</h3><div class=\"CloseBox\"><a href=\"\" onclick=\"return newHideDiv(\''+sDiv+'\');\">\&nbsp</a></div></div>';
   Element.insert(oDiv, {'before':pickertitlebar});
   
   var pickerbottom = new Element("div",{'class':'ProductOptionImagesBottom','id':'ProductOptionImagesBottomID'});
   Element.insert(oDiv,{'after':pickerbottom});
   
   pickerTitleP.style.display = 'none';
   Nifty("div.ProductOptionImagesTitle","top");
   Effect.BlindDown(sDiv, { duration: 0.4, queue: "end" });

   return false;
}

var g_nRPPage       = 1;
var g_nDirection    = 0;
function ShowImages(nPageOffset)
{
    var nRPPageMax      = Math.ceil(RPData.length / g_nProdsPerPage);
    if (g_nDirection == 0)
    {
        if (nPageOffset > 0)
            g_nDirection =  1;
        else
            g_nDirection = -1;
    }

    g_nRPPage += nPageOffset * g_nDirection;
    if (g_nRPPage < 1)
        g_nRPPage = nRPPageMax;
    else if (g_nRPPage > nRPPageMax)
        g_nRPPage = 1;

    var sPagingText = "Page " + g_nRPPage + " of " + nRPPageMax;
    document.getElementById("PageNumber1").innerHTML = sPagingText;
    document.getElementById("PageNumber2").innerHTML = sPagingText;

    var nProd = (g_nRPPage - 1) * g_nProdsPerPage;
    for (var nCount = 0; nCount < g_nProdsPerPage; nCount++)
    {
        var RPPos      = document.getElementById("RelatedProductsPosition" + nCount);
        if (nProd + nCount < RPData.length)
            RPPos.innerHTML = RPData[nProd + nCount];
        else
            RPPos.innerHTML = ""
    }
}

function setSameAsBilling()
{
    var shippingInputs = $("dvShippingInfo");
    if( shippingInputs.className != 'disabled'){
        shippingInputs.className = 'disabled';
        $$('#dvShippingInfo input', '#dvShippingInfo select').each(function(i){i.disabled=true;});
        }
    else {
        shippingInputs.className = '';
        $$('#dvShippingInfo input', '#dvShippingInfo select').each(function(i){i.disabled=false;});
    }
}

