// Cloack e-mail addresses
function emailCloak() {
	if (document.getElementById) {
		var alltags = document.all? document.all : document.getElementsByTagName("*");
		for (i=0; i < alltags.length; i++) {
			if (alltags[i].className == "email") {
				var oldText = alltags[i].firstChild;
				var emailAddress = alltags[i].firstChild.nodeValue;
				var user = emailAddress.substring(0, emailAddress.indexOf("("));
				var website = emailAddress.substring(emailAddress.indexOf(")")+1, emailAddress.length);
				var newText = user+"@"+website;
				var a = document.createElement("a");
				a.href = "mailto:"+newText;
				var address = document.createTextNode(newText);
				a.appendChild(address);
				alltags[i].replaceChild(a,oldText);
			}
		}
	}
}

// Open specific links in a new window
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
		anchor.getAttribute("rel") == "external")
		anchor.target = "_blank";
	}
}

// Show buying or renting drop down prices
function fShowDiv(boxid) {
	document.getElementById(boxid).style.display="block";
}

function fHideDiv(boxid) {
	document.getElementById(boxid).style.display="none";
}

function fPopulateMinMaxPrice(strType) {
	if (strType == "buy") {
		fHideDiv("divRent");
		fShowDiv("divBuy");
	}
	else {
		fHideDiv("divBuy");
		fShowDiv("divRent");
	}
}

function checkBuyRent(strType) {
	if (strType == "buy") {
		fHideDiv("divMLORent");
		fShowDiv("divMLOBuy");
	}
	else {
		fHideDiv("divMLOBuy");
		fShowDiv("divMLORent");
	}
}

function checkPriceBuying(iType) {
	var intPriceMin = document.searchForm.fSearchPriceMin.value;
	var intPriceMax = document.searchForm.fSearchPriceMax.value;

	intPriceMin = Math.round(intPriceMin)
	intPriceMax = Math.round(intPriceMax)

	if (intPriceMin >= intPriceMax) {
		if (iType==1) {
			i = document.searchForm.fSearchPriceMax.selectedIndex
			document.searchForm.fSearchPriceMin.options[i].selected = true
		}
		else {
			i = document.searchForm.fSearchPriceMin.selectedIndex
			document.searchForm.fSearchPriceMax.options[i].selected = true
		}
	}
}

function checkPriceRenting(iType) {
	var intRentMin = document.searchForm.fSearchRentMin.value;
	var intRentMax = document.searchForm.fSearchRentMax.value;

	intRentMin = Math.round(intRentMin)
	intRentMax = Math.round(intRentMax)

	if (intRentMin >= intRentMax) {
		if (iType==1) {
			i = document.searchForm.fSearchRentMax.selectedIndex
			document.searchForm.fSearchRentMin.options[i].selected = true
		}
		else {
			i = document.searchForm.fSearchRentMin.selectedIndex
			document.searchForm.fSearchRentMax.options[i].selected = true
		}
	}
}