<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript">
<!--
||ifdef||netscape_version||
var ns=true;
	||define||amp||&||
||else||
var ns=false;
	||define||amp||&amp;||
||endif||

||ifempty||changing_address||
var ch_addr=false;
||else||
var ch_addr=true;
var enc_nick="||encode_quotes||nick_name||";
||endif||

function create(){
	document.pickform.abook_edit.value = document.pickform.abook_new.value;
	document.pickform.abook_list.value = document.pickform.abook_new.value;
	document.pickform.submit();
}

function do_copy(sel){
	var i;
	for (i=0; i<sel.options.length; i++){
		if (sel.options[i].selected==true){
			if (sel.options[i].value == "Groups")
				document.pickform.page.value = "group";
			else if (sel.options[i].value == "Recent Addresses")
				document.pickform.page.value = "pick_recent";
			else
				document.pickform.abook_edit.value = sel.options[i].value;
			break;
		}
	}
	document.pickform.submit();
}

function do_copy2(sel){
	var i;
	for (i=0; i<sel.options.length; i++){
		if (sel.options[i].selected==true){
				document.pickform.abook_edit.value = sel.options[i].value;
		}
	}
	document.pickform.page.value = "group";
	document.pickform.group_name.value = document.pickform.new_group_name.value;
	document.pickform.submit();
}

function externwindow(){
	msgWindow = open('||action||?cmd=ext_addr||amp||utoken=||putoken||||amp||||amp||','EXTERNADDR','width=550,height=450,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes','POPUP');
	if (msgWindow.opener == null) msgWindow.opener = self;
	if (msgWindow.opener.pickform == null) msgWindow.opener.pickform = document.pickform;
}

function setTitle(){
	||ifequal||top||_top||
		window.top.document.title = "||cust_display_name|| - ||current_user|| - Address Book";
	||endif||
}

function importNew(){
	document.location = "||action||?cmd=import_new||amp||utoken=||utoken||";
}

function edit_group(name,value){
	document.editgrp.group_name.value = name;
	document.editgrp.stored_dist.value = value;
	document.editgrp.changing_address.value = "true";
	document.editgrp.submit();
}

function addSel(){
	var form = document.pickform;
	var from = form.abksel.options;
	var j, newentry;
	for(j=0; j<from.length; j++){
		if(from[j].selected){
			newentry = from[j].text;
			if (form.group_list.value.indexOf(newentry) == -1)  //only add the new entry if it's not already there
				form.group_list.value = form.group_list.value + newentry + ",\n";
		}
	}
}

var x_savedist = "||lang_str||You need to enter a name for the group||";
var x_toobig = "||lang_str||The group is too large, reduce the number of addresses or split it into several groups||";

function saveDist(){
	var form = document.pickform;
	if (form.new_group_name){
		if (!form.new_group_name.value.length){
			alert(x_savedist);
			return;
		}
		form.group_name.value = form.new_group_name.value;
	}
	var tmp=form.group_list.value;
	tmp.replace("@","!40")
	if (tmp.length>1020){
		alert(x_toobig);
		return;
	}
	form.cmd.value = "add_dist";
	form.page.value = "group";
	form.changing_address.value = "";
	form.submit();
}

function del_group(str){
	document.editgrp.group_name.value = str;
	document.editgrp.cmd.value = "del_dist";
	document.editgrp.submit();
}

// -->
</script>

||just_include||pickfcss.tpl||

<title>Address Book</title>
</head>

<body background="||cust_panel_background||" bgcolor="||cust_panel_bgcolor||" onload="setTitle();">

<center>

||ifdef||error||
	<table border="1">
		<tr>
			<td><img src="||nwimg||/attention.gif" alt="Attention" /></td>
			<td bgcolor="ffffff">||error||</td>
		</tr>
	</table>
||endif||


||ifdef||msg||
	<table border="1">
		<tr>
			<td><img src="||nwimg||/attention.gif" alt="Attention" /></td>
			<td bgcolor="ffffff">||msg||</td>
		</tr>
	</table>
||endif||


<form name="editgrp" method="post" action="||action||">
	<input type="hidden" name="cmd" value="pick_edit" />
	<input type="hidden" name="encode_text" value="group_name,stored_dist"/>
	<input type="hidden" name="page" value="group"/>
	<input type="hidden" name="group_name" value=""/>
	<input type="hidden" name="stored_dist" value="" />
	<input type="hidden" name="changing_address" value="||changing_address||" />
	<input type="hidden" name="utoken" value="||utoken||" />
