
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// This file represents functions used in the management pages (ie. manageclasses, managetemplates, etc.) //
////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////
// ******************************************** //
// Common functions - used by every manage page //
// ******************************************** //
//////////////////////////////////////////////////

function hilite(obj)
{
	///////////////////////////////////////////////////////////
	// Hilight the selected row, browser dependent branching //
	///////////////////////////////////////////////////////////

	if (navigator.appName == "Netscape")
	{
		//for(j=1; j<obj.parentNode.childNodes.length; j++)
		//{
		//	for(x=1; x<obj.parentNode.childNodes[j].childNodes.length; x=x+2)
		//		obj.parentNode.childNodes[j].childNodes[x].style.background="#FFFFFF";
		//}
		for(i=1; i<obj.childNodes.length; i=i+2)
			obj.childNodes[i].style.background="#dddddd";
	}
	else
	{
		//for(j=1; j<obj.parentNode.childNodes.length; j++)
		//{
		//	for(x=0; x<obj.parentNode.childNodes[j].childNodes.length; x++)
		//		obj.parentNode.childNodes[j].childNodes[x].style.background="#FFFFFF";
		//}
		for(i=0; i<obj.childNodes.length; i++)
			obj.childNodes[i].style.background="#dddddd";		
	}
}
function delite(obj)
{
	///////////////////////////////////////////////////////////
	// Hilight the selected row, browser dependent branching //
	///////////////////////////////////////////////////////////

	if (navigator.appName == "Netscape")
	{
		for(i=1; i<obj.childNodes.length; i=i+2)
			obj.childNodes[i].style.background="#ffffff";
	}
	else
	{
		for(i=0; i<obj.childNodes.length; i++)
			obj.childNodes[i].style.background="#ffffff";		
	}
}

function hilite1(obj)
{
	///////////////////////////////////////////////////////////
	// Hilight the selected row, browser dependent branching //
	///////////////////////////////////////////////////////////

	if (navigator.appName == "Netscape")
	{
		//for(j=1; j<obj.parentNode.childNodes.length; j++)
		//{
		//	for(x=1; x<obj.parentNode.childNodes[j].childNodes.length; x=x+2)
		//		obj.parentNode.childNodes[j].childNodes[x].style.background="#E2E2E2";
		//}
		for(i=1; i<obj.childNodes.length; i=i+2)
			obj.childNodes[i].style.background="red";
	}
	else
	{
		//for(j=1; j<obj.parentNode.childNodes.length; j++)
		//{
		//	for(x=0; x<obj.parentNode.childNodes[j].childNodes.length; x++)
		//		obj.parentNode.childNodes[j].childNodes[x].style.background="#E2E2E2";
		//}
		for(i=0; i<obj.childNodes.length; i++)
			obj.childNodes[i].style.background="gray";		
	}
}
function delite1(obj)
{
	///////////////////////////////////////////////////////////
	// Hilight the selected row, browser dependent branching //
	///////////////////////////////////////////////////////////

	if (navigator.appName == "Netscape")
	{
		for(i=1; i<obj.childNodes.length; i=i+2)
			obj.childNodes[i].style.background="#E2E2E2";
	}
	else
	{
		for(i=0; i<obj.childNodes.length; i++)
			obj.childNodes[i].style.background="#E2E2E2";		
	}
}

function isElementChecked(obj)
{
	/////////////////////////////////////////////////////////////
	// Check to see if a class has been selected from the list //
	/////////////////////////////////////////////////////////////

	var foundchecked = false;
	if(obj == "group")
		rExp = /mygroup\d+/gi;
	if(obj == "class")
		rExp = /myclass\d+/gi;
	if(obj == "program")
		rExp = /myprogram\d+/gi;
	if(obj == "indiv")
		rExp = /myindiv\d+/gi;
	if(obj == "template")
		rExp = /mytemplate\d+/gi;
	if(obj == "user")
		rExp = /myuser\d+/gi;
	if(obj == "size")
		rExp = /mysize\d+/gi;

	var arySelectors = new Array();
	
	var objElements = document.getElementsByTagName("input");
	
	var j = 0;
	for(i=0; i<objElements.length; i++)
	{
		if(objElements[i].id.search(rExp) >= 0)
		{
			arySelectors[j] = objElements[i];
			j++;
		}
	}

	for(i=0; i<arySelectors.length; i++)
	{
		if(arySelectors[i].checked)
			foundchecked = true;
	}
	
	return foundchecked;
}
function isElementCheckedValue(obj)
{
	/////////////////////////////////////////////////////////////
	// Check to see if a class has been selected from the list //
	/////////////////////////////////////////////////////////////

	var foundchecked = 0;
	if(obj == "group")
		rExp = /mygroup\d+/gi;
	if(obj == "class")
		rExp = /myclass\d+/gi;
	if(obj == "program")
		rExp = /myprogram\d+/gi;
	if(obj == "roster")
		rExp = /myindiv\d+/gi;
	if(obj == "template")
		rExp = /mytemplate\d+/gi;		

	var arySelectors = new Array();
	
	var objElements = document.getElementsByTagName("input");
	
	var j = 0;
	for(i=0; i<objElements.length; i++)
	{
		if(objElements[i].id.search(rExp) >= 0)
		{
			arySelectors[j] = objElements[i];
			j++;
		}
	}

	for(i=0; i<arySelectors.length; i++)
	{
		if(arySelectors[i].checked)
			foundchecked = arySelectors[i].value;
	}
	
	return foundchecked;
}
function add(obj)
{
	//////////////////////////////
	// Redirect to the add page //
	//////////////////////////////
	
	window.location = obj + ".do?action=add";
}

