<%
/******************************************************************************
 * Copyright (c) 2000-2005 e-Deal
 *
 * e-Deal S.A.
 * 55 rue Brillat Savarin
 * 75013 Paris
 * France
 *
 * T: +33 (0)1 53 80 80 30
 * F: +33 (0)1 73 01 69 77
 * http://www.e-deal.com
 * 
 * La diffusion de ce code source sous quelque forme que ce soit sans
 * l'autorisation de E-DEAL est interdite.
 *
 * Vous êtes autorisés à modifier ce code source uniquement pour votre usage
 * propre et sous réserve que les mentions de copyright demeurent intactes.
 *
 * Ce code est fourni en l'état. Aucune garantie d'aucune sorte, explicite ou
 * implicite n'est donnée. En aucun cas E-DEAL ne pourra être tenu pour
 * responsable des dommages pouvant résulter de l'utilisation de ce code
 * source.
 ******************************************************************************/
%>
<%@page session="true"%>
<%@ page import="com.edeal.frontline.navigation.FlRequest" %>
<%@ page import="com.edeal.frontline.FlContext" %>
<%@ page import="com.edeal.frontline.EnterpriseBean" %>
<%@ page import="com.edeal.frontline.Utils" %>
<%@ page import="com.edeal.frontline.FieldNotInitializedException" %>
<%@taglib uri="http://www.e-deal.com/taglib/fl" prefix="fl" %>
<link rel="stylesheet" type="text/css" href="<fl:webapp/>/css/smalltabs_css.jsp">

<jsp:useBean class="com.edeal.frontline.LocationBean" id="Location" scope="request"/>
<%
final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory.getLog(getClass());
FlRequest flRequest = new FlRequest(request);
FlContext context = flRequest.getContext();

