<%@ page import="com.fenalco.utilities.lists.ListView"%>
<%@ page import="com.fenalco.entities.User"%>
<%@ page import="com.fenalco.entities.Store"%>
<%@ page import="com.fenalco.entities.DataAccess"%>
<%@ page import="com.fenalco.utilities.MessageBuilder"%>
<%@ page import="com.fenalco.utilities.lists.StoreListViewShopKeeper"%>
<%@ page import="java.util.Enumeration"%>
<%@ page import="java.util.Hashtable"%>
<%@ page import="java.util.Vector"%>
<%@ page import="com.fenalco.entities.Country"%>
<%@ page import="com.fenalco.entities.Province"%>
<%@ page import="com.fenalco.entities.City"%>
<%@ 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>Actualizar establecimiento</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>



<script type='text/javascript' language='javascript' src='../js/library.js'></script>
<script>		
			function submitCombo(comboName){
				document.updateStore.combo.value=comboName;
				document.updateStore.operationType2.value="load";
				
				document.updateStore.action = "/minorista/actualizarestablecimientos";
                                document.updateStore.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.GLN)){
        message = message + "- El campo GLN está vacío.\n";
        flag = false;
    }*/
    if(isEmpty(formName.address)){
        message = message + "- El campo dirección está vacío.\n";
        flag = false;
    }
    if(isEmpty(formName.stratum)){
        message = message + "- El campo estrato está vacío.\n";
        flag = false;
    }
    if(isEmpty(formName.street)){
        message = message + "- El campo calle está vacío.\n";
        flag = false;
    }
    if(isEmpty(formName.avenue)){
        message = message + "- El campo carrera está vacío.\n";
        flag = false;
    }
    if(isEmpty(formName.contact1)){
        message = message + "- El campo contacto 1 está vacío.\n";
        flag = false;
    }
    if(isEmpty(formName.phoneNumber1)){
                            message = message + "- El campo de telefono 1 está vacío.\n";
                    flag = false;
    }
    else{
        if(!isNumber(formName.phoneNumber1)){
             message = message + "- El campo de telefono 1 no es de tipo numérico.\n";
             flag = false;
        }
    }

     if(!isEmpty(formName.phoneNumber2)){
        if(!isNumber(formName.phoneNumber2)){
             message = message + "- El campo de telefono 2 no es de tipo numérico.\n";
             flag = false;
        }
    }
    
    if(isEmpty(formName.storeArea)){
        message = message + "- El campo área de tienda está vacío.\n";
        flag = false;
    }
    else{
        if(!isNumber(formName.storeArea)){
              message = message + "- El campo área de tienda debe ser numérico.\n";
              flag = false; 
        }
        
    }
    
    if(isEmpty(formName.paymentPoints)){
        message = message + "- El campo puntos de pago está vacío.\n";
        flag = false;
    }
    else{
        if(!isNumber(formName.paymentPoints)){
              message = message + "- El campo puntos de pago debe ser numérico.\n";
              flag = false; 
        }
        
    }
        
    
    
    
    if(!flag){
        window.alert(message);
    }
    

    return flag;
}

</script>
<body bgcolor="#ffffff" background="../images/shopkeeper/general/fondo.jpg" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- 
-->
<%
	String helpId ="44";
%>
<table border="0" cellpadding="0" cellspacing="0" width="780">
    <%@ include file="encabezado.jsp" %>
</table>


