YAHOO.util.Event.on(window, 'load', init);



function init() {
	
	
	// set the variable based on the id of the form in question
	currentForm = document.forms[0];
	currentForm = currentForm.id;
	

	// assign the correct validation function based on the page the user is on
	switch (currentForm) {
		
		/* ---------- PHASE 1 ---------- */
		
		case ("problem"): /* problem is form id, submit is action, the last one is calling ValidateProblem function*/
			YAHOO.util.Event.on(currentForm, 'submit', validateProblem);
			break;

		case ("consequence"):
			YAHOO.util.Event.on(currentForm, 'submit', validateConsequence);
			break;

		case ("behavior"):
			YAHOO.util.Event.on(currentForm, 'submit', validateBehavior);
			break;

		case ("impact"):
			YAHOO.util.Event.on(currentForm, 'submit', validateImpact);
			break;

		case ("intervening"):
			YAHOO.util.Event.on(currentForm, 'submit', validateIntervening);
			break;

		case ("contributing"):
			YAHOO.util.Event.on(currentForm, 'submit', validateContributing);
			break;

		case ("datasource"):
			YAHOO.util.Event.on(currentForm, 'submit', validateFactorDatasources);
			break;
			
		/* ---------- PHASE 2 ---------- */
		
		case ("program"):
			YAHOO.util.Event.on(currentForm, 'submit', validateProgram);
			break;
			
		case ("strategy"):
			YAHOO.util.Event.on(currentForm, 'submit', validateStrategy);
			break;
			
		case ("population"):
			YAHOO.util.Event.on(currentForm, 'submit', validatePopulation);
			break;
			
		case ("funding"):
			YAHOO.util.Event.on(currentForm, 'submit', validateFunding);
			break;

		/* ---------- M test ---------- */
		
		case ("testvalidation"):
			YAHOO.util.Event.on(currentForm, 'submit', validateMtest);
			break;	
			
		/* ---------- PHASE 3 ---------- */	
		case ("problemstatement"):
			YAHOO.util.Event.on(currentForm, 'submit', validateStatementPhase3);
			break;

		case ("goal"):
			YAHOO.util.Event.on(currentForm, 'submit', validateGoalPhase3);
			break;
			
		case ("objective"):
			YAHOO.util.Event.on(currentForm, 'submit', validateObjectivePhase3);
			break;

		case ("strategyPhase3"):
			YAHOO.util.Event.on(currentForm, 'submit', validateStrategyPhase3);
			break;
			
		case ("strategyeditPhase3"):
			YAHOO.util.Event.on(currentForm, 'submit', validateStrategyPhase3);
			break;	


		/* ---------- Member sector survey ---------- */
		case ("membersectorsurvey"):
			YAHOO.util.Event.on(currentForm, 'submit', validateMemberSectorSurvey);
			break;	
			
		/* ---------- online registration ---------- */
		case ("onlineregistration"):
			YAHOO.util.Event.on(currentForm, 'submit', validateOnlineregistration);
			break;				

	}

}

// declare the error array
// we're declaring it here so that it can be accessed anywhere just like a global variable
var errorArray = new Array();

// this function shows either the lightboxed error window or an alert box depending on whether they have IE6 or not
// every validation function ends up calling this function
function showErrors(e) {
	
	// check the user's browser
	var userBrowser = navigator.appName;
	var userVersion = navigator.appVersion;
	var versionArray = userVersion.split("; ");		// returns MSIE 7.0 e.g.
	
	// specific absolute positioning code for IE 6
	if (versionArray[1] == "MSIE 6.0") {
		
		var alertString = "Please correct the following errors before progressing:\n\n";

		for (var i=0; i<errorArray.length; i++) {
			alertString += " - " + errorArray[i] + "\n\n";
		};

		// show the user what they need to fix
		alert(alertString);
		
	} else {
		
		/* --------------- Create the lightbox --------------- */

		// create the lightbox div
		var lightbox = document.createElement("div");
		lightbox.id = "darkDiv";

		// set the lightbox height equal to the page height
		lightbox.style.height = document.documentElement.clientHeight;

		// add the new div to the document
		document.body.appendChild(lightbox);


		/* --------------- Create the error window --------------- */

		// create the error alert div
		var errorAlertDiv = document.createElement("div");
		errorAlertDiv.id = "errorAlert";


		/* ----- Create the text ----- */

		var errorPara = document.createElement("p");
		var errorParaText = document.createTextNode("Please correct the following errors before progressing:");

		errorPara.appendChild(errorParaText);
		errorAlertDiv.appendChild(errorPara);

		/* ----------------------------*/


		/* ----- Create the unordered list ----- */

		var errorList = document.createElement("ul");

		for (var i=0; i<errorArray.length; i++) {

			var errorListItem = document.createElement("li");
			var errorListItemText = document.createTextNode(errorArray[i]);

			errorListItem.appendChild(errorListItemText);
			errorList.appendChild(errorListItem);

		};

		errorAlertDiv.appendChild(errorList);

		/* ------------------------------------- */


		/* ----- Close button ----- */

		// create the button
		var closeButton = document.createElement("button");

		// create and append the button text
		var closeButtonText = document.createTextNode("Close");
		closeButton.appendChild(closeButtonText);

		// set the button's attributes
		YAHOO.util.Event.on(closeButton, "click", closeLightbox);
		errorAlertDiv.appendChild(closeButton);

		/* ------------------------ */

		// figure out the window width and subtract the width of the div and css
		var errorAlertWidth = (document.body.clientWidth - 400 - 30) / 2;
		errorAlertDiv.style.left = errorAlertWidth + "px";

		// figure out the window height and subtract the width of the div and css
		var errorAlertHeight = (document.documentElement.clientHeight - errorAlertDiv.style.height - 30) / 3;
		errorAlertDiv.style.top = errorAlertHeight + "px";

		// add the new div to the document	
		document.body.appendChild(errorAlertDiv);
		
		
	}

	// reset the array so we won't keep adding to it when the user clicks again and again
	errorArray.length = 0;
	
	// stop the form from processing
	YAHOO.util.Event.preventDefault(e);
	
}


