var highlightOn = new Image();
var highlightOff = new Image();

function setPicky(imageName, image, imagePath)
{
	if (image.src == '')
	{
		image.src = imagePath;
	}
	document.images[imageName].src = image.src;
}

function NumberOfChar(str,character)
{
	var ii, charCount;
	charCount = 0;
	for (ii=0; ii < str.length;ii++)
	{
		var cc = str.charAt(ii);
		if (cc == character)
		{
			charCount = charCount + 1;
		}
	}
	return charCount;
}

function validEmail(str)
{
	var bool;
	bool = true;
	if (str.length < 6)
	{
		bool = false;
		alert("Email address has too few characters.");
	}
	if ((bool) && ((NumberOfChar(str,'@')==0)||(NumberOfChar(str,'@')>1)))
	{
		bool = false;
		alert("Email address contains the wrong number of @'s.");
	}
	if ((bool) && (NumberOfChar(str,'.')==0))
	{
		bool = false;
		alert("Email address must contain at least one '.'.");
	}
	if ((bool) && (NumberOfChar(str,' ')!=0))
	{
		bool = false;
		alert("Email address must not contain any spaces.");
	}
	return bool;
}

function validateContactForm(pForm)
{
	var bValid;
	bValid = true;

	if (pForm.Name.value=='')
	{
		alert('You must enter your Name.');
		bValid = false;
	}
	
	if ((bValid) && (pForm.Email_Address.value != ''))
	{
		if (validEmail(pForm.Email_Address.value))
		{
			bValid = true;
		}
		else
		{
			bValid = false;
		}
	}
	
	if ((bValid) && (pForm.How_To_Contact.value==''))
	{
		alert('You must choose a preferred method of contact.');
		bValid = false;	
	}
	else
	{
		if ((pForm.How_To_Contact.value=='Phone') && (pForm.Telephone_No.value==''))
		{
			alert('Your preferred method of contact is by phone - you must enter your phone number.');
			bValid = false;
		}
		else if ((pForm.How_To_Contact.value=='Email') && (pForm.Email_Address.value==''))
		{
			alert('Your preferred method of contact is by email - you must enter your email address.');
			bValid = false;
		}
		else if ((pForm.How_To_Contact.value=='Post') && (pForm.Address.value==''))
		{
			alert('Your preferred method of contact is by post - you must enter your address.');
			bValid = false;
		}
	}

	if ((bValid) && (pForm.Enquiry.value==''))
	{
		alert('You must enter an Enquiry.');
		bValid = false;
	}
	
	return bValid;
};
