<%@ page import="com.fenalco.utilities.lists.ListView"%>
<%@ page import="com.fenalco.entities.User"%>
<%@ page import="com.fenalco.entities.DataAccess"%>
<%@ page import="com.fenalco.entities.Province"%>
<%@ page import="com.fenalco.entities.City"%>
<%@ page import="java.util.Hashtable"%>
<%@ page import="java.util.Vector"%>
<%@ page import="java.util.Enumeration"%>
<html>
<head>
<link rel='stylesheet' style='text/css' href='../css/tablas.css'>
<link rel='stylesheet' style='text/css' href='../css/fuentes.css'>
<title>Minoristas del Sistema</title>
</head>
<body bgcolor="#ffffff" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload='showMessage("<%=request.getAttribute("message")%>");showFields(document.clientList.filterNew)'>
<script language='javascript' type='text/javascript' src='../js/library.js'></script>
<script language='javascript' type='text/javascript'>

    function showMessage(message){
        if(message!=null && message!=""){
            window.alert(message);
        }
        return true;
    }
    
    function showCompany(id){
           var left = (screen.availWidth-515)/2;
	   var top = (screen.availHeight-500)/2;
	   window.open('/proveedor/verminorista?key='+id,'','HEIGHT=360,WIDTH=515,scrollbars=no,left='+left+',top='+top);
    }
    
    function clearField( field ){
        field.value="";
    }
    
    function showFields( field ){
    
        document.clientList.date[0].disabled = !field.checked;
        document.clientList.date[1].disabled = !field.checked;
        document.clientList.date[2].disabled = !field.checked;
        document.clientList.date[3].disabled = !field.checked;
        
    }
</script>
<%
	String helpId = "53";
        String firstRow = ( String )request.getAttribute( "firstRow" );
        String lastRow = ( String )request.getAttribute( "lastRow" );
        String total = ( String )request.getAttribute( "total" );
        String page1 = ( String )request.getAttribute( "page" );
        String pages = ( String )request.getAttribute( "pages" );
        int pageResults = Integer.valueOf(request.getAttribute( "pageResults" ).toString()).intValue();
%>
<table border="0" cellpadding="0" cellspacing="0" width="760">
    <%@ include file="encabezado.jsp" %>