// function used to delete the lightbox and error window
function closeLightbox() {
	
	var lightbox = document.getElementById("darkDiv");
	var errorAlertDiv = document.getElementById("errorAlert");
	
	document.body.removeChild(lightbox);
	document.body.removeChild(errorAlertDiv);

}


// several of the page specific functions will call this to see if all the checkboxes or radio buttons are empty
function checkEmptyInputs(inputName, inputType) {
	
	// get all the inputs on the page
	var inputs = document.getElementsByTagName("input");
		
	var inputCounter = 0;
	var emptyCounter = 0;
	
	// loop through each input
	for (var i=0; i<inputs.length; i++) {
		
		// is the input a consequence radio button
		if (inputs[i].name == inputName && inputs[i].type == inputType) {
		
			// keep track of the number of radio buttons
			inputCounter++;
		
			// if the radio button is not selected, update the counter
			if (inputs[i].checked == false) {
				emptyCounter++;
			};
		
		};
		
	};
	
	
	/* ----- special section for intervening ----- */
	// this checks to see how many checkboxes were checked
	if (inputName == "intervening[]") {
		checkedCounter = inputCounter - emptyCounter;
	};
	
	
	// if no radio buttons were selected
	if (inputCounter == emptyCounter) {
		return false;
	};
	
};

/* ---------------------------------------- PHASE 1 ---------------------------------------- */

// validate the datasources found on consequence, behavior
// contributing factor datasources uses it's own function
function validateDatasources(e) {
		
	/* Empty Primary Datasource */
	
	var primarySource = document.getElementById("selectPrimary");
		
	if (primarySource.value == "none") {
		errorArray.push("No Primary Datasource selected");
	};
	
	/* Focus Groups selected but not described */
	
	var sourceArray = new Array("Primary", "Secondary", "Tertiary");
	
	for (var i=0; i<sourceArray.length; i++) {
		
		var sourceSelect = document.getElementById("select" + sourceArray[i]);
		var sourceDescribe = document.getElementById("ds" + sourceArray[i]);
		
		// if the user chose "Focus Groups" or "Key Informants" and they didn't describe it
		if ((sourceSelect.value == 35 || sourceSelect.value == 36 || sourceSelect.value == "other") && sourceDescribe.value == "") {
		
			if (sourceSelect.value == 35) {
				var selectedField = "Key Informants";
			} else if (sourceSelect.value == 36) {
				var selectedField = "Focus Groups";
			} else {
				var selectedField = "Other";
			}
			
			errorArray.push("You selected " + selectedField + " as your " + sourceArray[i] + " Source but did not describe it.");
		
		};
		
	};
	
	/* Run the error array check */
	if (errorArray.length > 0) {
		showErrors(e);
	};
		
};


// vaidate fields specific to the Problem
function validateProblem(e) {

	var otherProblem = document.getElementById("otherTextbox");
	
	if (otherProblem.value == "") {
		errorArray.push("You selected \"Other Problem\" but did not provide one");
	};
	
	if (errorArray.length > 0) {
		showErrors(e);
	};
	
};


// validate fields specific to Consequence
function validateConsequence(e) {

	// if no radio buttons were selected
	if (checkEmptyInputs("consequence_id", "radio") == false) {
		errorArray.push("No Consequence selected");
	};
	
	/* check the "Other" radio button */
	
	var otherTextbox = document.getElementById("otherTextbox");
	var otherRadio = document.getElementById("conOther");
				
	// if the "Other" radio button is selected and the text is empty
	if (otherRadio.checked == true && otherTextbox.value == "") {
		errorArray.push("You selected \"Other\" but did not provide your own Consequence.");
		otherTextbox.className += " error";
	};
		
	// check the datasources
	validateDatasources(e);
	
};


// validate fields found on the Behavior page
function validateBehavior(e) {
	
	// check the radio inputs to see if one has been checked
	if (checkEmptyInputs("behavior", "radio") == false) {
		errorArray.push("No Behavior selected");
	};
	
	// check the datasources
	validateDatasources(e);
	
};


