
var DHTML = (document.getElementById || document.all || document.layers);

function getObj(name)
{
  if (document.getElementById) {
    this.obj = document.getElementById(name);
    this.style = document.getElementById(name).style;
  }
  else if (document.all) {
    this.obj = document.all[name];
    this.style = document.all[name].style;
  }
  else if (document.layers) {
    this.obj = getObjNN4(document,name);
    this.style = this.obj;
  }
}

function getObjNN4(obj,name)
{
  var x = obj.layers;
  var foundLayer;
  for (var i=0;i<x.length;i++)
  {
    if (x[i].id == name)
      foundLayer = x[i];
    else if (x[i].layers.length)
      var tmp = getObjNN4(x[i],name);
    if (tmp) foundLayer = tmp;
  }
  return foundLayer;
}

function findPosX(obj)
{
  var curleft = 0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {
      curleft += obj.offsetLeft
      obj = obj.offsetParent;
    }
  }
  else if (obj.x)
    curleft += obj.x;
  return curleft;
}

function findPosY(obj)
{
  var curtop = 0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {
      curtop += obj.offsetTop
      obj = obj.offsetParent;
    }
  }
  else if (obj.y)
    curtop += obj.y;
  return curtop;
}

function f() {
	if (xmlhttp.readyState == 4) {
		resp = xmlhttp.responseText;
		dListObj = new getObj('memberList');
		dListObj.obj.innerHTML = resp;
	}
}

// the initial population of the membership list is done using xmlhttp
// which makes a request to the rpc module and gets a formatted version
// of the list of groups that it passes along
/*	function populateMemberList()
{
	dListText = '';
	for (i=0; i<userMemberOf.length; i++) {
		dListText = dListText + userMemberOf[i] + ", ";
	}
	
	xmlhttp.open("GET", "mat.php?mod=ModMembership&func=doInitialGroupRPC&grps="+dListText, true);
	xmlhttp.onreadystatechange = f;
	xmlhttp.send(null);
}

function removeFromGroup(grp) {
	tmp = new Array();
	c = 0;
	for (i=0; i<userMemberOf.length; i++) {
		if (grp != userMemberOf[i]) {
			tmp[c] = userMemberOf[i];
			c = c + 1;
		}
	}
	userMemberOf = tmp;
	populateMemberList();
}
*/
/*
function addGroupWindow() {
	// opens the "add to group" window
	window.open('mat.php?mod=ModMembership&func=groupBrowser', 
	            'mat_addGroupWindow', 
	            'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=300,height=420');
}

function drawSuggest() {
	if (xmlhttp.readyState == 4) {
		resp = xmlhttp.responseText;
		dListObj = new getObj('suggest');
		dListObj.obj.innerHTML = resp;
	}
}

function performSuggestRPC(text) {
	dListObj = new getObj('suggest');
	dListObj.obj.innerHTML = "please wait...";
	xmlhttp.open("GET", "mat.php?mod=ModMembership&func=doSuggest&text="+text, true);
	xmlhttp.onreadystatechange = drawSuggest;
	xmlhttp.send(null);
}
*/
/*
function doSuggest(w, e) {
	var key;
	
	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode; 
	}
	else if(e.which) {
		// netscape
		key = e.which; 
	}
	else {
		// no event, so pass through
		return true;
	}
	
	xArg = w.value + String.fromCharCode(key);
	if(lastTimerID) {
		clearTimeout(lastTimerID);
		lastTimerID  = 0;
	}
	lastTimerID = setTimeout("performSuggestRPC(xArg)", 500);
}
*/
/**
 * This code is used by the so-called AJAX portion of the membership
 * app.  This is used to dynamically get bits and pieces of LDAP requests
 * from the XMLRPC Modules.
 */
var xmlhttp=false;
try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
	try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (E) {
		xmlhttp = false;
	}
}

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}

