

	function uiDataSuggest ()
	{
		this.obj = '';
		
		this.fieldname = new Array('dataSuggestEntryBox', 0);
		this.searchfield = new Array('', 0);
		this.searchtable = '';
		this.anchorobject = '';
		this.setfield = '';
		this.setcolumn = '';
		this.settitle = '';
		this.alsoWhere = '';
		this.args = '';
		
		this.either = 0;
		this.hideOnSelect = '';
		this.showOnSelect = '';
		
		this.iteration = 0;
		
		this.getGenericSuccess = function (o)
		{
			this.showBox();
			document.getElementById('dataSuggestBoxResults').innerHTML = o.responseText;
		}
		
		this.getGeneric = function (url)
		{
			var callback =
			{
				success: this.obj.getGenericSuccess,
				failure: this.obj.failed,
				scope: this.obj
			}	
			
			var cObj = YAHOO.util.Connect.asyncRequest('GET','/lib/request/'+url,callback,null);
		}
		
		this.setField = function (value, display)
		{
			console.log('setting '+this.setfield+' to '+value);
			document.getElementById(this.setfield).value = value;
			document.getElementById(this.settitle).innerHTML = display;
			hideBox(this.hideOnSelect);
			showBox(this.showOnSelect);
			this.hide();
		}	

		this.show = function (returndata)
		{			
			var fieldname = returndata[1];
			
			if (returndata[2] == '0')
			{
				if (document.getElementById('dataSuggestEntry').style.display == 'none')
					this.hide();
				return;
			}
		
			this.showBox();
			document.getElementById('dataSuggestBoxResults').innerHTML = returndata[2];
		}
		
		this.success = function (o)
		{
			var returndata = o.responseText.split('|||');
			
			if (returndata[0] < dataSuggestCurrent.iteration)
				return;
				
			this.show(returndata);
		}
		
		this.showBox = function ()
		{		
			if (document.getElementById('dataSuggestBox').style.display == 'none')
				document.getElementById('dataSuggestBoxResults').innerHTML = '';
			
			console.log(this.anchorobject);
			var fieldbox = YAHOO.util.Region.getRegion(this.anchorobject);
			var pos = Array();
			pos[0] = fieldbox.left;
			pos[1] = fieldbox.top + document.getElementById(this.anchorobject).offsetHeight;
			//alert(pos[0]+' '+pos[1]);
			document.getElementById('dataSuggestBox').style.display = '';		
			YAHOO.util.Dom.setXY('dataSuggestBox', pos);
			if (document.getElementById(this.fieldname))
				document.getElementById(this.fieldname).focus();
				
			dataSuggestCurrent = this;
		}
		
		this.hide = function ()
		{
			this.iteration++;
			hideBox('dataSuggestBox');
		}
		
		this.failed = function(o)
		{
			console.log('dataSuggest failed');
		}
			
		this.suggest = function (iteration)
		{
			if (iteration < this.iteration)
				return;
				
			var addToRequest = '';
			var doSearch = 0;
			//alert(this.searchfield.length);
			for (var x=0; x < this.fieldname.length; x++) //x in this.searchfield)
			{
				addToRequest += '&fieldname['+x+']='+this.searchfield[x];
				if (this.fieldname[x])
				{
					if (document.getElementById(this.fieldname[x]).value.length)
						doSearch = 1;
					addToRequest += '&sofar['+x+']='+document.getElementById(this.fieldname[x]).value;
				}
			}
			
			if (!doSearch)
			{
				this.hide();
				return;
			}
			
			var callback =
			{
				success: this.obj.success,
				failure: this.obj.failed,
				scope: this.obj
			}	
			
			this.iteration++;
			var cObj = YAHOO.util.Connect.asyncRequest('GET',this.url+'?iteration='+this.iteration+'&searchtable='+this.searchtable+'&fieldname='+this.fieldname+'&setfield='+this.setfield+'&setcolumn='+this.setcolumn+'&settitle='+this.settitle+'&either='+this.either+'&alsowhere='+this.alsoWhere+this.args+addToRequest,callback,null);
		}	
		
		this.spring = function (hideinbuilt)
		{
			if (hideinbuilt)
				document.getElementById('dataSuggestEntry').style.display = 'none';
			else
				document.getElementById('dataSuggestEntry').style.display = '';
			
			setTimeout(this.obj+'.suggest('+this.iteration+');', 350);
		}		
	}

	/* not needed?
	function uiSelectorContactPrefill (name_first, name_last, company_id, ph_office, ph_mobile, email)
	{
		this.name_first = name_first;
		this.name_last = name_last;
		this.company_id = company_id;
		this.ph_office = ph_office;
		this.ph_mobile = ph_mobile;
		this.email = email;
	}
	*/
	
	function uiSelectorContact (field)
	{
		this.field = field;
		this.theAnchor = 'uiSelectorContactButtons_'+this.field;
		
		this.dataSuggest = new uiDataSuggest();
		this.dataSuggest.url = '/admin/contacts/request/search';
		this.dataSuggest.searchfield = new Array('name_first,name_last');
		this.dataSuggest.fieldname = new Array('uiSelectorContactSearch_'+this.field);
		this.dataSuggest.anchorobject = this.theAnchor;
		this.dataSuggest.hideOnSelect = 'uiSelectorContactButtons_'+this.field;
		this.dataSuggest.showOnSelect = 'uiSelectorContactRight_'+this.field;
		
		this.setPrefill = function (name_first, name_last, company_id, ph_office, ph_mobile, email)
		{
			this.prefill = new Array;
			this.prefill.name_first = name_first;
			this.prefill.name_last = name_last;
			this.prefill.company_id = company_id;
			this.prefill.ph_office = ph_office;
			this.prefill.ph_mobile = ph_mobile;
			this.prefill.email = email;
		}
		
		this.createSuccess = function (o)
		{
			if (o.responseText == '0')
			{
				alert('Contact creation failed - please try again.');
				return;
			}
			
			bits = o.responseText.split('|||');
			field = contactSelectorCurrent.field;
			
			document.getElementById(field).value = bits[1];
			document.getElementById('uiSelectorContactDisplay_'+field).innerHTML = bits[2];
			hideBox('uiSelectorContactButtons_'+field);
			showBox('uiSelectorContactDisplay_'+field);
			showBox('uiSelectorContactRight_'+field);
			hideBox('contactCreateBox');			
		}
		
		this.createFailure = function(o)
		{
			return;
		}
		
		this.create = function (f)
		{
			// do validation here
			
			var callback = 
			{
				success:contactSelectorCurrent.createSuccess,
				failure:contactSelectorCurrent.createFailure
			}
			
			var cObj = YAHOO.util.Connect.asyncRequest('GET','/core/request/contactCreate.php?field='+document.getElementById('contactCreateField').value+'&name_first='+URLEncode(f.contactCreate_name_first.value)+'&name_last='+URLEncode(f.contactCreate_name_last.value)+'&company_id='+URLEncode(f.contactCreate_company_id.value)+'&company_new='+URLEncode(f.contactCreate_company_new.value)+'&ph_office='+URLEncode(f.contactCreate_ph_office.value)+'&ph_mobile='+URLEncode(f.contactCreate_ph_mobile.value)+'&email='+URLEncode(f.contactCreate_email.value),callback,null);			
		}
		
		this.showCreate = function ()
		{
			contactSelectorCurrent = this;

			f = document.getElementById('contactCreateForm');
			f.reset();

			f.contactCreate_name_first.value = this.prefill.name_first;
			f.contactCreate_name_last.value = this.prefill.name_last;
			f.contactCreate_ph_office.value = this.prefill.ph_office;
			f.contactCreate_ph_mobile.value = this.prefill.ph_mobile;
			f.contactCreate_email.value = this.prefill.email;
			
			var fieldbox = YAHOO.util.Region.getRegion(this.theAnchor);
			var pos = Array();
			
			pos[0] = fieldbox.left;
			pos[1] = fieldbox.top + document.getElementById(this.theAnchor).offsetHeight;

			showBox('contactCreateBox');		
			YAHOO.util.Dom.setXY('contactCreateBox', pos);
			
			document.getElementById('contactCreate_name_first').focus();		
		}
		
		this.showSearch = function ()
		{
			var searchBox = YAHOO.util.Dom.get('uiSelectorContactSearch_'+this.field);
			searchBox.value = '';
			
			hideBox('contactCreateBox');
			hideBox('uiSelectorContactButtons_'+this.field);
			showBox('uiSelectorContactRight_'+this.field);
			showBox('uiSelectorContactSearchDisplay_'+this.field);
			
			searchBox.focus();
		}
		
		this.searchSpring = function ()
		{
			hideBox('dataSuggestEntry');
			
			setTimeout('uiSelectorContact_'+this.field+'.dataSuggest.suggest('+this.dataSuggest.iteration+');', 350);
		}
		
		this.clear = function ()
		{
			setField(this.field, '0');
			setHTML('uiSelectorContactDisplay_'+this.field,'');
			showBox('uiSelectorContactButtons_'+this.field);
			hideBox('uiSelectorContactRight_'+this.field);
			hideBox('uiSelectorContactSearchDisplay_'+this.field);
		}
	}

	function uiList (id)
	{
		this.id = id;
		
		this.arrayName;
		this.request;
		this.deleteable = false;
		this.deleteTable;
		this.deleteField;
		
		this.checkboxLabel = null;
		
		this.sortable;
		this.sortInitial;
		this.sortBy;
		this.sortDirection;
		this.offset = 0;
		this.count = document.getElementById("uiListPagination['" + this.id + "'][count]");
		
		this.tableBody;
		
		this.searchBox;
		this.searchField;
		
		this.getBody = function ()
		{
			isBody = function (el)
			{
				return (el.tagName == 'TBODY');
			}
			
			this.tableBody = YAHOO.util.Dom.getFirstChildBy(YAHOO.util.Dom.get(this.id), isBody);
		}
		
		this.deleteItem = function (id)
		{
			//deleteGeneric(this.deleteTable, this.deleteField, id, this.arrayName+'['+id+']');
			deleteGenericURL(this.deleteURL+id, this.arrayName+'['+id+']');			
		}
		
		this.clearList = function ()
		{
			if (!this.tableBody)
				this.getBody();

			while (this.tableBody.firstChild)
				this.tableBody.removeChild(this.tableBody.lastChild);
		}
		
		this.receiveList = function (o)
		{	
			if (!this.tableBody)
				this.getBody();
				
			this.clearList();
				
			listItems = xml2array(o.responseXML);
			
			if (undefined === listItems)
				return;
			
			browser = YAHOO.util.Dom.get('uiListPagination[\''+this.id+'\'][browser]');
			if (browser)
			{
				if (listItems['xml']['status'])
					document.getElementById('uiListPagination[\''+this.id+'\'][status]').innerHTML = listItems['xml']['status'];
				if (listItems['xml']['browser'])
				{
					browser.innerHTML = listItems['xml']['browser'];
					var browser2 = YAHOO.util.Dom.get('uiListPagination[\''+this.id+'\'][browser2]');
					if (browser2)
						browser2.innerHTML = listItems['xml']['browser'];
				}		
			}
			
			var drawn = [];
			var i = 0;			
			for (x in listItems['xml']['row'])
			{
				// if only one item is returned the structure is slightly different
				if (isNaN(x))
					branch = listItems['xml']['row'];
				else
					branch = listItems['xml']['row'][x];
				
				row = document.createElement('tr');
				if (this.arrayName)
					row.id = this.arrayName+'['+branch['id']+']';
				else
					row.id = branch['id'];
					
				// check for double up
				if (drawn[row.id])
					continue;
					
				if (branch['highlight'] == '1')
					YAHOO.util.Dom.addClass(row, 'highlight');
					
				if (this.checkboxLabel)
				{
					cell = document.createElement('td');
					YAHOO.util.Dom.addClass(cell, 'check');
					cell.innerHTML = '<input type="checkbox" name="'+this.checkboxLabel+'['+branch['id']+']" id="'+this.checkboxLabel+'['+branch['id']+']" value="1" />';
					
					row.appendChild(cell);
				}
				
				for (y in branch['cell'])
				{	
					cell = document.createElement('td');
					if (branch['cell'][y]['align'])
						YAHOO.util.Dom.setStyle(cell, 'text-align', branch['cell'][y]['align']);
					if (branch['cell'][y]['value'])
						cell.innerHTML = branch['cell'][y]['value'];
					
					row.appendChild(cell);
				}
				
				if (this.deleteable || this.browseChildren)
				{
					cell = document.createElement('td');
					YAHOO.util.Dom.addClass(cell, 'remove');
					
					cell.innerHTML = '';
					if (this.deleteable)
						cell.innerHTML += '<a href="#" onClick="uiListObject[\''+this.id+'\'].deleteItem('+branch['id']+'); return false"><img src="/core/assets/admin/icons/x.png" width=16 height=16></a>';
					if (this.browseChildren)
					{
						if (branch['browse'])
							cell.innerHTML += '&nbsp;<a href="'+branch['browse']+'"><img src="/core/assets/admin/icons/arrow-right.png" width=16 height=16></a>';
						else
							cell.innerHTML += '&nbsp;<img src="/core/assets/images/clearpixel.gif" width=16 height=16>';
					}
					
					row.appendChild(cell);
				}
								
				/*
				if (i)
				{
					YAHOO.util.Dom.addClass(row, 'alt');
					i = 0;
				}
				else
					i = 1;
				*/
				
				this.tableBody.appendChild(row);
				drawn[row.id] = 1;
			}
		}
		
		this.updateList = function ()
		{
			var query = 'id='+this.id+'&';
			if (this.sortBy)
				query += 'sortby='+this.sortBy+'&';
			if (this.sortDirection)
				query += 'sortdirection='+this.sortDirection+'&';
			if (this.searchText)
				query += 'search='+this.searchText+'&';
			query += 'offset='+this.offset+'&';

			if (this.count && this.count.value)
				query += 'count='+this.count.value+'&';

			if (this.additionalQueryExec)
				query += this.additionalQueryExec();
			
			var callback =
			{
				success: uiListObject[this.id].receiveList,
				failure: uiListObject[this.id].failure,
				scope: uiListObject[this.id]
			}	

			var cObj = YAHOO.util.Connect.asyncRequest('GET', this.request+'?'+query, callback, null);
		}
		
		this.sortMouseOver = function (field)
		{
			sorter = 'uiListSorter[\''+this.id+'\'][\''+field+'\']';
			
			YAHOO.util.Dom.removeClass(sorter, 'asc');
			YAHOO.util.Dom.removeClass(sorter, 'desc');
			
			if (this.sortBy == field)
			{
				if (this.sortDirection == 'asc')
					YAHOO.util.Dom.addClass(sorter, 'desc');
				else
					YAHOO.util.Dom.addClass(sorter, 'asc');
			}
			else
				YAHOO.util.Dom.addClass(sorter, 'asc');
		}
		
		this.sortMouseOut = function (field)
		{
			sorter = 'uiListSorter[\''+this.id+'\'][\''+field+'\']';
		
			YAHOO.util.Dom.removeClass(sorter, 'asc');
			YAHOO.util.Dom.removeClass(sorter, 'desc');		
		
			if (this.sortBy == field)
				YAHOO.util.Dom.addClass(sorter, this.sortDirection);
		}			
		
		this.sortList = function (by)
		{
			sorter = 'uiListSorter[\''+this.id+'\'][\''+by+'\']';
			
			YAHOO.util.Dom.removeClass(sorter, 'asc');
			YAHOO.util.Dom.removeClass(sorter, 'desc');
			
			if (this.sortBy == by)
			{
				if (this.sortDirection == 'asc')
					this.sortDirection = 'desc';
				else
					this.sortDirection = 'asc';
			}
			else
			{
				oldSorter = 'uiListSorter[\''+this.id+'\'][\''+this.sortBy+'\']'; 
				YAHOO.util.Dom.removeClass(oldSorter, 'asc');
				YAHOO.util.Dom.removeClass(oldSorter, 'desc');
			}
			
			YAHOO.util.Dom.addClass(sorter, this.sortDirection);
			
			this.sortBy = by;
			this.offset = 0;
			this.updateList();
		}
		
		this.changeOffset = function (to)
		{
			//this.offset += by;
			//if (this.offset < 0)
				//this.offset = 0;
			this.offset = to;
			this.updateList();
		}
		
		this.searchSpring = function ()
		{
			this.searchSpringTimeout = setTimeout('uiListObject[\''+this.id+'\'].searchStart();', 350);
		}
		
		this.searchStart = function ()
		{
			q = document.getElementById(this.searchBox).value;
			
			if (!q.length)
			{
				this.searchText = null;
				this.updateList();
				return;
			}
				
			this.searchText = q;
			this.sortList(this.searchField);
		}
		
		this.searchClear = function ()
		{
			document.getElementById(this.searchBox).value = '';
			this.searchText = null;
			this.offset = 0;
			this.updateList();
		}
		
		this.init = function ()
		{	
			if (this.sortable)
				this.sortList(this.sortInitial);
			else
				this.updateList();
		}
	}
	


	function uiTemplate ()
	{
		this.editor;
		this.filename;
		
		this.baseURL = '/admin/cms/request';
		
		this.sectionArgs = new Array;
		
		this.editorSet = function (content)
		{
			if (!this.editor)
				this.editor = WPro.editors['cms_editor_wpro']; //FCKeditorAPI.GetInstance('cms_editor_fck');
				
			return this.editor.setValue(content); //this.editor.SetHTML(content);
						
		}
		
		this.editorGet = function ()
		{
			if (!this.editor)
				this.editor = WPro.editors['cms_editor_wpro']; //FCKeditorAPI.GetInstance('cms_editor_fck');
			
			return this.editor.getValue(); //this.editor.GetHTML();
		}
		
		this.inheritToggle = function (state)
		{
			if (state)
				YAHOO.util.Dom.setStyle('cms_editor_wysiwyg', 'display', 'none');
			else
				YAHOO.util.Dom.setStyle('cms_editor_wysiwyg', 'display', 'block');
		}
		
		this.editSection = function (name, type, args)
		{
			this.currentTarget = name;
			
			var callback =
			{
				success: currentTemplate.receiveUnformatted,
				failure: currentTemplate.failure,
				scope: currentTemplate
			}	
	
			var cObj = YAHOO.util.Connect.asyncRequest('GET', this.baseURL+'/get/'+this.currentTarget+'&type='+type, callback, null);
		}
		
		this.receiveUnformatted = function (o)
		{
			data = xml2array(o.responseXML);
			
			if (data['xml']['type'] == 'video')
			{
				openFileBrowser('media', this.applyVideo, function() { return data['xml']['file']; });
				return;
			}
			
			if (data['xml']['type'] == 'image')
			{
				openFileBrowser('image', this.applyImage, function() { return data['xml']['file']; });
				return;
			}
			
			if ((data['xml']['content'] != null) && strlen(data['xml']['content']))
				data['xml']['content'] = utf8_decode(data['xml']['content']);
			
			if (data['xml']['type'] == 'string')
			{
				var text = Prompt.show('Enter value:', data['xml']['content']);
				if (typeof(text) == 'string')
					this.applyString(text);
					
				return;
			}
			
			if (data['xml']['inherit_id'])
			{
				YAHOO.util.Dom.get('inherit').checked = true;
				YAHOO.util.Dom.get('inherit_id').value = data['xml']['inherit_id'];
				hideBox('cms_editor_wysiwyg');
			}
			else
			{
				inherit = YAHOO.util.Dom.get('inherit');
				if (inherit)
					inherit.checked = false;
				showBox('cms_editor_wysiwyg');
			}
				
			if (!data['xml']['content'])
				data['xml']['content'] = '';
			
			var currentHTML = new String(data['xml']['content']);
			this.editorSet(currentHTML);
			
			var targetDiv = YAHOO.util.Dom.get('cms_'+this.currentTarget);			

			var targetRegion = YAHOO.util.Dom.getRegion(targetDiv);
			var targetWidth = targetRegion.right - targetRegion.left;
			if (targetWidth < 400)
				var width = '400px';
			else
				var width = targetWidth+'px';
				
			//console.log('targetWidth is '+targetWidth+', width set to '+width);
				
			YAHOO.util.Dom.setStyle('cms_editor', 'width', width);
			YAHOO.util.Dom.setStyle('cms_editor', 'display', 'block');
			
			var targetPosition = YAHOO.util.Dom.getXY(targetDiv);
			if (targetPosition[1] < YAHOO.util.Dom.getDocumentScrollTop())
				targetPosition[1] = YAHOO.util.Dom.getDocumentScrollTop();
			YAHOO.util.Dom.setXY('cms_editor', targetPosition);
		}
		
		this.receiveFormatted = function (o)
		{
			data = xml2array(o.responseXML);
			
			if (data['xml']['type'] == 'video')
			{
				loadFile('videoPlayer',{file:data['xml']['file']});
				sendEvent('videoPlayer', 'playpause');
				//wasp_loadAndPlay(data['xml']['file']);
			}
			else if (data['xml']['type'] == 'image')
			{
				var imageTarget = YAHOO.util.Dom.get('cms_'+data['xml']['name']+'_image');
				imageTarget.src = data['xml']['file'];
			}
			else
			{
				var display = YAHOO.util.Dom.get('cms_'+data['xml']['name']);
				
				if ((data['xml']['content'] != null) && strlen(data['xml']['content']))
					display.innerHTML = utf8_decode(data['xml']['content']);
				else
					display.innerHTML = '';				
			}
			
			this.currentTarget = null;
		}
		
		this.applyVideo = function (file)
		{
			currentTemplate.applySend(null, file, 0, 'video');
		}
		
		this.applyImage = function (file)
		{
			currentTemplate.applySend(null, file, 0, 'image');
		}
		
		this.applyString = function (text)
		{
			currentTemplate.applySend(text, null, 0, 'string');
		}
		
		this.apply = function ()
		{
			var inherit_id = 0;
			if (inherit && inherit.checked)
				inherit_id = YAHOO.util.Dom.get('inherit_id').value;

			this.applySend(this.editorGet(), null, inherit_id, 'text');

			this.hideEditor();
		}
		
		this.applySend = function (content, file, inherit_id, type)
		{
			var callback =
			{
				success: currentTemplate.receiveFormatted,
				failure: currentTemplate.failure,
				scope: currentTemplate
			}

			var query = 'type='+type+'&content=';
			if ((content != null) && strlen(content))
				query += urlencode(utf8_encode(content));

			if (inherit_id)
				query += '&inherit_id='+YAHOO.util.Dom.get('inherit_id').value;
			if (file)
				query += '&file='+file;
			if (this.sectionArgs[this.currentTarget])
				query += '&'+this.sectionArgs[this.currentTarget];
	
			var cObj = YAHOO.util.Connect.asyncRequest('POST', this.baseURL+'/update/'+this.currentTarget, callback, query);
		}
		
		this.cancel = function ()
		{
			this.editorSet('');

			this.hideEditor();
		}
		
		this.hideEditor = function ()
		{
			this.currentTarget = null;
			YAHOO.util.Dom.setStyle('cms_editor', 'display', 'none');
		}
	}
	
	function uiGroupManager (id, type)
	{
		this.id = id;
		this.type = type;
		
		this.types = [];
		
		this.failure = function (o)
		{
			console.log('uiGroupManager AJAX failure');
		}
		
		this.receiveGroup = function (o)
		{
			var data = xml2array(o.responseXML);
						
			if (data['xml']['added'] == '1')
			{
				var target = YAHOO.util.Dom.get('uiGroupManager_container');
				target.innerHTML += data['xml']['content'];
			}
			else
			{
				var option = document.createElement('option');
				option.id = 'uiGroupManager_palette_group_'+data['xml']['id'];
				option.innerHTML = data['xml']['name'];
				option.value = data['xml']['id'];
				
				var target = YAHOO.util.Dom.get('uiGroupManager_palette');
				target.appendChild(option);
			}
		}
		
		this.add = function ()
		{
			var groupSelector = YAHOO.util.Dom.get('uiGroupManager_palette');
			var group_id = groupSelector.parentNode.value;
			
			if (group_id != '0')
			{
				var group = YAHOO.util.Dom.get('uiGroupManager_palette_group_'+group_id);
				
				if (group)
				{
					group.parentNode.removeChild(group);
					//console.log(group.parentNode.removeChild(group));
				}
				
				this.get(group_id, 1);
			}
			else
			{
				var groupName = prompt('What would you like to call the group?');
				
				if (groupName)
				{
					var callback =
					{
						success: uiGroupManagerObject.receiveGroup,
						failure: uiGroupManagerObject.failure,
						scope: uiGroupManagerObject
					}
					
					var cObj = YAHOO.util.Connect.asyncRequest('GET', '/admin/groups/request/create?type='+this.type+'&name='+URLEncode(groupName), callback, null);
				}
			}
		}
		
		this.remove = function (group_id)
		{
			var group = YAHOO.util.Dom.get('uiGroupManager_group_'+group_id);
			
			if (group)
				group.parentNode.removeChild(group);
			
			this.get(group_id, 0);
		}
		
		this.get = function (group_id, added)
		{
			var callback =
			{
				success: uiGroupManagerObject.receiveGroup,
				failure: uiGroupManagerObject.failure,
				scope: uiGroupManagerObject
			}
			
			var cObj = YAHOO.util.Connect.asyncRequest('GET', '/admin/groups/request/get?group_id='+group_id+'&added='+added, callback, null);
		}
	}
	
	function uiRecipientManager (id)
	{
		this.id = id;
		
		this.failure = function (o)
		{
			console.log('uiRecipientManager AJAX failure');
		}
		
		this.addContact = function ()
		{
			
		}
		
		this.removeContact = function (contact_id)
		{
			var contact = YAHOO.util.Dom.get('uiRecipientManager_contact_'+contact_id);
			
			if (contact)
				contact.parentNode.removeChild(contact);
		}
		
		this.receiveGroup = function (o)
		{
			var data = xml2array(o.responseXML);
						
			if (data['xml']['added'] == '1')
			{
				var target = YAHOO.util.Dom.get('uiRecipientManager_group_container');
				target.innerHTML += data['xml']['content'];
			}
			else
			{
				var option = document.createElement('option');
				option.id = 'uiRecipientManager_group_palette_group_'+data['xml']['id'];
				option.innerHTML = data['xml']['name'];
				option.value = data['xml']['id'];
				
				var target = YAHOO.util.Dom.get('uiRecipientManager_group_palette');
				target.appendChild(option);
			}
		}
		
		this.addGroup = function ()
		{
			var groupSelector = YAHOO.util.Dom.get('uiRecipientManager_group_palette');
			var group_id = groupSelector.parentNode.value;
			
			if (group_id != '0')
			{
				var group = YAHOO.util.Dom.get('uiRecipientManager_group_palette_group_'+group_id);
				
				if (group)
				{
					group.parentNode.removeChild(group);
					//console.log(group.parentNode.removeChild(group));
				}
				
				this.getGroup(group_id, 1);
			}
			else
			{
				var groupName = prompt('What would you like to call the group?');
				
				if (groupName)
				{
					var callback =
					{
						success: uiRecipientManagerObject.receiveGroup,
						failure: uiRecipientManagerObject.failure,
						scope: uiRecipientManagerObject
					}
					
					var cObj = YAHOO.util.Connect.asyncRequest('GET', '/admin/groups/request/create?type='+this.type+'&name='+URLEncode(groupName)+'&onDeActivate=uiRecipientManagerObject.removeGroup', callback, null);
				}
			}
		}
		
		this.removeGroup = function (group_id)
		{
			var group = YAHOO.util.Dom.get('uiRecipientManager_group_'+group_id);
			
			if (group)
				group.parentNode.removeChild(group);
			
			this.getGroup(group_id, 0);
		}
		
		this.getGroup = function (group_id, added)
		{
			var callback =
			{
				success: uiRecipientManagerObject.receiveGroup,
				failure: uiRecipientManagerObject.failure,
				scope: uiRecipientManagerObject
			}
			
			var cObj = YAHOO.util.Connect.asyncRequest('GET', '/admin/groups/request/get?group_id='+group_id+'&added='+added+'&onDeActivate=uiRecipientManagerObject.removeGroup', callback, null);
		}
	}	