<%@ Page Language="C#"  AutoEventWireup="true"  Codebehind="Cart.aspx.cs" Inherits="PPFOR.CustomAction.Cart" Title="购物车" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<link type="text/css" href="/CustomAction/goods/Css/cart.css" rel="stylesheet" />
<script type="text/javascript" src="JS/doAjax.js"></script>
<script type="text/javascript" src="JS/cart.js"></script>
<title>购物车</title>
<script type="text/javascript">
var moneySign="<%=PPFOR_moneySign %>";
function increaseNumber(id,maxValue){
    var obj=docEle(id);
    if(obj){            
        var count=parseInt(obj.value);
        if(maxValue>=count+1){
            obj.value=count+1;
            checkIsUNumber(obj,1);     
        }  
    }
}
function decreaseNumber(id){
    var obj=docEle(id);
    if(obj){        
        var count=parseInt(obj.value);
        if(count-1>0){
            obj.value=count-1;
            checkIsUNumber(obj,1);
        }        
    }
}
function checkIsUNumber(obj,defValue)
{
    if(obj!=null && obj.type=="text")
    { 
        var r=/[^\d]*([\d]*)[\D]*/; 
        var value=obj.value;
        var P=value.match(r);
        if(P[1]==null || P[1]==''){  
            value=(defValue!=null&&typeof(defValue)=='number')?defValue:1;
        }else{
            value=P[1];
        }
        try{
            value=parseInt(value);        
            
            var maxValue=obj.getAttribute('store');
            if(maxValue){
                maxValue=parseInt(maxValue);
            }else{
                maxValue=1;
            }                      
            if(isNaN(value)){
                value=1;
            }
            if(value>0 && value<=maxValue){
                obj.value=value;
            }else if(value<=0 && maxValue>0){
                obj.value='1';
            }else if(maxValue>0){
                obj.value=maxValue;
            }else{
                obj.value='0';
            }
        }catch(e){
            obj.value='0';
        }   
        var oldCount=obj.getAttribute('oldcount');  
        if(oldCount==null || oldCount!=obj.value){
            var cartid=obj.getAttribute('cartid');
            var price=obj.getAttribute('price');        
            var count=parseInt(obj.value);
            var proid=obj.getAttribute('proid');
            var goodsid=obj.getAttribute('goodsid');                
            var lanid=obj.getAttribute('lanid');            
            if(cartid && price && count && proid && goodsid && lanid){
                var priceObj=document.getElementById('goodsTotalPriceOf_'+cartid);
                if(priceObj){
                    priceObj.innerHTML=formatMoney(price*count,moneySign);
                }               
                var objLinks=document.getElementsByTagName('a');
                if(objLinks!=null && objLinks.length>0){
                    for(var i=0;i<objLinks.length;i++){
                        if(objLinks[i].getAttribute('name')!=null && objLinks[i].getAttribute('name')=='gotoProductPage_'+cartid){                              
                            var url=objLinks[i].href.indexOf('?')>0?objLinks[i].href.substr(0,objLinks[i].href.indexOf('?')):objLinks[i].href;                           
                            objLinks[i].href=url+'?count='+count+(goodsid>0?('&goodsid='+goodsid):'');
                        }
                    }
                }
                updateGoodsToCart(lanid,proid,goodsid,count,initAllGoodsCount);
            }  
        }   
        obj.setAttribute('oldcount',obj.value);
    }
}
function initAllGoodsCount()
{
    var totalMoney=0;
    var objCounts=document.getElementsByName('cartGoodsCount');
    if(objCounts!=null && objCounts.length>0){
        for(var i=0;i<objCounts.length;i++){
            checkIsUNumber(objCounts[i],1);
            var price=objCounts[i].getAttribute('price');
            if(price){
                totalMoney+=objCounts[i].value * price;
            }            
        }
    }
    var obj=docEle("<%=PPFOR_totalMoney.ClientID %>");
    if(obj){
        obj.innerHTML=formatMoney(totalMoney,moneySign);
    }
}
</script>
</head>
<body onload="initAllGoodsCount();">
<div class="tableco">
    <h1><asp:Label ID="PPFOR_goodsInCartTitle" runat="server"></asp:Label></h1>   
    <form runat="server" id="form1">
        <asp:Label ID="PPFOR_currentLanguageId" runat="server" Visible="false" Enabled="false"></asp:Label>
        <asp:GridView ID="PPFOR_showGoodsList" CssClass="listtable" runat="server" OnRowDeleting="PPFOR_showGoodsList_RowDeleting" OnRowDataBound="PPFOR_gridViewRowDataBound" AllowPaging="false" AutoGenerateColumns="False"  DataKeyNames="Id"  Width="100%" CellPadding="0" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="0px">
           <Columns>  
             <asp:BoundField HeaderStyle-CssClass="title" HeaderText="" HeaderStyle-Font-Bold="false"/> 
             <asp:BoundField HeaderStyle-CssClass="title" ItemStyle-Width="30%" HeaderText="" HeaderStyle-Font-Bold="false"/> 
             <asp:BoundField HeaderStyle-CssClass="title" HeaderText="" HeaderStyle-Font-Bold="false"/> 
             <asp:BoundField HeaderStyle-CssClass="title" ItemStyle-Font-Strikeout="true" HeaderText="" HeaderStyle-Font-Bold="false"/> 
             <asp:BoundField HeaderStyle-CssClass="title" HeaderText="" HeaderStyle-Font-Bold="false"/> 
             <asp:BoundField HeaderStyle-CssClass="title" HeaderText="" HeaderStyle-Font-Bold="false"/>                
             <asp:BoundField HeaderStyle-CssClass="title" HeaderText="" DataField="" HeaderStyle-Font-Bold="false"/> 
              <asp:TemplateField HeaderStyle-CssClass="title" HeaderText="" HeaderStyle-Font-Bold="false" >
                <ItemTemplate>
                    <asp:LinkButton ID="PPFOR_deleteGoods" runat="server" CausesValidation="False" CommandName="Delete"
                    Text="" ></asp:LinkButton>
                </ItemTemplate>
             </asp:TemplateField>              
            </Columns>            
             <FooterStyle BackColor="#990000" ForeColor="White" /> 
             <RowStyle Font-Bold="false" BackColor="#ffffff"/> 
             <HeaderStyle BackColor="#F5F5F5" Font-Bold="false" ForeColor="#000000" />
             <AlternatingRowStyle BackColor="#F5F5F5" />
        </asp:GridView> 
        <table width="100%" cellpadding="5px" cellspacing="3px" border="0">
            <tr>
             <td align="left">
                  <asp:Button ID="PPFOR_continueShopping"  CssClass="blueinput" runat="server" Text="" />  
                  <asp:Button ID="PPFOR_clearCartList" CssClass="blueinput" runat="server" Text="" OnClick="PPFOR_clearProductCart" />     
            </td>
              <td align="right">
                  <asp:Label ID="PPFOR_totalMoneyText" runat="server"></asp:Label>
                  <asp:Label ID="PPFOR_totalMoney" CssClass="cart_yellow" runat="server"></asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;
                  <asp:Button ID="PPFOR_goCheckOut" CssClass="blueinput" runat="server" Text="" OnClientClick="location.href='CheckOut.aspx';return false;" />            
            </td>
            </tr>
         </table>             
    </form>
</div>
</body>
</html>
