<%@ 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"%>
 <% 
List<ThongTinSanPham> sanpham = new SanPham().category();
 String user = (String) session.getAttribute("user");
%>   
<% if (user == null) { response.sendRedirect("login.jsp");} else {
user = user.toLowerCase();
if (!user.equals("admin")){
	response.sendRedirect("permission.jsp");
}
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 catenew(){
var a = document.getElementById("toshow");
html='<input size="26" type="text" name="newcate"/>';
		a.innerHTML=html;
}

function upload(){
	window.open("upload.jsp","Upload Ảnh","width=400px; height=200px;");
	
}

function numberonly(event) {
	 var chCode = (event.charCode === undefined) ? event.keyCode : event.charCode;
	 if (chCode > 31 && (chCode < 48 || chCode > 57))
	 {return false;}
	 else { return true;}
	  }
	  
document.title="Thêm Sản Phẩm";
document.getElementById("titleMod").innerHTML = "Thêm Sản Phẩm";
</script>

<title>Tao 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="formRegister" action="../ProductController" onsubmit="return validate(this)" method="post">
  <input type="hidden" name="rep" value="createpd">
  <Table>
<tr><td><b>Tên sản phẩm</b></td><td><input size="26" type="text" name="name" id="name"></td></tr>
<tr><td><b>Link hình sản phẩm</b></td><td><input size="26" type="text" name="image" id="image"><a href="javascript: upload()">&nbsp; &nbsp;&nbsp; Upload ảnh</a></td></tr>
<tr><td><b>Thể loại</b></td><td>
<div id="toshow">
<select class="UniXT" name="cate">

  <% for(int i  = 0; i < sanpham.size(); i++) { %>
<% if (sanpham.get(i).getCategory() !=null) {
%>
  <option value="<%= sanpham.get(i).getCategory() %>"> <%= sanpham.get(i).getCategory() %></option>
<% }} %>
</select> 
<INPUT class="UniXT" TYPE=RADIO onmousedown="return catenew();" /> Tạo mới
</div>
  </td></tr>
<tr><td><b>Giá</b></td><td><input size="26" type="text" name="price" id="price" onkeypress="return numberonly(event);">&nbsp; &nbsp;&nbsp; vnđ</td></tr>
<tr><td><b>Trạng thái</b></td><td>
<select class="UniXT" name="status">
<option value="ConHang">Còn hàng</option>
<option value="HetHang">Đã hết 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"></textarea></td></tr>
<tr><td><br><input type="submit" class="UniXT" value="Hoàn thành"></td><td><br><input class="UniXT" type="reset" value="Nhập lại"></td></tr>
 </table> 
   </form>
</div> 
</center>
</body>
<% }} %>
</html>