//Created By: Chris Campbell
//www.particletree.com
// modified by Web Solutions 9


var gErrors = 0; //number of errors is set to none to begin with

function validate()
{
var spans; //variable which will become an array holding all elements with the td tagname

// store all <td> elements in the tables array
spans = document.getElementsByTagName('span')

//loop through all the <span> elements 
	for (i=0; i<spans.length; i++)
		{
		// if the class name of that td element is rules check to see if there are error warnings
		if (spans[i].className == "rules")
			{

				//if there is a thank you or its blank then it passes
				if (spans[i].innerHTML == 'Thank You' || spans[i].innerHTML == '' )
				{
				spans[i].style.color = '#000000';//the color is changed to blank or stays black
				}
				else
				{
				  gErrors = gErrors + 1; //the error count increases by 1
				  spans[i].style.color = '#ff0000';//error messages are changed to red
          if (spans[i].innerHTML == '*') {
            spans[i].innerHTML = 'Required';
          }
				}
			}
		}
		
		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 
		{
            pass_01 = document.getElementById('pass_01');
            pass_02 = document.getElementById('pass_02');

            if (pass_01.value != pass_02.value) {
              alert("Please check to make sure the entered the same password both times.");
              return false;
            }
            
			return true;//set this to true in practice to allow the form to submit
		}
	

}
