<%@ page import="java.util.Vector" %>
<%@ page import="java.util.Enumeration" %>
<%@ 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.Zone"%>
<%@ page import="com.fenalco.entities.Neighbourhood"%>
<!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 barrios</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.neighbourhoodList.combo.value=comboName;
                document.neighbourhoodList.action = "listabarrios";
                document.neighbourhoodList.submit();
                return true;
     }
     
     function validateForm(formName){

            var message = "Han ocurrido los siguientes errores:\n";
            var flag = true;
            if(isEmpty(formName.name)){
                    message = message + "- El campo nombre está vacío.\n";
                    flag = false;
            }
            if(isEmpty(formName.zone)){
                    message = message + "- El campo zona está vacío.\n";
                    flag = false;
            }
            
            
            if(!flag){
                    window.alert(message);
            }
                        
            return flag;
    }
</script>
<!-- 
-->
<table border="0" cellpadding="0" cellspacing="0" width="780">
        <%
            String helpId = "0";
        %>
        <%@ include file="encabezado.jsp" %>
</table>
<table width="760">
	<tr>
		<td width="152" valign='top'>
			<%@ include file="menuadministrador.jsp" %>
		</td>
		<td valign='top'>
            <%
                String tittle = "Barrios";
            %>
            <%@ include file="/titulo.jsp" %>

			<table width="603">
                                <% Vector aux = (Vector)request.getAttribute("neighbourhoods");
                                    if(aux.size()<1){
                                %>
                                        <tr><td><br><br><br></td></tr>
                                        <tr><td align="center">No se han definido barrios</td></tr>
                                        <tr><td><br><br><br></td></tr>
			
				<tr><td align="center"><%= request.getAttribute("message")%></td></tr>
				<tr><td height='10'></td></tr>
				<tr>
				<form name="neighbourhoodList" method="post" action="/administrador/actualizarbarrios">
                                <%  }else{ %>				
                                <form name="neighbourhoodList" method="post" action="/administrador/actualizarbarrios">
				<table align="center">
					<tr class='tableheader'>
						<!-- Encabezado del listado -->
						<td align="center">Nombre</td>
						<td align="center">Eliminar</td>
					</tr>
			<% 
                                        Vector neighbourhoods = (Vector)request.getAttribute("neighbourhoods");
                                        Enumeration e = neighbourhoods.elements();
					while(e.hasMoreElements()){
                                                Neighbourhood neighbourhood = (Neighbourhood)e.nextElement();
						int id=neighbourhood.getId();
				%>
						<tr>
                                                    <td><%= neighbourhood.getName() %></td>
							<!-- Columnas para las opciones -->
							<td align="center"><input name="item" type="checkbox" value="<%= id %>"></td> 
						</tr>
					<% } %>
        					<tr>
                                                    <td colspan='1'></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>
                                                <tr><td><br></td></tr>
                                </table>
                                <% } %>                                
                                <table align="center">
                                                <tr>
                                                        <td align="right">Pa&iacute;s</td>
                                                        <td><select name="country" onChange="submitCombo(this.name)">
                                                        <%
                                                        Vector countriesList = (Vector)request.getAttribute("countries");
                                                        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 align="right">Departamento</td>
                                                        <td><select name="province" onChange="submitCombo(this.name)">
                                                        <%
                                                        Vector provincesList = (Vector)request.getAttribute("provinces");
                                                        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 align="right">Ciudad</td>
                                                        <td><select name="city" onChange="submitCombo(this.name)">
                                                        <%
                                                        Vector citiesList = (Vector)request.getAttribute("cities");
                                                        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>
                                                <tr>
                                                        <td align="right">Zona</td>
                                                        <td><select name="zone" onChange="submitCombo(this.name)">
                                                        <%
                                                        Vector zonesList = (Vector)request.getAttribute("zones");
                                                        en = zonesList.elements();
                                                        selected = "";
                                                        temp = Integer.parseInt(request.getAttribute("zoneId").toString());
                                                        for(int i = 0 ; i < zonesList.size() ; i++){
                                                            int key = ((Zone)en.nextElement()).getId();
                                                            int temp2 = key;

                                                            if(temp == temp2){
                                                                selected = "selected";
                                                            }
                                                            else{
                                                                selected = "";
                                                            }   
                                                        %>
                                                            <option value="<%=key%>" <%=selected%>><%=((Zone)zonesList.elementAt(i)).getName()%> </option>
                                                        <%
                                                        }
                                                        %>
                                                        </select></td>
                                                </tr>
                                                 <tr><td><br></td></tr>
						 <tr>
                                                    <td align="right">Nuevo barrio</td>
                                                    <td><input type="text" name='name' size='12'></td>
						 </tr>
						 <tr><td><br></td></tr>
						 <tr>
                                                    <td align="center" colspan='2'><input name="new" type="submit" value="Agregar" onClick="operationType.value='new';return validateForm(document.neighbourhoodList);"></td>
						 </tr>
						 </table>
				</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>







