<%
/******************************************************************************
 * Copyright (c) 2000-2013 E-DEAL
 *
 * E-DEAL S.A.
 * 41, rue Périer
 * 92120 Montrouge
 * France
 *
 * T: +33 (0)1 73 03 29 80
 * 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.DataDictionary" %>
<%@ page import="com.edeal.frontline.Utils" %>
<%@ page import="com.edeal.frontline.SalesInvestBean" %>
<%@ page import="com.edeal.frontline.FieldNotInitializedException" %>
<%@ page import="com.edeal.frontline.FrontlineException" %>
<%@ page import="com.edeal.frontline.BasicBean" %>
<%@ page import="com.edeal.frontline.EnterpriseBean" %>
<%@ page import="java.util.Vector" %>
<%@ page import="com.edeal.frontline.helper.ContextHelper" %>
<%@ page import="com.edeal.frontline.helper.custom.FlTaskHelper" %>
<%@ page import="org.apache.commons.lang.StringUtils" %>
<%@ taglib uri="http://www.e-deal.com/taglib/fl" prefix="fl" %>
<jsp:useBean class="com.edeal.frontline.EnterpriseBean" id="Enterprise" 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();
	DataDictionary dico = context.getDataDictionary();
	String objID = dico.getTable("rad", "Ent").getID();

	boolean hasDoubloon = false;
	if(flRequest.getAttribute("HasDoubloon") != null) {
		hasDoubloon = (Boolean)flRequest.getAttribute("HasDoubloon");	
	}
	
	
	Vector<String> listFieldsForDbl = (Vector)flRequest.getAttribute("matchCodeFields");
	// If no match code fields is undefined
	if (listFieldsForDbl == null) {
		listFieldsForDbl = new Vector<String>();
	}
	//Vector matchCodeTemplates = (Vector)flRequest.getAttribute("matchCodeTemplates");
	Vector<String> fieldDisplay = (Vector)flRequest.getAttribute("fieldDisplay");
	if (fieldDisplay == null) {
		fieldDisplay = new Vector<String>();
	}
	Vector<Integer> seuils = (Vector)flRequest.getAttribute("seuils");
	boolean isCreation = true;
	String entId = null;
	try {
		entId = Enterprise.getID();
		isCreation = false;
	} catch(FieldNotInitializedException fnie) {
	}
	
	
	String typOrganisation = null;
	boolean isAssociation = false;
	boolean isResto = false;
	boolean isPartenaire = false;
	Boolean afficherDansCatalogue = true;
	try {
		typOrganisation = Enterprise.getEntTyeID();
		if(typOrganisation != null){
			isAssociation = typOrganisation.equals((String)dico.getRefIdByCode("EntTyeID", "ASSO"));
			if(typOrganisation.equals((String)dico.getRefIdByCode("EntTyeID", "ETAB")) || typOrganisation.equals((String)dico.getRefIdByCode("EntTyeID", "RESTO"))) {
				isResto = true;	
			}
			isPartenaire = typOrganisation.equals((String)dico.getRefIdByCode("EntTyeID", "PART"));
		}
	} catch (FieldNotInitializedException e) {}
	
	// JSA Yellow Pages integation
	if (flRequest.getAttribute("__YPBean__") != null) {

		BasicBean bean = (BasicBean)flRequest.getAttribute("__YPBean__");
		
		if (bean != null) {
			request.setAttribute("Enterprise", (EnterpriseBean)bean);
			Enterprise = (EnterpriseBean)bean;
			try {
				String pPhone = Enterprise.getEntPhone();
				if (!pPhone.startsWith("+33")) {
					//pPhone = Utils.formatPhone("+33 (?)? ?? ?? ?? ?? ",pPhone);
					pPhone = Utils.formatPhone("?? ?? ?? ?? ??", pPhone);		
					Enterprise.setEntPhone(pPhone);
				}
			} catch (FieldNotInitializedException e) {
			}		
		}
		flRequest.removeAttribute("__YPBean__");
	} else if (flRequest.getAttribute("__Address__Enterprise") != null || session.getAttribute("__Address__Enterprise") != null) {

		BasicBean bean = (BasicBean)flRequest.getAttribute("__Address__Enterprise");
		if (bean == null) 
			bean = (BasicBean)session.getAttribute("__Address__Enterprise");
	
		if (bean != null) {
			
			request.setAttribute("Enterprise", (EnterpriseBean)bean);
			Enterprise=(EnterpriseBean)bean;
			try {
				String pPhone = Enterprise.getEntPhone();
				if (!pPhone.startsWith("+33")) {
					//pPhone = Utils.formatPhone("+33 (?)? ?? ?? ?? ?? ",pPhone);
					pPhone = Utils.formatPhone("?? ?? ?? ?? ??", pPhone);		
					Enterprise.setEntPhone(pPhone);
				}
			} catch (FieldNotInitializedException e) {	
			}	
		}
		flRequest.removeAttribute("__Address__Enterprise");
	}
	String id = null;
	try {
		id = Enterprise.getID();
	} catch (FieldNotInitializedException fnie) {
	}
	
	boolean isCreate = id == null;
	
	String actionSave = null;
	
	if (isCreate) {
		actionSave="/save_enterprise.fl";
	} else {
		actionSave="/save_enterprise.fl";
	}
	
	logger.debug("isCreate: " + isCreate);
	logger.debug("Save action: " + actionSave);
	
	String entCtrID;
	String entCtrCode = null;
	try {
		entCtrID = Enterprise.getEntCtrID();
		entCtrCode = dico.getRefCode("EntCtrID", entCtrID);
	} catch (Exception e) {
		entCtrID = "";
	}
	String entFRCtrCode = null;
	try {
		entFRCtrCode = dico.getRefIdByCode("EntCtrID", "FR");
	} catch (Exception e) {
	}
	
	String entIntraVAT;
	try {
		entIntraVAT = Enterprise.getEntIntraVAT();
	} catch (FieldNotInitializedException e) {
		entIntraVAT = "";
	}
	

 	String typoStructID = null;
	try {
		typoStructID = (String)Enterprise.getCustomProperty("EntTypoStructure_");
	} catch (FieldNotInitializedException e){
		typoStructID = "";
	}
	
	String departID;
	try {
		departID = dico.getRefIdByCode("EntTypoStructure_", "DEPARTEMENTALE");
	} catch (FrontlineException e) {
		departID = "";
	}
	
	String regionID;
	try {
		regionID = dico.getRefIdByCode("EntTypoStructure_", "REGIONAL");
	} catch (FrontlineException e) {
		regionID = "";
	}
	
	String paysID;
	try {
		paysID = dico.getRefIdByCode("EntTypoStructure_", "PAYS");
	} catch (FrontlineException e) {
		paysID = "";
	}
	String codePays = null;
	String codeRegion = null; 
	String regiondedepartementID = null;
	String paysderegionID = null;
	
	String entregionID = null;
	try {
		entregionID = (String) Enterprise.getCustomProperty("EntRegionID_");
	} catch (FieldNotInitializedException e) {
	}
	
	String entdepartementID = null;
	try {
		entdepartementID = (String) Enterprise.getCustomProperty("EntDepartmentID_");
	} catch (FieldNotInitializedException e) {
	}

	if(entregionID != null) {
		codePays = (String)dico.getRefDisp("Rg_", "Te2", entregionID);
		if(codePays != null) {
			try {
				paysderegionID = (String) dico.getRefIdByCode("EntCtrID", codePays);
				if (paysderegionID != null) {
					Enterprise.setEntCtrID(paysderegionID);	
				}
			} catch (FrontlineException e) {
			}
		} else {
			Enterprise.setEntCtrID(null);
		}
	} 
	
	if(entdepartementID != null ) {
		codeRegion = (String)dico.getRefDisp("Dp_", "Te2", entdepartementID);
		if(codeRegion != null) {
			try {
				regiondedepartementID = (String) dico.getRefIdByCode("EntRegionID_", codeRegion);
				if (regiondedepartementID != null) {
					Enterprise.setCustomProperty("EntRegionID_", regiondedepartementID);	
				}
			} catch (FrontlineException e) {
			}
			if (regiondedepartementID != null) {
				codePays = (String)dico.getRefDisp("Rg_", "Te2", regiondedepartementID);
			}
			if(codePays != null) {
				try {
					paysderegionID = (String) dico.getRefIdByCode("EntCtrID", codePays);
					if (paysderegionID != null) {					
						Enterprise.setEntCtrID(paysderegionID);
					}
				} catch (FrontlineException e) {
				}
			}	
		} else {
			Enterprise.setCustomProperty("EntRegionID_", null);
			Enterprise.setEntCtrID(null);
		}
	} 
	
%>
<script type="text/javascript" language="javascript">
	//var fieldsList = new Array;
	var fieldsList = {};
	var seuilcert = <%= (seuils != null && !seuils.isEmpty()) ? seuils.get(0) : null %>;

	function doCheckSiret(siret) {
		if (siret != "") {
		    var errTxt = '<fl:getMessage code="M80A0" alt="Siret Incorrect" js="true"/>';
	
		    if (siret.length != 14) {
				window.alert(errTxt + '. <fl:getMessage code="M80A1" alt="Le Siret doit avoir 14 chiffres" js="true"/>.');
		    	return false;
		    }
		      
		    if (isNaN(siret)) {
		    	alert('<fl:getMessage code="M80A2" alt="Le 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;
			}   
			doCalculateEntIntraVAT();
			return estValide;
		}
	} 	

	//chercher sociÃ©tÃ© avec siren
	function searchSociete() {
		var f = window.document.forms[0];
		
		if (f && f.elements['EntCorpName']) {
			entCorpName = f.elements['EntCorpName'].value;
		} 
		if (f && f.elements['EntSiret']) {
			siren = f.elements['EntSiret'].value;
		} 
		if (f && f.elements['EntZip']) {
			entZip = f.elements['EntZip'].value;
		} 
		
		if (siren != '') {
			if (siren.length > 9) {
				try {
					siren = siren.substring(0,9);
				} catch(e) {
				}
			}
			window.open('http://www.societe.com/cgi-bin/recherche?rncs=' + siren);
		} else if (entCorpName != '' || entZip != '') {
			if (entZip != '') {
				entZip = entZip.substring(0,2);
			}
			window.open('http://www.societe.com/cgi-bin/liste?nom=' + entCorpName + '&dep=' + entZip);
		} else {
			window.open('http://www.societe.com');
		}
	}
	
function stripPhoneNo(phoneNo) {
	if (phoneNo == '') {
		return '';
	}
	
	// We have to strip the extraneous characters from the phone to make it work properly
	var finalPhone = '';
	var haveParan = false;
	
	for (var cnt = 0; cnt < phoneNo.length; cnt++) {
		var charPhoneNo = phoneNo.charAt(cnt);
		if (charPhoneNo == '(') {
			haveParan = true;
			continue;
		}
		
		if (charPhoneNo == ')') {
			haveParan = false;
			continue;
		}
		
		if (haveParan) {
			continue;
		}
			
		switch (charPhoneNo) {
		case '+':
		case '.':
		case ' ':
			continue;
		}
		
		finalPhone += charPhoneNo;
	}
	
	return finalPhone;
}
<% if (hasDoubloon) { %>
	$(function() {
		<% for (String field : listFieldsForDbl) { %>
		 $('#<%= field %>').bind('change', function() {
	  		checkDoublon('<%= field %>', $('#<%= field %>').val());
		});
		<% } %>
	
	});
<% } %> 	

	function checkDoublon(field, value){
		<% if (isCreation) { %>
			checkArrayValue(field, value);
		<% } else { %>
			updateArrayValues();
		<% } %>
		var jsonstring = JSON.stringify(fieldsList);

		var data = {};
		data.objID = '<%= objID %>';
		<% if (Utils.isEmpty(id)) {
			} else { %>
			data.id = '<%= id %>';
		<% } %>
		
		data.notDoublon = $("#notDoublon").val();
		data.fieldsList = jsonstring;
		
		$.ajax({
			data: data,
			url: "<fl:webapp/>/find_double.fl",
			timeout: 20000,
			contentType: "application/json;charset=utf-8",
			dataType: 'json',
			async: true,
			success: function (data) {
				if (data.status == 0) {
					return;
				} else {
					data.objID = '<%= objID %>';
					namePopup = "doublonPopup";
					urlPopup = "<fl:webapp/>/open_popup_doublon.fl";
					openAjaxPopup(namePopup, urlPopup, data);
				}
			},
            error:function (xhr, ajaxOptions, thrownError){
                    //alert(xhr.status);
                    //alert(thrownError);
            }    
	 	});
	}
	
	function updateArrayValues() {
		//fieldsList = new Array;
		fieldsList = {};
		<% for (String field : listFieldsForDbl) { %>
			if ($("#<%= field %>").val() == undefined) {
				fieldsList['<%= field %>'] = '';
			} else {	
				fieldsList['<%= field %>'] = $("#<%= field %>").val();
			}	
		<% } %>
	};
	
	function checkArrayValue(field, value) {
		fieldsList[field] = value;
	};
	
	function isNotDoublon(id, poids){
		$("#tr_" + id.toString()).hide();
		$("#notDoublon").val($("#notDoublon").val() + id + '#'+ poids + ';');
	}
	function openObjPopup(id){
		window.open('<fl:webapp/>/read_enterprise.fl?id='+id, 'Enterprise', 'menubar=no,status=no,toolbar=no,scrollbars=yes,resizable=yes,width=1024,height=768');
	}
	
	function openAjaxPopup(namePopup, urlPopup, jsonResponse){
		var cmp = 0;
		jQuery.openPopupLayer({
			name: namePopup,
			width: "auto",
			height: "auto",
			url: urlPopup,
			cache: true,
			success: function () {
				$("#doublon_content").append("<thead><tr valign=\"top\">" +
								"<th width='5px'>&nbsp;</th>" +
								<% for (String fieldDisp : fieldDisplay) { %>
								"<th><%= fieldDisp %></th>" +
								<% } %>
							"</tr></thead>");
				$.each(jsonResponse.doublons, function(i, doublon) {
					var str = $("#notDoublon").val();
					if (str.indexOf(doublon.id) > -1) {
					} else {
						cmp++;
						var lignCssClass = (i%2 == 0) ? "even" : "odd"; 
						var content = "<tr id=\"tr_" + doublon.id.toString() + "\" class=\"" + lignCssClass + " bean\" ";
						var poidsColor = "";
						if (doublon.poids >= seuilcert) {
							poidsColor = "background-color: #F2D5D9;";
						} else {
							poidsColor = "background-color: #FBFAC8;";
						}
						content += ">" +
									"<td width=\"20px\" class=\"\" style=\"" + poidsColor + "\">" +
										"<a href=\"javascript:openObjPopup('" + doublon.id + "')\"><img title=\"Voir\" alt=\"Voir\" src=\"<fl:webapp/>/icons/ico/zoom.gif\"></a> " +
										"<a href=\"javascript:doMerge('" + doublon.id + "')\"><img title=\"Fusionner\" alt=\"Fusionner\" src=\"<fl:webapp/>/icons/fusion.gif\"></a> " +
										"<a href=\"javascript:isNotDoublon('" + doublon.id + "','" + doublon.poids + "')\"><img title=\"Enregistrer en non-doublon\" alt=\"Enregistrer en non-doublon\" src=\"<fl:webapp/>/icons/ico/supprimer.gif\"></a>" +
									"</td>" +
									<% for (String field : listFieldsForDbl) { %>
									"<td class=\"dataValue\">" + doublon.<%= field %> + "</td>" +
									<% } %>
								"</tr>";									
					 	$("#doublon_content").append(content);
				 	}
				});	
		    },
	        error: function () {
				//alert("Erreur lors de l'ouverture de la popup !");
		    }
		});
	}
	
function doYellowPage() {
	var f = window.document.forms[0];
	var phone = "";
	if (f && f.elements['EntPhone']) {
		phone = f.elements['EntPhone'].value;
	} 
	phone = stripPhoneNo(phone);
	if (phone == '') {
		alert('<fl:getMessage code="M60F9" alt="Une recherche sur l\'annuaire inversÃ© Amabis ne peut Ãªtre lancÃ©e si aucun numÃ©ro de tÃ©lÃ©phone n\'a Ã©tÃ© fourni." js="true"/>');				
	} else {
		//window.parent.location = "<fl:webapp/>/check_phone_enterprise.fl?id=<%=id%>&type=Enterprise&EntPhone=" + phone;
		//doAjax('<fl:webapp/>/check_phone_enterprise.fl?id=<%=id%>&EntPhone=' + phone + '&type=Enterprise');
		presentFieldsValue();
		f.action = '<fl:link url="<%= \"/check_phone_enterprise.fl?id=\" + ( id != null ? id : \"\") %>"/>' + '&EntPhone=' + phone + '&type=Enterprise';
		doExitConf = false;
		f.submit();
	}
}

function doMerge(id) {
	var f = document.forms[0];
	f.action = "<fl:webapp/>/save_merge_enterprise.fl?objMasterID=" + id;
	f.submit();
}

function doCalculateEntIntraVAT() {
	var f = document.forms[0];
	var entSiret = f.EntSiret.value;
	var entSiren = entSiret.length > 9 ? entSiret.substring(0, 9) : '';
	var entCtrID = f.EntCtrID.options[f.EntCtrID.selectedIndex].value;
	if (entSiren != '') {
		doAjax('<fl:webapp/>/do_calculate_entintravat.fl?EntSiren=' + entSiren + '&EntCtrID=' + entCtrID);
	}
}

function doDisplayEntIntraVAT() {
	if ('<%= entFRCtrCode %>' == $("#EntCtrID").val()) {
		//FR
		$("#EntIntraVAT").attr("disabled", true);
		$("#EntIntraVAT").attr("readonly", true);
		$("#EntIntraVAT").addClass("transRead");
		doCalculateEntIntraVAT();
	} else {
		$("#EntIntraVAT").removeAttr("disabled");
		$("#EntIntraVAT").removeAttr("readonly");
		$("#EntIntraVAT").removeAttr("onfocus");
		$("#EntIntraVAT").removeClass("transRead");
	}
}

function doEntTypoStructure_Change() {	
	doRefreshEnterprise();
}

function doEntRegionID_Change() {	
	doRefreshEnterprise();
}

function doEntDepartmentID_Change() {	
	doRefreshEnterprise();
}

function doRefreshEnterprise() {		
	var f = document.forms[0];
	f.action = "<fl:webapp/>/refresh_enterprise_custom.fl";
	f.submit();
}

function loadRegion(ctrID) {
	if (ctrID == undefined || ctrID == null || ctrID == '') {
		$("#EntRegionID_").html("<option value=''>&nbsp;</option>");
		$("#EntRegionID_").width($("#div_EntRegionID_").width());
		return;
	}
	$.getJSON("<fl:webapp/>/get_enterprise_regions.fl?ctrID=" + ctrID, function(data) {
		if (data != null) {
			var optContent = "<option value=''>&nbsp;</option>";
			for (var i = 0; i < data.length; i++) {
				var optValue = data[i].value;
				var optText = data[i].text;
				optContent += "<option"
				if (optValue == '<%=entCtrID%>') {
					optContent += " selected";
				}	
				optContent += " value='" + optValue + "'>" + optText + "</option>"
			}
			$("#EntRegionID_").html(optContent);
			$("#EntRegionID_").width($("#div_EntRegionID_").width());//For IE7
		}	
	});
}
	
function loadDepartment(rg_ID) {
	if (rg_ID == undefined || rg_ID == null || rg_ID == '') {
		$("#EntDepartmentID_").html("<option value=''>&nbsp;</option>");
		$("#EntDepartmentID_").width($("#div_EntDepartmentID_").width());
		return;
	}
	$.getJSON("<fl:webapp/>/get_enterprise_departments.fl?rg_ID=" + rg_ID, function(data) {
		if (data != null) {
			var optContent = "<option value=''>&nbsp;</option>";
			for (var i = 0; i < data.length; i++) {
				var optValue = data[i].value;
				var optText = data[i].text;
				optContent += "<option"
				if (optValue == '<%=entregionID%>') {
					optContent += " selected";
				}	
				optContent += " value='" + optValue + "'>" + optText + "</option>"
			}
			$("#EntDepartmentID_").html(optContent);
			$("#EntDepartmentID_").width($("#div_EntDepartmentID_").width());//For IE7
		}
	});
}

function doSubmit() {
	var f = document.forms[0];
	var filter = /^[0-9-+() ]+$/;
	if (f.EntMail_){
		var entmailVal = f.EntMail_.value;
		
		if (entmailVal != null && entmailVal.length > 0){
			if (!checkEmail(entmailVal)){ 
				alert('<fl:getMessage code="LF188" alt="Veuillez vérifier votre adresse mail principal." js="true"/>');
				f.EntMail_.focus();
				return false;
			}
		}
	}
	
	if (f.EntSecondMail_){
		var entmailVal = f.EntSecondMail_.value;
		if (entmailVal != null && entmailVal.length > 0){
			if (!checkEmail(entmailVal)){ 
				alert('<fl:getMessage code="LF189" alt="Veuillez vérifier votre adresse mail secondaire." js="true"/>');
				f.EntSecondMail_.focus();
				return false;
			}
		}
	}
	
	if(f.EntWeb) {
		var entwebVal = f.EntWeb.value;
		if(entwebVal != null && entwebVal.length > 0){
			if(!checkUrl(entwebVal)) {
				alert('<fl:getMessage code="L6633" alt="Veuillez vérifier l\\\'adresse de votre site web." js="true"/>');
				f.EntWeb.focus();
				return false;
			}
		}
	}
	
	if(f.EntPhone) {
		var entphoneVal = f.EntPhone.value;
		if(entphoneVal != null && entphoneVal.length > 0){
			if(!filter.test(entphoneVal)) {
				alert('<fl:getMessage code="MF08C" alt="Veuillez vérifier le numéro de téléphone principal." js="true"/>');
				f.EntPhone.focus();
				return false;
			}
		}
	}
	
	if(f.EntSecondPhone_) {
		var entsecondphoneVal = f.EntSecondPhone_.value;
		if(entsecondphoneVal != null && entsecondphoneVal.length > 0){			
			if(!filter.test(entsecondphoneVal)) {
				alert('<fl:getMessage code="MF08D" alt="Veuillez vérifier le numéro de téléphone secondaire." js="true"/>');
				f.EntSecondPhone_.focus();
				return false;
			}
		}
	}
	
	if(f.EntFax) {
		var entfaxVal = f.EntFax.value;
		if(entfaxVal != null && entfaxVal.length > 0){
			if(!filter.test(entfaxVal)) {
				alert('<fl:getMessage code="MF08E" alt="Veuillez vérifier le fax." js="true"/>');
				f.EntFax.focus();
				return false;
			}
		}
	}
	
	return true;
}

</script>

<fl:form action="<%= actionSave %>" bean="Enterprise">
	
	<input type="hidden" name="notDoublon" id="notDoublon" value="">
	<% if(typoStructID.equalsIgnoreCase(departID)) { 
		if(regiondedepartementID != null) {	%>
	 	<input type="hidden" name="EntRegionID_" value="<%=regiondedepartementID%>">
		<%} else {%> 
		<input type="hidden" name="EntRegionID_" value="">
		<%}
		
		if(paysderegionID != null) {%>
	 	<input type="hidden" name="EntCtrID" value="<%=paysderegionID%>">
		<%} else {%> 
		<input type="hidden" name="EntCtrID" value="">
		<%}%>
	<%} %>
	<% if(typoStructID.equalsIgnoreCase(regionID)) { 
		if(paysderegionID != null) {%>
	 	<input type="hidden" name="EntCtrID" value="<%=paysderegionID%>">
		<%} %>
	<%} %>
	
	<fl:bigTabs objectTitle="<%= (isAssociation)? Utils.getMessage(session, \"LF09E\", \"Association\") : ((isResto)? Utils.getMessage(session, \"FF13A\", true, \"Restaurant\") : ((isPartenaire)?Utils.getMessage(session, \"FF071\", true, \"Partenaire\") : Utils.getMessage(session, \"F002B\", \"Entreprise\"))) %>" listTitle="<%= Utils.getMessage(session, \"L30A2\", false, true, \"Liste des entreprises\") %>" ou="<%= \"/edit_enterprise.fl\" + (id != null ? \"?id=\" + id : \"\") %>">

		<table class="container" cellpadding="0">
			<%-- 
			<tr>
				<td colspan="5">
					<table class="container" cellpadding="0">
						<tr class="fieldline">
							<td class="labelTitreFiche">
								<fl:label field="EntCorpName" labelClassName="titreFiche"/>
							</td>
							<td class="fieldTitreFiche">
								<fl:input property="EntCorpName" mandatoryMsgCode="M3001" onblur="if (this.form.EntAcronym.value == '') this.form.EntAcronym.value = this.value;"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr><td colspan="5" class="ligne_separation"/></tr>--%>
			<tr>
				<td class="column2">
					<%-- begin : Adresse --%>
					<table class="container" cellpadding="0">
						<tr class="fieldline">
							<td class="dataLabel"><fl:label field="EntCorpName" labelClassName="titreFiche"/></td>
							<td class="dataValue"><fl:input property="EntCorpName" mandatoryMsgCode="M3001" onblur="if (this.form.EntAcronym && this.form.EntAcronym.value == '') this.form.EntAcronym.value = this.value;"/></td>
						</tr>
						<% if(!isAssociation && !isResto && !isPartenaire){ %>
							<fl:fieldEdit property="EntHotelID_" alt=""/>
						<% }else if(isResto){ %>
							<fl:fieldEdit property="EntRatachHotelID_"/>
							<%-- <fl:fieldEdit property="EntRestoDispName_"/>
							<fl:fieldEdit property="EntRestoTriName_"/> --%>
						<% } %>
						<fl:fieldEdit property="EntTriName_" mandatoryMsgCode="MF070"/>
						<td class="titreInterneSmalltabs" colspan="5">
						<fl:getMessage code="LF002" alt="Adresse Postale"/>
						</td>
						<tr><td colspan="5" class="ligne_separation"/></tr>	
						<tr class="fieldline">
							<td class="dataLabel"><fl:getMessage code="FF1D0" alt="Numéro/Nature/Libellé Voie"/></td>
							<td class="dataValue"><div class="fieldTable" >
									<table class="fieldTable" cellpadding="0">
										<tr>
											<td class="smallFieldPart">
												<fl:input property="EntVoieNum_" width="auto"/>
											</td>
											<td class="smallFieldPart">
												<%-- <fl:input property="EntNatureVoieID_" mandatoryMsgCode="MF075" width="auto"/> --%>
												<fl:input property="EntNatureVoieID_" width="auto"/>
											</td>
											<td class="bigFieldPart">
												<%-- <fl:input property="EntLblVoie_" mandatoryMsgCode="MF076" /> --%>
												<fl:input property="EntLblVoie_" mandatoryMsgCode="MF076" />
											</td>
										</tr>
									</table>
							</div>
							</td>
						</tr>
						<fl:fieldEdit property="EntGeoCplt_" alt="" />
						<fl:fieldEdit property="EntPtRmCourrier_" alt="" />
						<fl:fieldEdit property="EntBP_"/>
						<fl:fieldEdit property="EntLieuDit_" alt="" />
						<tr class="fieldline">
							<td class="dataLabel"><fl:getMessage code="FF096" alt="Code Postal/Ville"/></td>
							<td class="dataValue"><div class="fieldTable" >
									<table class="fieldTable" cellpadding="0">
										<tr>
											<td class="smallFieldPart">
												<!--  <input class="input text" type="text" id="EntZip" name="EntZip" value="<fl:getProperty name="Enterprise" property="EntZip" alt=""/>" size="4" style="width: auto;"/> -->
												<fl:input property="EntZip" mandatoryMsgCode="MF074" width="auto"/>
											</td>
											<td class="bigFieldPart">
												<!-- <input class="input text" type="text" maxlength="50" id="EntCity" onblur="this.value = checkString(this.value, 'upper');" name="EntCity" value="<fl:getProperty name="Enterprise" property="EntCity" alt=""/>" style="width:100%" /> -->
												<fl:input property="EntCity" mandatoryMsgCode="MF073"/>
											</td>
										</tr>
									</table>
								</div></td>
						</tr>
						<% if(typoStructID.equalsIgnoreCase(departID) || typoStructID.equalsIgnoreCase(regionID)) { %>
						<fl:fieldRead property="EntCtrID"/>
						<%} else {%>
						<% if(!isPartenaire){ %>
							<fl:fieldEdit property="EntCtrID" alt="" mandatoryMsgCode="MF06F"/>
						<%}%>
						<%} %>
						<% if(isPartenaire){ %>
						<fl:fieldEdit property="EntCtrID" alt="" onchange="loadRegion(this.value);" mandatoryMsgCode="MF06F"/>
						<fl:fieldEdit property="EntRegionID_" alt="" onchange="loadDepartment(this.value);"/>
						<fl:fieldEdit property="EntDepartmentID_" alt=""/>
						<% } %> 
						<%--
						<tr class="fieldline">
							<td class="dataLabel" rowspan="5">
								<fl:getMessage code="F2012" alt="Adresse"/>&nbsp;
								<fl:addressNormalisation bean="Enterprise" operation="edit" 
								addressStatusField="EntAddressStatus" getAddressMethod="getAddress" setAddressMethod="setAddress" getStatusMethod="getAddressNormalisationStatus" 
								setStatusMethod="setAddressNormalisationStatus" 
								returnUrl="/edit_enterprise.fl"/>
							</td>
							<td class="dataValue">
								<fl:input property="EntAd1"/>
							</td>
						</tr>
						<tr class="fieldline">
							<td class="dataValue">
								<fl:input property="EntAd2"/>
							</td>
						</tr>
						<tr class="fieldline">
							<td class="dataValue">
								<fl:input property="EntAd3"/>
							</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="EntZip" name="EntZip" value="<fl:getProperty name="Enterprise" property="EntZip" alt=""/>" size="4" style="width: auto;"/>
											</td>
											<td class="bigFieldPart">
												<input class="input text" type="text" maxlength="50" id="EntCity" onblur="this.value = checkString(this.value, 'upper');" name="EntCity" value="<fl:getProperty name="Enterprise" property="EntCity" alt=""/>" style="width:100%" />
											</td>
										</tr>
									</table>
								</div>
							</td>
						</tr>
						<tr class="fieldline">
							<td class="dataValue"><fl:input property="EntCtrID"/><input type="hidden" name="country" value="<%= entCtrID --%><%--</td>
						</tr>
					</table>
						
					 --%>
					<table class="container" >
						<tr><td colspan="5" class="ligne_separation"/></tr>		
						<fl:fieldEdit property="EntPhone" mandatoryMsgCode="MF00B" format="phone"/>
						<fl:fieldEdit property="EntSecondPhone_"/>
						<fl:fieldEdit property="EntFax"/>
						<fl:fieldEdit property="EntMail_" mandatoryMsgCode="MF071"/>
						<fl:fieldEdit property="EntSecondMail_" />
						<%if(!isAssociation && !isPartenaire) {%>
						
						<fl:fieldEdit property="EntBillingMail_" mandatoryMsgCode="MF072"/>
						<%} %>
						<fl:fieldEdit property="EntWeb"/>
						<% if(!isAssociation && !isPartenaire) { %>
						<% if (typOrganisation == null ) {%>
						<tr><td colspan="5" class="ligne_separation"/></tr>		
						<fl:fieldEdit property="EntTyeID" except="ASSO;PART" mandatoryMsgCode="LF183" alt=""/>
						<%} else if ( (id != null && typOrganisation != null) || (id == null && typOrganisation != null)) {%>
						<tr class="fieldline">
						<td id="EntTyeID_label" class="dataLabel"><fl:label code="FF03C" label="Type de Tiers"/></td>
						<td id="EntTyeID_value" class="dataValue">
						<div class="input text">
							<input id="EntTyeID" type="hidden" value="<%=typOrganisation%>" name="EntTyeID" >
							<input id="EntTyeIDVal" class="input text" value="<%=dico.getRefDisp(session, "EntTyeID", typOrganisation)%>" name="EntTyeIDVal" readonly>
						</div>
						</td>
						</tr>
						<%} %>
						<%} %>
						<% if(!isAssociation && !isPartenaire) { %>
						<tr><td colspan="5" class="ligne_separation"/></tr>	
						<tr><td colspan="5" class="ligne_separation"/></tr>	
						<fl:fieldEdit property="EntActsID_" mandatoryMsgCode="MF077"/>
						<td class="titreInterneSmalltabs" colspan="5">
						<fl:getMessage code="LF004" alt="Structure Locale"/>
						</td>
						<tr><td colspan="5" class="ligne_separation"/></tr>	
						<fl:fieldEdit property="EntStructureLocalID_" query="EntTyeID:RefVal = 'ASSO'"/>
						<% } else if (isPartenaire) {%>
						<tr><td colspan="5" class="ligne_separation"/></tr>		
						<% if (typOrganisation == null ) {%>
							<fl:fieldEdit property="EntTyeID"/>
							<%} else if ( (id != null && typOrganisation != null) || (id == null && typOrganisation != null)) {%>
							<tr class="fieldline">
							<td id="EntTyeID_label" class="dataLabel"><fl:label code="FF03C" label="Type de Tiers"/></td>
							<td id="EntTyeID_value" class="dataValue">
							<div class="input text">
								<input id="EntTyeID" type="hidden" value="<%=typOrganisation%>" name="EntTyeID" >
								<input id="EntTyeIDVal" class="input text" value="<%=dico.getRefDisp(session, "EntTyeID", typOrganisation)%>" name="EntTyeIDVal" readonly>
							</div>
							</td>
							</tr>
							<fl:fieldEdit property="EntSousGrp_" />
							<tr><td colspan="5" class="ligne_separation"/></tr>	
							<fl:fieldEdit property="EntInterlocuteurID_" />
						<%} %>
						<%} %>
					</table>
				</td>
				<td class="separation"><div class="separation"></div></td>
				<td class="column2">
					<table class="container" cellpadding="0">
						<% if(isAssociation) { %>
						<% if( typOrganisation == null ) {%>
						<fl:fieldEdit property="EntTyeID"/>
						<%} else if ( (id != null && typOrganisation != null) || (id == null && typOrganisation != null)) {%>
						<tr class="fieldline">
						<td id="EntTyeID_label" class="dataLabel"><fl:label code="FF03C" label="Type de Tiers"/></td>
						<td id="EntTyeID_value" class="dataValue">
						<div class="input text">
							<input id="EntTyeID" type="hidden" value="<%=typOrganisation%>" name="EntTyeID" >
							<input id="EntTyeIDVal" class="input text" value="<%=dico.getRefDisp(session, "EntTyeID", typOrganisation)%>" name="EntTyeIDVal" readonly>
						</div>
						</td>
						</tr>
						<%} %>
						<%} %>
						<% if(!isAssociation && !isPartenaire) { %>
						
						<fl:fieldEdit property="EntPhotoID_"/>
						<td class="titreInterneSmalltabs" colspan="5">
						<fl:getMessage code="L8267" alt="Localité"/>
						</td>
						<tr><td colspan="5" class="ligne_separation"/></tr>	
						<fl:fieldEdit property="EntLocalityID_"/>
						<tr><td colspan="5" class="ligne_separation"/></tr>	
						<fl:fieldEdit property="EntNextAuditDt_"/>
<%-- 						<fl:fieldRead property="EntCheNbID_"  alt=""/>					 --%>
<%-- 						<fl:fieldRead property="EntCocNbID_"  alt=""/> --%>
						<tr><td colspan="5" class="ligne_separation"/></tr>	
						<fl:fieldEdit property="EntRefLngID_"  alt=""/>
						<tr><td colspan="5" class="ligne_separation"/></tr>	
						<td class="titreInterneSmalltabs" colspan="5">
						<fl:getMessage code="FF01F" alt="Classement étoile"/>
						</td>
						<tr><td colspan="5" class="ligne_separation"/></tr>	
						<fl:fieldEdit property="EntStarClassID_"  alt=""/>
						<fl:fieldEdit property="EntNormStarDt_"/>
<%-- 						<fl:fieldRead property="EntReclassDate_"/> --%>
						<tr><td colspan="5" class="ligne_separation"/></tr>	
						<fl:fieldEdit property="EntPmsID_"  alt=""/>					
						<fl:fieldEdit property="EntAnnexe_"/>
						<%} else if (isAssociation) {%>
						<td class="titreInterneSmalltabs" colspan="5">
						<fl:getMessage code="LF09E" alt="Association"/>
						</td>
						<fl:fieldEdit property="EntTypoStructure_" onchange="doEntTypoStructure_Change();" alt=""/> 	 
						<% if(typoStructID.equalsIgnoreCase(departID)) { %>
						<tr>
							<td class="titrePartie"><fl:getMessage code="FF01D" alt="Département Association"/></td>
						
							<td class="dataValue noPaddingLeft">
								<fl:input property="EntDepartmentID_" onchange="doEntDepartmentID_Change();" alt="" mandatoryMsgCode="MF06D"/>
							</td>
						</tr>
						<tr>
							<td class="titrePartie"><fl:getMessage code="FF01C" alt="Région Association"/></td>
						
							<td class="dataValue noPaddingLeft">
								<fl:input property="EntRegionID_" alt="" readOnly="true"/>
							</td>
						</tr>
						 
						<%} else if (typoStructID.equalsIgnoreCase(regionID)) {%>
						<tr>
							<td class="titrePartie"><fl:getMessage code="FF01C" alt="Région Association"/></td>
						
							<td class="dataValue noPaddingLeft">
								<fl:input property="EntRegionID_" onchange="doEntRegionID_Change();" mandatoryMsgCode="MF06E"/> 
							</td>
						</tr>
						 
						<%}%>
						<fl:fieldEdit property="EntAssoDissolDt_"/>
						<tr class="fieldline">
							<td class="labelTitreFiche">
								<fl:label field="EntEditListLogis_"/>
							</td>
							<td class="dataValue">
								<fl:input property="EntEditListLogis_"/>
							</td>
						</tr>	
						<fl:fieldEdit property="EntAnimStatut_"/>
						<fl:fieldEdit property="EntAffectedTaux_"/>

						<%} else if (isPartenaire) {%>
						<fl:fieldEdit property="EntPhotoID_"/>
						<%} %>
					</table>
				</td>
			</tr>
		</table>
			<table class="container" cellpadding="0">
			<tr class="ligne_separation"><td></td></tr>
			<tr>
				<td class="titrePartie"><fl:getMessage code="L64B4" alt="Commentaires"/></td>
			</tr>
			<tr>
				<td class="dataValue noPaddingLeft">
					<fl:input property="EntNotes" style="width:100%" 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>
		<link href="<fl:webapp/>/css/smalltabs_css.jsp" rel="stylesheet" type="text/css">
		<fl:smallTabs name="EnterpriseTabs">
		<%if(isPartenaire) {%>
		<%-- Infos Société --%>
			<fl:sTab id="infosoc" title="<%= Utils.getMessage(session, \"LF005\", false, true, \"Infos société\") %>">
			<table class="container" cellpadding="0">
			<tr>
			<td class="column3">
				<table class="data_column" cellpadding="0">
					<fl:fieldEdit property="EntSiret"/>
					<fl:fieldEdit property="EntSiren"/>
					<tr><td colspan="5" class="ligne_separation"/></tr>
					<fl:fieldEdit property="EntRCS_"/>
					<fl:fieldEdit property="EntCodeAPE_"/>
					<tr><td colspan="5" class="ligne_separation"/></tr>
					<fl:fieldEdit property="EntTVAIntracom_"/>
				</table>
			</td>
			<td class="separation"><div class="separation"></div></td>
			<td class="column3">
				<table class="data_column" cellpadding="0">
					<td class="titreInterneSmalltabs" colspan="5">
					<fl:getMessage code="LF00E" alt="Coordonnées GPS"/>
					</td>
					<tr><td colspan="5" class="ligne_separation"/></tr>
					<fl:fieldEdit property="EntGPSX_"/>
					<fl:fieldEdit property="EntGPSY_"/>
				</table>
			</td>
			<td class="separation"><div class="separation"></div></td>
			<td class="column3">
				<table class="data_column" cellpadding="0">
					<td class="titreInterneSmalltabs" colspan="5">
					<fl:getMessage code="LF12D" alt="Coordonnées Bancaires"/>
					</td>
					<fl:fieldEdit property="EntBanque_"/>
					<fl:fieldEdit property="EntIBAN_"/>
					<fl:fieldEdit property="EntBIC_"/>
				</table>
			</td>
			</tr>
			</table>
			</fl:sTab>
		<%} else if(isAssociation) {%>
		<%-- Infos Société --%>
			<fl:sTab id="infosoc" title="<%= Utils.getMessage(session, \"LF005\", false, true, \"Infos société\") %>">
			<table class="container" cellpadding="0">
			<tr>
			<td class="column3">
				<table class="data_column" cellpadding="0">
					<fl:fieldEdit property="EntDispName_"/>
					<fl:fieldEdit property="EntSiret"/>
				</table>
			</td>
			<td class="separation"><div class="separation"></div></td>
			<td class="column3">
				<table class="data_column" cellpadding="0">
					<fl:fieldEdit property="EntSiren"/>
					<fl:fieldEdit property="EntRCS_"/>
				</table>
			</td>
			<td class="separation"><div class="separation"></div></td>
			<td class="column3">
				<table class="data_column" cellpadding="0">
					<fl:fieldEdit property="EntCodeAPE_"/>
					<fl:fieldEdit property="EntTVAIntracom_"/>
				</table>
			</td>
			</tr>
			</table>
			</fl:sTab>
		<%} else if(!isAssociation && !isPartenaire) {%>
		<%-- Infos Société --%>
			<fl:sTab id="infosoc" title="<%= Utils.getMessage(session, \"LF005\", false, true, \"Infos société\") %>">
			<table class="container" cellpadding="0">
			<tr>
			<td class="column3">
				<table class="data_column" cellpadding="0">
					<fl:fieldEdit property="EntDispName_"/>
					<fl:fieldEdit property="EntSiret"/>
					<fl:fieldEdit property="EntSiren"/>
					<tr><td colspan="5" class="ligne_separation"/></tr>
					<fl:fieldEdit property="EntRCS_"/>
					<fl:fieldEdit property="EntCodeAPE_"/>
					<tr><td colspan="5" class="ligne_separation"/></tr>
					<fl:fieldEdit property="EntTVAIntracom_"/>
					<tr><td colspan="5" class="ligne_separation"/></tr>
					<fl:fieldEdit property="EntCA_"/>
					<fl:fieldEdit property="EntNbEmployees_"/>
					<fl:fieldEdit property="EntAtvID_"/>
				</table>
			</td>
			<td class="separation"><div class="separation"></div></td>
			<td class="column3">
				<table class="data_column" cellpadding="0">
					<td class="titreInterneSmalltabs" colspan="5">
					<fl:getMessage code="LF00E" alt="Coordonnées GPS"/>
					</td>
					<tr><td colspan="5" class="ligne_separation"/></tr>
					<fl:fieldEdit property="EntGPSX_"/>
					<fl:fieldEdit property="EntGPSY_"/>
					<tr><td colspan="5" class="ligne_separation"/></tr>
					<td class="titreInterneSmalltabs" colspan="5">
					<fl:getMessage code="LF12D" alt="Coordonnées Bancaires"/>
					<tr><td colspan="5" class="ligne_separation"/></tr>
					</td>
					<fl:fieldEdit property="EntBanque_"/>
					<fl:fieldEdit property="EntIBAN_"/>
					<fl:fieldEdit property="EntBIC_"/>
				</table>
			</td>
			<td class="separation"><div class="separation"></div></td>
			<td class="column3">
				<table class="data_column" cellpadding="0">
				<fl:fieldEdit property="EntLimitedResto_"/>
				<fl:fieldEdit property="EntMajGA_"/>
				</table>
			</td>
			</tr>
			</table>
			</fl:sTab>
			<%-- Prestations --%>
			<fl:sTab id="prestasoc" title="<%= Utils.getMessage(session, \"LF006\", false, true, \"Prestations\") %>">
			<table class="container" cellpadding="0">
			<tr>
			<td class="column2">
				<table class="data_column" cellpadding="0">
					<fl:fieldEdit property="EntThema_" type="list"/>
					<fl:fieldEdit property="EntBankCardID_" />
				</table>
			</td>
			<td class="separation"><div class="separation"></div></td>
			<td class="column2">
				<table class="data_column" cellpadding="0">
					<fl:fieldEdit property="EntSpokLngID_"/>
				</table>
			</td>
			</tr>
			</table>
			</fl:sTab>
		<%} %>
			<fl:sTab id="ATTACHMENT" title="<%= Utils.getMessage(session, \"L201C\", \"Documents joints\") %>">
				<fl:attach name="Enterprise" colID="EntAttID" edit="true" />
			</fl:sTab>
		</fl:smallTabs>
	</fl:bigTabs>
</fl:form>
