/**
 * Set the display of an element to '' or 'none'
 *
 * @param string The id of the element to show or hide
 * @param boolean If this is true, show the element. Otherwise, hide the element
 */
function setElementDisplay(id, show)
{
	document.getElementById(id).style.display = (show) ? '' : 'none';
}


/**
 * Register a subsublist (used for closing all of the subsublists when displaying another one)
 *
 * @param id The id of the subsublist to register
 */
function registerSubSubList(id)
{
	if (document.subSubLists == null)
	{
		document.subSubLists = new Array();
	}
	
	document.subSubLists.push(id);
}


/**
 * Close all of the subsublists on the page
 *
 */
function closeSubSubLists()
{
	if (document.subSubLists != null)
	{
		for (var i = 0; i < document.subSubLists.length; i++)
		{
			setElementDisplay(document.subSubLists[i], false);
		}		
	}
}

/**
 * Submit a form
 * 
 * @param string The form Id
 * @param string The form action
 */
function submitForm(id, action)
{
	if (action != undefined) document.getElementById(id).action = action;
	document.getElementById(id).submit();
}	


/**
 * Select all checkboxes for a given model
 * @param string The list name to select all of
 * @param string The id of the checkbox which dispatched the request
 */
function selectAll(list, sourceCheckbox)
{	
	if (document.selectAllLists[list] != null)
	{	
		var checking = document.getElementById(sourceCheckbox).checked;	
		
		for(var i=0; i<document.selectAllLists[list].length; i++)
		{
			document.selectAllLists[list][i].checked = checking;
		}
	}
}


/**
 * Register a checkbox to be included in a select all list
 *
 * @param string The id of the checkbox to register
 * @param string The list name to register with
 */
function registerSelectAll(id, list)
{
	if (document.selectAllLists == null)
	{
		document.selectAllLists = new Array();
	}
	
	if (document.selectAllLists[list] == null)
	{
		document.selectAllLists[list] = new Array();
	}
	
	document.selectAllLists[list].push(document.getElementById(id));
}


/**
 * Validate the mailing list form
 */
function validateMailingList()
{
	var error = '';
	
	if (document.getElementById('mailingListEmailAddress').value == '' || !checkEmail(document.getElementById('mailingListEmailAddress').value))
	{
		error = 'Please supply your email address so that we can add you to our mailing list.';
	}
	
	if (error != '')
	{
		alert(error);
		return false;
	}
	
	return true;

}


/**
 * Validate the wishlist form
 */
function validateWishlistForm()
{
	var error = '';
	
	if (document.getElementById('OrderName').value == '')
	{
		error = 'Please enter your name.';
	}
	else	
	if (document.getElementById('OrderEmailAddress').value == '' || !checkEmail(document.getElementById('OrderEmailAddress').value))
	{
		error = 'Please enter your email address.';
	}
	else	
	if (document.getElementById('OrderTelephoneNumber').value == '')
	{
		error = 'Please enter your telephone number.';
	}
	
	
	if (error != '')
	{
		alert(error);
		return false;
	}
	
	return true;

}


/**
 * Make sure an email address is valid
 */
function checkEmail(str){
	var filter=/^.+@.+\..{2,3}$/
	return (filter.test(str))
}


/**
 * Fade a nav button in
 */
function navFadeIn(button, from, to)
{	
	if (from == undefined)
		from = '#619180';
		
	if (to == undefined)
		to = '#90C4B1';
	
	NLBfadeBg(button.id,from,to,'300');
}	


/**
 * Fade a nav button out
 */
function navFadeOut(button, from, to)
{	
	if (from == undefined)
		from = '#90C4B1';
		
	if (to == undefined)
		to = '#619180';
	
	NLBfadeBg(button.id,from,to,'300');
}	


/**
 * Change nav button bg color on click
 */
function navClick(button, to)
{			
	if (to == undefined)
		to = '#3C6051';
	
	button.style.backgroundColor = to;
}	



/**
 * Copyright notice script
 */
function right(e) {
var msg = "Copyright 2000 - 2009 by Oberon Art. WARNING! All content on this site is protected by copyright laws. Unauthorised use of our material is strictly prohibited.";
if (navigator.appName == 'Netscape' && e.which == 3) {
alert(msg);
return false;
}
if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) {
alert(msg);
return false;
}
else return true;
}

function trap() 
{
if(document.images)
{
for(i=0;i<document.images.length;i++)
  {
  document.images[i].onmousedown = right;
  document.images[i].onmouseup = right;
  }
}
}
