var Recipients = {target_obj:"recipient_text_list",target_field:"recipient_list", Multi_Select: false, Form:null};
Recipients.Add = function()
{
	if (typeof(this.Window) != "undefined") {
		this.Window.close();
	}
	this.Window = window.open("/sendemail/add_recipient.asp?char=65&multi_select=" + this.Multi_Select, "NewRecipient", "width=500,height=500,resizable=no, status=no, scrollbars=no");
	this.Window.focus();
}
Recipients.Clear = function()
{
	if (!confirm("Are you sure you want to remove all recipients?")) return false;
	if (typeof(this.Form) == "string") this.Form = document.forms[this.Form];
	if (typeof(this.target_field) == "string") this.target_field = this.Form[this.target_field];
	if (typeof(this.target_obj) == "string") this.target_obj = document.getElementById(this.target_obj);
	this.target_field.value = "";
	this.target_obj.innerHTML = "";
	return false;
}
Recipients.Remove = function(item_id, item_type)
{
	if (typeof(this.Form) == "string") this.Form = document.forms[this.Form];
	if (typeof(this.target_field) == "string") this.target_field = this.Form[this.target_field];
	var obj = document.getElementById("recipient_" + item_id + "_" + item_type);
	var item_name = obj.innerHTML.replace(/<a[^>]*>[\s\S]*<\/a>/gi, "");
	if (!confirm('Are you sure you want to remove "' + item_name + '"?')) return false;
	
	this.target_field.value = this.target_field.value.replace(item_id + "," + item_type + ";", "");
	obj.parentNode.removeChild(obj);
	
	return false;
}
Recipients.Select = function(frm)
{
	var obj = frm.recipients;
	var idx = -1;
	if (this.Multi_Select)
	{
		while (obj.selectedIndex != -1)
		{
			idx = obj.selectedIndex;
			//deal with selection,
			this.AddToList(obj.options[idx]);
			obj.options[idx].selected = false;
		}
	}
	else
	{
		idx = obj.selectedIndex;
		this.AddToList(obj.options[idx]);
	}
	return true;
}
Recipients.AddToList = function(obj)
{
	if (typeof(this.Form) == "string") this.Form = document.forms[this.Form];
	if (typeof(this.target_obj) == "string") this.target_obj = document.getElementById(this.target_obj);
	if (typeof(this.target_field) == "string") this.target_field = this.Form[this.target_field];
	var item_id = obj.value;
	var item_name = obj.text.replace(/(^(\s|\xA0)*|(\s|\xA0)*$|\&nbsp\;)/gi, "");
	var item_type = obj.getAttribute("recipient_type");
	
	var new_obj = document.createElement("DIV");
	new_obj.id = "recipient_" + item_id + "_" + item_type;
	new_obj.innerHTML = item_name;
	var new_link = document.createElement("A");
	new_link.href = "javascript:void(0);"
	new_link.onclick = function() {return Recipients.Remove(item_id, item_type);};
	new_link.innerHTML = "x";
	new_link.title = "Remove recipient";
	new_obj.appendChild(new_link);
	if (!this.Multi_Select)
	{
		this.target_obj.innerHTML = "";
		this.target_field.value = "";
	}
	this.target_obj.appendChild(new_obj);
	
	this.target_field.value += item_id + "," + item_type + ";";
}