</form>

<form name="pickform" method="post" action="||action||">
<input type="hidden" name="dist_list" value="||dist_list||" />
<input type="hidden" name="picklist" value="||picklist||" />
<input type="hidden" name="utoken" value="||utoken||" />
<input type="hidden" name="cmd" value="pick_edit" />
<input type="hidden" name="page" value="" />
<input type="hidden" name="abook_edit" value="||abook_edit||" />
<input type="hidden" name="abook_list" value="" />
<input type="hidden" name="changing_address" value="||changing_address||" />
<input type="hidden" name="stored_dist" value="" />

||ifempty||changing_address||
<table width="95%">
<tr>
	<td class="head" align="center">Address Book</td>
	<td></td>
	<td class="head" align="center">New Address Book</td>
	||ifdef||external_book||
		<td></td>
		<td></td>
		<td align="center"><input type="button" value="External Address Book" onclick="javascript:externwindow()" /></td>
	||endif||
</tr>
<tr>
	<td><select size="1" name="addr_books" onchange="do_copy(this)">
		||begin_book||
			<option value="||addr_book||" ||selected||>||trans_addr_book||</option>
		||end_book||
			<option value="Recent Addresses">Recent Addresses</option>
			<option value="Groups" selected="selected">Groups</option>
		</select></td>
	<td nowrap>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
	<td><input type="Text" name="abook_new" size="26"></td>
	<td><input type="button" value="Create" onclick="javascript:create()" /></td>
	<td width="100%">&nbsp;</td>
	<td align="center">
		<input type="button" value="Import an Address Book" onclick="javascript:importNew()">
	</td>
</tr>
</table>
<table width="95%" border="0" cellspacing="0" class="LT">
<tr bgcolor="#D6D6CE">
	<td width="30%" nowrap>Group Name</td>
	<td width="70%" nowrap>Addresses in Group</td>
	<td></td>
</tr>
||define||color||1||
||begin_distlist||
	<tr class="L||color||">
		||ifequal||color||1||
			||define||color||0||
		||else||
			||define||color||1||
		||endif||
		<td><a href="javascript:edit_group('||encode_text||dist_label||','||encode_text||dist_value||')">||html_text||dist_label||</a></td>
		<td nowrap>||lchop||dist_value||80||</td>
		<td><a href="javascript:del_group('||dist_label||')">delete</a></td>
	</tr>
||end_distlist||
</table>

||endif||

<br />
<table bgcolor="#D6D6CE" width="500">
<tr>
	<td colspan="3" align="center" class="head"><b>
	||ifempty||changing_address||
		Add a new Group
	||else||
		Edit "||html_text||group_name||" Group List<br />
		<a class="head" href="||action||?cmd=pick_edit&abook_edit=||abook_edit||&page=group&utoken=||utoken||">Back to Groups</a>
		<input type="hidden" name="group_name" value="||ifnempty||group_name||||message_text||group_name||||endif||" />
	||endif||
	</td>
</tr>
||ifempty||changing_address||
<tr>
	<td colspan="3" align="center" class="head">
		Group Name:
		<input type="Text" name="new_group_name" size="26" value="||ifnempty||group_name||||message_text||group_name||||endif||">
		<input type="hidden" name="group_name" value="||ifnempty||group_name||||message_text||group_name||||endif||" />
	</td>
</tr>
||endif||
<tr>
	<td align="center" class="head">
		Address Book<br />
		<select size="1" name="addr_books" onchange="do_copy2(this)">
		||begin_book||
			<option value="||addr_book||" ||selected||>||trans_addr_book||</option>
		||end_book||
		</select><br>
		<select name="abksel" size="8" multiple="true">
			||begin_address||
		  		||ifdef||abk_email||<option value="">||html_text||abk_email||</option>||endif||
			||end_address||
		</select>
	</td>

	<td align="center">
	<input type="button" value="Add >>" onclick="addSel();" />
	</td>

	<td align="center" class="head">
		Group list<br />
		||ifdef||stored_dist||
<textarea rows="9" name="group_list" cols="25">||begin_email||stored_dist||||email||,
||end_email||</textarea>
		||else||
			<textarea rows="9" name="group_list" cols="25">||group_list||</textarea>
		||endif||
	</td>
</tr>
<tr><td colspan="3" align="center"><input type="button" onclick="saveDist();" value="Save ||ifnempty||changing_address||changes to ||endif||Group List"></td></tr>
</table>
</form>
</center>
</body>
</html>