<table width="760" border="0" cellspacing="0" cellpadding="0">
    
    
<tr>
        <td width="155" valign="top">
			<%@ include file="menuminorista.jsp" %>
	</td>
        <td width='505'>
            <%
                String tittle = "Actualizar Establecimiento";
            %>
            <%@ include file="/titulo.jsp" %>

			<table width="100%">
				<tr><td align="center">
				
                                    <%String message = ( String )request.getAttribute("message");
                                        if( message != null )
                                        {
                                            %>
                                            <%=message%>
                                            <%
                                        }      
                                    %>
                                    </td></tr>
                                    <tr><td>
                                    <!-- -->
                        
                                    <tr>
                                    <form name="updateStore" method="post" action="/minorista/administrarestablecimientos" onSubmit='return validateForm(updateStore);'>
		<table align="center">
			
			<tr>
				<td><b>Nombre</b></td>
				<td><input type="text" name="name" maxlength="30" value="<%=request.getAttribute("name")%>"></td>
				<!-- JS: Validación campo vacío, obligatorio-->
			</tr>
			<tr>
				<td><b>GLN</b></td>
				<td><input type="text" name="GLN" maxlength="30" value="<%=request.getAttribute("GLN")%>" readonly></td>
                        
				<!-- JS: Validación campo vacío, obligatorio-->
			</tr>
			<tr>
				<td><b>Dirección</b></td>
				<td><input type="text" name="address" maxlength="50"  value="<%=request.getAttribute("address")%>"></td>
				<!-- JS: Validación campo vacío, obligatorio-->
			</tr>
			<tr>
				<td><b>Estrato</b></td>
				<td><select name="stratum">
				<%  int maxStratum = DataAccess.getStratum();
                                
                                
                                  String selectStratum ="";
                                 for(int i  = 0; i <= maxStratum; i++){
                                     selectStratum ="";
                                     if(i == Integer.parseInt((String)request.getAttribute("stratum"))){
                                        selectStratum = "selected";
                                     }    
                                %>
                                  <option value="<%=i%>" <%=selectStratum%>><%=i%></option>
                                <%
                                }
                                %>
                                </select></td>
				<!-- JS: Validación campo vacío, obligatorio-->
			</tr>
                        <tr>
    				<td><b>Calle</b></td>
				<td><input type="text" name="street" maxlength="3"  value="<%=request.getAttribute("street")%>"></td>
				<!-- JS: Validación campo vacío, obligatorio-->
			</tr>
			<tr>
				<td><b>Carrera</b></td>
				<td><input type="text" name="avenue" maxlength="3"  value="<%=request.getAttribute("avenue")%>"></td>
				<!-- JS: Validación campo vacío, obligatorio-->
			</tr>
			<tr>
				<td><b>Orientación Carrera</b></td>
				<td>
					<select name="avenueOrientation">
                                                <%String avenueOrientation = (String)request.getAttribute("avenueOrientation");
                                                    String north="";
                                                    String south="";
                                                    String west="";
                                                    String east="";
                                                    if(avenueOrientation.equals("N")){
                                                        north = "selected";
                                                    }
                                                    else if(avenueOrientation.equals("S")){
                                                        south = "selected";
                                                    }
                                                    else if(avenueOrientation.equals("O")){
                                                        west = "selected";
                                                    }
                                                    else if(avenueOrientation.equals("E")){
                                                        east = "selected";
                                                    }
                                                %>
						<option value="N" <%=north%> >Norte</option>
						<option value="S" <%=south%>>Sur</option>
						<option value="O" <%=west%>>Oeste</option>
						<option value="E" <%=east%>>Este</option>
					</select>
				</td>
				<!-- JS: Validación campo vacío, obligatorio-->
			</tr>
			<tr>
				<td><b>Orientación Calle</b></td>
				<td>
					<select name="streetOrientation">
                                                <%String streetOrientation = (String)request.getAttribute("streetOrientation");
                                                    north="";
                                                    south="";
                                                    west="";
                                                    east="";
                                                    if(streetOrientation.equals("N")){
                                                        north = "selected";
                                                    }
                                                    else if(streetOrientation.equals("S")){
                                                        south = "selected";
                                                    }
                                                    else if(streetOrientation.equals("O")){
                                                        west = "selected";
                                                    }
                                                    else if(streetOrientation.equals("E")){
                                                        east = "selected";
                                                    }
                                                %>
						<option value="N" <%=north%> >Norte</option>
						<option value="S" <%=south%>>Sur</option>
						<option value="O" <%=west%>>Oeste</option>
						<option value="E" <%=east%>>Este</option>
					</select>
				</td>
				</td>
				<!-- JS: Validación campo vacío, obligatorio-->
			</tr>
			<tr>
				<td><b>Persona Contacto 1</b></td>
				<td><input type="text" name="contact1" maxlength="30"  value="<%=request.getAttribute("contact1")%>"></td>
				<!-- JS: Validación campo vacío, obligatorio-->
			</tr>
			<tr>
				<td><b>Persona Contacto 2</b></td>
				<td><input type="text" name="contact2" maxlength="30"  value="<%=request.getAttribute("contact2")%>"></td>
				
			</tr>
			<tr>
				<td><b>Teléfono 1</b></td>
				<td><input type="text" name="phoneNumber1" maxlength="15"  value="<%=request.getAttribute("phoneNumber1")%>"></td>
				<!-- JS: Validación campo vacío, obligatorio-->
			</tr>
			<tr>
				<td><b>Teléfono 2</b></td>
				<td><input type="text" name="phoneNumber2" maxlength="15"  value="<%=request.getAttribute("phoneNumber2")%>"></td>
				
			</tr>
			<tr>
				<td><b>Área de Tienda</b></td>
				<td><input type="text" name="storeArea"  value="<%=request.getAttribute("storeArea")%>"></td>
				<!-- JS: Validación campo vacío, obligatorio, numérico - real-->
			</tr>
			<tr>
				<td><b>Número de puntos de pago</b></td>
				<td><input type="text" name="paymentPoints"  value="<%=request.getAttribute("paymentPoints")%>"></td>
				<!-- JS: Validación campo vacío, obligatorio, numérico -entero-->
			</tr>
			<tr>
				<td><b>Área de bodega</b></td>
				<td><input type="text" name="wareHouseArea"  value="<%=request.getAttribute("wareHouseArea")%>"></td>
			</tr>
			<tr>
				<td><b>País</b></td>
				<td><select name="country" onChange="submitCombo(this.name)">
				<%
                                Vector countriesList = (Vector)request.getAttribute("countriesList");
                                Enumeration en = countriesList.elements();
                                String selected = "";
                                Integer temp = (Integer) request.getAttribute("countryId");
                                for(int i = 0 ; i < countriesList.size() ; i++){
                                    Country country = (Country)en.nextElement();
                                    Integer temp2 = new Integer(country.getId());
                                    
                                    if(temp.intValue() == temp2.intValue()){
                                        selected = "selected";
                                    }
                                    else{
                                        selected = "";
                                    }   
                                    
                                    
                                %>
                                    <option value="<%=country.getId()%>" <%=selected%>><%=country.getName()%> </option>
                                <%
                                }
                                %>
				
				</select></td>
			</tr>
			<tr>
				<td><b>Departamento</b></td>
				<td><select name="province" onChange="submitCombo(this.name)">
				<%
                                Vector provincesList = (Vector)request.getAttribute("provincesList");
                                en = provincesList.elements();
                                selected = "";
                                temp = (Integer) request.getAttribute("provinceId");
                                for(int i = 0 ; i < provincesList.size() ; i++){
                                   Province province = (Province)en.nextElement();
                                    Integer temp2 = new Integer( province.getId() );
                                    
                                    if(temp.intValue() == temp2.intValue()){
                                        selected = "selected";
                                    }
                                    else{
                                        selected = "";
                                    }   
                                %>
                                    <option value="<%=province.getId()%>" <%=selected%>><%=province.getName()%> </option>
                                <%
                                }
                                %>
				
				</select></td>
			</tr>
			<tr>
				<td><b>Ciudad</b></td>
				<td><select name="city" onChange="submitCombo(this.name)">
				<%
                                Vector citiesList = (Vector)request.getAttribute("citiesList");
                                en = citiesList.elements();
                                selected = "";
                                temp = (Integer) request.getAttribute("cityId");
                                for(int i = 0 ; i < citiesList.size() ; i++){
                                    City city = (City)en.nextElement();
                                    Integer temp2 = new Integer(city.getId());
                                    
                                    if(temp.intValue() == temp2.intValue()){
                                        selected = "selected";
                                    }
                                    else{
                                        selected = "";
                                    }   
                                %>
                                    <option value="<%=city.getId()%>" <%=selected%>><%=city.getName()%> </option>
                                <%
                                }
                                %>
				</select></td>
			</tr>
			<!-- <tr>
				<td>Zona</td>
				<td><select name="zone" onChange="submitCombo(this.name)">
				
				</select></td>
			</tr> -->
			
			<tr>
				<td><b>Barrio</b></td>
				<td><select name="neighbourhood" onChange="submitCombo(this.name)">
				<%
                                Vector neighbourhoodsList = (Vector)request.getAttribute("neighbourhoodsList");
                                en = neighbourhoodsList.elements();
                                selected = "";
                                temp = (Integer) request.getAttribute("neighbourhoodId");
                                for(int i = 0 ; i < neighbourhoodsList.size() ; i++){
                                    Neighbourhood key = (Neighbourhood)en.nextElement();
                                    Integer temp2 = new Integer( key.getId());
                                    
                                    if(temp.intValue() == temp2.intValue()){
                                        selected = "selected";
                                    }
                                    else{
                                        selected = "";
                                    }   
                                %>
                                    <option value="<%=key.getId()%>" <%=selected%>><%=key.getName()%> </option>
                                <%
                                }
                                %>
				
				</select></td>
			</tr>
			<tr>
				<td><input type="hidden" name="combo" value=""></td>
				<td><input type="hidden" name="operationType" value="update"></td>
				<td><input type="hidden" name="operationType2" value=""></td>
				<td><input type="hidden" name="id" value="<%=request.getAttribute("id")%>"></td>
			</tr>
			<tr>
                            <td colspan='3'>
                                <hr>
                            </td>
			</tr>
			<tr>
				<td colspan="2"><input type="submit" name="enviar" value="Guardar"></td>
			</tr>
		</table>
	</form>
                                    </tr>
                                    </td>
                                   

                                    
				
			</table>
	</td>
    </tr>
	
</table>
<table width="760">
	<tr>
		<td><%@ include file="/piepagina.jsp" %></td>
	</tr>
</table>

</body>
</html>