function edit(obj)
{
	///////////////////////////////////////////////////////////////
	// If an element has been checked, redirect to the edit page //
	///////////////////////////////////////////////////////////////
	
	if(isElementChecked(obj))
	{
		string1 = obj + ".do?action=edit&id=" + isElementCheckedValue(obj);
		window.location = string1;
	}
	else
		alert("You must select a " + obj + " to edit.");
}

function remove(obj)
{
	////////////////////////////////////////////////////////////////
	// If an element has been checked, delete and reload the page //
	////////////////////////////////////////////////////////////////
		
	if(isElementChecked(obj))
	{
		if(confirm("Are you sure you wish to delete this?"))
		{
			string1 = obj + ".do?action=delete&id=" + isElementCheckedValue(obj);			
			window.location = string1;
		}
	}
	else
		alert("You must select a " + obj + " to delete.");
}

function viewClasses(obj)
{
	////////////////////////////////////////////////////////////////
	// If an element has been checked, delete and reload the page //
	////////////////////////////////////////////////////////////////
		
	if(isElementChecked(obj))
	{
			string1 = "manageclasses.do?id=" + isElementCheckedValue(obj);			
			window.location = string1;
	}
	else
		alert("You must select a " + obj + " to view.");
}

/////////////////////////////////////////////////////////////////////////////////////////////
// *************************************************************************************** //
// Function specific to manageclasses.jsp, manageprograms.jsp, and manageprogramgroups.jsp //
// *************************************************************************************** //
/////////////////////////////////////////////////////////////////////////////////////////////

function sendnotification(objTo)
{
	/////////////////////////////////////////////////////////////////////////////
	// If an element has been checked, redirect to the send notifications page //
	/////////////////////////////////////////////////////////////////////////////
	if(objTo == "class")
		levelId = 3;
	if(objTo == "program")
		levelId = 2;
	if(objTo == "group")
		levelId = 1;
		
	if(isElementChecked(objTo))
		window.location = "sendnotifications.do?level=" + levelId + "&id=" + isElementCheckedValue(objTo);
	else
		alert("You must select a " + objTo + " to notify.");
}

/////////////////////////////////////////////
// *************************************** //
// Functions specific to manageclasses.jsp //
// *************************************** //
/////////////////////////////////////////////

function viewroster()
{
	/////////////////////////////////////////////////////////////////////
	// If a class has been checked, redirect to the manageroster page //
	////////////////////////////////////////////////////////////////////	

	if(isElementChecked("class"))
		window.location = "manageroster.do?id=" + isElementCheckedValue("class");
	else
		alert("You must select a class to view.");
}

function viewwait()
{
	/////////////////////////////////////////////////////////////////////////
	// If a class has been checked, redirect to the managewaitinglist page //
	/////////////////////////////////////////////////////////////////////////	

	if(isElementChecked("class"))
		window.location = "managewaitinglist.do?id=" + isElementCheckedValue("class");
	else
		alert("You must select a class to view.");
}

function editfbform()
{
	////////////////////////////////////////////////////////////////////////////////
	// If a class has been checked, redirect to the editfeedback page //
	////////////////////////////////////////////////////////////////////////////////		
		
	if(isElementChecked("class"))
		window.location = "fbform.do?action=edit&section=" + isElementCheckedValue("class");
	else
		alert("You must select a class to view the submitted feedback.");
}

