function toggleClassName( event, elem, onStr, offStr )
{
	var elem = document.getElementById( elem.id );
	elem.className = ( event.type == 'mouseover' ) ? elem.id + onStr : elem.id + offStr;
}
function toggle( event, elem )
{
	toggleClassName( event, elem, ' on', ' off' );
}
function swapImage( event, elem )
{
	toggleClassName( event, elem, '_on', '' );
}
function openWindow( url, winWidth, winHeight ) 
{
	try
	{
		var left = ( ( screen.width - winWidth ) / 2 );
		var top = ( ( screen.height - winHeight ) / 2 );
		var theWin = window.open( url, 'results', 'toolbar=no,locationbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=' + winWidth + ',height=' + winHeight + ',left=' + left + ',top=' + top );
		theWin.focus();
	}
	catch ( ex )
	{
		debug( "exception thrown : " + ex.message );
	}
}
function swap(name, flag, imgPath)
{
	var state = (flag) ? '_on' : '';
	var srcPath = imgPath + name + state + '.gif';
	document.getElementById(name).src = srcPath;
}

var message;
var hasErrors;
function validateContactForm()
{
	hasErrors = false;
	message = "Please complete the following field(s):\n\n";
	checkField(document.forms[0].realname.value, "Your Name");
	checkEmailField(document.forms[0].email.value, "E-mail address");
	checkField(document.forms[0].subject.value, "Subject");
	checkField(document.forms[0].message.value, "Text of message");
	
	if (hasErrors)
	{
		alert(message);
		return;
	}

	document.forms[0].submit();
}
function checkField(fieldValue, fieldName)
{
	if (fieldValue == null || fieldValue.length < 1)
	{
		message += "* " + fieldName + "\n";
		hasErrors = true;
	}
}
function checkEmailField(fieldValue, fieldName)
{

	if (fieldValue == null || fieldValue.length < 1 || fieldValue.indexOf(".") == -1 || fieldValue.indexOf("@") == -1)
	{
		message += "* " + fieldName + "\n";
		hasErrors = true;
	}
}
function writeYear(id)
{
	var elem = document.getElementById(id);
	if (elem != null)
	{
		elem.innerHTML = new Date().getFullYear();
	}
}

window.onload = function()
{
	writeYear('year');
};
