// JavaScript form error checking functions

function isEmpty()
{
	for(i=0;i<arguments.length;i++)
	{
		els = document.getElementsByName(arguments[i]);
		for(j=0;test = els[j];j++)
		{
			var str = test.value.trim();
			if( str.length == 0 )
			{
				alert('Must have a value');
				test.style.background = '#e9c5b3';
				return false;	
			}
			else
			{
				test.style.background = '#FFFFFF';
			}
		}
	}
	return true;
}


function emailValidate()
{
	var reg = /^(.+@.+\..+)$/g;
	for(i=0;i<arguments.length;i++)
	{
		els = document.getElementsByName(arguments[i]);
		for(j=0;test = els[j];j++)
		{
			if(matched = test.value.match(reg))
			{
				test.style.background = '#FFFFFF';
			}
			else
			{
				alert('Not a valid Email address: ' + test.value);
				test.style.background = '#e9c5b3';
				return false;
			}
		}
	}
	return true;
}

function phoneCheck()
{
	for(i=0;i<arguments.length;i++)
	{
		els = document.getElementsByName(arguments[i]);
		for(j=0;test = els[j];j++)
		{
			var phone = test.value.replace(/\D/g, ''); 
			if(phone.length > 9)
			{
				test.style.background = '#FFFFFF';
			}
			else
			{
				alert('Please give a full phone number, including area code: ' + test.value);
				test.style.background = '#e9c5b3';
				return false;
			}
		}
	}
	return true;
}


// Freeware functionality plucked from the interweb
String.prototype.trim = function() {
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};
