// Based on the validation type, ensures that the user selects at least one answer in each section
function ValidateSurveyForm(confirmMsg, validationMsg, validateFlag)
{
	if(validateFlag) 
	{
		var msg = "";
		var f = document.forms[0];
		var sectionCnt = f.scnt.value;
		var i = 0;
		for (i = 1; i <= sectionCnt; i++)
		{
			// check radio options
			var rcnt = f["rcnt_"+i].value;
			var j = 0;
			var optSelected = false;
			for (j = 1; j <= rcnt; j++)
			{
				var radioOption = f["r_"+ i + "_" + j];
				if(radioOption.checked)
				{
					optSelected = true;
					break;
				}
			}
			// check checkbox options
			if(!optSelected)
			{
				var checkBoxes = f["clist_"+i].value + "";
				if(checkBoxes != "")
				{
					var arr = checkBoxes.split(",");
					var length = arr.length - 1; // remove one for the last string, which is always empty
					for(j = 0; j < length; j++)
					{
						var optionName = arr[j];
						var checkOption = f[optionName];
						if(checkOption.checked)
						{
							optSelected = true;
							break;
						}
					}
				}
			}

			// check dropdown options
			if(!optSelected)
			{
				var dropDowns = f["dlist_"+i].value + "";
				if(dropDowns != "")
				{
					var arr = dropDowns.split(",");
					var length = arr.length - 1; // remove one for the last empty string
					for(j = 0; j < length; j++)
					{
						var optionName = arr[j];
						var dropDownOption = f[optionName];
						if(dropDownOption.selectedIndex > 0) // if a non-default value is selected
						{
							optSelected = true;
							break;
						}
					}
				}
			}
			
			// if no answer selected, add the section to the message list
			if(!optSelected)
				msg += "\n - " + f["sname_"+i].value;
		}

		if(msg != "")
		{
			confirmMsg = validationMsg;
			confirmMsg += msg;
		}
	}
	
	return confirm(confirmMsg);
}