function addfbform()
{
	////////////////////////////////////////////////////////////////////////////////
	// If a class has been checked, delete and redirect to the editfeedback page //
	////////////////////////////////////////////////////////////////////////////////		

	if(isElementChecked("class"))
		window.location = "editfeedback.jsp?from=addform";
	else
		alert("You must select a class to view the feedback form.");
}

function sendfbform()
{
	/////////////////////////////////////////////////////////
	// If a class has been checked, send the feedback form //
	/////////////////////////////////////////////////////////		

	if(isElementChecked("class"))
		alert("The feedback form has been sent to the atendees of this class");
	else
		alert("You must select a class to send the feedback form.");
}

function viewfb()
{
	////////////////////////////////////////////////////////////////////////////////
	// If a class has been checked, redirect to the viewfeedback page //
	////////////////////////////////////////////////////////////////////////////////		

	if(isElementChecked("class"))
		window.location = "viewfbresponses.do?id=" + isElementCheckedValue("class");
	else
		alert("You must select a class to view the submitted feedback.");
}

function choosetemplate()
{
	if(isElementChecked("template"))
		window.location = "fbform.do?action=load&temp=" + isElementCheckedValue("template") + "&section=" + GetFromQueryString("section");
	else
		alert("You must select an option to continue.");
}

//////////////////////////////////////////////////////////////////////
// **************************************************************** //
// Functions specific to manageroster.jsp and managewaitinglist.jsp //
// **************************************************************** //
//////////////////////////////////////////////////////////////////////

function addindiv(obj)
{
	window.location = "../registration.do?id=" + obj;
}

function editindiv(obj)
{
	if(isElementChecked("indiv"))
		window.location = "editindividual.do?id=" + isElementCheckedValue("indiv") + "&from=" + obj;
	else
		alert("You must select an individual to edit.");
}

function removeindiv(obj)
{
	if(isElementChecked("indiv"))
	{
		if(confirm("Are you sure you wish to remove this individual?"))
		{
			if(confirm("Do you wish to send an email regarding this?\n\nOK - Send Email\nCancel - Do NOT Send Email"))
				window.location = "editindividual.do?id=" + isElementCheckedValue("indiv") + "&action=delete&from=" + obj + "&email=yes";
			else
				window.location = "editindividual.do?id=" + isElementCheckedValue("indiv") + "&action=delete&from=" + obj + "&email=no";
		}
	}
	else
		alert("You must select an individual to remove.");
}

function copyindiv(obj)
{
	if(isElementChecked("indiv"))
		window.location = "copyindividual.do?id=" + isElementCheckedValue("indiv") + "&from=" + obj;
	else
		alert("You must select an individual to move.");
}

function copytoclass()
{

	if(isElementChecked("class"))
	{
		window.location = "copyindividual.do?cid=" + isElementCheckedValue("class") + "&id=" +  GetFromQueryString("id") ;
	}
	else	
		alert("You must select a class to move.");
}
/////////////////////////////////////////////////
// ******************************************* //
// Functions specific to managewaitinglist.jsp //
// ******************************************* //
/////////////////////////////////////////////////

function addroster()
{
	if(isElementChecked("indiv"))
	{
		if(confirm("Are you sure you wish to add this individual to the class roster?"))
			window.location = "addtoroster.do?cid=" + GetFromQueryString("id") + "&rid=" + isElementCheckedValue("indiv");
	}
	else
		alert("You must select an individual to transfer.");
}

function addnewroster()
{
	if(isElementChecked("indiv"))
	{
		if(confirm("Are you sure you wish to add this individual to a different class roster?"))
			window.location = "addtoroster.do?rid=" + isElementCheckedValue("indiv");
	}
	else
		alert("You must select an individual to transfer.");
}

function chooseclass()
{
	if(isElementChecked("class"))
	{
		if(confirm("Are you sure you wish to add this individual to this class roster?"))
			window.location = "addtoroster.do?cid=" + isElementCheckedValue("class") + "&rid=" + GetFromQueryString("rid");
	}
	else
		alert("You must select an individual to transfer.");
}

///////////////////////////////////////////////
// ***************************************** //
// Functions specific to managetemplates.jsp //
// ***************************************** //
///////////////////////////////////////////////

function addtemp()
{
	window.location = "fbform.do";
}

function edittemp()
{
	if(isElementChecked("template"))
		window.location = "fbform.do?action=edit&id=" + isElementCheckedValue("template");
	else
		alert("You must select a form template to edit.");
}

function removetemp()
{
	if(isElementChecked("template"))
	{
		if(confirm("Are you sure you wish to remove this template?"))
			window.location = "fbform.do?action=delete&id=" + isElementCheckedValue("template");
	}
	else
		alert("You must select a form template to remove.");
}
