//Created By: Chris Campbell
//www.particletree.com

var gErrors = 0; //number of errors is set to none to begin with
var img_err = null;
function validate()
{
	
	var objInput = document.getElementsByTagName('input'); // store all input fields
	for (var iCounter=0; iCounter<objInput.length; iCounter++) {
		attach(objInput[iCounter]);
	}
	
	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")
			{
				img_err = document.getElementById(tables[i].id+"-err");
				//if there is a thank you or its blank then it passes
				if (img_err.style.display == 'block')
				{
					gErrors = gErrors + 1; //the error count increases by 1
				}
			}
		}
		
		if (gErrors > 0){
			//if there are any errors give a message
			alert ("SVP, veuillez compléter tout les champs requis. Ils sont marqués d'un point rouge");
			gErrors = 0;// reset errors to 0
			return false;
		}
		
		else 
		{
			return true;//set this to true in practice to allow the form to submit
		}
	

}