function validateImpact(e) {
	
	var impactSelects = document.getElementsByTagName("select");
	var emptyCounter = 0;
	
	for (var i=0; i<impactSelects.length; i++) {
		
		if (impactSelects[i].value == 1) {
			emptyCounter++;
		};
	
	};
	
	if (emptyCounter == impactSelects.length) {
		errorArray.push("No Impact Population characteristics selected");
	};
	
	/* other race */
	
	var otherText = document.getElementById("otherTextbox");
	var raceSelect = document.getElementById("selectRace");
	
	if (raceSelect.value == "other" && otherText.value == "") {
		errorArray.push("You selected \"Other\" for Race but did not provide one");
	};
	
	if (errorArray.length > 0) {
		showErrors(e);
	};
	
};


function validateIntervening(e) {

	if (checkEmptyInputs("intervening[]", "checkbox") == false) {
		errorArray.push("No Intervening Variables were selected");
	} 
	/*
	else if (checkedCounter > 3) {
		errorArray.push("More than three Intervening Variables were selected");
	};
	*/
	if (errorArray.length > 0) {
		showErrors(e);
	};

};


function validateContributing(e) {
	
	var allInputs = document.getElementsByTagName("input");
	var interveningCounter = 0;
	var interveningNames = new Array();
	
	// loop through all inputs
	for (var i=0; i<allInputs.length; i++) {
		
		// locate the hidden inputs that denote intervening variables
		if (allInputs[i].type == "hidden") {
		
			if (allInputs[i].name == "intervening_id[]") {
				interveningCounter++;
			} else if (allInputs[i].name == "intervening[]") {
				// store the name of the intervening variable so we can use it in error messages
				interveningNames.push(allInputs[i].value);
			}
			
		};
		
	};
	
	// loop through each intervening variable
	for (var i=0; i<interveningCounter; i++) {

		var contributingCounter = 0;
		var emptyCounter = 0;

		// loop through all inputs
		for (var x=0; x<allInputs.length; x++) {

			// locate the hidden inputs that denote intervening variables
			if (allInputs[x].type == "checkbox" && allInputs[x].name == "contributing-" + i + "[]") {
				
				contributingCounter++;
			
				if (allInputs[x].checked == false) {
					emptyCounter++;
				};
			
			};
			
			// don't forget about the text boxes for "Other Factors"
			if (allInputs[x].type == "text" && allInputs[x].name == "othercontributing-" + i + "[]") {
				
				contributingCounter++;
				
				if (allInputs[x].value == "") {
					emptyCounter++;
				};
				
			};

		};

		if (emptyCounter == contributingCounter) {
			errorArray.push("No Factors selected for \"" + interveningNames[i] + "\"");
		};

	};
		
	if (errorArray.length > 0) {
		showErrors(e);
	};
	
};


function validateFactorDatasources(e) {
	
	var allInputs = document.getElementsByTagName("input");
	
	// used to keep track of the number of Factors
	var contributingArray = new Array();
	
	// used for keeping track of intervening variables
	var interveningArray = new Array();
	
	// loop through all inputs
	for (var i=0; i<allInputs.length; i++) {
	
		// find the hidden inputs with contributing and intervening data
		if (allInputs[i].type == "hidden") {
			
			// get the names of the contributing factors so we can use them in the error messages
			if (allInputs[i].name == "contributing[]") {
				contributingArray.push(allInputs[i].value);
			};
			
		};
		
	};
	
	var sourceArray = new Array("Primary", "Secondary", "Tertiary");
	
	// loop through all the duplicate intervening variables
	for (var i=0; i<contributingArray.length; i++) {
		
		var primarySource = document.getElementById("selectPrimary" + i);

		if (primarySource.value == "none") {
			errorArray.push("No Primary Datasource selected for \"" + contributingArray[i] + "\"");
		};

		/* Focus Groups selected but not described */

		for (var x=0; x<sourceArray.length; x++) {

			var sourceSelect = document.getElementById("select" + sourceArray[x] + i);
			var sourceDescribe = document.getElementById("ds" + sourceArray[x] + i);

			// if the user chose "Focus Groups" or "Key Informants" and they didn't describe it
			if ((sourceSelect.value == 35 || sourceSelect.value == 36 || sourceSelect.value == "other") && sourceDescribe.value == "") {

				if (sourceSelect.value == 35) {
					var selectedField = "Key Informants";
				} else if (sourceSelect.value == 36) {
					var selectedField = "Focus Groups";
				} else {
					var selectedField = "Other";
				}

				errorArray.push("You selected " + selectedField + " as your " + sourceArray[x] + " Source for \"" + contributingArray[i] + "\" but did not describe it.");

			};

		};
		
	};
	
	/* Run the error array check */
	if (errorArray.length > 0) {
		showErrors(e);
	};
	
};


/* ---------------------------------------- PHASE 2 ---------------------------------------- */