</table>
<table width="760" border='0'>
    
    <tr>
        <td width="152" valign='top'>
			<%@ include file="menuproveedor.jsp" %>
			<table align="center">
                            <tr>
                                <td colspan='3'><br></td>
                            </tr>
                            <form action="/proveedor/clientesproveedor" method="post">
                            <tr>
                                <td colspan='3' align="left"><input type="image" name='back' src="../images/buttons/regresar.gif"></td>
                            </tr>
                            </form>
			</table>
	</td>
        <td valign='top'>
            <%
                String tittle = "Minoristas";
            %>
            <%@ include file="/titulo.jsp" %>

			<table width="100%">
				<!--<tr><td align="center"><%--= request.getAttribute("message")--%></td></tr>-->
				<tr>
                                    <td>&nbsp;</td>
				</tr>
				<form name="clientList" method="post" action ="/proveedor/adminclientesproveedor">
				<table align="center" width='70%' border="0" cellpadding="0" cellspacing="0" bgcolor="#E8E8F4" align="center">
                                        <tr>
                                            <td width="16" align="left" valign="top"><img src="/proveedor/images/bus1.gif" width="16" height="14"></td>
                                            <td colspan='4'>&nbsp;</td>
                                            <td width="15" align="right" valign="top"><img src="/proveedor/images/bus3.gif" width="15" height="14"></td>
                                        </tr>
                                        <input type="hidden" name="clicked" value="">
                                        <tr>
                                            <td>&nbsp;</td>
                                        <%
                                            Vector provinces = (Vector)request.getAttribute("provinces");
                                            Vector cities = (Vector)request.getAttribute("cities");
                                            int provinceId = ((Integer)request.getAttribute("provinceId")).intValue();
                                            int cityId = ((Integer)request.getAttribute("cityId")).intValue();
                                        %>
                                            <td>Departamento</td>
                                            <td>
                                                <select name="province" onChange="document.clientList.clicked.value=0;document.clientList.action='/proveedor/verminoristas';document.clientList.submit()">
                                                    <option value='-1'>Todos</option>
                                                <%
                                                Enumeration en = provinces.elements();
                                                String selected = "";
                                                while( en.hasMoreElements() ){
                                                    Province p = (Province)en.nextElement();
                                                    selected = ( p.getId() == provinceId )?"selected":"";
                                                    %><option value='<%=p.getId()%>' <%=selected%> ><%=p.getName()%></option><%
                                                }
                                                %>
                                                </select>
                                            </td>
                                            <td>Ciudad</td>
                                            <td>
                                                <select name="city"  onChange="document.clientList.clicked.value=1;document.clientList.action='/proveedor/verminoristas';document.clientList.submit()">
                                                    <option value='-1'>Todas</option>
                                                <%
                                                en = cities.elements();
                                                selected = "";
                                                while( en.hasMoreElements() ){
                                                    City c = (City)en.nextElement();
                                                    selected = ( c.getId() == cityId )?"selected":"";
                                                    %><option value='<%=c.getId()%>' <%=selected%> ><%=c.getName()%></option><%
                                                }
                                                %>    
                                                </select>
                                            </td>
                                            <td>&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td colspan='6'>&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td>&nbsp;</td>
                                            <td colspan='4'>Nombre Comercial <input type="text" name="shopKeeperName"> <input type="submit" value="Consultar"></td>
                                            <td>&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td colspan='6'>&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <%
                                             int filterNew = ( (Integer)request.getAttribute( "filterNew" ) ).intValue();
                                            %>
                                            <td colspan='6'><input type="checkbox" name='filterNew' value='1' <%if( filterNew == 1){%> checked <%}%> ONCLICK='showFields( this )'> Nuevos Minoristas</td>
                                        </tr>
                                        <tr>
                                            <%
                                                int date = ( ( Integer )request.getAttribute( "date" )).intValue();
                                                System.out.println( date );
                                            %>
                                            <td>&nbsp;</td>
                                            <td><input type="radio"  name="date" value="1" <%if(date==1){%>checked<%}%>> Hoy </td>
                                            <td><input type="radio"  name="date" value="2" <%if(date==2){%>checked<%}%>> &Uacute;ltimos 8 d&iacute;as </td>
                                            <td><input type="radio"  name="date" value="3" <%if(date==3){%>checked<%}%>> Este mes </td>
                                            <td><input type="radio"  name="date" value="4" <%if(date==4){%>checked<%}%>> Este a&ntilde;o </td>
                                            <td>&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td>&nbsp;</td>
                                            <td colspan='4' align="center"><input type="submit" value="Buscar" onclick="document.clientList.clicked.value=1;document.clientList.action='/proveedor/verminoristas';document.clientList.submit()"></td>
                                            <td>&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td align="left" valign="bottom"><img src="/proveedor/images/bus2.gif" width="16" height="15"></td>
                                            <td colspan='4'>&nbsp;</td>
                                            <td align="right" valign="bottom"><img src="/proveedor/images/bus4.gif" width="15" height="15"></td>
                                        </tr>
                                </table>
                                <table align="center">
                                    <tr>
                                        <td>
                                            <jsp:include page="/general/paginador.jsp" flush="true">
                                                <jsp:param name="page" value="<%=page1%>" />
                                                <jsp:param name="pages" value="<%=pages%>" />
                                                <jsp:param name="pageResults" value="<%=pageResults%>" />
                                            </jsp:include>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <jsp:include page="/general/resultados.jsp" flush="true">
                                                <jsp:param name="firstRow" value="<%=firstRow%>" />
                                                <jsp:param name="lastRow" value="<%=lastRow%>" />
                                                <jsp:param name="total" value="<%=total%>" />
                                            </jsp:include>
                                        </td>
                                    </tr>
                                </table>
				<table align="center" width="80%">
                                        <tr class='tableheader' align="center">
                                                
						<!-- Encabezado del listado -->
						<td><strong>Nombre Comercial</td>
						<td><strong>Ciudad</td>
						<td align='center'><strong>Ver Detalle</td>
						<td align='center'><strong>Seleccionar</td>
					</tr>
                                        <% 
                                        ListView view = (ListView)request.getAttribute("view");
                                        int cont = 0;
                                            String data;
                                            int countRows = 0;
                                            String color = "";
                                            while(view.move()){
                                                    if( countRows % 2 == 0 )
                                                    {
                                                            color = "FFFFF0";
                                                    }
                                                    else
                                                    {
                                                            color = "EFEFEF";
                                                    }
                                                    countRows++;
                                                    int i=0;
                                                    cont++;
                                                    String id="";
                                        %>          <tr bgcolor='<%=color%>'>
                                                    <% while((data=(String)view.nextElement()) != null){
                                                            if(i==1){%>
                                                                    <td><%= data %></td>
                                                            <%}else{ 
                                                                    i=1; 
                                                                    id=data;
                                                              }%>
                                                    <%}%>
                                                        <!--
                                                        Columnas para las opciones
                                                        -->
                                                        <td align='center'><a href='javascript: showCompany(<%=id%>)'><img name='stores'alt="Ver Detalle" src='/images/buttons/supplier/detalle.gif'  border='0'></a></td>
                                                        <td align='center'><input type='checkbox' name='item' value='<%=id%>'></td>
                                                    </tr>  

                                        <%}
                                            if( cont == 0 ){%>
                                             <tr>
                                                <td colspan='4' align="center">
                                                    <b><br>NO HAY MINORISTAS DISPONIBLES PARA SER ACTIVADOS COMO CLIENTES</b>
                                                </td>
                                             </tr>
                                        <%}
                                          else{%>
                                <tr>
                                    <td colspan='4' align="center">
                                        <input type="button" onClick="checkAll( document.clientList.item );" value='Activar Todos'>
                                        &nbsp;&nbsp;&nbsp;
                                        <input type="button" onClick="unCheckAll( document.clientList.item );" value='Desactivar Todos'>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan='4'>&nbsp;</td>
                                </tr>
                                <tr>
                                    <td colspan='4' align='right'><input type='submit' name='new' onClick="document.clientList.operationType.value='add'" value='Establecer Clientes'></td>
                                </tr>          
                                <tr><td colspan='4'>&nbsp;</td></tr>
                                <tr>
                                    <td colspan='4'>
                                        <jsp:include page="/general/resultados.jsp" flush="true">
                                            <jsp:param name="firstRow" value="<%=firstRow%>" />
                                            <jsp:param name="lastRow" value="<%=lastRow%>" />
                                            <jsp:param name="total" value="<%=total%>" />
                                        </jsp:include>
                                    </td>
                                </tr>
                                <%}%>
                                <input name="operationType" type="hidden" value="">
                                </table>
				</form>
				</tr>
	</td>
    </tr>
	
</table>
<table width="760">
	<tr>
		<td><%@ include file="/piepagina.jsp" %></td>
	</tr>
</table>
</body>
</html>
// “Copyright (C) <2008> Multilateral Investment Fund of the Inter-American Development Bank.
// Este archivo es parte de <ICT4BUS-PVL>
// < ICT4BUS-PVL > es software libre: usted puede redistribuirlo y/o modificarlo bajo los términos de la Licencia Pública General GNU publicada por la Fundación para el Software Libre, ya sea la versión 3 de la Licencia, o (a su elección) cualquier versión posterior.
// < ICT4BUS-PVL > se distribuye con la esperanza de que sea útil, pero SIN GARANTÍA ALGUNA; ni siquiera la garantía implícita MERCANTIL o de APTITUD PARA UN PROPÓSITO DETERMINADO. 
// Consulte los detalles de la Licencia Pública General GNU para obtener una información más detallada. 
// Debería haber recibido una copia de la Licencia Pública General GNU junto a este programa. En caso contrario, consulte http://www.gnu.org/licenses/.”