// Used by select_task() for deselecting previous elements.
var oCurrentArrow = null;
var oCurrentText = null;


/*
 *	Name:		init()
 *
 *	Arguments:	
 *
 *	Description:	Initializes everything and sets focus to the first enabled input field if it exists
 */
function init()
{
	if (document.forms[0] != null)
	{
		iIndex = 1;
		bStop = false;
		oElement = document.forms[0][0];
		while (oElement != null && bStop == false)
		{
			if (oElement.disabled == false)
			{
				oElement.focus();
				bStop = true;
			}
			else
			{
				oElement = document.forms[0][iIndex];
				++iIndex;
			}
		}
	}
	
	// Implemented in ajax script
	resize_boxes();
	window.onresize = resize_boxes;
}


/*
 *	Name:		confirm_delete()
 *
 *	Arguments:	sElement	-	The value needed for the post to handle deleting the element
 *
 *	Description:	Warns the user before deleting an element and allows the user to cancel the process
 */
function confirm_delete(sElement)
{
	sMsg = "WARNING! Data will be lost!\nAre you sure you want to delete this element?\n\nClick \"OK\" to continue\nClick \"Cancel\" to stop";
	if (confirm(sMsg))
	{
		document.getElementById('delete_id').value = sElement;
		return true;
	}
	else
	{
		return false;
	}
}


/*
 *	Name:		confirm_combine()
 *
 *	Arguments:	
 *
 *	Description:	Warns the user before combining the selected elements and allows the user to cancel the process
 */
function confirm_combine()
{
	sMsg = "Are you sure you want to combine these element?\n\nClick \"OK\" to continue\nClick \"Cancel\" to stop";
	if (confirm(sMsg))
	{
		return true;
	}
	else
	{
		return false;
	}
}


/*
 *	Name:		expand()
 *
 *	Arguments:	iDutyID		-	The ID of the duty that's tasks need to be shown
 *				iValue		-	Value for the radio button to pass to the tasks
 *
 *	Description:	Displays the rows that contain the Tasks for the given Duty
 */
function expand(iDutyID, iValue)
{
	document.getElementById('Duty_' + iDutyID + '_expand').style.display = "none";
	document.getElementById('Duty_' + iDutyID + '_collapse').style.display = "";
	
	oElement = document.getElementById('Task_' + iDutyID + '_0');
	iCount = 0;
	while (oElement != null)
	{
		oElement.style.display = ""
		
		if (iValue != null &&
			document.getElementById('Rating_Task_' + iDutyID + '_' + iCount + '_0').checked == false &&
			document.getElementById('Rating_Task_' + iDutyID + '_' + iCount + '_1').checked == false &&
			document.getElementById('Rating_Task_' + iDutyID + '_' + iCount + '_2').checked == false &&
			document.getElementById('Rating_Task_' + iDutyID + '_' + iCount + '_3').checked == false &&
			document.getElementById('Rating_Task_' + iDutyID + '_' + iCount + '_4').checked == false)
		{
			document.getElementById('Rating_Task_' + iDutyID + '_' + iCount + '_' + iValue).checked = true;
		}
		
		++iCount;
		oElement = document.getElementById('Task_' + iDutyID + '_' + iCount);
	}
}


/*
 *	Name:		collapse()
 *
 *	Arguments:	iDutyID		-	The ID of the duty that's tasks need to be hidden
 *
 *	Description:	Hides the rows that contain the Tasks for the given Duty
 */
function collapse(iDutyID)
{
	document.getElementById('Duty_' + iDutyID + '_expand').style.display = "";
	document.getElementById('Duty_' + iDutyID + '_collapse').style.display = "none";
	
	oElement = document.getElementById('Task_' + iDutyID + '_0');
	iCount = 1;
	while (oElement != null)
	{
		oElement.style.display = "none"
		oElement = document.getElementById('Task_' + iDutyID + '_' + iCount);
		++iCount;
	}
}


/*
 *	Name:		select_task()
 *
 *	Arguments:	iElementID		-	The id for the element being manipulated
 *
 *	Description:	Loads and adjusts the passed in elements so it appears as selected
 */
function select_task(iElementID)
{
	oArrow = document.getElementById(iElementID + '_arrow');
	oText = document.getElementById(iElementID + '_text');
	
	// If an element is already marked as selected, unmark it
	if (oCurrentArrow != null)
	{
		oCurrentArrow.innerHTML = '';
		oCurrentText.style.fontWeight = 'normal';
	}
	
	oArrow.innerHTML = '<img src="images/ico_arrow.gif" />';
	oText.style.fontWeight = 'bold';
	
	// Set the selected element so it can be deselected later
	oCurrentArrow = oArrow;
	oCurrentText = oText;
}


/*
 *	Name:		check_boxes()
 *
 *	Arguments:	sElementList	-	The list of elements to be changed
 *				sStatus		-	Tells if the check boxes should be checked or unchecked
 *
 *	Description:	Will go through the list of elements and either check or check all of the boxes in the list
 */
function check_boxes(sElementList, sStatus)
{
	aList = sElementList.split(',');
	for (i = 0; i < aList.length; ++i)
	{
		document.getElementById(aList[i]).checked = sStatus;
	}
}

function loading_message()
{
	document.getElementById('report').style.display = 'none';
	document.getElementById('hidden_table').style.display = 'none';
	msg_box = document.getElementById("working_box");
	msg_box.style.display = "block";
	msg_box.style.margin = "20px 0px 0px 0px";
	msg_box.style.width = "100%";
	msg_box.style.textAlign = "center";
	msg_box.innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" WIDTH="300" HEIGHT="150" id="myMovieName"><PARAM NAME=movie VALUE="images/WaitingAnimation.swf"><PARAM NAME=quality VALUE=high><PARAM NAME=bgcolor VALUE=#F5F5F5><EMBED src="images/WaitingAnimation.swf" quality=high bgcolor=#F5F5F5 WIDTH="300" HEIGHT="150" NAME="myMovieName" ALIGN="center" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>';
	return;
}