	//when next button is clicked
	//find out which step is clicked
	//validate the fields in that step
	//if all fields validate
	//move to the next step

	function initNextButtons() {
		nextButtons = document.getElementsByTagName("p");
		for(i=0;i<nextButtons.length;i++){
			if(nextButtons[i].className == "next_button"){
				nextLink = nextButtons[i].getElementsByTagName("a");
				nextLink[0].onclick = validateForm;
			}
		}
	}
	
	function initBackButtons() {
		backButtons = document.getElementsByTagName("p");
		for(i=0;i<backButtons.length;i++){
			if(backButtons[i].className == "back_button"){
				backLink = backButtons[i].getElementsByTagName("a");
				backLink[0].onclick = moveBackStep;
			}
		}
	}
	
	function validateForm() {
		//if all fields validate, move to the next step
		currentStep = this.parentNode.parentNode.parentNode;
		requiredFieldsArr = new Array();
		
		//find all input fields that are required in the current step
		requiredFields = currentStep.getElementsByTagName("input");
		requiredSelects = currentStep.getElementsByTagName("select");
		
		//check inputs
		for(i=0;i<requiredFields.length;i++){
			required = requiredFields[i].className.split(" ");
			for(j=0;j<required.length;j++){
				if(required[j]=="required"){
					requiredFieldsArr[requiredFieldsArr.length] = requiredFields[i];
				}
			}
		}
		
		//check selects
		for(i=0;i<requiredSelects.length;i++){
			required = requiredSelects[i].className.split(" ");
			for(j=0;j<required.length;j++){
				if(required[j]=="required"){
					requiredFieldsArr[requiredFieldsArr.length] = requiredSelects[i];
				}
			}
		}		
		
		//now we have an array with all the inputs that we need to check
		//so lets check them! bad ones get added to totalErrorsArr
		totalErrorsArr = new Array();
		for (i=0;i<requiredFieldsArr.length;i++){
			highlightArea = requiredFieldsArr[i].parentNode;
			if (requiredFieldsArr[i].value == ""){
				currentClasses = highlightArea.className.split(" ");
				var addError = true;  //to see if we should add an error
				for (j=0;j<currentClasses.length;j++){
					if (currentClasses[j] == "error") {
						addError = false;
					}
				}
				if (addError){
					//highlightArea.className = "error " + highlightArea.className;
					highlightArea.style.backgroundColor = "#F6F6C3";
				}
				
				//add to the bad error array
				totalErrorsArr[totalErrorsArr.length] = requiredFieldsArr[i];
				
			} else {
				highlightArea.style.backgroundColor = "";
				//remove the error class from the paragraph
				/*errorHighlight = highlightArea.className.split(" ");
				highlightArea.className = "";
				for(j=0;j<errorHighlight.length;j++){
					//only re-add the non error class
					if(errorHighlight[j] != "error"){
						highlightArea.className = highlightArea.className + " " + errorHighlight[j];
					}
				}*/
			}
		}		

		//find the error message box
		findErrorMessage = currentStep.getElementsByTagName("p");
		for(i=0;i<findErrorMessage.length;i++){
			if(findErrorMessage[i].className=="error_message"){
				errorMessage = findErrorMessage[i];
			}
		}

		if(totalErrorsArr.length > 0){		
			errorMessage.style.display="block";
			errorMessage.innerHTML = "Please fill in the " + totalErrorsArr.length + " required field" + (totalErrorsArr.length > 1 ? "s" : "") + " highlighted below before proceeding.";
			
			//fail the form, because you have errors
			return false;
		} else {
			errorMessage.style.display="none";
			//all valid, move to next step
			moveToNextStep(currentStep);
		}
	}
	
	function moveToNextStep(previousStep) {
//		alert('here we go' + previousStep.id);
				
		//check form_tabs object to see what the next step is
		stepChecker = previousStep.id.split("_");
		stepChecker = stepChecker[0];
		
		formTabs = document.getElementById("form_tabs");
		searchFormTabs = formTabs.getElementsByTagName("li");
		for(i=0;i<searchFormTabs.length;i++){
			if(searchFormTabs[i].id == stepChecker + "_tab"){
				//found the current tab so the next one is the one we want
				nextTab = searchFormTabs[i+1];
			}
		}
		
		//split off the _tab
		nextTab = nextTab.id.split("_");
		document.body.className = nextTab[0];
		return false;
		
		//move to the next step
		
		//steps involved in moving to the next step:
		//1.change the body class to show the next tab structure
		//2.set a cookie so that if the page is accidentally 
		//refreshed all the form fields are saved
	}
	
	function moveBackStep() {
		//we don't need to do any validation to move back,
		//just find out what step we are on, and move back a step
		currentStep = this.parentNode.parentNode.parentNode;
		//strip content
		currentStep = currentStep.id.split("_");
		currentStep = currentStep[0];

		//find the step before the current step in form_tabs
		formTabs = document.getElementById("form_tabs");
		formTab = formTabs.getElementsByTagName("li");
		
		for(i=0;i<formTab.length;i++){
			//strip _tab
			stripTab = formTab[i].id.split("_");
			stripTab = stripTab[0];
			if(stripTab == currentStep) {
				moveBackTo = formTab[i-1].id;
			}
		}
		
		//strip _tab
		moveBackTo = moveBackTo.split("_");
		moveBackTo = moveBackTo[0];
		
		//move back!
		document.body.className = moveBackTo;
		return false;
	}

	
	function GetCookie(sName)
	{
	  // cookies are separated by semicolons
	  var aCookie = document.cookie.split("; ");
	  for (var i=0; i < aCookie.length; i++)
	  {
	    // a name/value pair (a crumb) is separated by an equal sign
	    var aCrumb = aCookie[i].split("=");
	    if (sName == aCrumb[0]) 
	      return unescape(aCrumb[1]);
	  }

	  // a cookie with the requested name does not exist
	  return null;
	}
		
	Event.addEvent(window,"load",initBackButtons);
	Event.addEvent(window,"load",initNextButtons);

