function _Messages() {

	this.recipients;

	this.onLoad = function() {
			if (($('to_phrase') != null) && ($('to_phrase') != 'undefined'))
			{
			    $('to_phrase').onfocus = function() {this.value=''; };
			    $('to_phrase').onblur = function() {this.value='Start typing a contact\'s name'; };
            		}
		}

	this.replaceRecipientNullValues = function(element,name,id) {
			var ndList = element.childNodes;
			for (var i=0; i<ndList.length; i++) this.replaceRecipientNullValues(ndList[i],name,id);
			if (element.id) element.id = element.id.replace(0,id);
			if (element.disabled) element.disabled = '';
			if (element.type && element.type == 'hidden') element.value = id;
			if (element.tagName == 'P') element.innerHTML = name;
		}

	this.addRecipient = function(selectedItem) {
			$('to_phrase').value = 'Start typing a contact\'s name';
			if (selectedItem.id == 0) return false;
			var name;
			var RecipientTemplate = $('recipient_frame_0').cloneNode(true);

			var spans = selectedItem.getElementsByTagName('span');
			for (var i=0; i<spans.length; i++) {
				if (spans[i].className != 'name') continue;
				name = spans[i].innerHTML;
				while (name.indexOf('<strong>') > -1) {
					name = name.replace('<strong>','');
					name = name.replace('</strong>','');
				}
			}
			if (!name) return false;

			RecipientTemplate.style.display = '';
			this.replaceRecipientNullValues(RecipientTemplate,name,selectedItem.id);
			$('recipients').appendChild(RecipientTemplate);

		}

	this.removeRecipient = function(Recipient) {
			$('recipients').removeChild(Recipient);
		}
}




var Messages = new _Messages();
