
function UseAlternativeBestSellersOverlay()
{
    return (document.getElementById('bestSellDetBoxB') ? true : false);
}

function DisplayBestSellerRank(rank)
{
    var useAltOverlay = UseAlternativeBestSellersOverlay();
    var bestSellDetBoxMain = document.getElementById(useAltOverlay ? 'bestSellDetBoxMain' : 'bestSellDetBox');
    var bestSellDetBox     = document.getElementById(useAltOverlay ? 'bestSellDetBoxB'    : 'bestSellDetBox');

    if( bestSellDetBox && bestSellDetBoxMain )
    {
        bestSellDetBox.innerHTML = GetBestSellerDivHTML(rank);
        bestSellDetBoxMain.style.visibility = "visible";

        if( document.getElementById('rotator') )
        {
            HideRotator();
        }
    }
}

function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [ scrOfX, scrOfY ];
}

function DelayedRestoreBestSellerRank(event)
{
    var bestPromos = document.getElementById('bestPromos');

    if( bestPromos )
    {
        offsetXY = getScrollXY();

        var mouseX = (event.pageX ? event.pageX : (window.event.clientX + offsetXY[0]));
        var mouseY = (event.pageY ? event.pageY : (window.event.clientY + offsetXY[1]));

        if( !IsInsideElement(bestPromos, mouseX, mouseY) )
            RestoreBestSellerRank(); // no delay
    }
}

function RestoreBestSellerRank()
{
    var useAltOverlay = UseAlternativeBestSellersOverlay();
    var bestSellDetBoxMain = document.getElementById(useAltOverlay ? 'bestSellDetBoxMain' : 'bestSellDetBox');

    if( bestSellDetBoxMain )
    {
        bestSellDetBoxMain.style.visibility = "hidden";

        if( document.getElementById('rotator') )
        {
            ShowRotator();
        }
    }
}

function IsInsideElement(obj, x, y)
{
    oTop = GetElementAbsoluteTop(obj);
    oLeft = GetElementAbsoluteLeft(obj);
    oBottom = oTop + obj.offsetHeight;
    oRight = oLeft + obj.offsetWidth;
    return (x > oLeft && x < oRight && y > oTop && y < oBottom);
}

function GetElementAbsoluteLeft(o)
{
    // Get an object left position from the upper left viewport corner
    oLeft = o.offsetLeft;            // Get left position from the parent object
    while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
        oParent = o.offsetParent;    // Get parent object reference
        oLeft += oParent.offsetLeft; // Add parent left position
        o = oParent;
    }
    return oLeft;     // Return left postion
}

function GetElementAbsoluteTop(o)
{
    // Get an object top position from the upper left viewport corner
    oTop = o.offsetTop;            // Get top position from the parent object
    while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
        oParent = o.offsetParent;  // Get parent object reference
        oTop += oParent.offsetTop; // Add parent top position
        o = oParent;
    }
    return oTop; // Return top position
}

function GetRatingBoxString(type, rate)
{
    return '\
        <span class="rateBox">\
            <img src="/img/newFrontEnd/rateBar_bg.gif" width="'+ (rate * 75 / 5.0)  +'" height="15" />\
            <img src="/img/newFrontEnd/rateStars.gif" alt="'+type+' Rating "'+ rate +'/5" title="'+type+' Rating "'+ rate+'/5" />\
        </span>';
}


