<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.util.ArrayList" %>
<%@page import="model.CartMod" %>
<%@page import="model.CartProduct" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel=stylesheet href='images/style.css' type=text/css>
<link rel="stylesheet" type="text/css" href="highslide/highslide.css" />
<link rel="stylesheet" type="text/css" href="images/AjaxForm.css" />

<script type="text/javascript">
	hs.graphicsDir = 'highslide/graphics/';
	hs.outlineType = 'rounded-white';
	hs.showCredits = false;
	hs.wrapperClassName = 'draggable-header';
	document.getElementById("titleCustomer").innerHTML = "Giỏ Hàng";
</script>

<title>Gio Hang Cua Toi</title>
<Script>
function delall(){
if(confirm('Bạn Thực Sự Muốn Xóa Toàn Bộ Sản Phẩm Trong Giỏ Hàng?'))
{return true;}
else {return false;}
}

function numberonly(event) {
	 var chCode = (event.charCode === undefined) ? event.keyCode : event.charCode;
	 if (chCode > 31 && (chCode < 48 || chCode > 57))
	 {return false;}
	 else { return true;}
	  }
</script>
<script src="js/cart.js"></script>
</head>
<body>
<%
Object obj=session.getAttribute("giohang");

//Neu Chua Co Seesion
if (obj==null) {%>
<div align="Center" style="border:1px solid #cfcfcf;padding:20px 10px 20px 10px;background-color:#f3f3f3; width:410px ">
<b> Chưa Có Sản Phẩm Nào Trong Giỏ Hàng</b></div>
<% }
// Ket Thuc Neu Chua Co Seesion
else{
CartMod giohang=(CartMod)obj;
ArrayList<CartProduct> Listpd=giohang.getGiohang();
if(Listpd.size() > 0){
%>
<br>
<table class="tablext" border="1" cellspacing="0" style="border-collapse: collapse" bordercolor="silver" cellpadding="3">
    <tr>
        <th style="background: #E3E3E3">STT</th>
        <th style="background: #E3E3E3">Tên Sản Phẩm</th>
        <th style="background: #E3E3E3">Đơn Giá</th>
        <th style="background: #E3E3E3">Số Lượng</th>
        <th style="background: #E3E3E3">Thành Tiền</th>
        <th style="background: #E3E3E3">Trả Lại</th>
    </tr>
    <%int i=1;
    for(CartProduct pd:Listpd){
        String id= pd.getSanpham().getId();
        String name = pd.getSanpham().getName();
        String image = pd.getSanpham().getImage();
        double price = pd.getSanpham().getPrice();
        int quantity = pd.getSoluong();
        double amount = price*quantity;
        %>
        <tr align="center">
            <td><%=(i++)%></td>
            <td>          
            <!-- 1 object -->
		<div>
<a href="#" onclick="return hs.htmlExpand(this, {headingText: '<%=name%>' })"> <%=name%></a>
	<div class="highslide-maincontent"><img src="<%= image %>" width="170" height="180" title="<%= name %>">
	</div>
		</div>
		<!-- End 1 object -->                             
            </td>
            <td><%=Math.round(price)%> đ</td>
            <td>
           <input type="hidden" value="<%= id %>" id="idpr<%= i %>"></input>
<input title="Cập nhật Số lượng" onkeydown="return edit(<%= i %>);"  onkeypress="return numberonly(event);" style="text-align: center" maxlength="2" size="1" type="text"  value="<%=quantity%>" id="sl<%= i %>">
<a onclick="return updatesl(<%= i %>);" href="#"><span id="upd<%=i %>"></span></a> 
            </td>
            <td><%=Math.round(amount)%> đ</td>
            <td>
             <a href="Cart?rep=discard&id=<%= id %>"  ><img border="0" src="images/discard.jpg" width="25" height="25" title="Xóa"></a>
            </td>
        </tr>
    <%}%>
    </table>  
    <br>
    <table>
    <Tr>
    <td><form action="Cart" onsubmit="return delall();">
                <input type="hidden" name="rep" value="clear" />
                <input type="submit" class="submit" value="Xóa hết" title="Xóa Hết Giỏ Hàng"/>
            </form>
            </td>
    <td>
    <form action="Cart">
                <input type="hidden" name="rep" value="checkout"/>
                <input type="submit" class="submit" onclick="return ajaxlog();" value="Thanh toán"/>
            </form>
            </td>
    </Tr>   
    </table>      
         
        <% } else {%> 
        <div align="Center" style="border:1px solid #cfcfcf;padding:20px 10px 20px 10px;background-color:#f3f3f3; width:410px ">
<b> Chưa Có Sản Phẩm Nào Trong Giỏ Hàng</b></div>
        <%}} %>
</body>
</html>