/*===========================================================================*/
// 20090421 AK added required fields
// 20090324 AK new code
/*===========================================================================*/
var message;

function getRegionCities(city_id) {
	var objControl = null;
	// source
	objControl = new getObj('ddlRegionId').obj;
	region_id = (objControl.options[objControl.selectedIndex]).value;
	// destination
	objControl = new getObj('ddlCityId').obj;
	ajaxRegionCities(objControl, region_id, city_id);
};

function submitForm() {
	if (isValidForm()) {
		var objControl = null;
		objControl = new getObj('frmSalesHomeSearch').obj;
		objControl.submit();
	} else {
		alert(message);
	};
};

function isValidForm() {
	var isValid = true;
	var objControl = null;
	var checkedBox = false;
	var countBoxes = 0;
	message = '';

	objControl = new getObj('ddlRegionId').obj;
	if (objControl.value == '') {
		addMessage('Please select a region.');
		isValid = false;
	};

	objControl = new getObj('ddlCityId').obj;
	if (objControl.value == '') {
		addMessage('Please select a city.');
		isValid = false;
	};

	try {// CAUTION getObj doesn't do it...
		objControl = document.forms['frmSalesHomeSearch'].elements['chkCommunityTypeId[]'];
		checkedBox = false;
		countBoxes = objControl.length;
		for (i = 0; i < countBoxes; i++) {
			if (objControl[i].checked) {
				checkedBox = true;
				break;
			};
		};
		if (!checkedBox) {
			addMessage('Please select a community type.');
			isValid = false;
		};
	}
	catch (exception) {
		// alert(exception);
		// alert(vstrControlID);
		// return;
	};

	objControl = new getObj('ddlSqFtMin').obj;
	if (objControl.value == '') {
		addMessage('Please select a minimum square footage.');
		isValid = false;
	};

	objControl = new getObj('ddlBedroomMin').obj;
	if (objControl.value == '') {
		addMessage('Please select a minimum number of bedrooms.');
		isValid = false;
	};

	objControl = new getObj('ddlBathMin').obj;
	if (objControl.value == '') {
		addMessage('Please select a minimum number of bathrooms.');
		isValid = false;
	};

	if (!isValid) {
		return false;
	} else {
		return true;
	};
};

function addMessage(str) {
	if (message != '') {
		message += '\n';	
	};
	message += str;
};
