var course_window_properties = "toolbar=no,menubar=no,location=no,directories=no," +
							   "resizable=yes,scrollbars=yes,width=785,height=410,left=100,top=100";

_theUnassignedRow = null;

doUnassign = function(rowEle, assignmentid)
{
	if(confirm("Are you sure you want to remove the selected course?"))
	{
		_theUnassignedRow = rowEle;
		
		new SimpleRequest("procDiv","/pub/user/unassign.htm","post","assignmentid="+assignmentid,onUnassignComplete);
	}
}

onUnassignComplete = function(rsp)
{
	if(rsp.status == 200)
	{
		var lastStyle = null;
		var tmpStyle = null;
		if($("unassignErrorMsg")) {
			msg = $("unassignErrorMsg").innerHTML;
			alert(msg);
		}
		else{ msg = null;}

		
		if(_theUnassignedRow != null && msg == null)
		{
			tab = _theUnassignedRow.parentNode;
			myIndex = -1;
			for(var i=0;i<tab.childNodes.length;i++)
			{
				if(tab.childNodes[i].id == _theUnassignedRow.id)
				{
					myIndex = i;
					lastStyle = _theUnassignedRow.className;
					_theUnassignedRow.style.display = "none";
					continue;
				}
				//don't assign a style to any previously removed rows
				if(myIndex > 0 && tab.childNodes[i].nodeName == "TR" && tab.childNodes[i].style.display != "none")
				{
					tmpStyle = tab.childNodes[i].className;
					tab.childNodes[i].className = lastStyle;
					
					//the SCHEDULED for removal is it's on row.  If so, hold on to the style and set it for
					//the next row - which is the course
					if(tab.childNodes[i].id != "alert")
						lastStyle = tmpStyle;
				}
			}
		}
		else
		{
			alert("Display could not be updated!");
		}
	}
	else
	{
		alert("There was a problem unassigning");
	}
}



toggleMe = function(obj, id)
{
	var e = $(id);
	if(e.style.display == "none")
	{
		obj.src = '/images/collapse.gif';
		e.style.display = "block";
	}
	else
	{
		obj.src = '/images/expand.gif';
		e.style.display = "none";
	}
}

goPage = function(itemIndex)
{
	var url = "/pub/u/coursework.html?p=" + itemIndex;
	if(document.location.search.indexOf("hideHeader=1") > 0)
	{
		url += "&hideHeader=1";
	}
	
	document.location = url;
}