function validateProgram(e) {

	// get the program list
	var selectProgram = document.getElementById("programSelect");
	
	// get the "Other Program" box if possible
	var otherProgram = document.getElementById("otherTextbox");
	
	// produce an error if the user selected "Other" but did not write one in the textbox
	if (selectProgram.value == "other" && otherProgram.value == "") {
		errorArray.push("You selected \"Other\" as your Program but did not provide one");
	};
	
	// if no contributing factors were selected
	if (checkEmptyInputs("factors[]", "checkbox") == false) {
		errorArray.push("You must relate your Program or Policy to at least one Contributing Factor");
	};
	
	// make sure the "Implementing Organization" isn't blank
	if (document.getElementById("implementing").value == "") {
		errorArray.push("You did not specify an Implementing Organization");
	};
	
	if (errorArray.length > 0) {
		showErrors(e);
	};

};


function validateStrategy(e) {

	// get the "Other" checkbox
	var otherCheckbox = document.getElementById("eduOther");
	
	// get the "Other" text box
	var otherTextbox = document.getElementById("otherEducation")

	// create an error if the user selected "Other" for educated groups but did not write anything
	if (otherCheckbox.checked == true && otherTextbox.value == "") {
		errorArray.push("You selected \"Other\" as an educated group but did not provide one");
	};
	
	if (errorArray.length > 0) {
		showErrors(e);
	};

};


function validatePopulation(e) {

	/* ----- Other Race ----- */
	
	var otherText = document.getElementById("otherTextbox");
	var raceSelect = document.getElementById("selectRace");
	
	if (raceSelect.value == "other" && otherText.value == "") {
		errorArray.push("You selected \"Other\" for Race but did not provide one");
	};

	/* ----- General Direction ----- */

	// if no "General Directions" were selection
	if (checkEmptyInputs("general_direction[]", "checkbox") == false) {
		errorArray.push("You must select at least one \"General Direction\"");
	};
	
	/* ----------------------------- */
	
	if (errorArray.length > 0) {
		showErrors(e);
	};

};


function validateFunding(e) {

	// these arrays will store each of the fields we need to check on for each funding source
	var fundingName = new Array();
	var fundingAmount = new Array();
	var fundingDuration = new Array();
	var fundingRemain = new Array();
	
	// get all the inputs so we can pick out the textboxes
	var allInputs = document.getElementsByTagName("input");
	
	for (var i=0; i<allInputs.length; i++) {
	
		// get the "Name of Source"
		if (allInputs[i].name == "funding_name[]") {
			fundingName.push(allInputs[i]);
		};
		
		// get the "Funding Amount"
		if (allInputs[i].name == "funding_amount[]") {
			fundingAmount.push(allInputs[i]);
		};
		
		// get the "Years of Funding Remaining""
		if (allInputs[i].name == "funding_remaining[]") {
			fundingRemain.push(allInputs[i]);
		};
	
	};
		
	// run a loop for each "Funding Source". We can use any one of the fields above for this.
	for (var i=0; i<fundingName.length; i++) {

		// check for the "Name of Source"
		if (fundingName[i].value == "") {
			errorArray.push("You did not provide a value for \"Name of Source\" under Funding Source "+(i+1));
		};
		
		// check for the "Funding Amount"
		if (fundingAmount[i].value == "") {
			errorArray.push("You did not provide a value for \"Funding Amount\" under Funding Source "+(i+1));
		};
		
		// use this for getting the durationSelect and otherTextbox fields
		if (i>0) {
			otherNumber = i+1;
		} else {
			otherNumber = "";
		}
		
		// get the "Funding Duration" select menu value and see if it's "other"
		if (document.getElementById("durationSelect"+otherNumber).value == "other") {
			
			// see if the "Other Duration" text box exists and if it's blank
			if (document.getElementById("otherTextbox_duration"+otherNumber).value == "") {
				errorArray.push("You did not provide a value for \"Other Duration\" under Funding Source "+(i+1));
			}
			
		};
		
		// make sure that the "Years of Funding Remaining" field is a number and not empty
		if (fundingRemain[i].value == "") {
			errorArray.push("You did not provide a value for \"Years of Funding Remaining\" under Funding Source "+(i+1));
		} else if (typeof (fundingRemain[i]*1) != "number") {
			errorArray.push("Only numbers may be used for \"Years of Funding Remaining\" under Funding Source "+(i+1));
		}

	};

	if (errorArray.length > 0) {
		showErrors(e);
	};

};

/* ---------------------------------------- M test ---------------------------------------- */


// vaidate fields specific to the Problem
function validateMtest(e) {

// for name (textbox) textName is form id
	var Name = document.getElementById("textName");	
	if (Name.value == "") {
		errorArray.push("Please enter your name");
	};
	
// for email (textbox) textEmail is form id
	var Email = document.getElementById("textEmail");	
	if (Email.value == "") {
		errorArray.push("Please enter your email, why do you always leave this blank");
	};

// for Favorite color (checkbox) favcolor is form name
	if (checkEmptyInputs("favcolor", "checkbox") == false) {
		errorArray.push("No favorite color were selected");
	};

// for Age (radio button) age is form name
	if (checkEmptyInputs("age", "radio") == false) {
		errorArray.push("Please let me know what your age is");
	};

// for favorite town (select list) TownSelect is form id
	var favtownSelects = document.getElementById("TownSelect");
	
	if (favtownSelects.value == "none") {
		errorArray.push("Oh oh oh, you forgot to tell me about your favorite town");
	};
	
	
// for life story (textarea)

	var Story = document.getElementById("textareaStory");	
	if (Story.value == "") {
		errorArray.push("Please tell me a little bit about your life");
	};


// display error	
	if (errorArray.length > 0) {
		showErrors(e);
	};

	
}; // end function

