<%
/******************************************************************************
 * 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" %>
<%@ page import="com.edeal.frontline.PopulationBean" %>
<%@ page import="com.edeal.frontline.FrontlineException" %>
<%@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) {
}
if (id == null){
	id = (String)request.getAttribute("PopID");
	if (id != null) {
		try {
			Population = new PopulationBean(id, context);
			request.setAttribute("Population", Population);
		} catch (FrontlineException e) {
		}
	}

}
String sfwID = (String)request.getAttribute("sfwID");
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");
%>
<!-- Javascript include -->
<script type="text/javascript" language="javascript">
function refreshSynthesis() {
	doAjax('<fl:link url="<%= \"/refresh_population_synthesis.fl?id=\" + Population.getID() %>"/>');
}
function refreshPopulationEntry() {
	myAjaxURL_PopulationEntryList = _grid__PopulationEntryList_js_.getAjaxUrl();
	params = {};
	params["PpePopID"]='<%= Population.getID() %>';
	params["PopType"]='<%= popType %>';	
	_grid__PopulationEntryList_js_.callAjaxForHtml(myAjaxURL_PopulationEntryList,params,false);
}
function refreshRemovedPopulationEntry() {
	myAjaxURL_RemovedPopulationEntryList = _grid__RemovedPopulationEntryList_js_.getAjaxUrl();
	params = {};
	params["PpePopID"]='<%= Population.getID() %>';
	params["PopType"]='<%= popType %>';	
	_grid__PopulationEntryList_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);
		}
	}
}
</script>
<fl:bigTabs objectTitle="<%= Utils.getMessage(session, \"F000C\", false, true, \"Population\") %>" ou="<%= \"/read_population.fl\" + (id != null ? \"?id=\" + id : \"\") %>">
	<table class="container" cellpadding="0">
		<tr>
			<td colspan="3" class="titreFiche">
				<fl:getProperty name="Population" property="PopName" alt="<%= Utils.getMessage(session, \"L0033\", \"Nouvelle population\") %>"/>
			</td>
		</tr>
		<tr class="ligne_separation"><td colspan="3"></td></tr>
		<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) {
		String selUri = flRequest.computeURL("/read_selection.fl");
%>						<fl:fieldRead property="PopSelID" bean="true" href="true" disp="<%= selUri %>"/>
<%	
	} else {
		String reqUri = flRequest.computeURL("/read_requester.fl");
%>						<fl:fieldRead property="PopReqID" bean="true" href="true" disp="<%= reqUri %>" />
<%
	}
}
%>
					<tr><fl:fieldRead property="PopAutoDel" valueCodeIfTrue="L2005" valueCodeIfFalse="L2006"/></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>
	<link href="<fl:webapp/>/css/smalltabs_css.jsp" rel="stylesheet" type="text/css">
	
	<fl:smallTabs name="PopulationTabs">
		<fl:sTab id="QUANTITATIF" title="<%= Utils.getMessage(session, \"L6382\", \"Synthèse\") %>" onselect="refreshSynthesis()">
			<div style="text-align: center;width: 100%">
				<table class="container" cellpadding="1" style="width:50%" align="center">
					<tr>
						<td colspan="2" class="tabSimpleFdBleu dataValue" style="width: 100%; text-align: center;" nowrap><span id="PopTotNbr"><fl:getProperty name="Population" property="PopTotNbr" alt="0" format="int"/></span>&nbsp;<fl:getMessage code="F0032" alt="Contact(s)"/></td>
					</tr>
					<tr style="vertical-align: top">
						<td class="tabSimpleFdBleu dataValue" 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">
										<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%; white-space: nowrap;" 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: auto; 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">
										<fl:getProperty name="Population" property="PopJouNbr" alt="0" format="int"/>
									</td>
									<td class="dataValue" style="width: auto; white-space: 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%; white-space: nowrap;" 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">
										<fl:getProperty name="Population" property="PopAddNbr" alt="0" format="int"/>
									</td>
									<td class="dataValue" style="width: 99%;" 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">
										<fl:getProperty name="Population" property="PopRmvNbr" alt="0" format="int"/>
									</td>
									<td class="dataValue" style="width: 99%;" 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="260px" width="100%" ajaxUrl="<%= \"/list_populationentry_ajax.fl?PpePopID=\" + id + \"&PopType=\" +  popType %>" />&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="260px" width="100%" ajaxUrl="<%= \"/list_removed_populationentry_ajax.fl?PpePopID=\" + id + \"&PopType=\" +  popType %>"></fl:grid>&nbsp;
		</fl:sTab>
	</fl:smallTabs>
</fl:bigTabs>
