/*
-------------------------------------------------------------------------------------------
				 WATSON ERROR CHECKING FUNCTIONS
-------------------------------------------------------------------------------------------
*/

var errorArray = new Array();
var showErrArray = '';

//------------------------------------------------------
// function to determine whether or not the form is in good enough condition to submit
function okForm(f,action,pageType)
{
	okSearchType(f);
	okCheckDates();
	getLengthOfStay(f.ciDate.value, f.coDate.value);
	okZipCode(f);
	okCountry(f);
	okCity(f);
	okRateRange(f,pageType);
	okSelected(f,pageType);
	
	if(pageType == 'advSearch'){
		commaStringFromCheckBox(f,'amenityTypeCheck','amenityType');
		commaStringFromCheckBox(f,'hotelTypeCheck','hotelType');
	}	
	checkForErrors(f,action,pageType);
}

//------------------------------------------------------
// function to determine if the rate range is valid
function okRateRange(f)
{
	if(f.country[f.country.selectedIndex].value !='US' && f.rateRange[f.rateRange.selectedIndex].value != '') {
		setErrCode(21);
		setErrCode(6);
		f.rateRange.disabled = false; //doesn't work
	}
}

//------------------------------------------------------
// function to reset address/postalCode fields if it's a city only search
function okSearchType(f)
{
	if (!document.layers){
		if(f.searchType[0].checked){ // if it's a city search (not an address search)
			f.address.value = '';
			f.postalCode.value = '';
		}
	}
}

//------------------------------------------------------
// function to ensure that something was selected
function okSelected(f,pageType)
{
	if (pageType == 'advSearch'){ // case for the advanced search page. hotelType is a series of checkboxes and not a dropdown
		if (f.country[f.country.selectedIndex].value == '' && f.city.value == '' && f.amenityType.value == '' && errorArray.length == 0){
			setErrCode(22);
		}
	} else {
		if (f.country[f.country.selectedIndex].value == '' && f.city.value == '' && errorArray.length == 0){
			setErrCode(22);
		}
	}
}
