
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'] = '32869';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1303';
        bsinfo['name'] = 'T-Mobile Wing';
        bsinfo['desc'] = 'Stay connected with the T-Mobile Wing, a powerful phone with a touch screen and slide out keyboard that lets you take the ... ';
        bsinfo['bulletPoints'] = '<li>Bluetooth v2.0     <li>2.0 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/32869_hbs.jpg';
        bsinfo['user_rate'] = '4.05';
        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 2:
        bsinfo['prId'] = '33374';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1284';
        bsinfo['name'] = 'Sony Ericsson W580i Black';
        bsinfo['desc'] = 'The Sony Ericsson W580i is a sleek, slim, street-style slider phone - and a portable music device too. Tempting to touch, ... ';
        bsinfo['bulletPoints'] = '<li>2.0 Megapixel Camera - for   Picture Messaging            <li>SMS, MMS,           ';
        bsinfo['carrier_corpId'] = '596';
        bsinfo['carrierName'] = 'AT&T';
        bsinfo['carrierLogoImgURL'] = '/img/corpLogos/plSm596.gif';
        bsinfo['prodImgURL'] = '/img/prod/cell-phones/att/sonyericsson/33374_hbs.jpg';
        bsinfo['user_rate'] = '4.37';
        bsinfo['expert_rate'] = '0';
        bsinfo['price'] = 'FREE';
        bsinfo['prRetailPrice'] = '$279.99';
        bsinfo['promoSpotPriceDisplay'] = '\
                <p>Product Price: <strike>$279.99</strike></p>\
                <p class="red"><strong>Your Price: FREE</strong></p>\
            ';
    break;
    case 3:
        bsinfo['prId'] = '34137';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1153';
        bsinfo['name'] = 'BlackBerry® Pearl™ 8120';
        bsinfo['desc'] = 'The BlackBerry® Pearl™ 8120 smartphone is designed to help you do everything you want with your life. It comes complete with ... ';
        bsinfo['bulletPoints'] = '<li>Wi-Fi for Mobile Calling     <li>Quad-Band 850/900/1800/1900 Mhz GSM/GPRS and EDGE networks     ';
        bsinfo['carrier_corpId'] = '543';
        bsinfo['carrierName'] = 'T-Mobile';
        bsinfo['carrierLogoImgURL'] = '/img/corpLogos/plSm543.gif';
        bsinfo['prodImgURL'] = '/img/prod/cell-phones/t-mobile/blackberry/34137_hbs.gif';
        bsinfo['user_rate'] = '4.27';
        bsinfo['expert_rate'] = '4.3';
        bsinfo['price'] = 'FREE';
        bsinfo['prRetailPrice'] = '$424.99';
        bsinfo['promoSpotPriceDisplay'] = '\
                <p>Product Price: <strike>$424.99</strike></p>\
                <p class="red"><strong>Your Price: FREE</strong></p>\
            ';
    break;
    case 4:
        bsinfo['prId'] = '33371';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1378';
        bsinfo['name'] = 'BlackBerry® Curve 8310 Titanium';
        bsinfo['desc'] = 'The BlackBerry Curve is the smallest, lightest BlackBerry ever with a QWERTY keyboard. It features a liquid silver finish ... ';
        bsinfo['bulletPoints'] = '<li>Smallest, lightest QWERTY Blackberry     <li>Access to work (BES) and personal (BIS) email     ';
        bsinfo['carrier_corpId'] = '596';
        bsinfo['carrierName'] = 'AT&T';
        bsinfo['carrierLogoImgURL'] = '/img/corpLogos/plSm596.gif';
        bsinfo['prodImgURL'] = '/img/prod/cell-phones/att/blackberry/33371_hbs.gif';
        bsinfo['user_rate'] = '4.55';
        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 5:
        bsinfo['prId'] = '34277';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1190';
        bsinfo['name'] = 'LG enV²™ in Black';
        bsinfo['desc'] = 'Get ready to join the next generation of mobile messaging with the new LG enV²™ in Black. Smaller, slimmer, and sleeker than ... ';
        bsinfo['bulletPoints'] = '<li>Music Player for MP3, WMA, Unprotected AAC & AAC+            <li>Sync music from PC to phone            ';
        bsinfo['carrier_corpId'] = '660';
        bsinfo['carrierName'] = 'Verizon Wireless';
        bsinfo['carrierLogoImgURL'] = '/img/corpLogos/plSm660.gif';
        bsinfo['prodImgURL'] = '/img/prod/cell-phones/verizonwireless/lg/34277_med.gif';
        bsinfo['user_rate'] = '4.37';
        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 6:
        bsinfo['prId'] = '33336';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1392';
        bsinfo['name'] = 'BlackBerry® Curve Titanium';
        bsinfo['desc'] = 'The BlackBerry Curve is the smallest, lightest BlackBerry ever with a QWERTY keyboard. It features a liquid silver finish ... ';
        bsinfo['bulletPoints'] = '<li>Smallest, lightest QWERTY Blackberry     <li>Access to work (BES) and personal (BIS) email     ';
        bsinfo['carrier_corpId'] = '543';
        bsinfo['carrierName'] = 'T-Mobile';
        bsinfo['carrierLogoImgURL'] = '/img/corpLogos/plSm543.gif';
        bsinfo['prodImgURL'] = '/img/prod/cell-phones/t-mobile/blackberry/33336_hbs.gif';
        bsinfo['user_rate'] = '4.43';
        bsinfo['expert_rate'] = '4';
        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 7:
        bsinfo['prId'] = '33889';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1423';
        bsinfo['name'] = 'Samsung SPH-M520';
        bsinfo['desc'] = 'The Samsung SPH-M520 ™ is a sleek ultra thin slider-style cell phone. Enjoy your music anytime, anywhere. Users can play ... ';
        bsinfo['bulletPoints'] = '<li>Access to Sprint Music Store             <li>High Speed Multimedia Streaming             ';
        bsinfo['carrier_corpId'] = '545';
        bsinfo['carrierName'] = 'Sprint';
        bsinfo['carrierLogoImgURL'] = '/img/corpLogos/plSm545.gif';
        bsinfo['prodImgURL'] = '/img/prod/cell-phones/sprintpcs/samsung/33889_hbs.jpg';
        bsinfo['user_rate'] = '4.87';
        bsinfo['expert_rate'] = '0';
        bsinfo['price'] = 'You make $50.00';
        bsinfo['prRetailPrice'] = '$279.99';
        bsinfo['promoSpotPriceDisplay'] = '\
                <p>Product Price: <strike>$279.99</strike></p>\
                <p class="red"><strong>Your Price: You make $50.00</strong></p>\
            ';
    break;
    case 8:
        bsinfo['prId'] = '33379';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1384';
        bsinfo['name'] = 'Palm Centro Black';
        bsinfo['desc'] = 'Life starts after five o\'clock. That\'s why there\'s the Palm® Centro™ smartphone. Palm Centro gives you voice, text, IM, ... ';
        bsinfo['bulletPoints'] = '<li>Palm OS 5.4.9          <li>Blazer® mobile web browser         ';
        bsinfo['carrier_corpId'] = '545';
        bsinfo['carrierName'] = 'Sprint';
        bsinfo['carrierLogoImgURL'] = '/img/corpLogos/plSm545.gif';
        bsinfo['prodImgURL'] = '/img/prod/cell-phones/sprintpcs/palm/33379_hbs.gif';
        bsinfo['user_rate'] = '4.37';
        bsinfo['expert_rate'] = '3.5';
        bsinfo['price'] = 'FREE';
        bsinfo['prRetailPrice'] = '$459.99';
        bsinfo['promoSpotPriceDisplay'] = '\
                <p>Product Price: <strike>$459.99</strike></p>\
                <p class="red"><strong>Your Price: FREE</strong></p>\
            ';
    break;
    case 9:
        bsinfo['prId'] = '34077';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1469';
        bsinfo['name'] = 'MOTO Z9';
        bsinfo['desc'] = 'The second generation Motorola Z9 for AT&T is strikingly beautiful with its 1/2\"-thick stainless steel, glass and metal ... ';
        bsinfo['bulletPoints'] = '<li>Built-in Music Player and External-mounted Controls Lets You Take Your Tunes With You        <li>2.0 Megapixel Camera - for   Picture Messaging       ';
        bsinfo['carrier_corpId'] = '596';
        bsinfo['carrierName'] = 'AT&T';
        bsinfo['carrierLogoImgURL'] = '/img/corpLogos/plSm596.gif';
        bsinfo['prodImgURL'] = '/img/prod/cell-phones/att/motorola/34077_med.gif';
        bsinfo['user_rate'] = '0';
        bsinfo['expert_rate'] = '0';
        bsinfo['price'] = 'FREE';
        bsinfo['prRetailPrice'] = '$339.99';
        bsinfo['promoSpotPriceDisplay'] = '\
                <p>Product Price: <strike>$339.99</strike></p>\
                <p class="red"><strong>Your Price: FREE</strong></p>\
            ';
    break;
    case 10:
        bsinfo['prId'] = '33174';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1357';
        bsinfo['name'] = 'Samsung Blast';
        bsinfo['desc'] = 'The Samsung Blast (SGH-T729) is a stylish ultra-thin slider that offers powerful multimedia features such as Bluetooth ... ';
        bsinfo['bulletPoints'] = '<li>Stereo Bluetooth® Wireless Technology     <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/samsung/33174_hbs.jpg';
        bsinfo['user_rate'] = '4.11';
        bsinfo['expert_rate'] = '0';
        bsinfo['price'] = 'You make $75.00';
        bsinfo['prRetailPrice'] = '$199.99';
        bsinfo['promoSpotPriceDisplay'] = '\
                <p>Product Price: <strike>$199.99</strike></p>\
                <p class="red"><strong>Your Price: You make $75.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>\
    ';
    }
}
