
// variables

var sectionArr;


var newwindow;
function poptastic(url)
{
	newwindow=window.open(url,'name','height=645,width=580,resizable=yes,scrollbars=yes,toolbar=0,menubar=0');
	if (window.focus) {newwindow.focus()}
}







// functions



function addToOptionList(OptionList, OptionValue, OptionText) {
   // Add option to the bottom of the list
   OptionList[OptionList.length] = new Option(OptionText, OptionValue);
}

function clearOptions(OptionList) {

   for (x = OptionList.length; x > 0; x--) {
      OptionList[x] = null;
   }
}



function repopulatePriceRange(objPropertyCat) {

	clearOptions(document.searchForm.searchForm__property__sbv__MinPrice);
	clearOptions(document.searchForm.searchForm__property__sbv__MaxPrice);
	
	if (objPropertyCat.value == 1) {					// sales
		for (i=0;i<salesPriceCaptionArr.length;i++) {
			addToOptionList(document.searchForm.searchForm__property__sbv__MinPrice, salesPriceValueArr[i],salesPriceCaptionArr[i]);
			addToOptionList(document.searchForm.searchForm__property__sbv__MaxPrice, salesPriceValueArr[i],salesPriceCaptionArr[i]);
		}
	} else {											// lettings
		for (i=0;i<lettingsPriceCaptionArr.length;i++) {
			addToOptionList(document.searchForm.searchForm__property__sbv__MinPrice, lettingsPriceValueArr[i],lettingsPriceCaptionArr[i]);
			addToOptionList(document.searchForm.searchForm__property__sbv__MaxPrice, lettingsPriceValueArr[i],lettingsPriceCaptionArr[i]);
		}
	}
}



function propertyCatModify(objPropertyCat) {

	if (objPropertyCat.value == 1) {
		section = 'sales';
		document.getElementById('minPrice').innerHTML="Minimum Price:";
		document.getElementById('maxPrice').innerHTML="Maximum Price:";
	} else {
		section = 'lettings';
		document.getElementById('minPrice').innerHTML="Minimum Rent:";
		document.getElementById('maxPrice').innerHTML="Maximum Rent:";
	}
	document.searchForm.action = phpSelf+'?section='+section;

	// modify price range select lists
	repopulatePriceRange(objPropertyCat);
}



function mapSelect(locationID) {
	var locationSelect = document.searchForm["searchForm__property__sbv__LocationID[]"];
	var optionCounter;

	// clear [All Areas] option
	locationSelect.options[0].selected = false;

	for (optionCounter = 0; optionCounter < locationSelect.length; optionCounter++) {

		if (locationSelect.options[optionCounter].value == locationID) {
			if (locationSelect.options[optionCounter].selected == false) {
				locationSelect.options[optionCounter].selected = true;
			} else if (locationSelect.options[optionCounter].selected == true) {
				locationSelect.options[optionCounter].selected = false;
			}
		}
	}
}


function clearText(thisItem, itemValue) {
	if (thisItem.value == itemValue) {
		thisItem.value = '';
	}
}

function showText(thisItem, itemValue) {
	if (thisItem.value == '') {
		thisItem.value = itemValue;
	}
}
