//Created By: Chris Campbell
//www.particletree.com

var gErrors = 0; //number of errors is set to none to begin with

function validate()
{
var feedback; //variable which will become an array holding all elements with the td tagname

// store all <td> elements in the tables array
feedback = document.getElementsByTagName('span')

//loop through all the <td> elements 
	for (i=0; i<feedback.length; i++)
		{
		// if the class name of that td element is rules check to see if there are error warnings
		if (feedback[i].className == "rules")
			{
				//if there is a thank you or its blank then it passes
				if (feedback[i].innerHTML == 'Thank You' || feedback[i].innerHTML == '' )
				{
				//feedback[i].style.display = 'block';
				feedback[i].style.background = '#666';
				}
				else
				{
				gErrors = gErrors + 1; //the error count increases by 1
				feedback[i].style.display = 'block';
				}
			}
		}
		
		if (gErrors > 0){
			//if there are any errors give a message
			alert ("Please make sure all fields are properly completed.  Errors are marked in red!");
			gErrors = 0;// reset errors to 0
			return false;
		}
		
		else 
		{
			//alert("The Form Is Valid!");
			return true;//set this to true in practice to allow the form to submit
		}
	

}