// JavaScript Document


/**
 * Clear a form element
 */ 
function clearFormElement(element, defaultValue){
	if (element.value == defaultValue)
		element.value = '';
}

/**
 * Unclear a form element
 */ 
function unclearFormElement(element, defaultValue){
	if (element.value == '')
		element.value = defaultValue;
}


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


/**
 * Make sure the mailing list form has the necessary things to submit
 */
function validateMailingList(){	
	var error = '';
	
	if (document.getElementById('mailingListName').value == '' || document.getElementById('mailingListName').value == 'name')
	{
		error = 'Please enter your name';
	}
	else 
	if (document.getElementById('mailingListEmailAddress').value == '' || document.getElementById('mailingListEmailAddress').value == 'email address' || !checkEmail(document.getElementById('mailingListEmailAddress').value))
	{
		error = 'Please enter a valid email address';
	}
	else 
	if (!document.getElementById('mailingListOptIn').checked)
	{
		error = 'You must tick the box in order to join the mailing list';
	}
	
	if (error != '')
	{
		alert(error);
		return false;
	}
	
	return true;
}


/**
 * Make sure the shout form has the necessary things to submit
 */
function validateShout(){	
	var error = '';
	
	if (document.getElementById('shoutAuthor').value == '' || document.getElementById('shoutAuthor').value == 'name')
	{
		error = 'Please enter your name';
	}
	else 
	if (document.getElementById('shoutBody').value == '' || document.getElementById('shoutBody').value == 'comment')
	{
		error = 'Please enter a comment';
	}
	
	if (error != '')
	{
		alert(error);
		return false;
	}
	
	return true;
}