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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel='stylesheet' style='text/css' href='../css/tablas.css'>
<title>Nuevo operador log&iacute;stico</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 validateForm(formName){
    
        var message = "Han ocurrido los siguientes errores:\n";
        var flag = true;
        var flag2 = true;

                                    
        
        if(isEmpty(formName.name)){
            message = message + "- El campo nombre 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.contact)){
            message = message + "- El campo contacto está vacío.\n";
            flag = false;
        }
       
        
        if(isEmpty(formName.email)){
                message = message + "- El campo de email está vacío.\n";
                flag = false;
        }
        else{

            if( !validEmail(formName.email.value)){
                    message = message + "- La dirección de email no es válida.\n";
                    flag = false;
            }
       }
       
       if(isEmpty(formName.phoneNumber)){
                message = message + "- El campo de telefono está vacío.\n";
                flag = false;
        }
        else{
            if(!isNumber(formName.phoneNumber)){
                 message = message + "- El campo de telefono no es de tipo numérico.\n";
                 flag = false;
            }
        }
        
        if(!flag){
                    window.alert(message);
        }
       
        
        
        return flag;
    }
  
     function submitCombo(comboName){
                document.newLogisticOperator.combo.value=comboName;
                document.newLogisticOperator.action = "actualizaroperadoreslogisticos";
                document.newLogisticOperator.submit();
                return true;
        }
</script>

<table border="0" cellpadding="0" cellspacing="0" width="780">
        <%
            String helpId = "23";
        %>
        <%@ include file="encabezado.jsp" %>
</table>

<table width="760">
	<tr>
		<td width="152" valign='top'>
			<%@ include file="menuadministrador.jsp" %>
		</td>
		<td valign='top'>
            <%
                String tittle = "Nuevo Operador Log&iacute;stico";
            %>
            <%@ include file="/titulo.jsp" %>

			<table width="603">
			<tr><td align="center"><%= request.getAttribute("message")%></td></tr>
			<tr>
			<form name="newLogisticOperator" method="post" action="/administrador/administraroperadorlogistico" onSubmit='return validateForm(document.newLogisticOperator)';>
				<table align="center">
					<tr><td height='10'></td></tr>
			<tr>
				<td>Nombre</td>
				<td><input type="text" name="name" maxlength="30" value="<%=request.getAttribute("name")%>"></td>
				<!-- JS: Verificación de campo vacío, Campo Obligatorio-->	
			</tr>
			
			<tr>
				<td>Pa&iacute;s</td>
				<td><select name="country" onChange="submitCombo(this.name)">
				<%
                                Vector countriesList = (Vector)request.getAttribute("countriesList");
                                Enumeration en = countriesList.elements();
                                String selected = "";
                                int temp = Integer.parseInt(request.getAttribute("countryId").toString());
                                for(int i = 0 ; i < countriesList.size() ; i++){
                                    int key = ((Country)en.nextElement()).getId();
                                    int temp2 = key;
                                    
                                    if(temp == temp2){
                                        selected = "selected";
                                    }
                                    else{
                                        selected = "";
                                    }   
                                    
                                    
                                %>
                                    <option value="<%=key%>" <%=selected%>><%=((Country)countriesList.elementAt(i)).getName()%> </option>
                                <%
                                }
                                %>
				</select></td>
			</tr>			
			
			<tr>
				<td>Departamento</td>
				<td><select name="province" onChange="submitCombo(this.name)">
				<%
                                Vector provincesList = (Vector)request.getAttribute("provincesList");
                                en = provincesList.elements();
                                selected = "";
                                temp = Integer.parseInt(request.getAttribute("provinceId").toString());
                                for(int i = 0 ; i < provincesList.size() ; i++){
                                    int key = ((Province)en.nextElement()).getId();
                                    int temp2 = key;
                                    
                                    if(temp == temp2){
                                        selected = "selected";
                                    }
                                    else{
                                        selected = "";
                                    }   
                                %>
                                    <option value="<%=key%>" <%=selected%>><%=((Province)provincesList.elementAt(i)).getName()%> </option>
                                <%
                                }
                                %>
				</select></td>
			</tr>
			<tr>
				<td>Ciudad</td>
				<td><select name="city" onChange="submitCombo(this.name)">
                                <%
                                Vector citiesList = (Vector)request.getAttribute("citiesList");
                                en = citiesList.elements();
                                selected = "";
                                temp = Integer.parseInt(request.getAttribute("cityId").toString());
                                for(int i = 0 ; i < citiesList.size() ; i++){
                                    int key = ((City)en.nextElement()).getId();
                                    int temp2 = key;
                                    
                                    if(temp == temp2){
                                        selected = "selected";
                                    }
                                    else{
                                        selected = "";
                                    }   
                                %>
                                    <option value="<%=key%>" <%=selected%>><%=((City)citiesList.elementAt(i)).getName()%> </option>
                                <%
                                }
                                %>
				</select></td>
			</tr>
			<tr>
				<td>Direcci&oacute;n</td>
				<td><input type="text" name="address" maxlength="40" value="<%=request.getAttribute("address")%>"></td>
				<!-- JS: Verificación de campo vacío, Campo Obligatorio-->	
			</tr>
			<tr>
				<td>Contacto</td>
				<td><input type="text" name="contact" maxlength="30" value="<%=request.getAttribute("contact")%>"></td>
				<!-- JS: Verificación de campo vacío, Campo Obligatorio, Numérico-->	
			</tr>
			<tr>
				<td>Tel&eacute;fono</td>
				<td><input type="text" name="phoneNumber" maxlength="15" value="<%=request.getAttribute("phoneNumber")%>"></td>
				<!-- JS: Verificación de campo vacío, Campo Obligatorio, Correo Eléctrónico-->	
			</tr>
			<tr>
				<td>Email</td>
				<td><input type="text" name="email" maxlength="60" value="<%=request.getAttribute("email")%>"></td>
				<!-- JS: Verificación de campo vacío, Campo Obligatorio, Correo Eléctrónico-->	
			</tr>
			<tr><td height='10'></td></tr>
                        </table>
				<table align="center">
					<tr>
						<td colspan="2" align="center"><input type="submit" name="enviar" value="Aceptar"></td>
						<!-- 
						El evento onClick inicia la verificación del formulario llamando a la función
						validateForm().
						-->
					</tr>
				</table>
                                <input name="operationType" type="hidden" value="new">
                                <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>