﻿
function AddToBuyCart(ItemId, SuitId,ItemCount) {
    //frmBuyCart.show();
    var strUrl = '/dl2/BuyCartAdd.aspx';
    if (ItemId) {
        strUrl += '?ItemId=' + ItemId;
    }
    else if (SuitId) {
        strUrl += '?SuitId=' + SuitId;
    }
    else {
        return;
    }
    if (ItemCount) {
        strUrl += '&ItemCount=' + ItemCount;
    }
    else {
        strUrl += '&ItemCount=1';
    }
    strUrl += '&rnd=' + new Date()
    frmBuyCart.attr('src', strUrl);
}




//function GetBuyCartUrl() {
//    return '/dl2/MyBuyCart.aspx?rnd=' + new Date();
//}
var frmBuyCart = null;
var divBuyCart = null;
var divPlayPanel = null;
$(function () {
    divPlayPanel = $('#divPlayPanel');
    divBuyCart = $('<div id="divBuyCart" class="BuyCartTip" style="position:absolute;left:0px;top:0px;display:none;"></div>');
    $(document.body).append(divBuyCart);
    frmBuyCart = $('<iframe id="frmBuyCart" name="BuyCartIframe" src="/dl2/MyBuyCart.aspx?rnd=' + new Date() 
        + '" style="width:300px;height:400px;position:absolute;left:300px;top:0px;display:none;" />');
    $(document.body).append(frmBuyCart);
    //LocateBuyCartTimeout = setTimeout(LocateBuyCart, 500);
});


var LocateBuyCartTimeout = null;
function ShowBuyCart(html) {
    if (LocateBuyCartTimeout) {
        clearTimeout(LocateBuyCartTimeout);
    }
    try {
        divBuyCart.html(html);
        PlayTip.AddPlayItemListener($('.PlayItem', divBuyCart));
        //frmBuyCart.hide();
        BuyCartTipDisplay = 'block'
        LocateBuyCartTimeout = setTimeout(LocateBuyCart, 1);
        //divBuyCart.show();
    }
    catch (ex) {
    }
}

var BuyCartTipTop = -1;
var BuyCartTipDisplay = 'block';
//定位购物车页面
function LocateBuyCart() {
    var pnl = { w: $(document.body).width(), w2: divPlayPanel.width(), h: $(document.body).height(), h2: document.documentElement.clientHeight, l: divPlayPanel.offset().left + 7, t: document.body.scrollTop || document.documentElement.scrollTop || 0 };
    var tip = { w: divBuyCart.width(), h: divBuyCart.height(), l: divBuyCart.offset().left, t: divBuyCart.offset().top };
    //if (tip.w < pnl.l) {
    //    tip.x = pnl.l - tip.w;
    //}
    //else {
    //    tip.x = pnl.w - tip.w-2;
    //}
    if (pnl.w - tip.w > pnl.l + pnl.w2 - 20) {
        tip.x = pnl.l + pnl.w2 - 20;
    }
    else {
        tip.x = pnl.w - tip.w - 2;
    }
    MaxTop = 92;

    if (tip.h + MaxTop < pnl.h2 - MaxTop) {
        tip.y = pnl.t + MaxTop;
    }
    else if (tip.h < pnl.h2) {
        tip.y = pnl.t + (pnl.h2 - tip.h) / 2;
    }
    //else if (tip.h < pnl.h) {
    //    if (pnl.t + pnl.h2 - tip.h > 0) {
    //        if (BuyCartTipTop >= 0 && BuyCartTipTop + tip.h > pnl.t + pnl.h2 - 2) {
    //            if (BuyCartTipTop + 2 <= pnl.t) {
    //                tip.y = BuyCartTipTop;
    //            }
    //            else {
    //                tip.y = pnl.t - 2;
    //            }
    //        }
    //        else {
    //            tip.y = pnl.t + pnl.h2 - tip.h - 2;
    //            BuyCartTipTop = tip.y;
    //        }
    //    }
    //    else {
    //        tip.y = 0;
    //        BuyCartTipTop = tip.y;
    //    }
    //}
    else {
        tip.y = 0;
    }


    //document.title = tip.w + ',' + tip.h + ',' + tip.l + ',' + tip.t + ',' + pnl.w + ',' + pnl.h + ',' + pnl.h2 + ',' + pnl.l + ',' + pnl.t;
    divBuyCart.css({ top: tip.y, left: tip.x, display: BuyCartTipDisplay });
    LocateBuyCartTimeout = setTimeout(LocateBuyCart, 100);
}

