<%@ 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"%>
<%@ page import="com.fenalco.entities.Zone"%>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel='stylesheet' style='text/css' href='../css/tablas.css'>
<title>Agregar nuevo establecimiento</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#ffffff" background="../images/shopkeeper/general/fondo.jpg" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload='showMessage("<%=request.getAttribute("message")%>")'>

<script type='text/javascript' language='javascript' src='../js/library.js'></script>
<script>		
			
 function showMessage(message){
        if(message!=null && message!=""){
            window.alert(message);
        }
        return true;
    }

function submitCombo(comboName){
        document.newStore.combo.value=comboName;
        document.newStore.operationType2.value="load";
        document.newStore.action = "/minorista/actualizarestablecimientos";
        document.newStore.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;
    }
    else{
        if(!isAllNumber(formName.GLN)){
            message = message + "- El campo GLN debe ser numérico.\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;
    }
       else{
        if(!isNumber(formName.street)){
             message = message + "- El campo calle no es de tipo numérico.\n";
             flag = false;
        }
    }

    if(isEmpty(formName.avenue)){
        message = message + "- El campo carrera está vacío.\n";
        flag = false;
    }
       else{
        if(!isNumber(formName.avenue)){
             message = message + "- El campo de carrera no es de tipo numérico.\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(isEmpty(formName.wareHouseArea)){
        message = message + "- El campo área de bodega de pago está vacío.\n";
        flag = false;
    }
    else{
        if(!isNumber(formName.wareHouseArea)){
              message = message + "- El campo área de bodega de pago debe ser numérico.\n";
              flag = false; 
        }
        
    } 
    
    
    if(!flag){
        window.alert(message);
    }
    else{
        sendAndBlockForm("wait","<%=((User)session.getAttribute("user")).getFirstName()%> los datos est&aacute;n siendo actualizados, espere un momento por favor..","enviar");
    }

    return flag;
}

</script>

<!-- 
-->
<%
	String helpId = "43";
%>
<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" %>
			<table align='center'>
                            <tr>
                                <td>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <a href='/minorista/misestablecimientos'><img src='/images/buttons/regresar.gif' border='0'></a>
                                </td>
                             </tr>
                        </table>
	</td>
        <td width='505'>
            <%
                String tittle = "Nuevo Establecimiento";
            %>
            <%@ include file="/titulo.jsp" %>

			<table width="100%">
				
                                    
                                    <!-- -->
                                    
                                    <tr>
                                        <td>
                                            <form name="newStore" method="post" action="/minorista/administrarestablecimientos" onSubmit='return validateForm(document.newStore);'>
              <table width="200" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FCF8D1">
                <tr valign="top"> 
                  <td colspan="4"><img src="../images/sysmanager/barra1form.gif" width="477" height="19"></td>
                </tr>
				 <tr bgcolor="FBF3B2"> 
                  <td height="15" bgcolor="#FBF3B2">&nbsp;</td>
                  <td height="15" colspan="3" bgcolor="#FBF3B2"><span class="Estilo2"><font color="#FF0000">Los 
                    campos con color son obligatorios </font> 
                    <input type="hidden" name="combo" value="">
                    <input type="hidden" name="operationType2" value="">
                    <input type="hidden" name="operationType" value="new">
                    <input type="hidden" name="id" value="<%=request.getAttribute("id")%>">
                    </span></td>
                </tr>
                <tr> 
                  <td width="20" height="25" bgcolor="#F9ED8C">&nbsp;</td>
                  <td width="152" height="25" bgcolor="#F9ED8C"><strong><span class="Estilo6"><font color="#FF0000">Nombre</font></span></strong></td>
                  <td width="20" height="25" bgcolor="#FBF5C1">&nbsp;</td>
                  <td width="285" height="25" bgcolor="#FBF5C1"><input type="text" name="name" maxlength="30" value="<%=request.getAttribute("name")%>"></td>
                </tr>
                <tr> 
                  <td height="25" bgcolor="#FAF09F">&nbsp;</td>
                  <td height="25" bgcolor="#FAF09F"><strong><span class="Estilo6"><font color="#FF0000">GLN</font></span></strong></td>
                  <td height="25">&nbsp;</td>
                  <td height="25"><input type="text" name="GLN" maxlength="30" value="<%=request.getAttribute("GLN")%>" ></td>
                </tr>
                <tr> 
                  <td height="25" bgcolor="#F9ED8C">&nbsp;</td>
                  <td height="25" bgcolor="#F9ED8C"><strong><span class="Estilo6"><font color="#FF0000">Direcci&oacute;n</font></span></strong></td>
                  <td height="25" bgcolor="#FBF5C1">&nbsp;</td>
                  <td height="25" bgcolor="#FBF5C1"><input type="text" name="address" maxlength="50"  value="<%=request.getAttribute("address")%>"></td>
                </tr>
                <tr> 
                  <td height="25" bgcolor="#FAF09F">&nbsp;</td>
                  <td height="25" bgcolor="#FAF09F"><strong><span class="Estilo6"><font color="#000000">Estrato</font></span></strong></td>
                  <td height="25">&nbsp;</td>
                  <td height="25"><select name="stratum">
                      <%  int maxStratum = DataAccess.getStratum();


                                                      String selectStratum ="";
                                                      String stratum = (String)request.getAttribute("stratum");
                                                      for(int i  = 0; i <= maxStratum; i++){
                                                         selectStratum ="";
                                                         
                                                         if(!stratum.equals("")){
                                                            if( i == Integer.parseInt(stratum)){
                                                                selectStratum = "selected";
                                                            }    
                                                         }
                                                         
                                                    %>
                      <option value="<%=i%>" <%=selectStratum%>><%=i%></option>
                      <%
                                                        }
                                                    %>
                    </select></td>
                </tr>
                <tr> 
                  <td height="26" bgcolor="#F9ED8C">&nbsp;</td>
                  <td height="26" bgcolor="#F9ED8C"><strong><span class="Estilo6"><font color="#FF0000">Calle</font></span></strong></td>
                  <td height="26" bgcolor="#FBF5C1">&nbsp;</td>
                  <td height="26" bgcolor="#FBF5C1"><input type="text" name="street" maxlength="3"  value="<%=request.getAttribute("street")%>"></td>
                </tr>
                <tr> 
                  <td height="25" bgcolor="#FAF09F">&nbsp;</td>
                  <td height="25" bgcolor="#FAF09F"><strong><span class="Estilo6"><font color="#FF0000">Carrera</font></span></strong></td>
                  <td height="25">&nbsp;</td>
                  <td height="25"><input type="text" name="avenue" maxlength="3"  value="<%=request.getAttribute("avenue")%>"></td>
                </tr>
                <tr> 
                  <td height="25" bgcolor="#F9ED8C">&nbsp;</td>
                  <td height="25" bgcolor="#F9ED8C"><strong><span class="Estilo6">Orientaci&oacute;n 
                    carrera</span></strong></td>
                  <td height="25" bgcolor="#FBF5C1">&nbsp;</td>
                  <td height="25" bgcolor="#FBF5C1"><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>
                </tr>
                <tr> 
                  <td height="25" bgcolor="#FAF09F">&nbsp;</td>
                  <td height="25" bgcolor="#FAF09F"><strong><span class="Estilo6">Orientaci&oacute;n 
                    calle </span></strong></td>
                  <td height="25">&nbsp;</td>
                  <td height="25"><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>
                </tr>
                <tr> 
                  <td height="25" bgcolor="#F9ED8C">&nbsp;</td>
                  <td height="25" bgcolor="#F9ED8C"><strong><span class="Estilo6"><font color="#FF0000">Persona 
                    contacto 1</font></span></strong></td>
                  <td height="25" bgcolor="#FBF5C1">&nbsp;</td>
                  <td height="25" bgcolor="#FBF5C1"><input type="text" name="contact1" maxlength="30"  value="<%=request.getAttribute("contact1")%>"></td>
                </tr>
                <tr> 
                  <td height="25" bgcolor="#FAF09F">&nbsp;</td>
                  <td height="25" bgcolor="#FAF09F"><strong><span class="Estilo6"><font color="#000000">Persona 
                    contacto 2</font></span></strong></td>
                  <td height="25">&nbsp;</td>
                  <td height="25"><input type="text" name="contact2" maxlength="30"  value="<%=request.getAttribute("contact2")%>"></td>
                </tr>
                <tr> 
                  <td height="25" bgcolor="#F9ED8C">&nbsp;</td>
                  <td height="25" bgcolor="#F9ED8C"><strong><span class="Estilo6"><font color="#FF0000">Telefono 
                    1 </font></span></strong></td>
                  <td height="25" bgcolor="#FBF5C1">&nbsp;</td>
                  <td height="25" bgcolor="#FBF5C1"><input type="text" name="phoneNumber1" maxlength="15"  value="<%=request.getAttribute("phoneNumber1")%>"></td>
                </tr>
                <tr> 
                  <td height="25" bgcolor="#FAF09F">&nbsp;</td>
                  <td height="25" bgcolor="#FAF09F"><strong><span class="Estilo6"><font color="#000000">Telefono 
                    2 </font></span></strong></td>
                  <td height="25">&nbsp;</td>
                  <td height="25"><input type="text" name="phoneNumber2" maxlength="15"  value="<%=request.getAttribute("phoneNumber2")%>"></td>
                </tr>
                <tr> 
                  <td height="25" bgcolor="#F9ED8C">&nbsp;</td>
                  <td height="25" bgcolor="#F9ED8C"><strong><span class="Estilo6"><font color="#FF0000">&Aacute;rea 
                    de tienda</font> </span></strong></td>
                  <td height="25" bgcolor="#FBF5C1">&nbsp;</td>
                  <td height="25" bgcolor="#FBF5C1"><input type="text" name="storeArea"  value="<%=request.getAttribute("storeArea")%>"></td>
                </tr>
                <tr> 
                  <td height="25" bgcolor="#FAF09F">&nbsp;</td>
                  <td height="25" bgcolor="#FAF09F"><strong><span class="Estilo6"><font color="#FF0000">N&uacute;mero 
                    de puntos de pago</font></span></strong></td>
                  <td height="25">&nbsp;</td>
                  <td height="25"><input type="text" name="paymentPoints"  value="<%=request.getAttribute("paymentPoints")%>"></td>
                </tr>
                <tr> 
                  <td height="25" bgcolor="#F9ED8C">&nbsp;</td>
                  <td height="25" bgcolor="#F9ED8C"><strong><span class="Estilo6"><font color="#FF0000">&Aacute;rea 
                    de bodega(en m<sup>2</sup>)</font></span></strong></td>
                  <td height="25" bgcolor="#FBF5C1">&nbsp;</td>
                  <td height="25" bgcolor="#FBF5C1"><input type="text" name="wareHouseArea"  value="<%=request.getAttribute("wareHouseArea")%>"></td>
                </tr>
                <tr> 
                  <td height="25" bgcolor="#FAF09F">&nbsp;</td>
                  <td height="25" bgcolor="#FAF09F"><strong><span class="Estilo6"><font color="#FF0000">Pa&iacute;s</font></span></strong></td>
                  <td height="25">&nbsp;</td>
                  <td height="25"><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 height="25" bgcolor="#F9ED8C">&nbsp;</td>
                  <td height="25" bgcolor="#F9ED8C"><strong><span class="Estilo6"><font color="#FF0000">Departamento</font></span></strong></td>
                  <td height="25" bgcolor="#FBF5C1">&nbsp;</td>
                  <td height="25" bgcolor="#FBF5C1"><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 height="25" bgcolor="#FAF09F">&nbsp;</td>
                  <td height="25" bgcolor="#FAF09F"><strong><span class="Estilo6"><font color="#FF0000">Ciudad</font></span></strong></td>
                  <td height="25">&nbsp;</td>
                  <td height="25"><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 height="25" bgcolor="#F9ED8C">&nbsp;</td>
                  <td height="25" bgcolor="#F9ED8C"><strong><span class="Estilo6"><font color="#FF0000">Zona</font></span></strong></td>
                  <td height="25" bgcolor="#FBF5C1">&nbsp;</td>
                  <td height="25" bgcolor="#FBF5C1"><select name="zone" onChange="submitCombo(this.name)">
                      <%
                                                    Vector zonesList = (Vector)request.getAttribute("zonesList");
                                                    en = zonesList.elements();
                                                    selected = "";
                                                    temp = (Integer) request.getAttribute("zoneId");
                                                    for(int i = 0 ; i < zonesList.size() ; i++){
                                                        Zone zone = (Zone)en.nextElement();
                                                        Integer temp2 = new Integer(zone.getId());

                                                        if(temp.intValue() == temp2.intValue()){
                                                            selected = "selected";
                                                        }
                                                        else{
                                                            selected = "";
                                                        }   
                                                    %>
                      <option value="<%=zone.getId()%>" <%=selected%>><%=zone.getName()%> 
                      </option>
                      <%
                                                    }
                                                    %>
                    </select></td>
                </tr>
               <tr> 
                  <td height="25" bgcolor="#FAF09F">&nbsp;</td>
                  <td height="25" bgcolor="#FAF09F"><strong><span class="Estilo6"><font color="#FF0000">Barrio</font></span></strong></td>
                  <td height="25">&nbsp;</td>
                  <td height="25"><select name="neighbourhood" >
                      <%
                                                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 height="0" bgcolor="#F9ED8C">&nbsp;</td>
                  <td height="40" bgcolor="#F9ED8C"><input type="submit" name="enviar" id="enviar" value="Guardar"></td>
                  <td height="0" bgcolor="#FBF5C1">&nbsp;</td>
                  <td height="0" bgcolor="#FBF5C1"> <span class="Estilo6"><a href="/index.jsp"> 
                    </a></span></td>
                </tr>
                               
                <tr valign="bottom"> 
                  <td colspan="4"><img src="../images/sysmanager/barra2form.gif" width="477" height="17"></td>
                </tr>
                
                <tr bgcolor="#ffffff">
                    <td colspan="4">
                        <center><div id="wait" ></div></center>
                    </td>
                </tr>
              </table>
              <p>&nbsp;</p>
              </form>
                                           
                                        </td>
                                    </tr>
                        </table>
            </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/.”