function groupShowJoinUpProcess()
{
	document.write('<DIV id="groupSearch"></DIV>');
	document.write('<DIV id="groupResults"></DIV>');
	var aJoinUp = new ajaxObject("objGroup.php", aShowResult);
	aJoinUp.elementId = "groupSearch";
	aJoinUp.update("action=groupGetSearchBox"); 
}

function groupRunSearch()
{
	
	var q = document.getElementById('groupSearchQuery').value;
	if(q=="")
	{
		alert("You need to type something in first...");
	}
	else
	{
		//q =encodeURI(); should really encode...		
		var aDoSearch = new ajaxObject("objGroup.php", aShowResult);
		aDoSearch.elementId = "groupResults";
		aDoSearch.update("action=groupGetSearchResults&groupSearchQuery="+q); 
	}
}

function groupAttemptJoin()
{	
	var groupIds = document.groups.elements["groupId[]"];
	var param = "";	
	if(groupIds.length == undefined)
	{
		// only one group showing (doesn't return array for weird reason)
		groupId = groupIds.value;
		key = document.getElementById("key" + groupId).value;
		if(key!= "") param = groupId + "¬" + key;
	}
	else
	{
		for(i=0;i<groupIds.length;i++)
		{
			groupId = groupIds[i].value;	
			key = document.getElementById("key" + groupId);
			if(key)
			{
				if(key != "") param = param + groupId + "¬" + key.value + "¬";
			}		
		}	
	}
	
	var aDoAttemptJoin = new ajaxObject("objGroup.php", aShowResult);
	aDoAttemptJoin.elementId = "groupResults";	
	aDoAttemptJoin.update("action=groupAttemptJoin&groups=" + param, "GET")
	
}

function groupShowMine()
{
	document.write('<DIV id="groupResults"></DIV>');
	var aObj = new ajaxObject("objGroup.php", aShowResult);
	aObj.elementId = "groupResults";
	aObj.update("action=groupShowMine"); 	
}

function groupShow()
{	
	if(!document.getElementById("groupResults")) document.write('<DIV id="groupResults"></DIV>');
	var aObj = new ajaxObject("objGroup.php", aShowResult);
	aObj.elementId = "groupResults";
	aObj.update("action=groupShow"); 
}

function groupLeave()
{
	var p = confirm("Really leave selected group(s)? (DOUBLE CHECK!)");
	if(p)
	{
		param = getIds(document.groups);
		if(param!="")
		{
			var aDoAttemptJoin = new ajaxObject("objGroup.php", aShowResult);
			aDoAttemptJoin.elementId = "groupResults";	
			aDoAttemptJoin.update("action=groupLeave&groups=" + param, "GET")
		}
	}
}

function aShowResult(responseText, responseStatus)
{	
	if(responseStatus==200) 
	{
		document.getElementById(this.elementId).innerHTML=responseText;
		focusSet('groupSearchQuery');
	}
}

//a
function groupShowMembers(id)
{	
	var aObj = new ajaxObject("objGroup.php", aShowResult);
	aObj.elementId = "groupResults";
	aObj.update("action=groupShowMembers&id="+id); 
}
