<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="model.SanPham"%>
<%@page import="model.ThongTinSanPham"%>
<%@page import="java.text.Normalizer"%>
<%@page import="java.text.Normalizer.Form"%>
 <% 
 String id = (String)request.getParameter("id");
 String pagex = (String)request.getParameter("page");
List<ThongTinSanPham> sanpham = new SanPham().category();
ThongTinSanPham product = (ThongTinSanPham) request.getAttribute("sanpham");
if (product ==null){
%><% }else { %>  
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="images/style.css" />
<link rel="stylesheet" type="text/css" href="images/AjaxForm.css" />
<script type="text/javascript" src="js/CreateProduct.js"></script>
<script>
function numberonly(event) {
	 var chCode = (event.charCode === undefined) ? event.keyCode : event.charCode;
	 if (chCode > 31 && (chCode < 48 || chCode > 57))
	 {return false;}
	 else { return true;}
	  }
function upload(){
	window.open("upload.jsp","Upload Ảnh","width=400px; height=200px;");
	
}  
document.title = "Sửa Sản Phẩm > <%= product.getName() %>"; 
document.getElementById("titleMod").innerHTML = "Sửa Sản Phẩm";
</script>

<title>Cap Nhat San Pham</title>
</head>
<body>
<center>
<div align="Center" style="border:1px solid #cfcfcf;padding:32px 20px 20px 20px;background-color:#f3f3f3; width:412px ">
  <form name="form" id="formUpdate" action="../ProductController" onsubmit="return validate(this)" method="post">
  <input type="hidden" name="rep" value="update">
  <input type="hidden" name="id" value="<%= id %>">
  <input type="hidden" name="page" value="<%= pagex %>">
  <Table>
<tr><td><b>Tên sản phẩm</b></td><td><input size="26" type="text" name="name" value="<%= product.getName() %>" id="name"></td></tr>
<tr><td><b>Link hình sản phẩm</b></td><td><input size="26" type="text" name="image" value="<%= product.getImage() %>" id="image"><a href="javascript: upload()">&nbsp; &nbsp;&nbsp; Upload ảnh</a></td></tr>
<tr><td><b>Thể loại</b></td><td>
<select class="UniXT" name="cate">
<option value="<%= product.getCategory() %>"><%= product.getCategory() %></option>
  <% for(int i  = 0; i < sanpham.size(); i++) { %>
<% if (sanpham.get(i).getCategory() !=null && !sanpham.get(i).getCategory().equals("null")) {
%>
  <option value="<%= sanpham.get(i).getCategory() %>"><%= sanpham.get(i).getCategory() %></option>
<% }} %>
</select> 
  </td></tr>
<tr><td><b>Giá</b></td><td><input size="26" type="text" name="price" value="<%= Math.round(product.getPrice()) %>" id="price" onkeypress="return numberonly(event);">&nbsp; &nbsp;&nbsp; vnđ</td></tr>
<tr><td><b>Trạng thái</b></td><td>
<% String TrangThaiMH = product.getStatus() ; if (TrangThaiMH == null){ TrangThaiMH = "HetHang" ;}%>
<select class="UniXT" name="status">
<% if (TrangThaiMH.equals("ConHang")) { %>
<option value="ConHang">Còn hàng</option>
<option value="HetHang">Đã hết hàng</option> <% } else { %>
<option value="HetHang">Đã hết hàng</option>
<option value="ConHang">Còn hàng</option> <% } %>
</select>
</td></tr>
<tr><td><b>Mô tả sản phẩm</b></td><td><textarea class="UniXT" name="des" rows="7" cols="34"><%= product.getDescription() %></textarea></td></tr>
<tr><td><br><input type="submit" class="UniXT" value="Cập nhật"></td><td></tr>
 </table> 
   </form>
</div> 
</center>
</body>
<% } %>
</html>