<%@ page import="com.fenalco.utilities.lists.ListView" %>
<%@ page import="com.fenalco.entities.User" %>
<%@ page import="com.fenalco.entities.DataAccess"%>
<%@ page import="com.fenalco.entities.Country"%>
<%@ page import="com.fenalco.entities.Province"%>
<%@ page import="com.fenalco.entities.City"%>
<%@ page import="com.fenalco.entities.Company"%>
<%@ page import="java.util.Hashtable"%>
<%@ page import="java.util.Enumeration"%>
<%@ page import="java.util.Vector"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel='stylesheet' style='text/css' href='../css/tablas.css'>
<title>Listado de empresas</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#ffffff" background="../images/sysmanager/general/fondo.jpg" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<script language='javascript' type='text/javascript' src='../js/library.js'></script>
<script>

     function submitCombo(comboName){
                document.companyList.combo.value=comboName;
                document.companyList.action = "listaempresas";
                document.companyList.submit();
                return true;
     }

</script>


<table border="0" cellpadding="0" cellspacing="0" width="780">
        <%
            String helpId = "3";
        %>
        <%@ include file="encabezado.jsp" %>
</table>

<table width="760">
	<tr>
		<td width="152" valign='top'>
			<%@ include file="menuadministrador.jsp" %>
		</td>
		<td valign='top'>
            <%
                String tittle = "Buscador";
            %>
            <%@ include file="/titulo.jsp" %>

			<table width="603">
			
				<tr><td align="center"><%= request.getAttribute("message")%></td></tr>
				<tr><td><br></td></tr>
				<tr>
				<form name="companyList" method="post" action="/administrador/actualizarempresas">
				<table align="center" cellspacing='5'>
                                        <tr><td>
                                            <table>
                                            <tr>
                                            <td align="center">Tipo de empresa&nbsp;
                                            <% Hashtable companyTypes = DataAccess.getCompanyTypes();
                                            Enumeration typesKeys=companyTypes.keys();
                                            String s=null;
                                            String cType="";
                                            %>
                                            <select name="companyType" onchange="submitCombo('city')">
                                            <% while(typesKeys.hasMoreElements()){
                                                Object object1 = typesKeys.nextElement();
                                                s=object1.toString();
                                                Object object2 = companyTypes.get(new Integer(s));
                                                String typeName=object2.toString();
                                                cType="1";
                                                if(request.getAttribute("companyType")!=null){
                                                    cType=(String)request.getAttribute("companyType");
                                                }
                                                if(cType.equals(s)){ %>
                                                        <option value="<%= s %>" selected ><%= typeName %></option>
                                                <%}else if(!typeName.equals("Fenalco")){%>
                                                        <option value="<%= s %>"><%= typeName %></option>
                                                <%}
                                               }%>
                                            </select></td>
                                            </tr>
                                            </table>
                                        </td></tr>
                                        
                                        <tr><td>
                                                <table>
                                                <tr>
                                                <td>Pa&iacute;s&nbsp;
                                                <select name="country" onChange="submitCombo(this.name)">
                                                <%
                                                Vector countriesList = (Vector)request.getAttribute("countriesList");
                                                Enumeration en = countriesList.elements();
                                                String selected = "";
                                                int temp = Integer.parseInt(request.getAttribute("countryId").toString());
                                                for(int i = 0 ; i < countriesList.size() ; i++){
                                                    int key = ((Country)en.nextElement()).getId();
                                                    int temp2 = key;

                                                    if(temp == temp2){
                                                        selected = "selected";
                                                    }
                                                    else{
                                                        selected = "";
                                                    }   
                                                %>
                                                    <option value="<%=key%>" <%=selected%>><%=((Country)countriesList.elementAt(i)).getName()%> </option>
                                                <%
                                                }
                                                %>
                                                </select></td>

                                                
                                                <td>&nbsp;&nbsp;Departamento&nbsp;
                                                <select name="province" onChange="submitCombo(this.name)">
                                                <%
                                                Vector provincesList = (Vector)request.getAttribute("provincesList");
                                                en = provincesList.elements();
                                                selected = "";
                                                temp = Integer.parseInt(request.getAttribute("provinceId").toString());
                                                for(int i = 0 ; i < provincesList.size() ; i++){
                                                    int key = ((Province)en.nextElement()).getId();
                                                    int temp2 = key;

                                                    if(temp == temp2){
                                                        selected = "selected";
                                                    }
                                                    else{
                                                        selected = "";
                                                    }   
                                                %>
                                                    <option value="<%=key%>" <%=selected%>><%=((Province)provincesList.elementAt(i)).getName()%> </option>
                                                <%
                                                }
                                                %>
                                                </select></td>

                                                <td>&nbsp;&nbsp;Ciudad&nbsp;
                                                <select name="city" onChange="submitCombo(this.name)">
                                                <%
                                                Vector citiesList = (Vector)request.getAttribute("citiesList");
                                                en = citiesList.elements();
                                                selected = "";
                                                temp = Integer.parseInt(request.getAttribute("cityId").toString());
                                                for(int i = 0 ; i < citiesList.size() ; i++){
                                                    int key = ((City)en.nextElement()).getId();
                                                    int temp2 = key;

                                                    if(temp == temp2){
                                                        selected = "selected";
                                                    }
                                                    else{
                                                        selected = "";
                                                    }   
                                                %>
                                                    <option value="<%=key%>" <%=selected%>><%=((City)citiesList.elementAt(i)).getName()%> </option>
                                                <%
                                                }
                                                %>
                                                </select></td>
                                                </tr>
                                                </table>
                                        </td></tr>

            <%
                tittle = "Empresas";
            %>
            <%@ include file="/titulo.jsp" %>
                                        <table align="center" cellspacing='2'>
                                            <% ListView aux = (ListView)request.getAttribute("view"); 
                                                if(false){
                                            %>
                                                    <tr><td><br><br><br></td></tr>
                                                    <tr><td align="center">No existen emresas</td></tr>
                                            <%  }else{ %>
                                        
                                        <tr><td colspan='5' height='10'></td></tr>
					<tr class='tableheader'>
						<!-- Encabezado del listado -->
						<td align="center">Nombre</td>
						<td align="center">Tel&eacute;fono</td>
                                                <td align="center">Estado</td>
						<% if(cType.equals("2")){%>
                                                    <td align="center">Establecer<br>Minoristas</td>
                                                <% }else{ %>
                                                    <td align="center">GLN</td>
                                                <%
                                                   }%>
                                                
						<td align="center">Ver</td>
                                                <td align="center">Eliminar</td>
					</tr>
			<% 
					ListView view = (ListView)request.getAttribute("view");
					String data;
                                        int count = 0;
					while(view.move())
                                        {
                                                count++;
						int i=0;
						String id="";
                                                String status="";
				%>
						<tr>
						<% while((data=(String)view.nextElement()) != null){
							if((i>1 && cType.equals("1")) || (i>2 && cType.equals("2")) ){
						%>
                                                            <td><%= data %></td>
                                                    <%  }else if(i==1){ 
                                                            status=data;
                                                        }else if(i==0){
                                                            id=data;
                                                        }
                                                        i++;
						   }
						%>
							<!-- Columnas para las opciones -->

                                                        <% Hashtable companyStatus = DataAccess.getCompanyStatus();
                                                        Enumeration keys=companyStatus.keys();
                                                        String temp2=null;
                                                        %>
                                                        <td align="center"><select name="<%="status"+id%>" onchange="operationType.value='changeStatus';companyList.action='/administrador/actualizarempresas?key=<%=id%>';companyList.submit()">
                                                        <% while(keys.hasMoreElements()){
                                                            Object object1 = keys.nextElement();
                                                            temp2=object1.toString();
                                                            Object object2 = companyStatus.get(new Integer(temp2));
                                                            String statusName=object2.toString();
                                                            if(status.equals(temp2)){%>
                                                                    <option value="<%= temp2 %>" selected><%= statusName %></option>
                                                            <%}else{%>
                                                                    <option value="<%= temp2 %>"><%= statusName %></option>
                                                            <%}
                                                           }%>
                                                        </select></td>
                                                        <% if(cType.equals("2")){%>
                                                            <td align="center"><a href="/administrador/actualizarempresas?key=<%= id %>&operationType=setStores"><img  name="update" src="/images/buttons/sysmanager/actualizar.gif" border="0"></a></td>
                                                        <% }else{ %>
                                                            <td align="center"><a href="/administrador/listaestablecimientos?key=<%= id %>"><img  name="update" src="/images/buttons/sysmanager/actualizar.gif" border="0"></a></td>
                                                        <% }%>
                                                        <td align="center"><a href="#"><img  name="view" src="/images/buttons/sysmanager/detalle.gif"  border="0" onClick="window.open('/administrador/verempresa?key=<%= id %>','','HEIGHT=400,WIDTH=515')"></a></td>
							<td align="center"><input name="item" type="radio" value="<%= id %>"></td> 
						</tr>
					<%
                                            }
                                            if( count == 0 )
                                            {
                                                %>
                                                <tr>
                                                    <td colspan='6' align="center">
                                                        <strong>No se encontraron empresas</strong>
                                                    </td>
                                                </tr>
                                                <%
                                            }
                                            else
                                            {
                                        %>
						 <tr>
                                                         <td colspan="5"></td>
                                                         <td align="center"><input name="delete" type="submit" value="Eliminar" onClick="operationType.value='delete';return window.confirm('Está a punto de eliminar registros del sistema, desea continuar?');"><td>
						 </tr>
                                         <%
                                            }
                                         %>
					 </table>	 
                                         </td></tr>
                                         <% } %>
				</table>
				<input name="operationType" type="hidden" value="">
				<input type="hidden" name="combo">
				</form>
			</tr>
			</table>
		</td>
	</tr>
	
</table>
<table width="760">
	<tr>
		<td><%@ include file="/piepagina.jsp" %></td>
	</tr>
</table>

</body>
</html>







