<%/******************************************************************************
 * 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.Utils" %>
<%@ page import="com.edeal.frontline.DataDictionary" %>
<%@ page import="com.edeal.frontline.FieldNotInitializedException" %>
<%@taglib uri="http://www.e-deal.com/taglib/fl" prefix="fl" %>
<jsp:useBean class="com.edeal.frontline.ProductBean" id="Product" scope="request"/>
<link href="<fl:webapp/>/css/smalltabs_css.jsp" rel="stylesheet" type="text/css"> 
<link rel="stylesheet" type="text/css" href="<fl:webapp/>/css/common_css.jsp">

<%
	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 id = null;

	try {
	    id = Product.getID();
	} catch (FieldNotInitializedException fnie) {
	}
	
	if(id==null){
		Product.setCustomProperty("PrdMaxQt_", 50);
	}

	boolean isGroup = false;
	try {
		String prdType = Product.getPrdTypID();
		isGroup = prdType != null && prdType.equals(dico.getRefIdByCode("PrdTypID","GROUPE"));
	} catch (FieldNotInitializedException fnie) {
	}	
	boolean toCalculate = false;
	try {
		String prdTpr = Product.getPrdTprID();
		toCalculate = isGroup && prdTpr != null && prdTpr.equals(dico.getRefIdByCode("PrdTprID","CAL"));
	} catch (FieldNotInitializedException fnie) {
	}
	
	boolean isGesStocks = false;
	try {
		isGesStocks = (Boolean)Product.getCustomProperty("PrdGestionStocks_");
	} catch (FieldNotInitializedException fnie) {
		
	}
	
	String productFamilyID = null;
	String productFamilyVal = "";
	try {
		productFamilyID = (String)Product.getCustomProperty("PrdFamilleProduit_");
		productFamilyVal = dico.getRefCode("PrdFamilleProduit_", productFamilyID);
	} catch (FieldNotInitializedException fnie) {
	}
	
	String label = null;
	try {
		label = (String)Product.getCustomProperty("PrdLabel_");
	} catch (FieldNotInitializedException fnie) {
	}
	
	
	//Evol 36185
	String CotisationAnnulle = dico.getRefIdByCode("Pf_", "Te1", "COTANN");
	String CotisationFixe = dico.getRefIdByCode("Pl_", "Te1", "COTFIX");
	if(id!=null){
		String regleCourante = null;
		try {
			regleCourante = (String)Product.getCustomProperty("PrdRegles_");
		} catch (FieldNotInitializedException fnie) {
		}
		if(regleCourante!=null){
			CotisationFixe = regleCourante;
		}
	}
	
	
%>
<script type="text/javascript" language="javascript">
	function doSubmit() {
	    var f = window.document.forms[0];
	    if (f.PrdPrice && f.PrdPrice.value == "") {
	    	f.PrdPrice.value = 0;
	    }
	    if (f.PrdMaxQt_ && f.PrdMaxQt_.value == "") {
	    	f.PrdMaxQt_.value = 50;
	    }
	    if(f.PrdGestionStocks_){
		    if(f.PrdGestionStocks_.checked) {
		    	if(f.PrdRespProduit_.value == '') {
		    		window.alert('<fl:getMessage code="MF03F" alt="Le responsable produit est obligatoire si la gestion des stocks est activée" js="true"/>');
		    		f.PrdRespProduit_.focus();
		    		return;
		    	}
		    	
		    	if(f.PrdStockMinimum_.value == '') {
		    		f.PrdStockMinimum_.value=0;
		    	}
		    }
	    }
		//presentFieldsValue();
	    var FamilleProduit = document.forms[0].PrdFamilleProduit_.value;
		var IncludedCot = document.forms[0].PrdIncludedInCot_;
		if(FamilleProduit == '<%=CotisationAnnulle%>' && IncludedCot.checked == true){
			if((!document.forms[0].PrdMillesime_.value && !document.forms[0].PrdRegles_.value) || (!document.forms[0].PrdMillesime_.value && document.forms[0].PrdRegles_.value) || (document.forms[0].PrdMillesime_.value && !document.forms[0].PrdRegles_.value) ){
				alert('<fl:getMessage code="M900A" alt="Veuillez saisir le(s) champ(s) obligatoire(s)." js="true"/>');
				return false;
			}
		}
		return true;    
	}

	function doRefresh() {
		var f = window.document.forms[0];
		presentFieldsValue();
		f.action = "<fl:link url="/refresh_product.fl"/>";
		doExitConf = false;
		f.submit();
	}
	
	function hideandshow() {
		var f = window.document.forms[0];
		var gestionstocks = f.PrdGestionStocks_;
	    var visibility = "hidden";
	    $("#lblPrdRespProduit_").css( "background-color","rgb(255, 255, 255)" );
	    
	    if(gestionstocks.checked){
	    	visibility = "visible";
	    	$("#lblPrdRespProduit_").css( "background-color","rgb(253, 203, 204)" );
	    }
	    
	    document.getElementById("stock_min").style.visibility = visibility;
	}
	
	function doOnLoad() {
		$("#lblPrdRespProduit_").css( "background-color","rgb(255, 255, 255)" );
		<% if(isGesStocks) { %>
	    document.getElementById("stock_min").style.visibility = "visible";
	    $("#lblPrdRespProduit_").css( "background-color","rgb(253, 203, 204)" );
		<% } %>
	}
	
	function includedCotisation() {
		var FamilleProduit = document.forms[0].PrdFamilleProduit_.value;
		var IncludedCot = document.forms[0].PrdIncludedInCot_;
		if(FamilleProduit == '<%=CotisationAnnulle%>' && IncludedCot.checked == true){
			document.getElementById('PrdMillesime_').className = 'input number chpsTextObligatoire';
			document.getElementById("PrdRegles__label").style.display = '';
			document.getElementById("PrdRegles__value").style.display = '';
			document.getElementById('PrdRegles_').className = 'input select chpsTextObligatoire';
			document.forms[0].PrdRegles_.value = '<%=CotisationFixe%>';
		}else{
			document.getElementById('PrdMillesime_').className = 'input number';
			document.getElementById("PrdRegles__label").style.display = 'none';
			document.getElementById("PrdRegles__value").style.display = 'none';
			document.getElementById('PrdRegles_').className = 'input select';
			document.forms[0].PrdRegles_.value = '';
		}
	}
	
	/* function doSelectLabel(field) {
		window.open('<fl:link url="/select_label.fl?1=1"/>&field=' + field, 'select_label', 'width=1000,height=500,menubar=no,status=no,resizable=yes');
	}
	
	function doRemoveLabel(field){
		var f = window.document.forms[0];
		if(field == 'PrdLabel_'){
			f.lblPrdLabel_.value='';
			f.PrdLabel_.value = '';
		}
	} */
