/**
* Scripts to respond to client side form entry.
* The intention is to place the wait graphic here.
*
/
/*
 *  Turn off any form elements
 *
 *  currentForm, 				the form clicked.
 *	loadingSplashId,			the id of the element which holds the loading message.
 *	progressIndicatorId 		the id of the element that has a progress indicator.
 *
 */
 function onformsubmit(currentForm,loadingSplashId,progressIndicatorId)
	{
	var warningElem = document.getElementById(progressIndicatorId);
	var loadingSplashElm = document.getElementById(loadingSplashId);

	// Show the splash
	displaySlashElement(loadingSplashElm);

	// Disable the form
	if ( warningElem != null )
		{
		warningElem.innerHTML="Please wait loading...";
		}
	window.status="Please wait loading...";

 	// Wait for the form to submit then disable every thing
 	window.setTimeout("disableAllForms()",200);

	if ( warningElem != null )
	 	window.setTimeout("showLoadProgress('"+ progressIndicatorId +"')",1000);

 	return true ;
	}

/**
 * Re-enable the page
 *
 * This function is required as under firefox when the user uses the browser back button they see
 * the previous page in its last accessed state i.e. with the form disabled, and the splash screen
 * showing.
 *
 * @param loadingSplashId The ID of the splash screen to hide
 */
function reenablePage(loadingSplashId)
	{
	// Hide the splash screen
	hideSplashElement(loadingSplashId);

	// Enable all the forms
	enableAllForms();

	return true;
	}

/*
 *  Show a counting message
 *
 *	progressIndicatorId the id of the element that has a progress indicator.
 *
 */
  function showLoadProgress(progressIndicatorId)
 {
	if ( showLoadProgress.count == null )
		showLoadProgress.count = new Number(0);

	showLoadProgress.count++;

	var warningElem = document.getElementById(progressIndicatorId);
	warningElem.innerHTML="Please wait loading..." + showLoadProgress.count ;

  	window.setTimeout("showLoadProgress('"+ progressIndicatorId +"')",1000);

 }

/*
 *  Turn off any form elements
 */
function disableAllForms()
	{
	// Get the number of forms on the page
	var count = document.forms.length;

	// Loop through all the forms on the page
	for (var i=0;
		 i<count;
		 ++i)
		{
		// Get this form
		var form = document.forms[i];

		// Disable the form
		setFormDisabled(form, true);
		}
 	}

/*
 *  Turn on any form elements
 */
function enableAllForms()
	{
	// Get the number of forms on the page
	var count = document.forms.length;

	// Loop through all the forms on the page
	for (var i=0;
		 i<count;
		 ++i)
		{
		// Get this form
		var form = document.forms[i];

		// Enable the form
		setFormDisabled(form, null);
		}
 	}

/**
 * Set the disabled attribute for all form elements within the supplied form
 *
 * @param form The form to disable elements within
 * @param disabled The disabled flag to set
 */
function setFormDisabled(form, disabled)
	{
	// Get the number of elements within the form
	var count = form.elements.length;

 	// Loop through all of the form elements
	for (var i=0; i<count; i++)
		{
		// Get this form element
		var element = form.elements[i];

		// Does this form element NOT have a name ?
		if ( element.name == null)
			{
			// Nothing
			}

		// Else, is this a text form element ?
		else if (element.type == "text")
			{
			// Set the disabled state
			element.disabled = disabled;
			}

		// Else, assume this is some other form element
		else
			{
			// Set the disabled state
			element.disabled = disabled;
			}
		}
	}

/**
 * Display the splash screen
 *
 * NOTE: This function should be called displaySplashElement().
 *		 But I typed it in correctly. Mea Culpa -- Bruce.
 *
 * @param elm The element to display
 *
 * Deprecated use displaySlashElement()
 */
function displaySlashElement(elm)
	{
	displaySplashElement(elm)
	}
function displaySplashElement(elm)
	{
	// Do we have an element to display ?
 	if ( elm != null )
 		{
 		// Get the style attribute for this element
	  	var el = elm.style;

	  	// Is the style attribute currently to hide the splash screen ?
	  	if(el.display == "none")
	  		{
	  		// Get the container
	  		var elmContainer = document.getElementById("container");

	  		// Check it exists
	  		if ( elmContainer )
	  			{
		  		// Get the height of the container element
		  		var containerHeight = elmContainer.clientHeight;
				if (containerHeight == 0)
					{
					containerHeight = document.body.clientHeight;
					}

		  		// Get the width of the container element
		  		var containerWidth = elmContainer.clientWidth;
				if (containerWidth == 0)
					{
					containerWidth = document.body.clientWidth;
					}

		  		// Get the left margin for the container element
		  		var containerLeft = elmContainer.offsetLeft;
				if (containerLeft == 0)
					{
					containerLeft = document.body.offsetLeft;
					}

		  		// Get the top margin for the container element
		  		var containerTop = elmContainer.offsetTop;
				if (containerTop == 0)
					{
					containerTop = document.body.offsetTop;
					}

		  		// Set the splash screen to display
		  		el.display = "block";

		  		// Set the height of the splash screen
		  		// [We need to add the 'px' to the end of the height value, as we should be using the
		  		//  HTML 4 doctype, which explictliy requires a type to be appended to any values supplied,
		  		//  I.E. will work without the type, but Firefox will not set the height unless they are supplied.]
				if (containerHeight != 0)
					{
			  		el.height = "" + containerHeight + "px";
			  		}

		  		// Set the width of the splash screen
		  		if (containerWidth != 0)
					{
			  		el.width = "" + containerWidth + "px";
			  		}

		  		// Set the left of the splash screen
		  		if (containerLeft != 0)
					{
			  		el.left = "" + containerLeft + "px";
			  		}

		  		// Set the top of the splash screen
		  		if (containerTop != 0)
					{
			  		el.top = "" + containerTop + "px";
			  		}
		  		}
	  		}
		}
	}

/**
 * Hide the splash screen element
 *
 * @param id The ID of the splash screen element
 */
function hideSplashElement(id)
	{
	// Get the splash screen element
	var loadingSplashElm = document.getElementById(id);

	// Do we have an element to hide ?
	if (loadingSplashElm != null)
		{
		// Hide the splash screen
		loadingSplashElm.style.display = "none";
		}
	}

