<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ page import="com.fenalco.entities.Supplier" %>
<%@ page import="com.fenalco.entities.SupplierProduct" %>
<%@ page import="com.fenalco.entities.SuperOffer" %>
<%@ page import="com.fenalco.entities.DataAccess" %>
<html>
<head>
    <link rel='stylesheet' style='text/css' href='../css/tablas.css'>
    <title>JSP Page</title>
</head>
<body>
<script type='text/javascript' language='javascript' src='../js/library.js'></script>
<script>
    
    function validateForm(formName){
        var message = "Han ocurrido los siguientes errores:\n";
        var flag = true;
        
       if(isEmpty(formName.quantity)){
            flag = false;
            message = message + "- El campo cantidad está vacío.\n";
        }
        else{
            if(!isNumber(formName.quantity)){
                flag = false;
                message = message + "- El campo cantidad debe ser numérico.\n";
            }
            else{
                if(formName.quantity.value<=0){
                    flag = false;
                    message = message + "- El campo cantidad debe ser mayor que cero.\n";
                }
            }
        }
        
        
        if(!flag){
            window.alert(message);
        }
        else{
            document.getElementById('temp').innerHTML="<font color='#FF0000'><b>Su superoferta esta siendo enviada, espere un momento por favor......</b></font>";
        }
        return flag;
    }
</script>
<%
SuperOffer view = (SuperOffer)request.getAttribute("view");
SupplierProduct product = new SupplierProduct(view.getProductId());

String urlImage = "/images/products/0.gif";
Boolean hasImage = ( Boolean )request.getAttribute( "hasImage" );
if( hasImage.booleanValue() )
{
    urlImage = product.getImage();
}

%>


<table width='280' align='center'>
<tr>
    <td colspan='3'>
        <%
            String tittle = "Super Oferta";
        %>
        <%@ include file="/titulo.jsp" %>

    </td>
</tr>

<tr>
    <td ><img src="<%=urlImage%>" width='100' height='100' alt='<%=view.getProductName()%>'></td>
    <td>
    <table>

            <tr>
                <td><b>Nombre:</b></td><td><%=view.getProductName()%></td>
            </tr>

            <tr>
                <td><b>Descripción:</b></td><td><%=view.getDescription()%></td>
            </tr>

            <tr>
                <td><b>Proveedor:</b></td><td><%=view.getSupplierName()%></td>
            </tr>

            <tr>
                <td><b>Fecha de finalización:</b></td><td><%=view.getEndDate()%></td>
            </tr>

            <tr>

                <td><b>Precio:</b></td><td><%=DataAccess.getCurrency(view.getPrice())%></td>
            </tr>

            <form name='superOffer' action='/minorista/comprarsuperoferta' method='post' onSubmit="return validateForm(document.superOffer);">
            <tr>
                <td><b>Cantidad de compra :</b></td><td><input type='text' name='quantity'></td>
            </tr>

            <tr>
                <input type='hidden' value ='<%=view.getId()%>' name='id' > 
                <td colspan='2'><input type='submit' value='Comprar'></td>
            </tr>
        </table>
    </td>
</tr>
<tr>
    <td colspan='2'><b>
		
    <%String message = ( String )request.getAttribute("message");
        if( message != null && !message.equals(""))
        {
            %>
            <script>
                
                window.alert(' <%=message%>');
                window.close();
               
            </script>
           
            <%
        }      
    %>
    </b></td>
</tr>
<tr>
    <td colspan='2'>
    <div id='temp' ></div>
        
    </td>
</tr>
</form>


</table>
</body>
</html>
