// 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 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
		}
	}
}

// PIP: Pages as tickboxes
function fCheckABox(strCheckBox) {
	if (document.getElementById(strCheckBox).checked == true) {
		document.getElementById(strCheckBox).checked = false
	}
	else {
		document.getElementById(strCheckBox).checked = true
	}
}

// PIP: Show/Hide Tabs
function showtab(id) { 
	whichdiv = document.getElementById(id);

	var thearray= new Array("pipmain","piptour","pipcalc","pipenqy","pipview","pipprnt","pipmail"); 
	for(i=0; i<thearray.length; i++) { 
		if(thearray[i] == id){
			whichdiv.className="panel";
			document.body.className=thearray[i];
		} else {
			document.getElementById(thearray[i]).className="hide"; 
		} 
	} 
}
/*
function showtabBehaviour() {
	if (!document.getElementById("pipnavtabs")) return false;
	var pipLinks = document.getElementById("pipnavtabs");
	var link = pipLinks.getElementsByTagName("a");
	for(var i=0; i<link.length; i++){ 
		link[i].onclick = function() {
			showtab(this.href.substring((this.href.length)-7,(this.href.length)));
			return false;
		}
	}
}

// PIP: Close tabs
function closetabBehaviour() {
	if (!document.getElementById("pipnavtabs")) return false;
	var pipLinks = new Array(document.getElementById("closetab1"),document.getElementById("closetab2"),document.getElementById("closetab3"),document.getElementById("closetab4"),document.getElementById("closetab5"),document.getElementById("closetab6"));
	for(var i=0; i<pipLinks.length; i++){
		pipLinks[i].onclick = function() {
			showtab("pipmain");
			return false;
		}
	}
}
*/

// PIP: Extra Photos
function showIMG()
{
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("pics")) return false;
	var extraPhotos = document.getElementById("pics");
	var photo = extraPhotos.getElementsByTagName("a");
	for ( var i=0; i < photo.length; i++) {
		photo[i].onclick = function() {
			if (document.all){
				document.getElementById('showphoto').style.filter="blendTrans(duration=2)"
				document.getElementById('showphoto').style.filter="blendTrans(duration=crossFadeDuration)"
				document.getElementById('showphoto').filters.blendTrans.Apply() 
			}
			document.getElementById('showphoto').src = this;
			if (document.all){
				document.getElementById('showphoto').filters.blendTrans.Play()
			}
			return false;
		}
	}
}

function fOnload() {
	emailCloak();
	externalLinks();
	//showtabBehaviour();
	//closetabBehaviour();
	showIMG();
}