<%@ 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="java.util.Enumeration"%>
<%@ page import="java.util.Vector"%>

<%
    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();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel='stylesheet' style='text/css' href='../css/tablas.css'>
<title>Inicio Administrador</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#ffffff" background="../images/sysmanager/fondo1.gif" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload='showMessage("<%=request.getAttribute("message")%>")'>

<script>

    function showMessage(message){
        if(message!=null && message!=""){
            window.alert(message);
        }
        return true;
    }

     function submitCombo(comboName){
                document.newCompanies.combo.value=comboName;
                document.newCompanies.action = "/administrador/administrador";
                document.newCompanies.submit();
                return true;
     }
     
    function showCompany(id){
           var left = (screen.availWidth-515)/2;
	   var top = (screen.availHeight-500)/2;
           window.open('/administrador/verempresa?key='+id,'','WIDTH=515,HEIGHT=520,left='+left+',top='+top+'SCROLLBARS=yes');
    }
     
</script>

<table border="0" cellpadding="0" cellspacing="0" width="780">
        <%
            String helpId = "1";
        %>
        <%@ include file="encabezado.jsp" %>
</table>
<table width="760">
    <tr>
        <td width="152" valign='top'>
			<%@ include file="menuadministrador.jsp" %>
	</td>
        <td valign='top'>
            <%
                String tittle = "Inicio - Empresas Nuevas";
            %>
            <%@ include file="/titulo.jsp" %>

            <!--<form name="" method="post" action="/administrador/administrador">-->
            <form name="newCompanies" method="post" action="/administrador/actualizarnuevasempresas">
            <table width="560" border="0" cellpadding="0" cellspacing="0" bgcolor="#E8E8F4" align="center">
                <!--<tr><td align="center"><%//= request.getAttribute("message")%></td></tr>-->
                <tr>
                    <td width="16" align="left" valign="top"><img src="/administrador/images/bus1.gif" width="16" height="14"></td>
                    <td width="529">&nbsp;</td>
                    <td width="15" align="right" valign="top"><img src="/administrador/images/bus3.gif" width="15" height="14"></td>
                </tr>

                <tr>
                    <td width='50%'>
                        <table>
                            <tr>
                                <td>&nbsp;&nbsp;Pa&iacute;s&nbsp;</td>
                                <td>
                                    <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>
                            </tr>
                            <tr>
                                <td>&nbsp;&nbsp;Departamento&nbsp;</td>
                                <td>
                                    <select name="province" onChange="submitCombo(this.name)">
                                        <option value="-1" selected>Todos</option>
                                    <%
                                    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>
                            </tr>
                            <tr>    
                                <td>&nbsp;&nbsp;Ciudad&nbsp;</td>
                                <td>
                                    <select name="city" <!--onChange="submitCombo(this.name)"-->>
                                        <option value="-1" selected>Todas</option>
                                    <%
                                    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>
                <tr>
                    <td align="left" valign="bottom"><img src="/administrador/images/bus2.gif" width="16" height="15"></td>
                    <td>&nbsp;</td>
                    <td align="right" valign="bottom"><img src="/administrador/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" cellspacing='2'>
                <tr><td colspan="6" align="center"></td></tr>
                <tr class='tableheader'>
                    <!-- Encabezado del listado -->
                    <td align="center"><font color='#FFFFFF'>Nombre Comercial</font></td>
                    <td align="center"><font color='#FFFFFF'>Tel&eacute;fono</font></td>
                    <td align="center"><font color='#FFFFFF'>Fecha de Registro</font></td>
                    <td align="center"><font color='#FFFFFF'>Ver</font></td>
                    <td align="center"><font color='#FFFFFF'>Activar</font></td>
                    <td align="center"><font color='#FFFFFF'>Eliminar</font></td>
                </tr>
                <% 
                    ListView view = (ListView)request.getAttribute("view");
                    String data;
                    int count = 0;
                    while(view.move()){
                        count++;
                        int i=0;
                        String id="";

                        String color = "";
                        if(count % 2 == 0){
                            color = "#EFEFEF";
                        }else{
                            color = "FFFFF";
                        }
                %>
                
                    <tr bgcolor='<%=color%>'>
                    <% while((data=(String)view.nextElement()) != null){
                            if(i>0){
                                if(i>0){
                    %>
                                    <td><%= data %></td>
                    <%
                                }else{
                    %>
                                    <td align="center"><%= data %></td>
                    <%
                                }
                            }else{ 
                                id=data;
                            }
                            i++;
                       }
                    %>
                
                        <!-- Columnas para las opciones -->
                        <td align="center"><a href="javascript: showCompany(<%=id%>)"><img  name="view" src="/images/buttons/sysmanager/detalle.gif" border="0" alt='Ver'></a></td>
                        <td align="center"><a href="/administrador/actualizarnuevasempresas?key=<%=id%>&operationType=changeStatus"><img src="/images/buttons/sysmanager/activar.gif"  border="0" alt='Dar de alta' onClick=""></a></td>
                        <td align="center"><input name="item" type="radio" value="<%= id %>"></td> 

                    </tr>
                <% 
                    }
                %>
                    <tr>
                        <td colspan='6'>
                            <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>

                <%
                    if( count == 0 ){
                %>
                        <tr>
                            <td align="center" colspan='6'>
                                <strong>No hay empresas nuevas en el sistema</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>
            <input name="operationType" type="hidden" value="">
            <input type="hidden" name="combo">
            </form>
	</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/.”