<%
/******************************************************************************
 * 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.FieldNotInitializedException" %>
<%@taglib uri="http://www.e-deal.com/taglib/fl" prefix="fl" %>
<jsp:useBean class="com.edeal.frontline.PopulationBean" id="Population" 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 = Population.getID();
} catch (FieldNotInitializedException fnie) {
}
String selID = null;
String reqID = null;
String sjoID = null;
try {
	selID = Population.getPopSelID();
} catch (FieldNotInitializedException ex) {
}
try {
	sjoID = Population.getPopSjoID();
} catch (FieldNotInitializedException ex) {
}
try {
	reqID = Population.getPopReqID();
} catch (FieldNotInitializedException ex) {
}
int popType = 0;
try {
	popType = Population.getPopType();
} catch (FieldNotInitializedException ex) {
}
String salesModel = context.getContextParameter("SalesModel");
String actorUrl = flRequest.computeURL("/read_actor.fl");
String reqUrl = flRequest.computeURL("/read_requester.fl");
String selUrl = flRequest.computeURL("/read_selection.fl");
boolean isAutoDel = false;
try {
	isAutoDel = Population.isPopAutoDel();
} catch (FieldNotInitializedException ex) {
}
%>
<!-- Javascript include -->
<script type="text/javascript" language="javascript">
function refreshSynthesis() {
	doAjax('<fl:link url="<%= \"/refresh_population_synthesis.fl\" + (id != null ? \"?id=\" + id : \"\") %>"/>');
}
function refreshPopulationEntry() {
	myAjaxURL_PopulationEntryList = _grid__PopulationEntryList_js_.getAjaxUrl();
	params={};
	params["PpePopID"] = '<%= id != null ? id : "" %>';
	params["PopType"] = '<%= popType %>';
	_grid__PopulationEntryList_js_.callAjaxForHtml(myAjaxURL_PopulationEntryList,params,false);
}
function refreshRemovedPopulationEntry() {
	myAjaxURL_RemovedPopulationEntryList = _grid__RemovedPopulationEntryList_js_.getAjaxUrl();
	params={};
	params["PpePopID"] = '<%= id != null ? id : "" %>';
	params["PopType"] = '<%= popType %>';
	_grid__RemovedPopulationEntryList_js_.callAjaxForHtml(myAjaxURL_RemovedPopulationEntryList,params,false);
}
function doRemove(ppeID, del) {
	if (del) {
		doAjax('<fl:link url="/delete_object_ajax.fl?type=PopulationEntry" />&id=' + ppeID, removeExcReturn);
	} else {
		doAjax('<fl:link url="/save_object_ajax.fl?type=PopulationEntry&PpeRemoved=true&$$presentFields=PpeRemoved" />&id=' + ppeID, removeExcReturn);
	}
}

function removeExcReturn(arrIndex) {
	if(eDealXmlhttpArr[arrIndex].readyState == 4) {
		var rtrn = trimStr(eDealXmlhttpArr[arrIndex].responseText);

		if (rtrn == '') {
			refreshPopulationEntry();
		} else {
			eval(rtrn);
		}
	}
}

function doAdd(ppeID) {
	doAjax('<fl:link url="/save_object_ajax.fl?type=PopulationEntry&PpeRemoved=false&$$presentFields=PpeRemoved" />&id=' + ppeID, addExcReturn);
}

function addExcReturn(arrIndex) {
	if(eDealXmlhttpArr[arrIndex].readyState == 4) {
		var rtrn = trimStr(eDealXmlhttpArr[arrIndex].responseText);

		if (rtrn == '') {
			refreshRemovedPopulationEntry();
		} else {
			eval(rtrn);
		}
	}
}
function doSubmit() {
	return true;
}
function isAuotDel(){
	var f = document.forms[0];
	if(f.PopAutoDelete.checked){
		f.PopAutoDel.value = "true";		
		}
	else{
		f.PopAutoDel.value= "false";	
		}
		
}
</script>
<fl:form action="/save_population.fl" bean="Population">
	<input type="hidden" name="PopType" id="PopType" value="<fl:getProperty name="Population" property="PopType" alt=""/>"/>
	<fl:bigTabs objectTitle="<%= Utils.getMessage(session, \"F000C\", false, true, \"Population\") %>" ou="<%= \"/edit_population.fl\" + (id != null ? \"?id=\" + id : \"\") %>">
		<table class="container" cellpadding="0">
			<tr>
				<td class="titreFiche" colspan="3">
					<table class="fieldline">
						<tr>
							<td class="labelTitreFiche"><fl:label field="PopName" labelClassName="titreFiche"/></td>
							<td class="fieldTitreFiche"><fl:input property="PopName" mandatoryMsgCode="M60A2"/></td>
						</tr>
					</table>
				</td>				
			</tr>
			<tr class="ligne_separation"><td></td></tr>
<% if (id != null) { %>
			<tr>
				<td class="column2">
					<table class="data_column" cellpadding="0">
						<tr class="fieldline">
							<fl:fieldRead property="PopCrDt" labelCode="F1015"/>
<% 
if (selID != null || reqID != null) {
	if (selID != null) {
%>							<fl:fieldRead property="PopSelID" bean="true" href="true" disp="/read_selection.fl"/>
<%	
	} else { 
%>							<fl:fieldRead property="PopReqID" bean="true" href="true" disp="/read_requester.fl"/>
<%
	}
}
%>						</tr>
						<tr class="fieldline">
							<td class="dataLabel"><fl:label field="PopAutoDel"/></td>
							<td class="dataValue">
							<input type="hidden" name="PopAutoDel" id="PopAutoDel" value="<%=isAutoDel%>"/><input type="checkbox" id="PopAutoDelete" name="PopAutoDelete" <%= isAutoDel ? "checked" : ""%> onclick='isAuotDel()'/>
							</td>							
						</tr>
					</table>
				</td>
				<td class="separation"><div class="separation"></div></td>
				<td class="column2">
					<table class="data_column" cellpadding="0">
						<fl:fieldRead property="PopCreID" bean="true" href="true" disp="/read_actor.fl" labelCode="F1014"/>
					</table>
				</td>
			</tr>
			<tr class="ligne_separation"><td colspan="3"></td></tr>
<% } %>
		</table>
<%
if (id != null) { 
%>
		<link href="<fl:webapp/>/css/smalltabs_css.jsp" rel="stylesheet" type="text/css">
		<script language="javascript" type="text/javascript" src="<fl:webapp/>/js/smalltabs.jsp"></script>
		<fl:smallTabs name="EnterpriseTabs">
			<fl:sTab id="QUANTITATIF" title="<%= Utils.getMessage(session, \"L6382\", \"Synthèse\") %>" onselect="refreshSynthesis()">
				<div style="text-align: center;width: 100%">
					<table class="container" cellpadding="2" style="width:50%" align="center">
						<tr>
							<td colspan="2" class="tabSimpleFdBleu dataValue" style="width: 100%; text-align: center;" nowrap><fl:getProperty name="Population" property="PopTotNbr" alt="0" format="int"/>&nbsp;<fl:getMessage code="F0032" alt="Contact(s)"/></td>
						</tr>
						<tr style="vertical-align: top">
							<td class="tabSimpleFdBleu dataValue" nowrap style="width:50%;text-align: center; white-space: nowrap;">
								<table class="container" cellpadding="0">
<% if(popType == 0) {
	if (!"B2C".equalsIgnoreCase(salesModel)) { %>
									<tr>
										<td class="dataValue" style="text-align: right; width: 1%; white-space: nowrap;" id="PopEntNbr">
											<fl:getProperty name="Population" property="PopEntNbr" alt="&nbsp;" format="int"/>
										</td>
										<td class="dataValue" style="width: 99%; white-space: nowrap;"><fl:getMessage code="F0033" alt="Entreprise(s)"/></td>
									</tr>
	<% } %>
									<tr>
										<td class="dataValue" style="text-align: right; width: 1%; white-space: nowrap;" id="PopPerNbr">
											<fl:getProperty name="Population" property="PopPerNbr" alt="0" format="int"/>
										</td>
										<td class="dataValue" style="width: 99%; white-space: nowrap;"><fl:getMessage code="F0034" alt="Personne(s)"/></td>
									</tr>
									<tr>
										<td class="dataValue" style="text-align: right; width: 1%; white-space: nowrap;" id="PopSilNbr" nowrap>
											<fl:getProperty name="Population" property="PopSilNbr" alt="0" format="int"/>
										</td>
										<td class="dataValue" style="width: 99%; white-space: nowrap;"><fl:getMessage code="F0035" alt="Silhouette(s)"/></td>
									</tr>
									<tr>
										<td class="dataValue" style="text-align: right; width: 1%; white-space: nowrap;" id="PopNonNbr" nowrap>
											<fl:getProperty name="Population" property="PopNonNbr" alt="0" format="int"/>
										</td>
										<td class="dataValue" style="width: 99%;" nowrap><fl:getMessage code="F0036" alt="Non nominatif(s)"/></td>
									</tr>
<%	} else { %>
									<tr>
										<td class="dataValue" style="text-align: right; width: 1%; white-space: nowrap;" id="PopSupNbr">
											<fl:getProperty name="Population" property="PopSupNbr" alt="0" format="int"/>
										</td>
										<td class="dataValue" style="width: 99%; white-space: nowrap;"><fl:getMessage code="F0037" alt="Support(s)"/></td>
									</tr>
									<tr>
										<td class="dataValue" style="text-align: right; width: 1%; white-space: nowrap;" id="PopJouNbr" nowrap>
											<fl:getProperty name="Population" property="PopJouNbr" alt="0" format="int"/>
										</td>
										<td class="dataValue" style="width: 99%; white-space: nowrap;" nowrap><fl:getMessage code="F0038" alt="Journaliste(s)"/></td>
									</tr>
									<tr>
										<td class="dataValue" style="text-align: right; width: 1%; white-space: nowrap;" id="PopNonNbr">
											<fl:getProperty name="Population" property="PopNonNbr" alt="0" format="int"/>
										</td>
										<td class="dataValue" style="width:99%;" nowrap><fl:getMessage code="F0036" alt="Non nominatif(s)"/></td>
									</tr>
<%	} %>
								</table>
							</td>
							<td class="tabSimpleFdBleu dataValue" style="width: 50%;text-align: center; white-space: nowrap;">
								<table class="container" cellpadding="0">
									<tr>
										<td class="dataValue" style="text-align: right; width: 1%; white-space: nowrap;" id="PopAddNbr" nowrap>
											<fl:getProperty name="Population" property="PopAddNbr" alt="0" format="int"/>
										</td>
										<td class="dataValue" style="width: 99%; white-space: nowrap;" nowrap><fl:getMessage code="F0039" alt="Contacts rajoutés manuellement"/></td>
									</tr>
									<tr>
										<td class="dataValue" style="text-align: right; width: 1%; white-space: nowrap;" id="PopRmvNbr" nowrap>
											<fl:getProperty name="Population" property="PopRmvNbr" alt="0" format="int"/>
										</td>
										<td class="dataValue" style="width: 99%; white-space: nowrap;" nowrap><fl:getMessage code="F003A" alt="Contacts retirés manuellement"/></td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
				</div>
			</fl:sTab>
			<fl:sTab id="BELONG" title="<%= Utils.getMessage(session, \"L002B\", \"Appartiennent à la cible\") %>" onselect="refreshPopulationEntry();">
				<fl:grid name="PopulationEntryList" height="150px" width="100%" ajaxUrl="<%= \"/list_populationentry_ajax.fl?PpePopID=\" + id + \"&PopType=\" +  popType %>"></fl:grid>&nbsp;
			</fl:sTab>
			<fl:sTab id="REMOVED" title="<%= Utils.getMessage(session, \"L002C\", \"Ont été retirés de la cible\") %>" onselect="refreshRemovedPopulationEntry();">
				<fl:grid name="RemovedPopulationEntryList" height="150px" width="100%" ajaxUrl="<%= \"/list_removed_populationentry_ajax.fl?PpePopID=\" + id + \"&PopType=\" +  popType %>"></fl:grid>&nbsp;
			</fl:sTab>
		</fl:smallTabs>
<%
}
%>
	</fl:bigTabs>
</fl:form>
