//Check if the Other Text Box is selected
function CheckOtherOption(p_oOtherText, p_oRadioCheckBoxObj)
{
	//If the Other Text Object is not empty, check the related Radio or Check box
	if (p_oOtherText.value != '')
		p_oRadioCheckBoxObj.checked = true;
}
	
//Check the Text Fields for JQuery Input fields
function CheckTextField(p_oTextObj, p_sDefaultValue)
{
	//Make sure the field value is not set to the default and not blank
	if ((p_oTextObj.value == p_sDefaultValue) || (isWhitespace(p_oTextObj.value)))
	{
		alert('Please enter a value for ' + p_sDefaultValue + '.');
		p_oTextObj.focus();
		return false;
	}
	
	return true;
}

//Check Zipcode
function CheckZipCodeField(p_oTextObj, p_sDefaultValue, p_bRequired)
{
	if (p_bRequired)
	{
		return checkZIPCode(p_oTextObj, p_oTextObj.name);
	}
	else
	{
		//if the field value is not set to the default and not blank, validate zip
		if ((p_oTextObj.value != p_sDefaultValue) && (!isWhitespace(p_oTextObj.value)))
			return checkZIPCode(p_oTextObj, p_oTextObj.name);
	}
	
	return true;
}

//If default value is set for text object, clear the value.
function ClearDefaultTextValue(p_oObj, p_sDefaultValue)
{
	if (p_oObj == undefined) {
		return false;
	}
	if (p_oObj.value == p_sDefaultValue)
		p_oObj.value = '';
}

//If default value is set for select object, clear the value.
function ClearDefaultSelectValue(p_oObj, p_sDefaultValue)
{
	if (p_oObj[p_oObj.selectedIndex].value == p_sDefaultValue)
		p_oObj[p_oObj.selectedIndex].value = '';
}

//Validates Dropdowns, Radio buttons, and Checkboxes
function isValidNumberOfResponses(p_oFormElement, p_iMinResponses, p_iMaxResponses)
 {
	var iCount = 0;
	var x;
		
	switch (p_oFormElement.type) 
	{
		case "select-one":	// single dropdown
			if (p_oFormElement.selectedIndex != 0)
				iCount = 1;
			break;			
		case "select-multiple":	// multiple dropdown
			if (p_oFormElement.selectedIndex == -1)
				iCount = 0;
			else
			{
				for (x = 0; x < p_oFormElement.length; x++) 
				{
					if (p_oFormElement[x].selected) {
						iCount++;
					}
				}
			}
			break;									
	   	default:	// radio or checkbox
			if (isNaN(p_oFormElement.length)) {
				if (p_oFormElement.checked)
					iCount++;
			} else {
				for (x = 0; x < p_oFormElement.length; x++) {
					if (p_oFormElement[x].checked) {
						iCount++;
					}
				}
			}
	}				

	if (p_iMinResponses != 0) {
		if (p_iMinResponses > iCount)
			return false;
	}
	if (p_iMaxResponses != 0) {
		if (p_iMaxResponses < iCount)
			return false;
	}
	return true;
}

//Submits the form when the enter button is pressed	
function SubmitOnEnter(FORM, e) 
{ 
	var oSrcElement = e.srcElement ? e.srcElement : e.target; //e.srcElement for IE, target for e.FireFox

	if (oSrcElement.type != 'textarea') //Ignore for Text Areas
	{
		if (e && e.keyCode == 13) 
		{
			//Ignore key press in IE
			if (e.srcElement)
				e.keyCode = 0;
				 
			ValidateForm(FORM); //validate and submit
		}
	}
}		
	
//Validate Contact field
function ValidateContact(strContactField) {
	if (typeof(strContactField.length) == 'undefined') {
		
		if (!strContactField.checked) {
			return false;
		} else {
			return true;
		}
	}
	selectedButton = -1
	for (i=0; i<strContactField.length; i++) {
		if (strContactField[i].checked) {
			selectedButton = i
		}
	}
	if (selectedButton == -1) {
		return false;
	}
	return true;
}	