/* ---------------------------------------- PHASE 3 ---------------------------------------- */

function validateStatementPhase3(e) {
	
	var problem = document.getElementById("describeProblem");	
	if (problem.value == "") {
		errorArray.push("Please describe the problem abuse problem targeted");
	};
	
	if (errorArray.length > 0) {
		showErrors(e);
	};
};

function validateGoalPhase3(e) {
	
	var goal = document.getElementById("describeGoal");	
	if (goal.value == "") {
		errorArray.push("You did not provide a description of the goal of your problemstatement in the text box.");
	};
	
	var longterm = document.getElementById("describeLongTerm");	
	if (longterm.value == "") {
		errorArray.push("You did not provide a short description of long term outcome for your goal in the text box.");
	};

	if (errorArray.length > 0) {
		showErrors(e);
	};
};

function validateObjectivePhase3(e) {
	
	var goal = document.getElementById("describeObjective");	
	if (goal.value == "") {
		errorArray.push("You did not provide an objective of your goal.");
	};
	
	var shortterm = document.getElementById("describeShortTerm");	
	if (shortterm.value == "") {
		errorArray.push("You did not provide a short term outcome for your objective.");
	};
	
	var mediumterm = document.getElementById("describeIntermediateTerm");	
	if (mediumterm.value == "") {
		errorArray.push("You did not provide an intermediate term outcome for your objective");
	};	if (errorArray.length > 0) {
		showErrors(e);
	};
};

