<%@ page import="java.util.Enumeration"%>
<%@ page import="java.util.Hashtable"%>
<%@ page import="java.util.Vector"%>
<%@ page import="com.fenalco.entities.User"%>
<%@ page import="com.fenalco.entities.DataAccess"%>
<%@ page import="com.fenalco.utilities.MessageBuilder"%>
<%@ page import="com.fenalco.entities.Country"%>
<%@ page import="com.fenalco.entities.Province"%>
<%@ page import="com.fenalco.entities.City"%>
<%@ page import="com.fenalco.entities.Position"%>


<html>
<head>
<link rel='stylesheet' style='text/css' href='../css/tablas.css'>
<title>Datos de la empresa</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<!-- 
	Esta página permite al minorista ver los datos de su empresa y modificarlos
	
	Para construir la función de validación de formularios se deben utilizar las funciones incluidas 
	en la libreria de funciones bajo el nombre libreriaJS.js del directorio js.
	
	Hay que verificar el atributo message que viene en el request, si existe hay que pintarlo pues
	contiene los mensajes de error
	Esta página recibe los parámetros del servlet misdatos: 
	sectorList(sectores)
	companyTypes(tipos de empresa)
	countriesList(paises)
	citiesList(ciudades)
	provincesList(departamentos)
	neighbourhoodsList(barrios)
	zonesList(zonas )
	ciiuList(ciiu)
	
	atributos:
	Objeto User user;
	Objeto Company company;
-->

<script type='text/javascript' language='javascript' src='../js/md5.js'></script>
<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.shopKeeper.combo.value=comboName;
            document.shopKeeper.action = "/minorista/misdatos";
            document.shopKeeper.submit();
            return true;
    }
    
    
		
    function validateForm(){

            var message = "Han ocurrido los siguientes errores:\n";
            var flag = true;
            if(isEmpty(document.shopKeeper.socialName)){
                    message = message + "- El campo razón social vacío.\n";
                    flag = false;
            }
			
            if(isEmpty(document.shopKeeper.commercialName)){
                            message = message + "- El campo de nombre comercial está vacío.\n";
                            flag = false;
            }
            
            if(isEmpty(document.shopKeeper.companyId)){
                            message = message + "- El campo de NIT está vacío.\n";
                            flag = false;
            }
            else{
                if(!isNumber(document.shopKeeper.companyId)){
                     message = message + "- El campo de NIT no es de tipo numérico.\n";
                     flag = false;
                }
            }
            
            if(isEmpty(document.shopKeeper.address)){
                            message = message + "- El campo de dirección está vacío.\n";
                            flag = false;
            }
            
            if(!isEmpty(document.shopKeeper.fax)){
                
                if(!isNumber(document.shopKeeper.fax)){
                     message = message + "- El campo fax no es de tipo numérico.\n";
                     flag = false;
                }
                
            }
            
            if(isEmpty(document.shopKeeper.phoneNumber1)){
                            message = message + "- El campo de telefono 1 está vacío.\n";
                            flag = false;
            }
            else{
                if(!isNumber(document.shopKeeper.phoneNumber1)){
                     message = message + "- El campo de telefono 1 no es de tipo numérico.\n";
                     flag = false;
                }
            }
            
             if(!isEmpty(document.shopKeeper.phoneNumber2)){
                if(!isNumber(document.shopKeeper.phoneNumber2)){
                     message = message + "- El campo de telefono 2 no es de tipo numérico.\n";
                     flag = false;
                }
            }
            
            if(isEmpty(document.shopKeeper.contact1)){
                            message = message + "- El campo de contacto 1 está vacío.\n";
                            flag = false;
            }
            if(isEmpty(document.shopKeeper.email)){
                            message = message + "- El campo de email está vacío.\n";
                            flag = false;
            }
            else{
              
                if( !validEmail(document.shopKeeper.email.value)){
                        message = message + "- La dirección de email no es válida.\n";
                        flag = false;
                }
           }
           
           
		   
           if(document.shopKeeper.updatePasswd.checked){
                       if(isEmpty(document.shopKeeper.passwd)){
                            message = message + "- El campo contraseña  está vacío.\n";
                            flag = false;
                       }
                       if(isEmpty(document.shopKeeper.passwd2)){
                            message = message + "- El campo confirmación de contraseña  está vacío.\n";
                            flag = false;
                        }
           }
           
           if(isEmpty(document.shopKeeper.firstName)){
                            message = message + "- El campo nombre está vacío.\n";
                            flag = false;
           }
           if(isEmpty(document.shopKeeper.lastName)){
                            message = message + "- El campo apellido está vacío.\n";
                            flag = false;
           }
           
           if(isEmpty(document.shopKeeper.idNumber)){
                            message = message + "- El campo cédula está vacío.\n";
                            flag = false;
           }
           else{
                if(!isNumber(document.shopKeeper.idNumber)){
                     message = message + "- El campo cédula no es de tipo numérico.\n";
                     flag = false;
                }
            }
            if(isEmpty(document.shopKeeper.position)){
                            message = message + "- El campo cargo está vacío.\n";
                            flag = false;
           }
           if(isEmpty(document.shopKeeper.userEmail)){
                            message = message + "- El campo  email de usuario está vacío.\n";
                            flag = false;
            }
            else{
                if(!validEmail(document.shopKeeper.userEmail.value)){
                        message = message + "- La dirección de email del usuario no es válida.\n";
                        flag = false;
                }
           }	

            if(!flag){
                    window.alert(message);
            }
            else{
                document.shopKeeper.passwd.value = hex_md5(document.shopKeeper.passwd.value);
                document.shopKeeper.passwd2.value = hex_md5(document.shopKeeper.passwd2.value);
                sendAndBlockForm("wait","<%=((User)session.getAttribute("user")).getFirstName()%> sus datos est&aacute;n siendo actualizados, espere un momento por favor..","enviar");
            }
            
            return  flag;
    }
	
