﻿//  review.js

//  Inline script for bazaarvoice reviews. 
//  This runs in the head of the product details and review submission pages.
//  Only set the domain if we're on bikebandit.com, to avoid script errors during development.
if (window.location.hostname.indexOf("bikebandit.com") >= 0)
{
  document.domain = "bikebandit.com";
}

// BV's hook to the count data.
function ratingsDisplayed(totalReviewsCount, avgRating, ratingsOnlyReviewCount, someNumber, productID)
{
    // Custom items with these three values. 
    // Added the two additional arguments that it sends.
    //alert(totalReviewsCount + ", " + avgRating + ", " + ratingsOnlyReviewCount + ", " + someNumber + ", " + productID);
   
    // This is now done server side from our data; formerly here to query bv's data.
    // If we have no reviews, hide the tab.
    //if (totalReviewsCount == 0)
    //{
    //    setTimeout("hideTabReview()", 100);     // Giving scripts a little time.
    //}
}

// BV's hook for debugging.
function showReviewMarkup()
{
   document.getElementById("hideBV").style.display = "block";
}


// BikeBandit's tab handling.
var tabHideCount = 0;     // Safety count for tab hiding loop.

// Hide review tab.  UNUSED.
// Got the $ function from viewing source of the ajax tabs.
// Handle race conditions between reviews and the ajax tabs.
// TODO: Discover the id and tab number instead of hard-coded.
function hideTabReview()
{
    var tabs = $find('ctl00_cphMain_ucProductTabs_tcTabs');
    if (tabs)
    {
        tabs.get_tabs()[1].set_enabled(false);
    }
    else if (++tabHideCount < 10)
    {
        setTimeout("hideTabReview()", 100);     // Try again.
    }
}

// Set review tab active.  UNUSED.
//  Called from a user click, so it doesn't need the race condition checking.
// TODO: Discover the id and tab number instead of hard-coded.
function setActiveTabReview()
{
    var tabs = $find('ctl00_cphMain_ucProductTabs_tcTabs');
    if (tabs)    // Just in case.
    {
        tabs.set_activeTab(tabs.get_tabs()[1]);
    }
}