</script>
<fl:form action="/save_product.fl" bean="Product">
<fl:bigTabs objectTitle="<%= Utils.getMessage(session, \"F203E\", false, true, \"Produit\") %>" ou="<%= \"/edit_product.fl\" + (id != null ? \"?id=\" + id : \"\")%>">
	<% if(null == id) { %>
		<input name="PrdStockActuel_" value="0" type="hidden" >
	<% } %>
    <table class="container" cellpadding="0">
		<tr>
			<td colspan="5" class="width: 100%; margin: 0px; padding: 0px;">
				<table class="container" cellpadding="0">
					<tr class="fieldline">
						<td><fl:label field="PrdName" labelClassName="labelTitreFiche" code="F203F"/></td>
						<td class="fieldTitreFiche"><fl:input property="PrdName" mandatoryMsgCode="M201F"/></td>
					</tr>
				</table>
			</td>
		</tr>
		<tr class="ligne_separation"><td></td></tr>
		<tr>
			<td class="column2">
				<table class="data_column" cellpadding="0">
					<%-- <fl:fieldEdit property="PrdLabel_" mandatoryMsgCode="F203F"/> --%>
					<%-- <tr class="fieldline">
							<td class="dataLabel"><label for="selectFldDisplayLabel"><fl:getMessage code="F2001" alt="Libellé"/></label></td>
							<td class="dataValue">
								<div class="input fieldTable">
									<table class="fieldTable" cellpadding="0">
										<td class="principalText bigFieldPart">
											<div class="fobLeftDiv">
												<input name="lblPrdLabel_" id="lblPrdLabelID_" class="input text" onFocus="this.blur();" style="width: 100%;" type="text" value="<%= label == null ? "" : Utils.getMessage(session, label,  Utils.getMessage(session, "L60E0", "<non spécifié>")) %>"/>
												<input name="PrdLabel_" id="PrdLabel_" type="hidden" value="<%= label != null ? label : "" %>">
											</div>
										</td>
										<td class="smallFieldPart">
											<a id="selectPrdLabel_" href="javascript:doSelectLabel('PrdLabel_')"><img src="<fl:webapp/>/icons/ico/rechercher.gif" alt="" border="0"></a>
											<a href="javascript:doRemoveLabel('PrdLabel_')"><img src="<fl:webapp/>/icons/ico/supprimer.gif" alt="" border="0"></a>
										</td>
									</table>
								</div>
							</td>
						</tr> --%>
					<fl:fieldEdit property="PrdCode" mandatoryMsgCode="L6144"  unicityMsgCode="M60CE"/>
					<fl:fieldEdit property="PrdFamilleProduit_" alt="" mandatoryMsgCode="MF032" onchange="javascript:includedCotisation();doRefresh();"/>
					<tr class="fieldline">
						<td id="PhVoie_label" class="dataLabel"><span style="color:#0000;font-weight: bold;">&nbsp;</span></td>
					</tr>
					<fl:fieldEdit property="PrdDistributeur_" alt="" mandatoryMsgCode="MF030"/>
					<fl:fieldEdit property="PrdFournisseur_" />
					<tr class="fieldline">
						<td id="PhVoie_label" class="dataLabel"><span style="color:#0000;font-weight: bold;">&nbsp;</span></td>
					</tr>
					<fl:fieldEdit property="PrdGestionStocks_" onclick="javascript:hideandshow();"/>
					
					<tr id="stock_min" class="fieldline" style="visibility: hidden;">
						<td class="dataLabel">
							<fl:label field="PrdStockMinimum_"/>
						</td>
						<td class="dataValue">
							<fl:input property="PrdStockMinimum_" />
						</td>						
					</tr>
					   <fl:fieldEdit property="PrdMaxQt_" alt=""/>
					<tr class="fieldline">
						<td id="PhVoie_label" class="dataLabel"><span style="color:#0000;font-weight: bold;">&nbsp;</span></td>
					</tr>
					<tr class="fieldline">
						<td id="PhVoie_label" class="dataLabel"><span style="color:#0000;font-weight: bold;"><fl:getMessage code="LF090" alt="Commercialisation"/></span></td>
					</tr>
					<fl:fieldEdit property="PrdStatut_" alt="" mandatoryMsgCode="MF023"/>
					<fl:fieldEdit property="PrdPrice" postText="&nbsp;&euro;" format="money" mandatoryMsgCode="MF033"/>
					<fl:fieldEdit property="PrdTVADefaut_" alt="" mandatoryMsgCode="MF034" />
					<fl:fieldEdit property="PrdTaxeParafiscale_" alt=""/>
					<tr class="fieldline">
						<td id="PhVoie_label" class="dataLabel"><span style="color:#0000;font-weight: bold;">&nbsp;</span></td>
					</tr>
					<fl:fieldEdit property="PrdType_" alt="" mandatoryMsgCode="MF031"/>
					<fl:fieldEdit property="PrdPubSince" mandatoryMsgCode="MF0BA"/>
					<fl:fieldEdit property="PrdPubTo"/>
					<fl:fieldEdit property="PrdCodeComptable_" mandatoryMsgCode="MF035"/>
					<fl:fieldEdit property="PrdCodeAnalytique_" mandatoryMsgCode="MF036"/>
					<fl:fieldEdit property="PrdCompteFrance_" mandatoryMsgCode="MF037"/>
					<fl:fieldEdit property="PrdCompteExport_" mandatoryMsgCode="MF038"/>
					<fl:fieldEdit property="PrdCompteINTRACOM_" mandatoryMsgCode="MF039"/>
					 <fl:fieldEdit property="PrdCommentaires_" alt=""/>	 
					<%--
					<fl:fieldEdit property="PrdActID"/>
					<fl:fieldEdit property="PrdFamilyID"/>
					<fl:fieldEdit property="PrdTypID" type="buttons" separator="<br>" onclick="doRefresh();"/>
					<% if (isGroup) { %>
						<fl:fieldEdit property="PrdTprID" type="buttons" separator="<br>" onclick="doRefresh();"/>
					<% } %>
					<% if (toCalculate) { %>
						<fl:fieldEdit readOnly="true" format="#,##0.##" property="PrdPrice" postText="&nbsp;&euro;"/>
					<% } else { %>
						<fl:fieldEdit property="PrdPrice" format="#,##0.##" postText="&nbsp;&euro;"/>
					<% } %>
					<fl:fieldEdit property="PrdRopID" alt=" "/>
					<fl:fieldEdit property="PrdTvaID" postText="%"/>
					<fl:fieldEdit property="PrdQualification"/>
					 --%>
				</table>
			</td>
			<td class="separation"><div class="separation"></div></td>	
			<td class="column2">
				<table class="data_column" cellpadding="0">					
					<fl:fieldEdit property="PrdIncludedInCot_" onchange="javascript:includedCotisation();"/>
					<tr class="fieldline">
						<td id="PrdPicID_label" class="dataLabel">
							<fl:label code="F600A"/>
						</td>
						<td id="PrdPicID_value" class="dataValue">
							<fl:attach name="Product" colID="PrdPicID" htmlClass="fob" edit="true" allowedExtensions="'jpg', 'jpeg', 'png', 'gif'"/>
						</td>
					</tr>
					<tr class="fieldline">
						<td id="PhVoie_label" class="dataLabel"><span style="color:#0000;font-weight: bold;">&nbsp;</span></td>
					</tr>
					<tr class="fieldline">
						<td id="PhVoie_label" class="dataLabel"><span style="color:#0000;font-weight: bold;">&nbsp;</span></td>
					</tr>
					<tr class="fieldline">
						<td id="PhVoie_label" class="dataLabel"><span style="color:#0000;font-weight: bold;">&nbsp;</span></td>
					</tr>
					<fl:fieldEdit property="PrdRespProduit_" />
					<tr class="fieldline">
						<td id="PhVoie_label" class="dataLabel"><span style="color:#0000;font-weight: bold;">&nbsp;</span></td>
					</tr>
					<fl:fieldEdit property="PrdID_partenaire_"/>
					<fl:fieldEdit property="PrdTypologieProduit_" mandatoryMsgCode="LF1C9" alt=""/>
					<fl:fieldEdit property="PrdMillesime_" alt=""/>
					<fl:fieldEdit property="PrdCtrID_" alt=""/>
					<fl:fieldEdit property="PrdCtTypID_" alt=""/>
					<fl:fieldEdit property="PrdOrderQst_"/>
					<fl:fieldEdit property="PrdDontApplyTVArules_"/>
					<fl:fieldEdit property="PrdRegles_" alt=""/>
					<%--
									
					<tr class="fieldline">
						<td id="PrdPdfID_label" class="dataLabel">
							<fl:label code="F60C0"/>
						</td>
						<td id="PrdPdfID_value" class="dataValue">
							<fl:attach name="Product" colID="PrdPdfID" htmlClass="fob" allowedExtensions="'pdf'" edit="true"/>
						</td>
					</tr>				
					<fl:fieldEdit property="PrdStock"/>
					<fl:fieldEdit property="PrdPkgID"/>
					<fl:fieldEdit property="PrdCptID"/>
					 --%>
				</table>
			</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="ProductTabs">
