/******************************************************************************
*	client.js
*
*	Contains application client-side script for the Wallace Foundation Web.
*
******************************************************************************/
// ControlKeyPress(field, e, btnId)
//	Took basic functionality of the old method, but tried to 
//	better handle the scripting DOM.
function ControlKeyPress(field, e, btnId)
{
	var keycode;
	var btn;

	if (!window.event && !e)	// just exit here
		return true;

	if (window.event)	// ie-type event capable
		keycode = window.event.keyCode;
	else
		keycode = e.which;

	if (keycode == 13)
	{
		// this is how we check for newer browser...
		if (document.getElementById)
		{

			btn = document.getElementById(btnId);	

			if (btn)
			{
				btn.click();
				return false;
			}
		}
		else
		{
			// if we care about ns4, then change
			// this else clause to handle it.
		}
	}

	return true;
}

function popUp(URL)
{
	day=new Date();
	id=day.getTime();
	eval("page"+id+"=window.open(URL,'"+id+"');");
}

function popUp_Sized(URL)
{
	day=new Date();
	id=day.getTime();
	eval("page"+id+"=window.open(URL,'"+id+"','toolbars=0,scrollbars=1,location=0,statusbars=0,menubars=0,resizable=1,width=540,height=480');");
}

function CheckAll(field,len)
{
	for (i=0; i<len; i++)
	{	
		newField = field + "_" + i;
		input = eval(document.all[newField]);
		input.checked=true;
	}
}

function UnCheckAll(field,len)
{
	for (i=0; i<len; i++)
	{	
		newField = field + "_" + i;
		input = eval(document.all[newField]);
		input.checked=false;
	}
}

function popDocument(URL)
{
	day=new Date();
	id=day.getTime();
	eval("page"+id+"=window.open(URL,'"+id+"','toolbars=0,scrollbars=1,location=0,statusbars=0,menubars=0,resizable=1,width=813,height=615');");
}

function CheckRemove(object)
{
	if (object.checked)
	{	
		if (!confirm("Once a record has been removed, it may not be undone. Do you wish to continue?"))
			object.checked = false;
	}
}

// attempts to scroll the specified control into view (at bottom of the page).
function ScrollToControl(controlId)
{
	var control;

	if (document.getElementById)
	{
		control = document.getElementById(controlId);
		
		if (control.scrollIntoView)
		{
			control.scrollIntoView(false);

			if (control && control.focus)
				control.focus();
		}
	}
}