//Created By: Chris Campbell
//www.particletree.com

var gErrors = 0; //number of errors is set to none to begin with

function validate()
{
var tables; //variable which will become an array holding all elements with the td tagname

// store all <td> elements in the tables array
tables = document.getElementsByTagName('td')

//loop through all the <td> elements 
	for (i=0; i<tables.length; i++)
		{
		// if the class name of that td element is rules check to see if there are error warnings
		if (tables[i].className == "rules")
			{
				inputValue = document.getElementById(tables[i].id.substr(0,tables[i].id.length-3));
				inputRules = inputValue.className.split(' '); // get all the rules from the input box classname
				inputRequired = inputRules[1]; // required means field is required

				if (inputRequired == 'required') { attach(inputValue); }
				
				//if there is a thank you or its blank then it passes
				if (tables[i].innerHTML == 'Thank You' || tables[i].innerHTML == '')
				{
				tables[i].style.display = 'none';
				tables[i].style.float = 'left';
				tables[i].style.color = '#000000';//the color is changed to blank or stays black
				}
				else
				{
				gErrors = gErrors + 1; //the error count increases by 1
				tables[i].style.display = 'inline';
				tables[i].style.float = 'left';
				tables[i].style.color = '#ff0000';//error messages are changed to red
				}
			}
		}
		
		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 
		{
			return true;//set this to true in practice to allow the form to submit
		}
	

}