<%--
	<fl:sTab id="PRODUCT1" title="<%= context.getAutoDisplayManager().getTitle(session, \"Product\", \"Produit 1\") %>" visible="<%= context.getAutoDisplayManager().hasEntry(\"Product\", \"Produit 1\") %>">
		<fl:autodisplay name="Product" zone="Produit 1" edit="true"/>
	</fl:sTab>
	<fl:sTab id="PRODUCT2" title="<%= context.getAutoDisplayManager().getTitle(session, \"Product\", \"Produit 2\") %>" visible="<%= context.getAutoDisplayManager().hasEntry(\"Product\", \"Produit 2\") %>">
		<fl:autodisplay name="Product" zone="Produit 2" edit="true"/>
	</fl:sTab>
	<fl:sTab id="PRODUCT3" title="<%= context.getAutoDisplayManager().getTitle(session, \"Product\", \"Produit 3\") %>" visible="<%= context.getAutoDisplayManager().hasEntry(\"Product\", \"Produit 3\") %>">
		<fl:autodisplay name="Product" zone="Produit 3" edit="true"/>
	</fl:sTab>
	 --%>
	<fl:sTab id="DescCol" title="<%= Utils.getMessage(session, \"FF11C\", \"Descriptif\") %>">
		<fl:input property="PrdProdCard" rows="6" wrap="soft" width="100%"/>
	</fl:sTab>
	<fl:sTab id="infosComp" title="<%= Utils.getMessage(session, \"FF11D\", \"Informations complémentaires\") %>">
		<fl:input property="PrdInfosComplementaires_" rows="6" wrap="soft" width="100%"/>
	</fl:sTab>
	<fl:sTab id="PtFort" title="<%= Utils.getMessage(session, \"FF120\", \"Forces\") %>">
		<fl:input property="PrdStrength" rows="6" wrap="soft" width="100%"/>
	</fl:sTab>
	<fl:sTab id="PtFaible" title="<%= Utils.getMessage(session, \"FF121\", \"Faiblesses\") %>">
		<fl:input property="PrdWeakness" rows="6" wrap="soft" width="100%"/>
	</fl:sTab>
	<fl:sTab id="PrdAttach" title="<%=Utils.getMessage(session, \"L201C\", \"Documents joints\")%>">
		<fl:attach name="Product" colID="PrdAttID" />
	</fl:sTab>
</fl:smallTabs>
</fl:bigTabs>
</fl:form>

<script type="text/javascript" language="javascript">
includedCotisation();
</script>