// JavaScript Document /includes/form_validation.js

function chk_person()
{
	if (document.contact.person.value == '')
	{
		alert('Oops! You forgot to give us your name.');
		return false;
	}
	else return true;
}

function chk_email()
{
	var RegExpEmail = /^[a-zA-Z0-9_\.\-]+\@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/;
	if (document.contact.submit_by.value == '')
	{
		alert('We need your email address.');
		return false;
	}
	else if (RegExpEmail.test(document.contact.submit_by.value)) return true;
	else
	{
		alert('We need your valid email address.');
		return false;
	}
}

function chk_phone()
{
	var RegExpPhone = /^[2-9]{1}\d{9,13}$/;
	if (document.contact.phone.value == '')
	{
		alert('We need your phone number.');
		return false;
	}
	else if (RegExpPhone.test(document.contact.phone.value)) return true;
	else
	{
		alert('Your phone number needs to be 10 digits including your area code. OK to add an extension, but no spaces; digits only.');
		return false;
	}
}

function chk_zip()
{
	var RegExpZip = /^\d{5}$/;
	if (RegExpZip.test(document.contact.zip.value)) return true;
	else
	{
		alert('We\'d like your 5-digit zip code; digits only.');
		return false;
	}
}

function chk_message()
{
	if (document.contact.message.value == '')
	{
		alert('The \'Message\' field is empty. We want to hear what you have to say.');
		return false;
	}
	else return true;
}

function checkform()
{
	var RegExpZip = /^\d{5}$/;
	var RegExpPhone = /^[2-9]{1}\d{9,13}$/;
	var RegExpEmail = /^[a-zA-Z0-9_\.\-]+\@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/;
	var err_txt = '';
	if (document.contact.person.value == '') err_txt += '- First and Last Names\n';
	if (!RegExpEmail.test(document.contact.submit_by.value)) err_txt += '- Valid Email Address\n';
	if (!RegExpPhone.test(document.contact.phone.value)) err_txt += '- Area Code & Phone Number, no spaces or characters\n';
	if (document.contact.message.value == '') err_txt += '- Message\n';
	if (err_txt != '')
	{
		alert('Did you forget these fields?\n\n' + err_txt);
		return false;
	}
	else return true; // submit form
}
