
// Redirect the user to the full blown nzpost tool.
function RedirectTool(url)
{
	window.location = url;
}

// Give focus to the control based on the name provided.
function SetFocus(name)
{
	var control = document.getElementById(name);
	
	if (control != null)
	{
		control.focus();
	}
}

// Determines if the keypress by the client was a return key '13'
// If it is then call the click event for the button that is required
// to process the tools values.
function EvaluateKeyPress(e, buttonName)
{	
	if (e.which || e.keyCode)
	{
		if ((e.which == 13) || (e.keyCode == 13))
		{	
			var button = document.getElementById(buttonName);
	
			if (button != null) 
			{
				if (e.preventDefault)
				{
					e.preventDefault();
				}
				else
				{
					e.cancelBubble = true;
					e.returnValue = false;
					e.cancel = true;
				}
				
				button.click();
			}
		}
	}
}

var AnimateElm = null;
var Incrementer = 0;

//Display a loading message when submit buttons are clicked

function LoadingMessage(form)
{
	var formdiv = document.getElementById(form);
	var loadingdiv = document.createElement('div');
	loadingdiv.id = 'loading';
	var p = document.createElement('p');
	var text = document.createTextNode('Loading...');
	p.appendChild(text);
	loadingdiv.appendChild(p);	
	//we get and set the height and width of the loading div here so it fills the form properly 
	//(minus a couple of pixels so the borders of the background div show through)
	//we need to drill down one level as there's nested divs for each form
	loadingdiv.style.width = formdiv.getElementsByTagName('div')[0].offsetWidth - 2 + 'px';
	loadingdiv.style.height = formdiv.getElementsByTagName('div')[0].offsetHeight - 3 + 'px';
	formdiv.appendChild(loadingdiv);
	AnimateElm = p;
	Incrementer = 0;
	LoadingAnimate();
}

// loops thru 13 different sets of frames before looping thru again.
// 24 x 16 = 384. Each frame is 16px in height.

function LoadingAnimate(){
	var localtimer = setTimeout('LoadingAnimate()', 150)
	
	if (Incrementer >= '384') Incrementer = 0;
	else
	{
		AnimateElm.style.backgroundPosition = '0px -' + Incrementer + 'px';
		Incrementer = Incrementer + 16;
	}
}
	