// -----------------------------------------------------------------
//						Redland Shire Council 
// -----------------------------------------------------------------
// Class    : Scale 
// Purpose  : Handles the scale text box functionality required on
//			  client side.
// -----------------------------------------------------------------
// Calls    :
// Called by: the onkeydown event of the txtScale textbox control
//			  within default.aspx
// -----------------------------------------------------------------
// Arguments:
// Globals  :
// Returns  : False if enter key was pressed, true for all other cases.
// -----------------------------------------------------------------
// Notes    :
// -----------------------------------------------------------------
// History  :
// =================================================================	

//Function to check keyboard input and determine if the enter was the the key pressed
function isEnterKey(evt)
{
	if (!evt)
	{
		//grab IE event object
		evt = window.event;
	}
	else if (!evt.keyCode)
	{
		// grab NN4 event info
		evt.keyCode = evt.which;
	}
	return (evt.keyCode == 13);
}

//Function to adjust the current map scale, and submit a new
//scale value to the server for processing.
function adjustScale(evt)
{
	//Check if the enter key was pressed
	if (isEnterKey(evt))
	{
		//Check to see if the scale input is a number
		if (isNaN(document.forms["frmMapPage"].txtScale.value))
		{
			//Alert user of invalid input
			alert("Please enter a valid scale value, which can range from 50 to 500000.");
			
			//Highlight the invalid text so user can type over it
			document.forms["frmMapPage"].txtScale.select();
			
			return false;
		}
		
		//Check to see if the scale input is in the allowed range (50 - 500,000)
		if (Math.round(document.forms["frmMapPage"].txtScale.value) < 50 || Math.round(document.forms["frmMapPage"].txtScale.value) > 500000)
		{
			//Alert user of invalid input
			alert("Please enter a valid scale value, which can range from 50 to 500000.");
			
			//Highlight the invalid text so user can type over it
			document.forms["frmMapPage"].txtScale.select();
			
			return false;
		}
		
		//Show the loading splash
		LoadNextImage();
		
		//Submit the page to the server for processing
		document.getElementById('frmMapPage').submit();
		
		return false;
	}
	
	//enter key was not pressed so just return true and nothing will happen
	return true
}