
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'] = '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.13';
        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 2:
        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.95';
        bsinfo['expert_rate'] = '0';
        bsinfo['price'] = 'You make $50.00';
        bsinfo['prRetailPrice'] = '$399.99';
        bsinfo['promoSpotPriceDisplay'] = '\
                <p>Product Price: <strike>$399.99</strike></p>\
                <p class="red"><strong>Your Price: You make $50.00</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.45';
        bsinfo['expert_rate'] = '0';
        bsinfo['price'] = '$49.99';
        bsinfo['prRetailPrice'] = '$549.99';
        bsinfo['promoSpotPriceDisplay'] = '\
                <p>Product Price: <strike>$549.99</strike></p>\
                <p class="red"><strong>Your Price: $49.99</strong></p>\
            ';
    break;
    case 4:
        bsinfo['prId'] = '34675';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1530';
        bsinfo['name'] = 'Motorola Krave™ ZN4';
        bsinfo['desc'] = 'The Motorola Krave ZN4 is a portal into an interactive, multi-dimensional world of music, videos, web, and  more. ... ';
        bsinfo['bulletPoints'] = '<li>Innovative Touch Screen with Interactive Clear Flip                                                  <li>V CAST Mobile TV          ';
        bsinfo['carrier_corpId'] = '660';
        bsinfo['carrierName'] = 'Verizon Wireless';
        bsinfo['carrierLogoImgURL'] = '/img/corpLogos/plSm660.gif';
        bsinfo['prodImgURL'] = '/img/prod/cell-phones/verizonwireless/motorola/34675_pdi.gif';
        bsinfo['user_rate'] = '0';
        bsinfo['expert_rate'] = '0';
        bsinfo['price'] = '$99.99';
        bsinfo['prRetailPrice'] = '$349.99';
        bsinfo['promoSpotPriceDisplay'] = '\
                <p>Product Price: <strike>$349.99</strike></p>\
                <p class="red"><strong>Your Price: $99.99</strong></p>\
            ';
    break;
    case 5:
        bsinfo['prId'] = '34621';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1534';
        bsinfo['name'] = 'Pantech Matrix Black';
        bsinfo['desc'] = 'Designed to make messaging faster and easier than ever before, the Pantech Matrix cell phone features a cool convertible ... ';
        bsinfo['bulletPoints'] = '<li>3G technology for high-speed data                                         <li>Windows Mobile® 6                                      ';
        bsinfo['carrier_corpId'] = '596';
        bsinfo['carrierName'] = 'AT&T';
        bsinfo['carrierLogoImgURL'] = '/img/corpLogos/plSm596.gif';
        bsinfo['prodImgURL'] = '/img/prod/cell-phones/att/pantech/34621_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 6:
        bsinfo['prId'] = '34449';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1392';
        bsinfo['name'] = 'BlackBerry® Curve 8320 Sunset';
        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/34449_hbs.gif';
        bsinfo['user_rate'] = '4.46';
        bsinfo['expert_rate'] = '4';
        bsinfo['price'] = 'Too Low to Show';
        bsinfo['prRetailPrice'] = '$549.99';
        bsinfo['promoSpotPriceDisplay'] = '\
                <p class="red"><strong>Too Low to Show</strong><br />\
                <a href="/product/product.htm?prId=34449" onclick="UserTrackPageView(\'BS2LP\')">Click to See Price</a></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'] = '$369.99';
        bsinfo['promoSpotPriceDisplay'] = '\
                <p>Product Price: <strike>$369.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'] = '3.5';
        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'] = '34617';
        bsinfo['pgId'] = '100';
        bsinfo['pfId'] = '1539';
        bsinfo['name'] = 'Sony Ericsson W760a Black';
        bsinfo['desc'] = 'The Sony Ericsson W760a is packed with entertainment features that music and gaming to the next level. The cool new ... ';
        bsinfo['bulletPoints'] = '<li>3.2 Megapixel Camera - for    Picture Messaging                               <li>Stereo Bluetooth                              ';
        bsinfo['carrier_corpId'] = '596';
        bsinfo['carrierName'] = 'AT&T';
        bsinfo['carrierLogoImgURL'] = '/img/corpLogos/plSm596.gif';
        bsinfo['prodImgURL'] = '/img/prod/cell-phones/att/sonyericsson/34617_hbs.gif';
        bsinfo['user_rate'] = '0';
        bsinfo['expert_rate'] = '0';
        bsinfo['price'] = 'FREE';
        bsinfo['prRetailPrice'] = '$249.99';
        bsinfo['promoSpotPriceDisplay'] = '\
                <p>Product Price: <strike>$249.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'] = '$299.99';
        bsinfo['promoSpotPriceDisplay'] = '\
                <p>Product Price: <strike>$299.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>\
    ';
    }
}
