//Define some variables....

var hasSubmitted = "false";

// Functions....

function doFocus(fieldNumber)
{

	// Give the focus to the $fieldNumber element on the first form.
	if (document.forms[0].elements[fieldNumber])
	{

		//alert('Will focus:' + document.forms[0].elements[fieldNumber].name);
		document.forms[0].elements[fieldNumber].focus();

	}

}

function oneClickOnly() 
{

   if (hasSubmitted == "true")
   {

        alert("Please wait for the server to respond...\n\nIf you have had no response then please Refresh/Reload and try again.");
        return false;

   } else {

        hasSubmitted = "true";
        return true;   

   }

}

/*

	This function implements the ability to type a string inside a SELECT box.
	The highlighted element will reflect the string typed, much as usual GUI
	functionality.  This still appears to be absent within modern browsers?

	In blatant violation of all of my beliefs, I am sorry to admit that this
	feature is for.......wait for it.........Internet Explorer only....yik...

	Usage:		onKeyPress = "return shiftHighlight(event.keyCode, this);"	
	Returns:	Always returns false

*/

	var timerid     = null;
	var matchString = "";
	var mseconds    = 300;									// Length of time before search string is reset

	function shiftHighlight(keyCode,targ)
	{

		keyVal      = String.fromCharCode(keyCode);			// Convert ASCII Code to a string
		matchString = matchString + keyVal;					// Add to previously typed characters

		elementCnt  = targ.length - 1;						// Calculate length of array -1

		for (i = elementCnt; i > 0; i--)
		{

			selectText = targ.options[i].text.toLowerCase(); // convert text in SELECT to lower case

		//  if key presses match the first characters of the OPTION text
			if (selectText.substr(0,matchString.length) == 	matchString.toLowerCase())
			{

				targ.options[i].selected = true;			// Make the relevant OPTION selected

			}

		}

		clearTimeout(timerid);								// Clear the timeout
		timerid = setTimeout('matchString = ""',mseconds);	// Set a new timeout to reset the key press string
		
		return false;										// to prevent IE from doing its own highlight switching

	}

	function clearTimer(timerid)
	{

			//var timerid;
			clearTimeout(timerid);

	}

	function confirmDelete(page, id)
	{

		ok = confirm('Are you sure you wish to delete this record?');

		if (!ok)
		{

			return false;
		
		}

	}
	
	function toUpperCaseWords(field)
	{
	
		var buf = "";
		var i;

		fieldValue  = field.value
		fieldLength = field.value.length;

		for(i=0; i < fieldLength; ++i)
		{

			if(i == 0 || fieldValue.charAt(i - 1) == " ")
			{
	
				buf += fieldValue.charAt(i).toUpperCase();
				
			} else {
			
				buf += fieldValue.charAt(i).toLowerCase();
				field.value=buf;
				
			}
	
		}

		
	}

	function confirmRef(ref)
	{

		window.open("ref.php?ref=" + ref,"","scrollbars=no,left=20,top=20,width=200,height=45");	

	}

	function onlineHelp(ref, type)
	{

		window.open("help.php?type=" + type + "&amp;ssid=" + ref,"","scrollbars=yes,left=20,top=20,width=400,height=350");	

	}
