// JavaScript Document
function initiate_staff()
{
	newstaff_auto_completer = new Ajax.Autocompleter('newstaff', 'newstaff_auto_complete', '/snip_search.php?t=uid,gid', {
	  minChars: 2
	  ,	afterUpdateElement: staffAddItemToList
	  , select: "New"});	
}

function staffAddItemToList(text,li)
{
	var $id = li.id;
	var $value = li.down().innerHTML;
	
	/** we need to go up the DOM tree one branch, then add this person/organisation as a new line.
	value - hidden, text.
	*/
	
	var $new_li = new Element('li', {'class':'foo'}).update($id + ". " + $value);
	
	text.up().up().insert({top: "<li id='newstaff_"+$id+"'><input type='hidden' name='" + text.identify() + "_ID[]' class='" + text.identify() + "_ID' value='" + $id + "' />" + $value + " <small><a href='#' onclick='return removenewstaff(\""+$id+"\")'>Remove</a></small></li>"});
}

function removenewstaff($id)
{
    $('newstaff_'+$id).remove();
    return false;
}

function removestaff($id,$pageid)
{
  if(confirm("Are you sure you want to remove this owner from this page?"))
  {
	var $url = "pages.php5";
    var $params = { 
  	  method: 'post',
	  parameters: {
	      remove_staff: $id,
	      pageid: $pageid
		}
	};
    new Ajax.Updater("person_"+$id,$url,$params);
  }
  return false;
}

function removegroupowner($id,$pageid)
{
  if(confirm("Are you sure you want to remove this group owner from this page?"))
  {
	var $url = "pages.php5";
    var $params = { 
  	  method: 'post',
	  parameters: {
	      remove_groupowner: $id,
	      pageid: $pageid
		}
	};
    new Ajax.Updater("group_"+$id,$url,$params);
  }
  return false;
}

function addgroup()
{
  var $url = "pages.php5";
  var $params = {
    method: 'post',
    insertion: 'before',
    parameters: {
        addgroupselector: 1
      }
  };
  new Ajax.Updater("addgrouplink",$url,$params);
  return false;
}