/*	// Jim Mallmann
	// Ascedia, Inc.
	// November 1, 2002
	Using JM_copySameAs
	This function is used to copy one set of fields to another set, and is usually used to copy
	a billing address to a shipping address.
	All paired fields must be similarly named for this to work, such as billCity and shipCity.
	Also, it is expected that a checkbox is used to toggle the copy on or off.
	The function allows for a variable number of arguments, 
	but the first three arguments MUST be the name of the check box, the first field prefix,
	and the second field prefix.  
	For example, JM_copySameAs('copybilltoship', 'bill', 'ship', 'FirstName', 'LastName', 'Address', ...)
*/
function JM_copySameAs()
{
	args = JM_copySameAs.arguments;
	numArgs = args.length;
	if(numArgs < 4) return;
	else
	{
		check = args[0];
		c = MM_findObj(check);
		prefix1 = args[1];
		prefix2 = args[2];
		for(i = 3; i < numArgs; i++)
		{
			field1 = MM_findObj(prefix1 + args[i]);
			field2 = MM_findObj(prefix2 + args[i]);
			if(field1.type == "text")
			{
				if(c.checked)
				{
					field2.value = field1.value;
				}
				else
				{
					field2.value = "";
				}
			}
			else if (field1.type == "select-one")
			{
				if(c.checked)
				{
					field2.selectedIndex = field1.selectedIndex;
				}
				else
				{
					field2.selectedIndex = 0;
				}
			}
		}
	}
}

/*	// Jim Mallmann
	// Ascedia, Inc.
	// November 1, 2002
	Using JM_validateDropdowns
	Usually, this function will be used in conjunction with the MM_validateForm() function 
	that Dreamweaver creates to validate a form.
	In this case, alter the onSubmit statement that is created to look like the following:
		MM_validateForm(args); JM_validateDropdowns(fieldList); return (document.MM_returnValue && document.DD_returnValue);
	The fieldList should be replaced by a list of the dropdowns that need to be validated in alternating field name, display name fashion, 
	such as JM_validateDropdowns('state', 'State', 'country', 'Country', 'birthMonth', "Month of Birth', 'birthDay', 'Day of Birth', 'birthYear', 'Year of Birth');
*/
function JM_validateDropdowns()
{
	args = JM_validateDropdowns.arguments;
	errors = "";
	for(i = 0; i < args.length; i+=2)
	{
		dd = MM_findObj(args[i]);
		if(dd.selectedIndex == 0)
		{
			errors += "- selection of " + args[i+1] + " is required.\n";
		}
	}
	if(errors != "") alert("The following error(s) occurred:\n" + errors);
	document.DD_returnValue = (errors == "");
}

/*	// Jim Mallmann
	// Ascedia, Inc.
	// November 29, 2002
	Using JM_validateRadioButtons
	Usually, this function will be used in conjunction with the MM_validateForm() function 
	that Dreamweaver creates to validate a form.
	In this case, alter the onSubmit statement that is created to look like the following:
		MM_validateForm(args); JM_validateRadioButtons(fieldList); return (document.MM_returnValue && document.Radio_returnValue);
	The fieldList should be replaced by a list of the radio buttons that need to be validated, 
	such as JM_validateRadioButtons('receiveEmail', 'Would you like to receive email?');
*/
function JM_validateRadioButtons()
{
	args = JM_validateRadioButtons.arguments;
	errors = "";
	numArgs = args.length;
	for(i = 0; i < numArgs; i+=2)
	{
		radio = MM_findObj(args[i]);
		numButtons = radio.length;
		thisGroupOK = false;
		for(j = 0; j < numButtons; j++)
		{
			if(radio[j].checked)
			{
				thisGroupOK = true;
				break;
			}
		}
		if(!thisGroupOK)
		{
			errors += "- one of the " + args[i+1] + " radio buttons must be selected.\n";
		}
	}
	if(errors != "") alert("The following error(s) occurred:\n" + errors);
	document.Radio_returnValue = (errors == "");
}

/*	// Jim Mallmann
	// Ascedia, Inc.
	// November 29, 2002
	Using JM_validateCheckboxGroup
	Usually, this function will be used in conjunction with the MM_validateForm() function 
	that Dreamweaver creates to validate a form.
	In this case, alter the onSubmit statement that is created to look like the following:
		MM_validateForm(args); JM_validateCheckboxGroup(fieldList); return (document.MM_returnValue && document.CG_returnValue);
	The fieldList should be replaced by a list of the checkbox groups that need to be validated, 
	such as JM_validateCheckboxGroup('mailing');
*/
function JM_validateCheckboxGroup()
{
	args = JM_validateCheckboxGroup.arguments;
	errors = "";
	numArgs = args.length;
	if(numArgs % 3 != 0) return;
	for(i = 0; i < numArgs; i++)
	{
		minChecked = args[i];
		maxChecked = args[++i];
		checkbox = MM_findObj(args[++i]);
		numBoxes = checkbox.length;
		thisGroupMinOK = false;
		thisGroupMaxOK = false;
		if(maxChecked == -1) thisGroupMaxOK = true;
		numChecked = 0;
		for(j = 0; j < numBoxes; j++)
		{
			if(checkbox[j].checked)
			{
				thisGroupMinOK = true;
				if(thisGroupMaxOK) break;
				numChecked++;
			}
		}
		if(maxChecked != -1 && numChecked <= maxChecked) thisGroupMaxOK = true;
		if(!thisGroupMinOK)
		{
			errors += "- at least " + minChecked + " of the " + args[i] + " checkboxes must be checked.\n";
		}
		if(!thisGroupMaxOK)
		{
			errors += "- no more than " + maxChecked + " of the " + args[i] + " checkboxes must be checked.\n";
		}
	}
	if(errors != "") alert("The following error(s) occurred:\n" + errors);
	document.CG_returnValue = (errors == "");
}