</script>


<!-- 
-->
<%
	String helpId = "31";
    Integer ivaTemp = (Integer)request.getAttribute("iva");
    String checked = (ivaTemp.intValue() == 1?"checked":"");
   String tittle = "Mis Datos";                                  
%>
<body bgcolor="#ffffff" background="../images/shopkeeper/general/fondo.jpg" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload='showMessage("<%=request.getAttribute("message")%>")'>
<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' valign="top">
            <%@ include file="/titulo.jsp" %>
			<table width="505">
				<tr><td align="center">
                                    </td></tr>
									<form name="shopKeeper" method="post" action="/minorista/actualizardatos" onSubmit="return validateForm();">
                                    
        <tr> 
          <td>
            <!-- inicio tabla empresa-->
            <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> </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">Raz&oacute;n 
                  Social</font></span></strong></td>
                <td width="20" height="25" bgcolor="#FBF5C1">&nbsp;</td>
                <td width="285" height="25" bgcolor="#FBF5C1"><input type="text" name="socialName" maxlength="30" value="<%=request.getAttribute("socialName")%>"></td>
              </tr>
              <tr> 
                <td height="25" bgcolor="#FAF09F">&nbsp;</td>
                <td height="25" bgcolor="#FAF09F"><strong><span class="Estilo6"><font color="#FF0000">Nombre 
                  comercial</font></span></strong></td>
                <td height="25">&nbsp;</td>
                <td height="25"><input type="text" name="commercialName" maxlength="30" size="30" value="<%=request.getAttribute("commercialName")%>"></td>
              </tr>
              <tr> 
                <td height="25" bgcolor="#F9ED8C">&nbsp;</td>
                <td height="25" bgcolor="#F9ED8C"><strong><span class="Estilo6"><font color="#FF0000">NIT</font></span></strong></td>
                <td height="25" bgcolor="#FBF5C1">&nbsp;</td>
                <td height="25" bgcolor="#FBF5C1"><input type="text" name="companyId" maxlength="20" value="<%=request.getAttribute("companyId")%>"></td>
              </tr>
              <tr> 
                <td height="25" bgcolor="#FAF09F">&nbsp;</td>
                <td height="25" bgcolor="#FAF09F"><strong><span class="Estilo6"><font color="#333333">Sector 
                  econ&oacute;mico</font></span></strong></td>
                <td height="25">&nbsp;</td>
                <td height="25"><select name="sector">
                    <%
                                                            Hashtable sectorList = (Hashtable)request.getAttribute("sectorList");
                                                            Enumeration en = sectorList.keys();
                                                            String selected = "";
                                                            Integer temp = (Integer) request.getAttribute("sectorId");
                                                            for(int i = 0 ; i < sectorList.size() ; i++){
                                                                Object key = en.nextElement();
                                                                Integer temp2 = (Integer) key;

                                                                if(temp.intValue() == temp2.intValue()){
                                                                    selected = "selected";
                                                                }
                                                                else{
                                                                    selected = "";
                                                                }
                                                            %>
                    <option value="<%=key%>" <%=selected%>><%=sectorList.get(key)%> 
                    </option>
                    <%
                                                            }
                                                            %>
                  </select></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="#FF0000">Telefono 
                  1 </font></span></strong></td>
                <td height="25">&nbsp;</td>
                <td height="25"><input type="text" name="phoneNumber1" maxlength="15" value="<%=request.getAttribute("phoneNumber1")%>"></td>
              </tr>
              <tr> 
                <td height="25" bgcolor="#F9ED8C">&nbsp;</td>
                <td height="25" bgcolor="#F9ED8C"><strong><span class="Estilo6">Telefono 
                  2 </span></strong></td>
                <td height="25" bgcolor="#FBF5C1">&nbsp;</td>
                <td height="25" bgcolor="#FBF5C1"><input type="text" name="phoneNumber2" maxlength="15" value="<%=request.getAttribute("phoneNumber2")%>"> 
                </td>
              </tr>
              <tr> 
                <td height="25" bgcolor="#FAF09F">&nbsp;</td>
                <td height="25" bgcolor="#FAF09F"><strong><span class="Estilo6"><font color="#FF0000">Contacto 
                  1 </font></span></strong></td>
                <td height="25">&nbsp;</td>
                <td height="25"><input type="text" name="contact1" maxlength="30" value="<%=request.getAttribute("contact1")%>"></td>
              </tr>
              <tr> 
                <td height="25" bgcolor="#F9ED8C">&nbsp;</td>
                <td height="25" bgcolor="#F9ED8C"><strong><span class="Estilo6"><font color="#000000">Contacto 
                  2</font> </span></strong></td>
                <td height="25" bgcolor="#FBF5C1">&nbsp;</td>
                <td height="25" bgcolor="#FBF5C1"><input type="text" name="contact2" maxlength="30" value="<%=request.getAttribute("contact2")%>"></td>
              </tr>
              <tr> 
                <td height="25" bgcolor="#FAF09F">&nbsp;</td>
                <td height="25" bgcolor="#FAF09F"><strong><span class="Estilo6"><font color="#333333">Fax</font></span></strong></td>
                <td height="25">&nbsp;</td>
                <td height="25"><input type="text" name="fax" maxlength="30" value="<%=request.getAttribute("fax")%>"></td>
              </tr>
              <tr> 
                <td height="25" bgcolor="#F9ED8C">&nbsp;</td>
                <td height="25" bgcolor="#F9ED8C"><strong><span class="Estilo6"><font color="#FF0000">Correo 
                  electr&oacute;nico</font></span></strong></td>
                <td height="25" bgcolor="#FBF5C1">&nbsp;</td>
                <td height="25" bgcolor="#FBF5C1"><input type="text" name="email" maxlength="60" value="<%=request.getAttribute("email")%>"></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");
                                                            en = countriesList.elements();
                                                            selected = "";
                                                            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 valign="bottom"> 
                <td colspan="4"><img src="../images/sysmanager/barra2form.gif" width="477" height="17"></td>
              </tr>
            </table>
            <p> 
              <!-- fin tbala empresa -->
            </p>
            </td>
                                        </tr>
                                            <tr>
                                            
          <td> 
            <%
                                               tittle = "Datos del usuario";
                                            %>
            <%@ include file="/titulo.jsp" %>
            <!-- inicio tabkla usuario -->
            <table width="200" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FCF8D1">
            <tr bgcolor="#ffffff">
                <td colspan="4">
                    <center><div id="wait" ></div></center>
                </td>
            </tr>
              <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></span></td>
              </tr>
              <tr> 
                <td width="10" height="28" bgcolor="#F9ED8C">&nbsp;</td>
                <td width="162" height="28" bgcolor="#F9ED8C"><strong><span class="Estilo6"><font color="#FF0000">Usuario</font></span></strong></td>
                <td width="20" height="28" bgcolor="#FBF5C1">&nbsp;</td>
                <td width="285" height="28" bgcolor="#FBF5C1"><b><%=((User)request.getSession().getAttribute("user")).getLogin()%><b></td>
              </tr>
              <tr> 
                <td height="25" bgcolor="#FAF09F">&nbsp;</td>
                <td height="25" bgcolor="#FAF09F"><strong><span class="Estilo6"><font color="#FF0000">Contrase&ntilde;a</font></span></strong></td>
                <td height="25">&nbsp;</td>
                <td height="25"><input type="password" name="passwd" maxlength="12" ></td>
              </tr>
              <tr> 
                <td height="25" bgcolor="#F9ED8C">&nbsp;</td>
                <td height="25" bgcolor="#F9ED8C"><strong><span class="Estilo6"><font color="#FF0000">Confirme 
                  su contrase&ntilde;a</font> </span></strong></td>
                <td height="25" bgcolor="#FBF5C1">&nbsp;</td>
                <td height="25" bgcolor="#FBF5C1"><input type="password" name="passwd2" maxlength="12" ></td>
              </tr>
              <tr> 
                <td height="25" bgcolor="#FAF09F">&nbsp;</td>
                <td height="25" bgcolor="#FAF09F"><strong><span class="Estilo6"><font color="#FF0000">Nombre</font></span></strong></td>
                <td height="25">&nbsp;</td>
                <td height="25"><input type="text" name="firstName" maxlength="20" value="<%=request.getAttribute("firstName")%>"></td>
              </tr>
              <tr> 
                <td height="25" bgcolor="#F9ED8C">&nbsp;</td>
                <td height="25" bgcolor="#F9ED8C"><strong><span class="Estilo6"><font color="#FF0000">Apellido</font></span></strong></td>
                <td height="25" bgcolor="#FBF5C1">&nbsp;</td>
                <td height="25" bgcolor="#FBF5C1"><input type="text" name="lastName" maxlength="20" value="<%=request.getAttribute("lastName")%>"></td>
              </tr>
              <tr> 
                <td height="25" bgcolor="#FAF09F">&nbsp;</td>
                <td height="25" bgcolor="#FAF09F"><strong><span class="Estilo6"><font color="#FF0000">C&eacute;dula</font></span></strong></td>
                <td height="25">&nbsp;</td>
                <td height="25"><input type="text" name="idNumber" maxlength="15" value="<%=request.getAttribute("idNumber")%>"></td>
              </tr>
              <tr> 
                <td height="25" bgcolor="#F9ED8C">&nbsp;</td>
                <td height="25" bgcolor="#F9ED8C"><strong><span class="Estilo6">Cargo</span></strong></td>
                <td height="25" bgcolor="#FBF5C1">&nbsp;</td>
                <td height="25" bgcolor="#FBF5C1"><select name="position">
                    <%
                                                            Vector positionList = (Vector)request.getAttribute("positionList");
                                                            en = positionList.elements();
                                                            selected = "";
                                                            temp =  (Integer) request.getAttribute("position") ;
                                                            for(int i = 0 ; i < positionList.size() ; i++){
                                                               Position position = (Position)en.nextElement();
                                                                Integer temp2 = new Integer( position.getId() );

                                                                if(temp.intValue() == temp2.intValue()){
                                                                    selected = "selected";
                                                                }
                                                                else{
                                                                    selected = "";
                                                                }   
                                                            %>
                    <option value="<%=position.getId()%>" <%=selected%>><%=position.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">Correo 
                  electr&oacute;nico personal</font> </span></strong></td>
                <td height="25">&nbsp;</td>
                <td height="25"><input type="text" name="userEmail" maxlength="60" value="<%=request.getAttribute("userEmail")%>"></td>
              </tr>
              <tr bgcolor="FBF3B2"> 
                <td height="15" bgcolor="#FBF3B2">&nbsp;</td>
                <td height="15" colspan="3" bgcolor="#FBF3B2"> <b> 
                  <input name="iva" type="checkbox" id="iva" value="1" <%=checked%> >
                  Discriminar IVA en el carrito de compras</b> </td>
              </tr>
              <tr bgcolor="FBF3B2"> 
                <td height="15" bgcolor="#FBF3B2">&nbsp;</td>
                <td height="15" colspan="3" bgcolor="#FBF3B2"><input type="checkbox" name="updatePasswd" value='1'> 
                  &nbsp;<b>Cambiar contraseña</b> <input type="hidden" name="combo"> 
                </td>
              </tr>
              
              <tr> 
                <td height="0" bgcolor="#F9ED8C">&nbsp;</td>
                <td height="40" bgcolor="#F9ED8C"><input type="submit" name="enviar" id="enviar" value="Enviar" ></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>
            </table>
            <p>
              <!-- fin tabla usuario -->
            </p>
            </td>
                                            </tr>
                                            <tr>
                                            
          <td>&nbsp;</td>
        </tr>
									 </form>
                                    
</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/.”