function validateStrategyPhase3(e) {	


	var strategyList = document.getElementsByName("strategyListNumber");
	var strategyNum = strategyList.length;
	
	/*
	var actionStepList = document.getElementsByName("ActionSteps[]");
	var actionStepNum = actionStepList.length;
	document.write(actionStepList.length);
	*/
	
    
	
	
	for (var i=1; i<=strategyNum; i++) {
		
		if (i==1) {
	
			var strategy = document.getElementById("Strategy");
			if (strategy.value == "") {
				errorArray.push("You did not provide a value for Strategy" + i);
			} else if (strategy.value.length > 200) {
				errorArray.push("The response that you entered for \"Strategy " + i + "\"  exceeded the character limit. Please limit your strategy to 200 characters or less.");
			};
			
			
			var impagency = document.getElementById("ImpAgency");	
			if (impagency.value == "") {
				errorArray.push("You did not provide a value for \"Implementing Agency\" under Strategy " + i);
			} else if (impagency.value.length > 200) {
				errorArray.push("The response that you entered for the \"Implementing Agency\" under \"Strategy " + i + "\"  exceeded the character limit. Please limit your key action step to 200 characters or less.");
			};
			
			var expectedamt = document.getElementById("Expectedamount");	
			if (expectedamt.value == "") {
				errorArray.push("You did not provide a value for \"Expected Amount\" under Strategy " + i);
			} else if (isNaN(expectedamt.value) == true) {
				errorArray.push("You did not provide a value for \"Expected Amount\" in a number format");
			} else if ((expectedamt.value > 99999999) || (expectedamt.value < 0)) {
				errorArray.push("The value provided for \"Expected Amount\" was out of range. Please enter an amount from 0 to 99,999,999");
			};	
					
			var inkindamt = document.getElementById("Inkindamount");	
			if (isNaN(inkindamt.value) == true) {
				errorArray.push("You did not provide a value for \"In-Kind Amount\" in a number format under Strategy " + i);
			} else if ((inkindamt.value > 99999999) || (inkindamt.value < 0)) {
				errorArray.push("The value provided for \"In-Kind Amount\" was out of range. Please enter an amount from 0 to 99,999,999");
			};

			var leveragedamt = document.getElementById("Amountleveraged");	
			if (isNaN(leveragedamt.value) == true) {
				errorArray.push("You did not provide a value for \"Amount Leveraged\" in a number formatunder Strategy " + i);
			} else if ((leveragedamt.value > 99999999) || (leveragedamt.value < 0)) {
				errorArray.push("The value provided for \"Amount Leveraged\" was out of range. Please enter an amount from 0 to 99,999,999");
			};
			
			var element = document.getElementsByTagName("input"); 
			var actionstep = new Array();
			var begindate = new Array();
			var enddate = new Array();
			for(var a=0; a<element.length; a++) {		 
				if (element[a].name == "ActionSteps[]") {
					actionstep.push(element[a].value);
				 }
				if (element[a].name == "begindate[]") {
					begindate.push(element[a].value);
					
				 }	
				if (element[a].name == "enddate[]") {
					enddate.push(element[a].value);
				 }
				
			}
			
			//document.write(actionstep.length);
			//var actionstep = document.getElementsByName("ActionSteps[]");
			//var actionStepNum = actionStepList.length;	
			for (var x=0; x<actionstep.length; x++) {
				
				var actionCount = new String(actionstep[x]);
				if (actionstep[x] == "") {
					errorArray.push("You did not provide a value for \"Key Action Step\ " + (x+1) + "\" in Strategy " + i);	
				} else if (actionCount.length > 200) {
					errorArray.push("The response that you entered for the key action step exceeded the character limit. Please limit your key action step to 200 characters or less.");
				};
						
				if (begindate[x] == "") {
					errorArray.push("You did not provide the value for the Begin Date in \"Key Action Step\ " + (x+1) + "\" in Strategy " + i);
				} else {
					// convert the begin date value to a string
					var bdate = new String(begindate[x]);
					
					// if the length of the begin date is not equal to five then the string is not in the (mm/yy) format 
					if (bdate.length != 5) {
						//errorArray.push(begindate[0]);
						errorArray.push("You did not enter the \"Begin Date\" in \"Key Action Step\ " + (x+1) + "\" in Strategy " + i + " under the correct format. Please Enter the date in the \"mm/yy\" format.");
					}			
					// parses begin date string to see if mm is from 01 to 12 indicating January through December
					else if (parseInt(bdate, 10) < 0 || parseInt(bdate, 10) > 12 ) {
						errorArray.push("You did not enter the \"Begin Date\" in \"Key Action Step\ " + (x+1) + "\" in Strategy " + i + " under the correct format. Please Enter the date in the \"mm/yy\" format.");
					}				
					// checks to see if begin date string mm is from 01 to 12 indicating January through December
					else if (bdate.substr(2,1) != "/") {
						errorArray.push("You did not enter the \"Begin Date\" in \"Key Action Step\ " + (x+1) + "\" in Strategy " + i + " under the correct format. Please Enter the date in the \"mm/yy\" format.");
					}	
					// checks to see if begin date string yy is a number
					else if ( (isNaN(parseInt(bdate.substr(3,1),10)) == true) || (isNaN(parseInt(bdate.substr(4,1),10)) == true) ) {
						errorArray.push("You did not enter the \"Begin Date\" in \"Key Action Step\ " + (x+1) + "\" in Strategy " + i + " under the correct format. Please Enter the date in the \"mm/yy\" format.");
					} // end else if					
				} // else
				
				//var enddate = document.getElementsByName("enddate[]");	
				if (enddate[x] == "") {
					errorArray.push("You did not provide a value for \"End Date\" in \"Key Action Step\ " + (x+1) + "\" in Strategy " + i);
				} else {
					// convert the end date value to a string
					var edate = new String(enddate[x]);
					
					// if the length of the end date is not equal to five then the string is not in the (mm/yy) format 
					if (edate.length != 5) {
						errorArray.push("You did not enter the \"End Date\" in \"Key Action Step\ " + (x+1) + "\" in Strategy " + i + " under the correct format. Please Enter the date in the \"mm/yy\" format.");
					}
					
					// parses end date string to see if mm is from 01 to 12 indicating January through December
					else if (parseInt(edate, 10) < 0 || parseInt(edate, 10) > 12 ) {
						errorArray.push("You did not enter the \"End Date\" in \"Key Action Step\ " + (x+1) + "\" in Strategy " + i + " under the correct format. Please Enter the date in the \"mm/yy\" format.");
					}
					
					// checks to see if end date string mm is from 01 to 12 indicating January through December
					else if (edate.substr(2,1) != "/") {
						errorArray.push("You did not enter the \"End Date\" in \"Key Action Step\ " + (x+1) + "\" in Strategy " + i + " under the correct format. Please Enter the date in the \"mm/yy\" format.");
					}
						
					// checks to see if end date string yy is a number
					else if ( (isNaN(parseInt(edate.substr(3,1),10)) == true) || (isNaN(parseInt(edate.substr(4,1),10)) == true) ) {
						errorArray.push("You did not enter the \"End Date\" in \"Key Action Step\ " + (x+1) + "\" in Strategy " + i + " under the correct format. Please Enter the date in the \"mm/yy\" format.");
					}				
					
				} // end else
						
			} // end for x<actionstep.length
			

		delete actionstep;
		delete begindate;
		delete enddate;
			
		} else {	
		
			strategy = document.getElementById("Strategy" + i);
			if (strategy.value == "") {
				errorArray.push("You did not provide a value for Strategy " + i);
			} else if (strategy.value.length > 200) {
				errorArray.push("The response that you entered for \"Strategy " + i + "\"  exceeded the character limit. Please limit your key action step to 200 characters or less.");
			};
		
			var impagency = document.getElementById("ImpAgency" + i);	
			if (impagency.value == "") {
				errorArray.push("You did not provide a value for \"Implementing Agency\" under Strategy " + i);
			} else if (impagency.value.length > 200) {
				errorArray.push("The response that you entered for the \"Implementing Agency\" under \"Strategy " + i + "\"  exceeded the character limit. Please limit your key action step to 200 characters or less.");
			};
		
			var expectedamt = document.getElementById("Expectedamount" + i);	
			if (expectedamt.value == "") {
				errorArray.push("You did not provide a value for \"Expected Amount\" under Strategy " + i);
			} else if (isNaN(expectedamt.value) == true) {
				errorArray.push("You did not provide a value for \"Expected Amount\" in a number format under Strategy " + i);
			} else if ((expectedamt.value > 99999999) || (expectedamt.value < 0)) {
				errorArray.push("The value provided for \"Expected Amount\"  was out of range. Please enter an amount from 0 to 99,999,999 under Strategy " + i);
			};	
					
			var inkindamt = document.getElementById("Inkindamount" + i);	
			if (isNaN(inkindamt.value) == true) {
				errorArray.push("You did not provide a value for \"In-Kind Amount\" in a number format under Strategy " + i);
			} else if ((inkindamt.value > 99999999) || (inkindamt.value < 0)) {
				errorArray.push("The value provided for \"In-Kind Amount\" was out of range. Please enter an amount from 0 to 99,999,999 under Strategy " + i);
			};
			
			var leveragedamt = document.getElementById("Amountleveraged" + i);	
			if (isNaN(leveragedamt.value) == true) {
				errorArray.push("You did not provide a value for \"Amount Leveraged\" in a number format under Strategy " + i);
			} else if ((leveragedamt.value > 99999999) || (leveragedamt.value < 0)) {
				errorArray.push("The value provided for \"Amount Leveraged\" was out of range. Please enter an amount from 0 to 99,999,999 under Strategy " + i);
			};
				
			for(var a=0; a<element.length; a++) {		 
				if (element[a].name == "ActionSteps" + i + "[]") {
					actionstep.push(element[a].value);
				 }
				if (element[a].name == "begindate" + i + "[]") {
					begindate.push(element[a].value);
				 }	
				if (element[a].name == "enddate" + i + "[]") {
					enddate.push(element[a].value);
				 }	
			}
			
			//var actionstep = document.getElementsByName("ActionSteps" + i + "[]");
			//actionStepNum = actionStepList.length;
			for (var y=0; y<actionstep.length; y++) {
				var actionCount = new String(actionstep[y]);
				if (actionstep[y] == "") {
					errorArray.push("You did not provide a value for \"Key Action Step\ " + (y+1) + "\" in Strategy " + i);	
				} else if (actionCount.length > 200) {
					errorArray.push("The response that you entered for the key action step exceeded the character limit. Please limit your key action step to 200 characters or less.");
				};
				
				//var begindate = document.getElementsByName("begindate" + i + "[]");	
				if (begindate[y] == "") {
					errorArray.push("You did not provide the value for the Begin Date in \"Key Action Step\ " + (y+1) + "\" in Strategy " + i);
				} else {
					// convert the begin date value to a string
					bdate = new String(begindate[y]);
					// if the length of the begin date is not equal to five then the string is not in the (mm/yy) format 
					if (bdate.length != 5) {
						errorArray.push("You did not enter the \"Begin Date\" in \"Key Action Step\ " + (y+1) + "\" in Strategy " + i + " under the correct format. Please Enter the date in the \"mm/yy\" format.");
					}			
					// parses begin date string to see if mm is from 01 to 12 indicating January through December
					else if (parseInt(bdate, 10) < 0 || parseInt(bdate, 10) > 12 ) {
						errorArray.push("You did not enter the \"Begin Date\" in \"Key Action Step\ " + (y+1) + "\" in Strategy " + i + " under the correct format. Please Enter the date in the \"mm/yy\" format.");
					}				
					// checks to see if begin date string mm is from 01 to 12 indicating January through December
					else if (bdate.substr(2,1) != "/") {
						errorArray.push("You did not enter the \"Begin Date\" in \"Key Action Step\ " + (y+1) + "\" in Strategy " + i + " under the correct format. Please Enter the date in the \"mm/yy\" format.");
					}	
					// checks to see if begin date string yy is a number
					else if ( (isNaN(parseInt(bdate.substr(3,1),10)) == true) || (isNaN(parseInt(bdate.substr(4,1),10)) == true) ) {
						errorArray.push("You did not enter the \"Begin Date\" in \"Key Action Step\ " + (y+1) + "\" in Strategy " + i + " under the correct format. Please Enter the date in the \"mm/yy\" format.");
					} // end else if					
				} // else
				
				//var enddate = document.getElementsByName("enddate" + i + "[]");	
				if (enddate[y] == "") {
					errorArray.push("You did not provide a value the value for the \"End Date\" in \"Key Action Step\ " + (y+1) + "\" in Strategy " + i);
				} else {
					// convert the end date value to a string
					edate = new String(begindate[x]);
					// if the length of the end date is not equal to five then the string is not in the (mm/yy) format 
					if (edate.length != 5) {
						errorArray.push("You did not enter the \"End Date\" in \"Key Action Step\ " + (y+1) + "\" in Strategy " + i + " under the correct format. Please Enter the date in the \"mm/yy\" format.");
					}
					
					// parses end date string to see if mm is from 01 to 12 indicating January through December
					else if (parseInt(edate, 10) < 0 || parseInt(edate, 10) > 12 ) {
						errorArray.push("You did not enter the \"End Date\" in \"Key Action Step\ " + (y+1) + "\" in Strategy " + i + " under the correct format. Please Enter the date in the \"mm/yy\" format.");
					}
					
					// checks to see if end date string mm is from 01 to 12 indicating January through December
					else if (edate.substr(2,1) != "/") {
						errorArray.push("You did not enter the \"End Date\" in \"Key Action Step\ " + (y+1) + "\" in Strategy " + i + " under the correct format. Please Enter the date in the \"mm/yy\" format.");
					}
						
					// checks to see if end date string yy is a number
					else if ( (isNaN(parseInt(edate.substr(3,1),10)) == true) || (isNaN(parseInt(edate.substr(4,1),10)) == true) ) {
						errorArray.push("You did not enter the \"End Date\" in \"Key Action Step\ " + (y+1) + "\" in Strategy " + i + " under the correct format. Please Enter the date in the \"mm/yy\" format.");
					} // end else if	
				} // end else
			} // end for y<actionstep.length		
			
		delete actionstep;
		delete begindate;
		delete enddate;
				
				
		} // else i is not equal to 1
		
	} // end for strategyNum

	


	if (errorArray.length > 0) {
		showErrors(e);
	};


};



