<%
/******************************************************************************
 * 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 language="java"%>
<%@ page import="com.edeal.frontline.navigation.FlRequest" %>
<%@ page import="com.edeal.frontline.grid.GridData" %>
<%@ page import="com.edeal.frontline.Utils" %>
<%@ page import="java.util.Vector" %>
<%@ page import="com.edeal.frontline.navigation.WebUtils" %>
<%@ page import="com.edeal.frontline.FlContext" %>
<%@ page import="com.edeal.frontline.controller.actions.SelectAction" %>
<%@taglib uri="http://www.e-deal.com/taglib/fl" prefix="fl"%>
<jsp:useBean class="com.edeal.frontline.MessagesBean" id="Messages" scope="request"/>
<%
final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory.getLog(getClass());
FlRequest flRequest = new FlRequest(request);
String global = flRequest.getRequestParameterOrAttribute("global");
String sc = flRequest.getRequestParameterOrAttribute("sc");
FlContext context = flRequest.getContext();
String strAdress = (String)flRequest.getAttribute("strAdress");
Vector vectAddress = Utils.explodeList(strAdress,";");
String msgID = (String)flRequest.getAttribute("msgID");
%>
<style>
.message
{
	border: 1px solid #006699;
	overflow: auto;
	max-height: 260px;
}
.mail {
	
	width: 100%;
	white-space: normal;
	font-size: smaller;
	color: rgb(128, 128, 128);
}
</style>
<script language="javascript">

function mailCallBack(arrIndex){
	if (eDealXmlhttpArr[arrIndex].readyState == 4) {
		//$('#mail_view').html(eDealXmlhttpArr[arrIndex].responseText);
		 document.getElementById("mail_view").innerHTML = eDealXmlhttpArr[arrIndex].responseText;
	} 
}
$("#mail_view").ready(function() {
	doAjax("<fl:webapp/>/get_message.fl?msgID=<%= msgID %>",mailCallBack);
});

function openFob(i){
	f = document.forms[0];
	var typ = f.elements["typ"+i].options[f.elements["typ"+i].selectedIndex].value;
	var query = '<fl:link url="/select.fl?type='+ typ +'&field=ObjID'+i+'"/>';
	window.open(query, 'SelectActor', 'menubar=no,status=no,toolbar=no,scrollbars=yes,resizable=yes,width=<%= SelectAction.SELECT_WINDOW_WIDTH %>,height=500');
}
function closeWin(){
	this.close();
	
}
function doSubmit(){
	f = document.forms[0];
	var addressSize = <%=vectAddress != null ? vectAddress.size() : 0 %>;
	var act = false;
	var corresp = false;
	for(i = 0 ; i < addressSize ; i++){
		var typ = 'typ' + i;
		var att = 'lblObjID' + i;
		var objVal = document.getElementById(typ).options[document.getElementById(typ).selectedIndex].innerHTML;
		var attVal = document.getElementById(att).value;
		if (objVal == '<fl:getMessage code="L6207" alt="Personnes" js="true"/>' || objVal == '<fl:getMessage code="L206B" alt="Journalistes" js="true"/>'){
			if (attVal != '') corresp = true;		
		}
		if (objVal == '<fl:getMessage code="L607C" alt="Acteurs" js="true"/>'){
			if (attVal != '') act = true;		
		}	
	}
	if (act == false || corresp == false) {
		 alert('<fl:getMessage code="M6101" alt="Il faut qu\\\'au moins une adresse soit rattachée à Acteur et qu\\\'au moins une soit rattachée à Personne ou Journaliste" js="true"/>');
		 return;
	} 
	f.submit();
}
</script>
<fl:form action="/validate_attach_trash2.fl" bean="Messages"> 
	<input type="hidden" name="msgID" value="<%= msgID%>">
	<input type="hidden" name="size" value="<%= (vectAddress != null)? vectAddress.size() : 0 %>">
	<input type="hidden" name="vectAddress" value="<%= Utils.implodeList(vectAddress,";") %>">
<fl:bigTabs objectTitle="<%= Utils.getMessage(session, \"L6598\", false, true, \"Message rejeté\") %>" ou="/attach_list_trash.fl">

<% 
if (vectAddress != null) {

%>

<%
	for (int j = 0; j < vectAddress.size() ; j++) {
		
		Vector vectAtt = new Vector();
		vectAtt = Utils.explodeList((String)vectAddress.elementAt(j),":");
		logger.debug("vectAtt::::::"+vectAtt);
 		if (j > 0) {
%>

	<table class="container" cellpadding="0">
		<tr class="ligne_separation"><td></td></tr>
		<tr class="ligne_separation_couleur"><td></td></tr>
		<tr class="ligne_separation"><td></td></tr>
	</table>
<%	
}
%>
	<table class="container" cellpadding="0">
		<tr>
			<td class="titreFiche" colspan="2">
			
			<%= ((String)vectAtt.elementAt(3)).trim() %>
			</td>
		</tr>
		<tr class="ligne_separation"><td></td></tr>
	</table>
	<table class="container" cellpadding="0">
		<tr valign="top">
			<td>
				<table class="container" cellpadding="0">
					<tr class="fieldline">
						<td class="dataLabel">
							<fl:getMessage code="F1022" alt="Objet"/>						
						</td>
						<td class="dataValue">
							<select name="typ<%= j%>" id="typ<%= j%>" class="input select chpsTextObligatoire">
								<option value="">&nbsp;</option>
								<option value="Person" <%= "Person".equals((String)vectAtt.elementAt(0)) ? "Selected" : "" %>><fl:getMessage code="L6207" alt="Personnes"/></option>
								<option value="Actor" <%= "Actor".equals((String)vectAtt.elementAt(0)) ? "Selected" : "" %>><fl:getMessage code="L607C" alt="Acteurs"/></option>
								<option value="Journalist" <%= "Journalist".equals((String)vectAtt.elementAt(0)) ? "Selected" : "" %>><fl:getMessage code="L206B" alt="Journalistes"/></option>
							</select>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr valign="top">
			<td>
				<table class="container" cellpadding="0">
					<tr class="fieldline">
						<td class="dataLabel">
							<fl:getMessage code="F6178" alt="Rattaché à"/>
						</td>
						<td class="dataValue">
							<div class="fieldTable"><table class="fieldTable" cellpadding="0">
								<tr>								
									<td class="principalText">
										<input name="ObjID<%= j%>" type="hidden" value="<%= ((String)vectAtt.elementAt(1)).trim()%>">
										<input name="lblObjID<%= j%>" id="lblObjID<%= j%>" type="text" value="<%= ((String)vectAtt.elementAt(2)).trim()%>" class="input fob chpsTextObligatoire" readonly onfocus="this.blur();">&nbsp;
									</td>
									<td class="postText">&nbsp;
										<a href="javascript:openFob(<%= j%>);" tabindex="20">
											<img src="<fl:webapp/>/icons/ico/rechercher.gif" align="middle" border="0" width="17" height="17" alt="S&eacute;lectionner">
										</a>&nbsp;
										<a href="javascript:var f = window.document.forms[0]; f.ObjID<%= j%>.value = f.lblObjID<%= j%>.value =''; $('#ObjMail<%= j%>').html(''); void('')" tabindex="20">
											<img src="<fl:webapp/>/icons/ico/supprimer.gif" align="middle" border="0" width="17" height="17" alt="Supprimer">
										</a>
									</td>
								</tr>
							</table></div>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr valign="top">
			<td>
				<table class="container" cellpadding="0">
					<tr class="fieldline">
						<td class="dataLabel">
							<fl:getMessage code="F6179" alt="Mise à jour e-mail contact"/>							
						</td>
						<td class="dataValue">
							<input type="checkbox" name="saveMail<%= j%>" value="<%= !"".equals(((String)vectAtt.elementAt(1)).trim()) ? "false" : "true"%>" <%= !"".equals(((String)vectAtt.elementAt(1)).trim()) ? "" : "checked"%>>							
							<span class="mail" id="ObjMail<%= j%>"></span>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
	<script language="javascript">
		function doObjID<%= j%>Change() {
			f = document.forms[0];
			objID = f.ObjID<%= j%>.value;
			objType = f.elements["typ<%= j%>"].options[f.elements["typ<%= j%>"].selectedIndex].value;
			if (!((objID == '') && (objType == ''))) {
				$.getJSON("<fl:webapp/>/get_obj_mail.fl?objID=" + objID + "&objType=" + objType , function(data) {
					if ((data.mail != null) && (data.mail != '')) {
						message = "( " + data.mail + " )";
					} else {
						message = '<fl:getMessage code="L709A" alt="adresse e-mail non renseignée" js="true"/>';
					}
					$("#ObjMail<%= j%>").html(message);
				}); 
			}
		}
	</script>
<%	
	}
%>	
	<table class="container" cellpadding="0">
		<tr class="ligne_separation"><td class="ligne_separation">&nbsp;</td></tr>
		<tr><td class="dataLabel"><fl:label code="L7097"/></td></tr>
		<tr><td><div id="mail_view" class="message"></div></td></tr>
	</table>
<%		
 } else {
%>
<table class="container" cellpadding="0">
	<tr class="ligne_separation"><td class="ligne_separation">&nbsp;</td></tr>
	<tr>
		<td>
			<fl:getMessage code="L645E" alt="Cet e-mail n\'a pas pu être correctement rattaché :"/>
			<fl:getMessage code="M303A" alt="Erreur inconnue"/>
		</td>
	</tr>
</table>
<%	}
%>
</fl:bigTabs>
</fl:form>
