/***********************************************************************
*  CheckMultiClick_v404.js
*
*	This file is included in the FormatPage and contains a function
*	which is used to prevent multiple form submissions or link clicks
*	on a given page.
************************************************************************/

var multiClickOK = true;

var clickedArray = new Array(5);  // Array of objects that have been clicked
var addIndex = 0;				  // the index that is used to add a clicked object to the clicked object array

///////////////////////////////////////////////////////////////////////////
// Intended to be Called in MasterOnSubmit and in the onlick attribute of
// an ImageKeyHyperLinkControl if desired.
// The first time the function is called, it will return true.
// If the function has already been called and is called again, it will
// display a message to the user and return false.
///////////////////////////////////////////////////////////////////////////
function pagePreviouslyClicked()
{
	if (multiClickOK)
	{
		multiClickOK = false;
		return false;
	}
	else
	{
		alert('Please wait while we process your request.');
		return true;
	}
}

///////////////////////////////////////////////////////////////////////////
// Function that will prevent a specific object on a page from being
// clicked more than once. For example if the links on the nav bar all
// call this, then when the user clicks the KeySearch link a subsequent
// click on the KeySearch link will display an alert message.  Whereas
// when the user clicks the KeySearch link the user will be allowed to
// click a different link (e.g. Search).
///////////////////////////////////////////////////////////////////////////
function objectPreviouslyClicked(clickedObj)
{
	// If we haven't added any clicked objects to our array yet add the clicked object and return.
	if (addIndex == 0)
	{
		clickedArray[addIndex++] = clickedObj;
		return false;
	}

	// We've got some objects that have been clicked already so check if the clicked object matches one
	// that's in our array.
	for (var index=0; index < clickedArray.length; index++)
	{
		if (clickedArray[index] == null)
		{
			// Our initial array is a given size so when we run into a null that means
			// we need to add the current clicked object to our array.
			clickedArray[addIndex++] = clickedObj;
			return false;
		}

		if (clickedArray[index] == clickedObj)
		{
			// The clicked object has already been clicked on this page so display a 
			// message to the user.
			alert('Please wait while we process your request.');
			return true;
		}
	}

	// Add the clicked object to our array since we didn't find it in the objects already clicked.
	clickedArray[addIndex++] = clickedObj;
	return false;
}

if(typeof(Sys) !== "undefined") {
	Sys.Application.notifyScriptLoaded();
}