/* ----------------------------- member sector survey ------------------------- */


// vaidate fields specific to the Problem
function validateMemberSectorSurvey(e) {


	var countySelect = document.getElementById("county");
	
	if (countySelect.value == "none") {
		errorArray.push("Please select County");
	};
	

	var sectorSelect = document.getElementById("sector");
	
	if (sectorSelect.value == "none") {
		errorArray.push("Please select Sector");
	};

	var agencySelect = document.getElementById("agency");
	
	if (agencySelect.value == "none") {
		errorArray.push("Please select Agency");
	};
	

// for response (radio button) responsequestion1 is form name
	if (checkEmptyInputs("responsequestion1", "radio") == false) {
		errorArray.push("Please response question 1");
	};


// for response (radio button) responsequestion2 is form name
	if (checkEmptyInputs("responsequestion2", "radio") == false) {
		errorArray.push("Please response question 2");
	};	


// for response (radio button) responsequestion3 is form name
	if (checkEmptyInputs("responsequestion3", "radio") == false) {
		errorArray.push("Please response question 3");
	};


// for response (radio button) responsequestion4 is form name
	if (checkEmptyInputs("responsequestion4", "radio") == false) {
		errorArray.push("Please response question 4");
	};

// for response (radio button) responsequestion5 is form name
	if (checkEmptyInputs("responsequestion5", "radio") == false) {
		errorArray.push("Please response question 5");
	};

// for response (radio button) responsequestion6 is form name
	if (checkEmptyInputs("responsequestion6", "radio") == false) {
		errorArray.push("Please response question 6");
	};


// for response (radio button) responsequestion7 is form name
	if (checkEmptyInputs("responsequestion7", "radio") == false) {
		errorArray.push("Please response question 7");
	};


// for response (radio button) responsequestion8 is form name
	if (checkEmptyInputs("responsequestion8", "radio") == false) {
		errorArray.push("Please response question 8");
	};


// for response (radio button) responsequestion9 is form name
	if (checkEmptyInputs("responsequestion9", "radio") == false) {
		errorArray.push("Please response question 9");
	};


// for response (radio button) responsequestion01 is form name
	if (checkEmptyInputs("responsequestion10", "radio") == false) {
		errorArray.push("Please response question 10");
	};


// for response (radio button) responsequestion11 is form name
	if (checkEmptyInputs("responsequestion11", "radio") == false) {
		errorArray.push("Please response question 11");
	};



// display error	
	if (errorArray.length > 0) {
		showErrors(e);
	};

	
}; // end function


/* ----------------------------- Online registration ------------------------- */


// vaidate fields for online registration
function validateOnlineregistration(e) {


// for coalitionname 
	var coalitionname = document.getElementById("coalitionname");
	
	if (coalitionname.value == "") {
		errorArray.push("Please provide coalition name");
	};
	
// for firstname 
	var firstname = document.getElementById("firstname");
	
	if (firstname.value == "") {
		errorArray.push("Please provide first name");
	};

// for lastname 
	var lastname = document.getElementById("lastname");
	
	if (lastname.value == "") {
		errorArray.push("Please provide last name");
	};

// for email 
	var email = document.getElementById("email");
	
	if (email.value == "") {
		errorArray.push("Please provide email");
	};

// for phone 
	var phone = document.getElementById("phone");
	
	if (phone.value == "") {
		errorArray.push("Please provide phone");
	};


// display error	
	if (errorArray.length > 0) {
		showErrors(e);
	};

	
}; // end function