String id = null;
try {
	id = Location.getID();
} catch (FieldNotInitializedException fnie) {
}
String strSiren = null;
String strSirenClean = null;
try {
	EnterpriseBean ent = new EnterpriseBean(Location.getLocEntID(), session);
	strSiren = ent.getEntSiren();
	strSirenClean = strSiren;
} catch (Exception e) {
}
if (strSiren==null || "".equals((String)strSiren)) {
	strSiren = "";
} else {
	strSiren = strSiren + " - ";
}
%>
<script type="text/javascript">
function doCheckSiret(siret) {
	siret = '<%= strSirenClean %>' + siret;
    var errTxt = '<fl:getMessage code="M80A0" alt="Siret Incorrect" js="true"/>';

    if (siret.length != 14) {
		window.alert(errTxt + '. <fl:getMessage code="M80A1" alt="La taille doit Ãªtre 14" js="true"/>.');
    	return false; 
    }
      
    if (isNaN(siret)) {
    	alert('<fl:getMessage code="M80A2" alt="Le code SIRET doit Ãªtre numÃ©rique" js="true"/>');
    	return false;
    } 

    var estValide = true;

	// Donc le SIRET est un numÃ©rique Ã  14 chiffres 
	// Les 9 premiers chiffres sont ceux du SIREN , les 4 suivants 
	// correspondent au numÃ©ro d'Ã©tablissement 
	// et enfin le dernier chiffre est une clef. 
   	var somme = 0; 
   	for (var cpt = 0; cpt<siret.length; cpt++) { 
   		var tmpChar = siret.charAt(cpt);
   		var tmpSomme = parseInt(tmpChar);
        
        if (cpt % 2 == 0) { // Les positions impaires sont multipliÃ© par 2
    	    tmpSomme *= 2;
         
        	if (tmpSomme > 9) { 
        		tmpSomme -= 9;    // Si le rÃ©sultat est supÃ©rieur Ã  9, on lui soustrait 9
        	} 
        } 
	        
		somme += tmpSomme;
    }
      
	if (somme % 10 != 0) {
		window.alert(errTxt);
        estValide = false;
	}   
	return estValide;
}
</script>
<fl:form action="/save_location.fl" bean="Location">
<input type="hidden" name="LocEntID" id="LocEntID" value="<%=Location.getLocEntID()%>"/>
<fl:bigTabs objectTitle="<%=Utils.getMessage(session, \"F200C\", \"Implantation\")%>" ou="<%= \"/edit_location.fl\" + (id != null ? \"?id=\" + id: \"\") %>">
	<table class="container" cellpadding="0">
		<tr>
			<td colspan="3">
				<table class="container" cellpadding="0">
					<tr class="fieldline">
						<td class="labelTitreFiche"><fl:label field="LocName" labelClassName="titreFiche"/></td>
						<td class="fieldTitreFiche"><fl:input property="LocName" mandatoryMsgCode="M3012"/></td>
					</tr>
				</table>
			</td>
		</tr>
		<tr><td colspan="3" class="ligne_separation"></td></tr>
		<tr>
			<td class="column2">
				<table class="container" cellpadding="0">
					<fl:fieldRead property="LocEntID" alt="" bean="true" />
					<% if (strSiren != null && !"".equals(strSiren)) { %>
					<tr class="fieldline">
						<td class="dataLabel"><fl:label code="F3007" forInput="LocSiren"/></td>
						<td class="dataValue">
							<div>
								<table class="fieldTable" cellpadding="0">
									<tr>
										<td class="postText"><%= Utils.formatToWeb(strSiren, false) + "&nbsp;" %></td>
										<td class="principalText"><fl:input property="LocSiren" size="5" nodiv="false" onchange="doCheckSiret(this.value);"/></td>
									</tr>
								</table>
							</div>
						</td>
					</tr>
					<% } %>
					<fl:fieldEdit property="LocPhone" size="20"/>
					<fl:fieldEdit property="LocFax" size="20"/>
				</table>
			</td>
			<td class="separation"><div class="separation"></div></td>
			<td class="column2">
				<table class="container" cellpadding="0">
					<fl:fieldEdit property="LocAddressType" alt="" />
					<tr class="fieldline">
						<td class="dataLabel" rowspan="5"><fl:label code="F2012" forInput="LocAd1"/></td>
						<td class="dataValue"><fl:input property="LocAd1"/></td>
					</tr>
					<tr class="fieldline">
						<td class="dataValue"><fl:input property="LocAd2"/></td>
					</tr>
					<tr class="fieldline">
						<td class="dataValue"><fl:input property="LocAd3"/></td>
					</tr>
					<tr class="fieldline">
						<td class="dataValue">
							<div class="fieldTable" >
								<table class="fieldTable" cellpadding="0">
									<tr>
										<td class="smallFieldPart">
											<input class="input text" type="text" id="LocZip" name="LocZip" value="<fl:getProperty name="Location" property="LocZip" alt=""/>" size="6" style="width: auto;"/>
										</td>
										<td class="bigFieldPart">
											<input class="input text" type="text" maxlength="50" id="LocCity" onblur="this.value = checkString(this.value, 'upper');" name="LocCity" value="<fl:getProperty name="Location" property="LocCity" alt=""/>" style="width:100%" />
										</td>
									</tr>
								</table>
							</div>
						</td>
					</tr>
					<tr class="fieldline">
						<td class="dataValue"><fl:input property="LocCtrID"/></td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
	<table class="container" cellpadding="0">
			<tr class="ligne_separation"><td></td></tr>
			<tr>
				<td class="titrePartie"><fl:getMessage code="F2024" alt="Notes"/></td>
			</tr>
			<tr>
				<td class="dataValue noPaddingLeft"><fl:input property="LocDetails" nodiv="false"/></td>
			</tr>
			<tr class="ligne_separation"><td></td></tr>
			<tr class="ligne_separation_couleur"><td></td></tr>
			<tr class="ligne_separation"><td></td></tr>
		</table>
		<fl:smallTabs name="LocationTabs">
			<fl:sTab id="LOCATION1" title="<%= context.getAutoDisplayManager().getTitle(session, \"Location\", \"Implantation 1\") %>" visible="<%= context.getAutoDisplayManager().hasEntry(\"Location\", \"Implantation 1\") %>">
				<fl:autodisplay name="Location" zone="Implantation 1" edit="true"/>
			</fl:sTab>
			<fl:sTab id="LOCATION2" title="<%= context.getAutoDisplayManager().getTitle(session, \"Location\", \"Implantation 2\") %>" visible="<%= context.getAutoDisplayManager().hasEntry(\"Location\", \"Implantation 2\") %>">
				<fl:autodisplay name="Location" zone="Implantation 2" edit="true"/>
			</fl:sTab>
			<fl:sTab id="locAttFile" title="<%= Utils.getMessage(session, \"L201C\", \"Documents joints\") %>">
				<fl:attach name="Location" colID="LocAttID" edit="true"/> 
			</fl:sTab>
		</fl:smallTabs>
</fl:bigTabs>
</fl:form>
