//All rights reserved. OxfordHousing. 2005-2006.

var ns4=document.layers;
var ie4=document.all;
var ns6=document.getElementById&&!document.all;
var isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;

var popup;
var overlay;

function HelpCursor(sender)
{
	var lnk = sender;
	sender.style.cursor = "help";
}

function repaintsrchbx()
{
	popup = document.getElementById('advancedsearch');
	if (popup.style.visibility == 'visible')
	{
		HideSearch();
		ShowSearch();
	}
}


function exec_search()
{
	searchstring=searchstring+'ppttype='+searchppttype.selectedIndex;
	searchstring=searchstring+'&pptbedrooms='+searchpptbdrms.selectedIndex;
	if (minprice.value!=null && minprice.value!="")
		searchstring=searchstring+'&pptprice='+minprice.value;
	if (maxprice.value!=null && maxprice.value!="")
		searchstring=searchstring+'-'+maxprice.value;
	if (searchlocation.value!=null && searchlocation.value!="")
		searchstring=searchstring+'&pptlocation='+searchlocation.value;
	if (searchpstcd.value!=null && searchpstcd.value!="")
		searchstring=searchstring+'&pptpstcd='+searchpstcd.value;

	window.location.href=searchstring;
}

function ShowSearch()
{
	if(ie4)
	{
		var selects = document.getElementsByTagName("select");
		for(var xx = 0; xx < selects.length; xx++)
		{
			if (selects[xx].name.substring(0,6)!='search')
				selects[xx].style.visibility = "hidden";
		}
	}

	var frames = document.getElementsByTagName("iframe");
	for(var xx = 0; xx < frames.length; xx++)
	{
		frames[xx].style.visibility = "hidden";
	}
			
	var loc = getCenter();
	popup = document.getElementById('advancedsearch');

	var width;
	var height;
	
	if (ie4)
	{
		width = isMac ? document.body.offsetWidth : document.body.scrollWidth;
		height = isMac ? document.body.offsetHeight : document.body.scrollHeight;
	}
	else if (ns4)
	{
		width = document.width;
		height = document.height;
	}
	else if (ns6)
	{
		width = document.body.offsetWidth+document.body.offsetLeft;
		height = document.body.offsetHeight+document.body.offsetTop;
	}
	
	overlay = createOverlayLayer();
		
	overlay.visibility = 'visible';
	
	if(popup.filters != null)
		popup.filters[0].apply();
	popup.style.position = "absolute";
	popup.style.top = loc.y - 80;
	popup.style.left = loc.x - 267;
	popup.style.display = 'block';
	popup.style.visibility = 'visible';
	if(popup.filters != null)
		popup.filters[0].play();	
}

function HideSearch()
{

	if(ie4)
	{
		var selects = document.getElementsByTagName("select");
		for(var xx = 0; xx < selects.length; xx++)
		{
			if (selects[xx].name.substring(0,6)!='search')
				selects[xx].style.visibility = "visible";
		}
	}
	
	var frames = document.getElementsByTagName("iframe");
	for(var xx = 0; xx < frames.length; xx++)
	{
		frames[xx].style.visibility = "visible";
	}
	
	if(popup)
	{
		overlay.visibility = 'hidden';
		
		if(popup.filters != null)
			popup.filters[0].apply();
		popup.style.visibility = "hidden";
		if(popup.filters != null)
			popup.filters[0].play();
			
		
		document.getElementById('overlay').parentNode.removeChild(document.getElementById('overlay'));
	}
}

function getCenter()
{
	var clientHeight;
	var clientWidth;
	var docTop;
	var docLeft;
	
	if (ie4) 
	{
		clientHeight = document.body.clientHeight;
		clientWidth = document.body.clientWidth;
		docTop = document.body.scrollTop;
		docLeft = document.body.scrollLeft;
	} 
	else if (ns4 || ns6)
	{
		clientHeight = window.innerHeight - 20;
		clientWidth = window.innerWidth - 20;
		docTop = window.pageYOffset;
		docLeft = window.pageXOffset;
	}
    
	var loc = new Object();
	loc.x = docLeft + clientWidth/2;
	loc.y = docTop + clientHeight/2;
	return loc;
}

function createOverlayLayer()
{
	var nL;
	var left = 0;
	var top = 0;
	var name = "overlay";
	var html = "";
	
	if (ie4)
	{
		var width = isMac ? document.body.offsetWidth : document.body.scrollWidth;
		var height = isMac ? document.body.offsetHeight : document.body.scrollHeight;
		var divhtml = '<div id=' + name + ' style="visibility:visible;left:' + left + 
			'px;top:' + top + 'px;width:' + width + 
			'px;height:' + height + 'px;position:absolute;">' + 
			html + '</div>';
		document.body.insertAdjacentHTML('afterBegin', divhtml);
		nL = document.all[name].style;
	}
	else if (ns4)
	{
		var width = document.width;
		var height = document.height;
		nL=new Layer(width);
		nL.name = name;
		nL.left=left;
		nL.top=top;
		nL.height = height;
		nL.clip.width = width;
		nL.clip.height = height;
		nL.background = "/pic/opaque.png";
		nL.visibility = "show";
		nL.document.open();
		nL.document.write('<table border=0><tr><td><img src="/pic/opaque.png" width="' + width + '" height="' + height +'"></td></tr></table>');
		nL.document.close();
	}
	else if (ns6)
	{
		var nL = document.createElement("DIV");
		nL.innerHTML = "";
		var mybody=document.body;
		mybody.appendChild(nL);
		nL.style.position = "absolute";
		nL.style.visibility = "visible";
		nL.style.left = left;
		nL.style.top = top;
		nL.style.width = document.body.offsetWidth+document.body.offsetLeft;
		nL.style.height = document.body.offsetHeight+document.body.offsetTop;
		nL.style.background = "url(/pic/opaque.png)";
		nL.id = name;
		nL = nL.style;
	}
	return nL;
}