function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_validateForm() 
{ 
	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
	for (i=0; i<(args.length-2); i+=3) 
	{ 
		test=args[i+2]; 
		val=MM_findObj(args[i]);
		if (val) 
		{ 
			//nm=val.name; 
			// changed name to take value between form field name 
			// and validation type --JM 3/11/2003
			nm = args[i+1];
			if ((val=val.value)!="")
			{
				if (test.indexOf('isEmail')!=-1) 
				{ 
					p=val.indexOf('@');
					if (p<1 || p==(val.length-1)) 
						errors+='- '+nm+' must contain an e-mail address.\n';
				}
				else if (test!='R')
				{
					num = parseFloat(val);
					if (isNaN(val)) 
						errors+='- '+nm+' must contain a number.\n';
					if (test.indexOf('inRange') != -1) 
					{
						p=test.indexOf(':');
						min=test.substring(8,p); 
						max=test.substring(p+1);
						if (num<min || max<num) 
							errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
					}
				}
			}
			else if (test.charAt(0) == 'R') 
				errors += '- '+nm+' is required.\n'; 
		}
	}
	if (errors) 
		alert('The following error(s) occurred:\n'+errors);
	document.MM_returnValue = (errors == '');
}

/*	// 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 validateRadioButtons2
	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', 'Please indicate whether or not you would like to receive email?'); 
	where the second term is the full validation response.
*/
function validateRadioButtons2()
{
	args = validateRadioButtons2.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 += "- " + args[i+1] + "\n";
		}
	}
	if(errors != "") alert("The following error(s) occurred:\n" + errors);
	document.Radio2_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(minChecked, maxChecked, 'category', 'Employment Category');
	Use -1 for maxChecked if there is no maximum.
*/
function JM_validateCheckboxGroup()
{
	args = JM_validateCheckboxGroup.arguments;
	errors = "";
	numArgs = args.length;
	if(numArgs % 4 != 0) return;
	for(i = 0; i < numArgs; i++)
	{
		minChecked = args[i];
		maxChecked = args[++i];
		checkbox = MM_findObj(args[++i]);
		checkboxName = 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 " + checkboxName + " checkboxes must be checked.\n";
		}
		if(!thisGroupMaxOK)
		{
			errors += "- no more than " + maxChecked + " of the " + checkboxName + " checkboxes must be checked.\n";
		}
	}
	if(errors != "") alert("The following error(s) occurred:\n" + errors);
	document.CG_returnValue = (errors == "");
}

/*	// Jim Mallmann
	// Modified by: Jarrod Smith
	// Ascedia, Inc.
	// June 28, 2007
	Using JS_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(minChecked, maxChecked, 'category', 'Employment Category');
	Use -1 for maxChecked if there is no maximum.
*/
function JS_validateCheckboxGroup()
{
	
	args = JS_validateCheckboxGroup.arguments;
	errors = "";
	numArgs = args.length;
	if(numArgs % 4 != 0) return;
	for(i = 0; i < numArgs; i++)
	{		
		minChecked = args[i];
		maxChecked = args[++i];
		checkbox = MM_findObj(args[++i]);
		checkboxName = 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)
			{
				if(thisGroupMaxOK) break;
				numChecked++;
			}
		}
		if(maxChecked != -1 && numChecked <= maxChecked) thisGroupMaxOK = true;
		if(numChecked >= 1) thisGroupMinOK = true;
		if(!thisGroupMinOK && thisGroupMaxOK)
		{
			errors += "- at least " + minChecked + " of the " + checkboxName + " checkboxes must be checked.\n";
		}
		if(!thisGroupMaxOK)
		{
			errors += "- no more than " + maxChecked + " of the " + checkboxName + " checkboxes should be checked.\n";
		}
	}
	if(errors != "") alert("The following error(s) occurred:\n" + errors);
	document.CG_returnValue = (errors == "");
}

<!-- Original:  Ronnie T. Moore -->
<!-- Web Site:  The JavaScript Source -->

<!-- Dynamic 'fix' by: Nannette Thacker -->
<!-- Web Site: http://www.shiningstar.net -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

function textCounter(field, countfield, maxlimit) 
{
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else 
		countfield.value = maxlimit - field.value.length;
}

/*	// Jim Mallmann
	// Ascedia, Inc.
	// November 29, 2002
	Using wordCounter
	This function is used to limit the number words entered in a textarea box (textfield).  The textarea box 
	should be accompanied by a text box showing the number of words remaining (countfield).  The parameter 
	maxwords is simply the number of words allowed to be entered.  The words remaining box should be 
	initialized to the max number of words to be entered.  The textarea box should have its onKeyDown, 
	onKeyUp, and onChange events set to call wordCounter, for example:
	
	<textarea name="description" cols="60" rows="10" 
		onKeyDown="wordCounter(this.form.description,this.form.remWords,5);" 
		onKeyUp="wordCounter(this.form.description,this.form.remWords,5);" 
		onChange="wordCounter(this.form.description,this.form.remWords,5);"></textarea>
*/

function wordCounter(textfield, countfield, maxwords)
{
	textEntered = textfield.value;
	numChars = textEntered.length;
	numWords = 0;
	previousChar = "";
	for(i = 0; i < numChars; i++)
	{
		thisChar = textEntered.charAt(i);
		if(thisChar == " " && previousChar != " " && previousChar != "\n" && previousChar != "\r")
		{
			//alert("space at " + i);
			numWords++;
			//alert(numWords);
			if(numWords == maxwords)
			{
				textfield.value = textEntered.substring(0,i);
				break;
			}
		}
		else if(thisChar == "\n")
		{
			//alert("cr at " + i);
			if(previousChar != " " && previousChar != "\n" && previousChar != "\r")
			{
				numWords++;
				//alert(numWords);
				if(numWords == maxwords)
				{
					textfield.value = textEntered.substring(0,i);
					break;
				}
			}
		}
		else if(thisChar == "\r")
		{
			//alert("lf at " + i);
			if(previousChar != " " && previousChar != "\n" && previousChar != "\r")
			{
				numWords++;
				//alert(numWords);
				if(numWords == maxwords)
				{
					textfield.value = textEntered.substring(0,i);
					break;
				}
			}
		}
		previousChar = thisChar;
	}
	countfield.value = maxwords - numWords;
}

function IsInteger(strString)
{
   	var strValidChars = "0123456789";
   	var strChar;
   	var blnResult = true;

   	if (strString.length == 0) return false;

   	//  test strString consists of valid characters listed above
   	for (i = 0; i < strString.length && blnResult == true; i++)
    {
      	strChar = strString.charAt(i);
      	if (strValidChars.indexOf(strChar) == -1)
        {
         	blnResult = false;
        }
     }
   	return blnResult;
}