function GetBestSellerDivHTML(rank)
{
    var bsinfo = new Array();
    switch(rank)
    {
    case 1:
        bsinfo['prId'] = '34451';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1495';
        bsinfo['name'] = 'T-Mobile Sidekick 2008';
        bsinfo['desc'] = 'The new Sidekick is better than ever, with enhanced Web browsing plus video recording, playback, and sharing capabilities. ... ';
        bsinfo['bulletPoints'] = '<li>Best-in-class IM, text-messaging, e-mail, and phone                                        <li>Integrated, true Instant Messaging (AIM, Yahoo! Instant Messanger, Windows Live Messanger - formerly MSN Messanger)                                        ';
        bsinfo['carrier_corpId'] = '543';
        bsinfo['carrierName'] = 'T-Mobile';
        bsinfo['carrierLogoImgURL'] = '/img/corpLogos/plSm543.gif';
        bsinfo['prodImgURL'] = '/img/prod/cell-phones/t-mobile/danger/34451_hbs.gif';
        bsinfo['user_rate'] = '4.21';
        bsinfo['expert_rate'] = '3.8';
        bsinfo['price'] = 'Too Low to Show';
        bsinfo['prRetailPrice'] = '$459.99';
        bsinfo['promoSpotPriceDisplay'] = '\
                <p class="red"><strong>Too Low to Show</strong><br />\
                <a  href=\"/popups/zipcode_popup.htm?prId=34451&p2l2s=1\" onClick=\"popupWin(this.href,\'zipcode\',\'300\',\'200\',\'\');   return false;\" target=\"newWin\">Click to See Price</a></p>\
            ';
    break;
    case 2:
        bsinfo['prId'] = '34180';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1472';
        bsinfo['name'] = 'LG Vu™ CU920';
        bsinfo['desc'] = 'Elegantly and simply designed, the LG Vu CU920 cell phone for AT&T features a stunning 3-inch touchscreen that provides ... ';
        bsinfo['bulletPoints'] = '<li>  Watch live streaming TV shows with AT&T Mobile TV (where applicable)                                   <li>Gorgeous Touch-Screen With Tactile Feedback Is Huge And Easy To Navigate                                ';
        bsinfo['carrier_corpId'] = '596';
        bsinfo['carrierName'] = 'AT&T';
        bsinfo['carrierLogoImgURL'] = '/img/corpLogos/plSm596.gif';
        bsinfo['prodImgURL'] = '/img/prod/cell-phones/att/lg/34180_hbs.gif';
        bsinfo['user_rate'] = '4.23';
        bsinfo['expert_rate'] = '0';
        bsinfo['price'] = 'FREE';
        bsinfo['prRetailPrice'] = '$299.99';
        bsinfo['promoSpotPriceDisplay'] = '\
                <p>Product Price: <strike>$299.99</strike></p>\
                <p class="red"><strong>Your Price: FREE</strong></p>\
            ';
    break;
    case 3:
        bsinfo['prId'] = '34423';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1503';
        bsinfo['name'] = 'Samsung Instinct';
        bsinfo['desc'] = 'There are touchscreens, and then there’s the Samsung Instinct™. The Instinct is the touchscreen that keeps you in touch ... ';
        bsinfo['bulletPoints'] = '<li>Advanced responsive touchscreen with tactile feedback                        <li>Turn-by-turn GPS and Live Search                        ';
        bsinfo['carrier_corpId'] = '545';
        bsinfo['carrierName'] = 'Sprint';
        bsinfo['carrierLogoImgURL'] = '/img/corpLogos/plSm545.gif';
        bsinfo['prodImgURL'] = '/img/prod/cell-phones/sprint/samsung/34423_hbs.gif';
        bsinfo['user_rate'] = '4.53';
        bsinfo['expert_rate'] = '0';
        bsinfo['price'] = 'FREE';
        bsinfo['prRetailPrice'] = '$599.99';
        bsinfo['promoSpotPriceDisplay'] = '\
                <p>Product Price: <strike>$599.99</strike></p>\
                <p class="red"><strong>Your Price: FREE</strong></p>\
            ';
    break;
    case 4:
        bsinfo['prId'] = '34678';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1548';
        bsinfo['name'] = 'Motorola Rapture™ VU30';
        bsinfo['desc'] = 'The Motorola Rapture™VU30 will get you noticed. With its unique, rounded design and jewel-like keypad, all you have to do is ... ';
        bsinfo['bulletPoints'] = '<li>Vanishing External Display                <li>microSD™ Memory Port capable of up to 8GB removable memory                ';
        bsinfo['carrier_corpId'] = '660';
        bsinfo['carrierName'] = 'Verizon Wireless';
        bsinfo['carrierLogoImgURL'] = '/img/corpLogos/plSm660.gif';
        bsinfo['prodImgURL'] = '/img/prod/cell-phones/verizonwireless/motorola/34678_hbs.gif';
        bsinfo['user_rate'] = '0';
        bsinfo['expert_rate'] = '0';
        bsinfo['price'] = 'FREE';
        bsinfo['prRetailPrice'] = '$299.99';
        bsinfo['promoSpotPriceDisplay'] = '\
                <p>Product Price: <strike>$299.99</strike></p>\
                <p class="red"><strong>Your Price: FREE</strong></p>\
            ';
    break;
    case 5:
        bsinfo['prId'] = '31855';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1175';
        bsinfo['name'] = 'T-Mobile Dash';
        bsinfo['desc'] = 'The exclusive T-Mobile Dash!  The T-Mobile Dash is a sleek Smartphone with a full QWERTY keyboard that brings e-mail and ... ';
        bsinfo['bulletPoints'] = '<li>Bluetooth           <li>1.3 Megapixel Camera           ';
        bsinfo['carrier_corpId'] = '543';
        bsinfo['carrierName'] = 'T-Mobile';
        bsinfo['carrierLogoImgURL'] = '/img/corpLogos/plSm543.gif';
        bsinfo['prodImgURL'] = '/img/prod/cell-phones/t-mobile/htc/31855_hbs.jpg';
        bsinfo['user_rate'] = '3.96';
        bsinfo['expert_rate'] = '0';
        bsinfo['price'] = 'You make $50.00';
        bsinfo['prRetailPrice'] = '$449.99';
        bsinfo['promoSpotPriceDisplay'] = '\
                <p>Product Price: <strike>$449.99</strike></p>\
                <p class="red"><strong>Your Price: You make $50.00</strong></p>\
            ';
    break;
    case 6:
        bsinfo['prId'] = '34777';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1562';
        bsinfo['name'] = 'AT&T Quickfire Silver';
        bsinfo['desc'] = 'Designed to make messaging faster and easier than ever before, the AT&T Quickfire messaging-focused cell phone is great for ... ';
        bsinfo['bulletPoints'] = '<li>High-Speed data access via broadband 3G Network.                  <li>Cool touch screen for fun, easy access to your favorites.                   ';
        bsinfo['carrier_corpId'] = '596';
        bsinfo['carrierName'] = 'AT&T';
        bsinfo['carrierLogoImgURL'] = '/img/corpLogos/plSm596.gif';
        bsinfo['prodImgURL'] = '/img/prod/cell-phones/att/utstarcom/34777_hbs.gif';
        bsinfo['user_rate'] = '0';
        bsinfo['expert_rate'] = '0';
        bsinfo['price'] = '$49.99';
        bsinfo['prRetailPrice'] = '$299.99';
        bsinfo['promoSpotPriceDisplay'] = '\
                <p>Product Price: <strike>$299.99</strike></p>\
                <p class="red"><strong>Your Price: $49.99</strong></p>\
            ';
    break;
    case 7:
        bsinfo['prId'] = '34634';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1511';
        bsinfo['name'] = 'Samsung Rant - Black';
        bsinfo['desc'] = 'The Samsung Rant features a messaging-centric form factor in two great colors. This sideways slider hides a full qwerty ... ';
        bsinfo['bulletPoints'] = '<li>Sprint One Click                    <li>2.0MP Camera/camcorder                    ';
        bsinfo['carrier_corpId'] = '545';
        bsinfo['carrierName'] = 'Sprint';
        bsinfo['carrierLogoImgURL'] = '/img/corpLogos/plSm545.gif';
        bsinfo['prodImgURL'] = '/img/prod/cell-phones/sprint/samsung/34634_hbs.gif';
        bsinfo['user_rate'] = '0';
        bsinfo['expert_rate'] = '0';
        bsinfo['price'] = 'FREE';
        bsinfo['prRetailPrice'] = '$399.99';
        bsinfo['promoSpotPriceDisplay'] = '\
                <p>Product Price: <strike>$399.99</strike></p>\
                <p class="red"><strong>Your Price: FREE</strong></p>\
            ';
    break;
    case 8:
        bsinfo['prId'] = '34478';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1525';
        bsinfo['name'] = 'Verizon Wireless Blitz';
        bsinfo['desc'] = 'The Blitz, a Verizon Wireless exclusive, is a new messaging phone with slide-out QWERTY keyboard, is perfect for heavy ... ';
        bsinfo['bulletPoints'] = '<li>Slide-out QWERTY Keyboard                                                            <li>V Cast Music with Rhapsody®                                               ';
        bsinfo['carrier_corpId'] = '660';
        bsinfo['carrierName'] = 'Verizon Wireless';
        bsinfo['carrierLogoImgURL'] = '/img/corpLogos/plSm660.gif';
        bsinfo['prodImgURL'] = '/img/prod/cell-phones/verizonwireless/utstarcom/34478_hbs.gif';
        bsinfo['user_rate'] = '4.42';
        bsinfo['expert_rate'] = '3.5';
        bsinfo['price'] = 'FREE';
        bsinfo['prRetailPrice'] = '$229.99';
        bsinfo['promoSpotPriceDisplay'] = '\
                <p>Product Price: <strike>$229.99</strike></p>\
                <p class="red"><strong>Your Price: FREE</strong></p>\
            ';
    break;
    case 9:
        bsinfo['prId'] = '34793';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1567';
        bsinfo['name'] = 'LG Incite';
        bsinfo['desc'] = 'A sophisticated styled Smartphone has finally arrived. The LG INCITE is the successful implementation of minimalist design ... ';
        bsinfo['bulletPoints'] = '<li>Beautiful touch screen with haptic feedback (vibrates when you touch)          <li>Windows Mobile 6.1 with copy and paste, document viewing, editing, & storing capabilities            ';
        bsinfo['carrier_corpId'] = '596';
        bsinfo['carrierName'] = 'AT&T';
        bsinfo['carrierLogoImgURL'] = '/img/corpLogos/plSm596.gif';
        bsinfo['prodImgURL'] = '/img/prod/cell-phones/att/lg/34793_hbs.gif';
        bsinfo['user_rate'] = '0';
        bsinfo['expert_rate'] = '0';
        bsinfo['price'] = 'FREE';
        bsinfo['prRetailPrice'] = '$449.99';
        bsinfo['promoSpotPriceDisplay'] = '\
                <p>Product Price: <strike>$449.99</strike></p>\
                <p class="red"><strong>Your Price: FREE</strong></p>\
            ';
    break;
    case 10:
        bsinfo['prId'] = '34401';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1374';
        bsinfo['name'] = 'MOTO W490 Black/Mandarine';
        bsinfo['desc'] = 'Balancing advanced functionality and affordability, the Motorola W490 with video capture and playback, an integrated 1.3 ... ';
        bsinfo['bulletPoints'] = '<li>Integrated 1.3 Mega-pixel camera with 4x zoom                 <li>EDGE technology for high speed data exchange                 ';
        bsinfo['carrier_corpId'] = '543';
        bsinfo['carrierName'] = 'T-Mobile';
        bsinfo['carrierLogoImgURL'] = '/img/corpLogos/plSm543.gif';
        bsinfo['prodImgURL'] = '/img/prod/cell-phones/t-mobile/motorola/34401_hbs.gif';
        bsinfo['user_rate'] = '4.27';
        bsinfo['expert_rate'] = '0';
        bsinfo['price'] = 'You make $50.00';
        bsinfo['prRetailPrice'] = '$349.99';
        bsinfo['promoSpotPriceDisplay'] = '\
                <p>Product Price: <strike>$349.99</strike></p>\
                <p class="red"><strong>Your Price: You make $50.00</strong></p>\
            ';
    break;
    default:
    break;
    }

    var useAltOverlay = UseAlternativeBestSellersOverlay();

    var userRating = '';
    var expertRating = '';
    var carrierLogo = '';
    var prodDetailURL = '/product/product.htm?prId='+bsinfo['prId'];


    var prodImg = '<a href="'+prodDetailURL+'" onclick="UserTrackPageView(\'BSOIM\')"><img src='+bsinfo['prodImgURL']+' border=0 height="170"/></a>';

    if( bsinfo['user_rate'] > 0 )
    {
        var ratebox = GetRatingBoxString('User', bsinfo['user_rate']);

        if( useAltOverlay )
        {
            userRating = '\
        <p class="rating">\
        ' + ratebox + '\
        <a href="/reviews/review.htm?pfId='+bsinfo['pfId']+'&rNav=2" onclick="UserTrackPageView(\'BSOUR\')">User Rating '+bsinfo['user_rate']+'</a>\
        </p>';
        }
        else
        {
            userRating = '\
        <a href="/reviews/review.htm?pfId='+bsinfo['pfId']+'&rNav=2" onclick="UserTrackPageView(\'BSOUR\')">\
        <p>User Rating<br>'+bsinfo['user_rate']+'</p>\
        ' + ratebox + '\
        </a>';
        }
    }

    if( bsinfo['expert_rate'] > 0 )
    {
        var ratebox = GetRatingBoxString('Expert', bsinfo['expert_rate']);

        if( useAltOverlay )
        {
            expertRating = '\
        <p class="rating">\
        '+ ratebox + '\
        <a href="/reviews/review.htm?pfId='+bsinfo['pfId']+'&rNav=3" onclick="UserTrackPageView(\'BSOER\')">Expert Rating '+bsinfo['expert_rate']+'</a>\
        </p>';
        }
        else
        {
            expertRating = '\
        <a href="/reviews/review.htm?pfId='+bsinfo['pfId']+'&rNav=3" onclick="UserTrackPageView(\'BSOER\')">\
        <p>Expert Rating<br>'+bsinfo['expert_rate']+'</p>\
        ' + ratebox + '\
        </a>';
        }
    }

    if( bsinfo['carrierLogoImgURL'] )
    {
        carrierLogo = '<img src="'+ bsinfo['carrierLogoImgURL'] + '" class="'+ ( useAltOverlay ? 'botom' : 'carrLogo') +'" alt="'+bsinfo['carrierName']+'"/>';
    }



    if( useAltOverlay )
    {
        return '\
    <div id="bsPhnPic" class="col">\
        '+ prodImg + '<br />\
        '+ carrierLogo +'\
    </div>\
    <div id="bsDetails" class="col">\
        <h2><a href="'+prodDetailURL+'" onclick="UserTrackPageView(\'BSONM\')">'+ bsinfo['name']+'</a></h2>\
        '+ userRating +'\
        '+ expertRating +'\
        <p>'+ bsinfo['desc']+'</p>\
        <ul>'+ bsinfo['bulletPoints']+'</ul>\
        <div class="bottom">\
            '+ bsinfo['promoSpotPriceDisplay'] +'\
            <form name="detailSelection" action="/upgrades/buytype.htm?prId='+bsinfo['prId']+'&tNav=1&redirect=/plans/shop.htm" method="POST">\
                <input type=image src="/img/home/bs_shopNow_btn.gif" class="right" alt="Shop now" name="buyImage" onclick="UserTrackPageView(\'BSOAC\')" />\
            </form>\
        </div>\
    </div>\
    <a href="'+prodDetailURL+'" onclick="UserTrackPageView(\'BSOMI\')"><img src="/img/home/moreInfo_gfx.gif" id="moreInfo" alt="More Information" border="0"/></a>\
    ';
    }
    else
    {
        return '\
    <div id="bsPhnPic" class="col">\
        '+ prodImg + '<br />\
        <a href="'+prodDetailURL+'" onclick="UserTrackPageView(\'BSOMI\')"><img src="/img/newFrontEnd/moreInfo_btn.gif" class="bottom" border="0"/></a>\
    </div>\
    <div id="bsDetails" class="col">\
        <h2><a href="'+prodDetailURL+'" onclick="UserTrackPageView(\'BSONM\')">'+ bsinfo['name']+'</a></h2>\
        <p>'+ bsinfo['desc']+'</p>\
        <ul>'+ bsinfo['bulletPoints']+'</ul>\
        <div class="bottom">\
            '+ bsinfo['promoSpotPriceDisplay'] +'\
        </div>\
    </div>\
    <div id="bsAction" class="col">\
        '+ carrierLogo +'\
        '+ userRating +'\
        '+ expertRating +'\
        <form name="detailSelection" action="/upgrades/buytype.htm?prId='+bsinfo['prId']+'&tNav=1&redirect=/plans/shop.htm" class="bottom" method="POST">\
              <input type=image src="/img/newFrontEnd/hm_addToCart_btn.gif" alt="Add to Cart" name="buyImage" onclick="UserTrackPageView(\'BSOAC\')" />\
        </form>\
    </div>\
    ';
    }
}
