/*
*******************************************************************************************
Purpose:	Validates that a radio button is selected in each radio input object passed
			Optional anchor params will jump back to location of unanswered question
			If used, calling page must include file inc_JS_GoToAnchor.asp.
Arguments:	parrAnswers = array of radio objects
			pblnGoToAnchor (opt.) = calls GoToAnchor function
			parrAnchors (opt.) = parallel array of custom anchors
			pstrMessage (opt.) = custom message
Returns:	boolean
Created: 	07/09/1999
By: 		Neal Tillotson, Jamie Fisher
Supports:	JavaScript 1.1 or higher		
Usage:		Programs-specific usage:
				var arrAnswers = new Array()
				arrAnswers[0] = document.frm_Questions.mbQA_Q1111
				arrAnswers[1] = document.frm_Questions.mbQA_Q1112
				if (!ValidRadio(arrAnswers,true)) {return false};

:			General usage:
				var arrAnswers = new Array()
				arrAnswers[0] = document.form.radioobject1
				arrAnswers[1] = document.form.radioobject2
				if (!ValidRadio(arrAnswers)) {return false};
				==> validates that each radio button set has a button checked

Calls:		GoToAnchor()
Wrappers:	inc_UW_InputValidation.js

Changed:	
By:	   
*******************************************************************************************
*/

function ValidRadio(parrAnswers,pblnGoToAnchor,parrAnchors,pstrMessage)
{
	var i;
	var j;
	var blnOK;
	var strMessage;
	var blnGoToAnchor;
	var objRadioButtons;
	strMessage = "Please answer all questions.";
	blnGoToAnchor = false;
   
	if (!(typeof pstrMessage == "undefined" || pstrMessage == "")) {strMessage = pstrMessage};
	if (!(typeof pblnGoToAnchor == "undefined")) {blnGoToAnchor = pblnGoToAnchor};
	
	if (blnGoToAnchor == true && typeof parrAnchors == "undefined")
	{
		parrAnchors = new Array()
		for (i=0; i < parrAnswers.length; i++)			// page must assign default anchor 
		{												// names "1","2",etc. for this to work
			parrAnchors[i] = (i+1);
		}
	}
 	for (i=0; i < parrAnswers.length; i++)				// loop through radio objects
	{ 
		blnOK = false;

		for (j=0; j < parrAnswers[i].length; j++)		// loop through radio buttons until checked
		{	
			
	   		objRadioButtons = parrAnswers[i];
				 
			if (objRadioButtons[j].checked) {blnOK = true; break};
		}
		if (blnOK == false)
		{ 
			if (!(strMessage == "no")) {alert(strMessage)}; 
			if (pblnGoToAnchor)
			{
				GoToAnchor(parrAnchors[i]);
			}
			
			return false;
		}
	}
	return true;
}
