// code for menu rollovers
var hideMenuEvent;
var displayMenu="";
function showMenu(id)
{
	if (displayMenu!="" && displayMenu!=id) hideMenu(0)
	displayMenu = id;
	var obj = document.getElementById(id);
	obj.getElementsByTagName("ul")[0].style.left="1em"
}
function hideMenu(timeout)
{
	clearTimeout(hideMenuEvent);
	hideMenuEvent=window.setTimeout('document.getElementById("' + displayMenu + '").getElementsByTagName("ul")[0].style.left="-999px"', timeout);
}
function cancelHideMenu()
{
	clearTimeout(hideMenuEvent);
}
sfHover = function() {
	if (document.getElementById("nav"))
	{
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}

sfHover2 = function() {
	if (document.getElementById("leftMenuBar"))
	{
		var sfEls = document.getElementById("leftMenuBar").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover2";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover2\\b"), "");
			}
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);
if (window.attachEvent) window.attachEvent("onload", sfHover2);	

// function to open PDF's
function openPdf(url)
{

	var winWidth = 500
	var winHeight = 600
		
	if (screen.width==800||screen.height==600){
		winHeight = 562
		}
	else if (screen.width<=1024||screen.height<=768){
		winHeight = 600
		}			
		
	page="/pdfstream.aspx?url=" + url;
	newWin = window.open(page,"newWin","width=" + winWidth + ",height=" + winHeight)
	setTimeout("focusWin(newWin)",20)
}

function openCSPdf(url)
{

	var winWidth = 500
	var winHeight = 600
		
	if (screen.width==800||screen.height==600){
		winHeight = 562
		}
	else if (screen.width<=1024||screen.height<=768){
		winHeight = 600
		}			
		
	page="../pdfstream.aspx?url=" + url;
	newWin = window.open(page,"newWin","width=" + winWidth + ",height=" + winHeight)
	setTimeout("focusWin(newWin)",20)
}				

// browser redirection code

//if (parseFloat(navigator.appVersion) < 4 || (document.layers && parseFloat(navigator.appVersion)<4.06) //){location.href="/browser.html";}
//if(!document.layers && !navigator.cookieEnabled) location.href="/browser.html";
//----------------------------------------------------------------------------------------------
//for the 'go' button on keyword search
function keyWdSearch(){
	if (document.keywordSearch){
		document.keywordSearch.submit()
	}
	else if(document.layers){
			document.textareaDiv.document.keywordSearch.submit()
	}
}
//----------------------------------------------------------------------------------------------
//for the 'printer friendly' and 'contact savills' button on news

function doForm(sFormName){
	if (document[sFormName]){
		if(document[sFormName].target=="newPrintWin"){

			var queryStr="";
			var formObj=document[sFormName];
		
			// generate querystring from hidden form
			for(i=0;i<formObj.elements.length;i++){
				queryStr+="&"+formObj.elements[i].name+"="+formObj.elements[i].value;
			}
			queryStr = queryStr.substr(1);
	
			var page=formObj.action+"?"+queryStr;

			newWin = window.open(page, "newPrintWin", "width=600,height=500,scrollbars=yes,resizable=yes,toolbar=yes,menubar=yes")

			setTimeout("focusWin(newWin)",20)
		}
//		document[sFormName].submit()
	}
}
//----------------------------------------------------------------------------------------------
/* old function - popped up in same page

function goReg(){
	document.preReg.submit()
}
*/

 function goReg(){
	var newWin
	var thisWidth = "500"
	var thisHeight="800"
	
	newWin = window.open("../ResearchRegistration.aspx?sRegType=new","newWin","scrollbars=1,width=" + thisWidth + ",height=" + thisHeight)

}
//----------------------------------------------------------------------------------------------


function goContact(sEmail, sName, width, height,propertyId, sExtraMessage){
	var sPageName
	var newWin
	var thisWidth = "500"
	var thisHeight="600"
	if (propertyId==null) propertyId=""
	
	if(width) thisWidth=width
	if(height) thisHeight=height
	
	if(!sExtraMessage) sExtraMessage = ""
	//sEmail="gojones@savills.com"
	sPageName = document.location.href
	//get the page filename
	if(sPageName.lastIndexOf("/") != -1){
		sPageName = sPageName.substr(sPageName.lastIndexOf("/")+1)
		if (sPageName.indexOf("?") != -1){
			sPageName = sPageName.substr(0,sPageName.indexOf("?"))
		}
		if (sPageName.indexOf("#") != -1){
			sPageName = sPageName.substr(0,sPageName.indexOf("#"))
		}
	}
	//add to this list any page which supports 
	/*if(sPageName=="content.asp" || sPageName=="hub.asp" || sPageName=="research.asp" || sPageName=="service_directory.asp" || sPageName=="news.asp" || sPageName=="recruitment.asp")
		goLink(sEmail, sName)
	else{*/
		//newWin = openWin("http://www.savills.co.uk/ContactForm.aspx?toName="+escape(sName)+"&toEmail="+escape(sEmail)+"&popupWin=true&propertyId="+propertyId+"&extramsg="+escape(sExtraMessage),"newWin",thisWidth,thisHeight)
		newWin = window.open("../ContactForm.aspx?toName="+escape(sName)+"&toEmail="+escape(sEmail)+"&popupWin=true&propertyId="+propertyId+"&extramsg="+escape(sExtraMessage),"newWin","scrollbars=1,width=" + thisWidth + ",height=" + thisHeight)
		if (newWin){
			newWin.focus()	
		}
	//}
		
}


function doLinks()
{
	if(!linksState)
	{
		if(window.otherLinks) otherLinks.hide();
		//infoLinks.hide();
	}
	return;
}

//----------------------------------------------------------------------------------------------

function goLink(sLink, sContactName,sSpecial){
	var slinkPage
	var sFromPage = document.location.href
	var sContent = sLink.indexOf("/")==-1 ? sLink : escape(sLink)
	
	//workaround for netscape 4.08's pathetic attemps to pre-escape js
	if (sContent.indexOf(":")!=-1) sContent = sContent.replace(/:/g, "%3A")
	
	slinkPage = "/link.asp?from="+escape(sFromPage)+"&content="+sContent

	var email_yes_regExp = /@.*\./

	// all contact emails in popups now
	if (email_yes_regExp.test(sLink)){
		goContact(sLink, sContactName);
	}else{

		if (sContactName)
		{
			slinkPage += "&contactName="+escape(sContactName)
		}
		if (sSpecial)
		{
			slinkPage += "&sp="+sSpecial
		}
		if((sLink.indexOf('http://')!=-1 || sLink.indexOf('http:%2F%2F')!=-1 || sLink.indexOf('http%3A%2F%2F')!=-1)  && sLink.indexOf(getserverName())==-1)
		{
			window.open(slinkPage)
		}
		else
		{
			document.location.href = slinkPage
		}
	}	
}
//----------------------------------------------------------------------------------------------

	function goLet(sLet){
		var	sCurrentURL = document.location.href
		var sToURL
		var sExtraQuerystring
		
		sLet = sLet.toUpperCase()

		if (g_sServDirSection != sLet){
		//hack to clear the content
			sToURL = appendToQuerystring(sCurrentURL, "content", "")
			sToURL = appendToQuerystring(sToURL, "section", sLet)
			document.location.href = sToURL
		}
	}
//----------------------------------------------------------------------------------------------
	function appendToQuerystring(sCurrentURL, sKey, sVal){
		var sToURL, sExtraQuerystringItem, iPos
		sExtraQuerystringItem = sKey+"="

			if(sCurrentURL.indexOf("?") != -1){
				if (sCurrentURL.indexOf(sExtraQuerystringItem) != -1){
					iPos = sCurrentURL.indexOf(sExtraQuerystringItem)
					sToURL = sCurrentURL.substring(0, iPos)
					sToURL += sExtraQuerystringItem+sVal
					
					if (sCurrentURL.indexOf("&",iPos) != -1){
						sToURL += sCurrentURL.substr(sCurrentURL.indexOf("&",iPos))
					}
				}else{
					sToURL = sCurrentURL + "&"+sExtraQuerystringItem+sVal
				}
			}else{
				sToURL = sCurrentURL + "?"+sExtraQuerystringItem+sVal
			}
	
		return sToURL
	
	}
//----------------------------------------------------------------------------------------------
	var newWin
	function focusWin(oWin){
		if (oWin){
			oWin.focus()
		}
	}
	
function getserverName(){
	return document.location.protocol+"//"+document.location.host
}	


function getpopUp(page, name, details) {
newWin=window.open(page, name, details);
newWin.focus();
return false;
}

//Netscape 4 reload on resize
/*
if(document.layers)
{	
	var currHeight = window.innerHeight;
	var currWidth = window.innerWidth;
	window.onresize = function()
	{
		if((window.innerHeight!=currHeight)||(window.innerWidth!=currWidth)) location.reload(); 	
	}
}
*/



function popup(src,type){

	var newSrc = "";
	var str = "top=20;left=20,toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=1,"

	switch (type){
		case "sample" :
			str+= "scrollbars=0,toolbar=0,menubar=0,width=400,height=338"
			newSrc = ""+ src;
		break;
		case "print" :
			str+= "scrollbars=1,toolbar=1,menubar=1,width=590,height=580"
			newSrc = location +"?print=true&page="+ src;
		break;
		case "printAppendLoc" :
			str+= "scrollbars=1,toolbar=1,menubar=1,width=590,height=580"
			newSrc = location +"&print=true";
		break;
		default : 
			str+= "width=400,height=338,"
			newSrc = src
		;
	}

	var newWin = window.open(newSrc,"",str)
}

function viewCart(){
	// this will link to the cart url when we know what it is.
	var cartURL;
	cartURL = "http://kryton.clickandbuild.com/cnb/shop/savills?op=basket-view-null&return=";
	location = cartURL;
}

function getBasket(reportId,type){
	switch (type){
		case "report" :
		handlelink("http://kryton.clickandbuild.com/cnb/shop/savills?op-catalogue-search-null&search="+reportId)
		break;
		default : 
		viewCart();
	}
}

function handlelink(url){
	location = url;
}

function getReportId() {
	// contentId is populated in look and feel functions, it's taken from the path of the source content HTML (which contains the contentId)
	pageId=contentId;
	return pageId;
}

// -----------------------------------------------------------------CUT HERE----------------------------------------------------------------------
var firstClick = false;
var displayedDropDown;
								
function showDropDown(dropDownId) {
	if (displayedDropDown) {
		hideDropDown(displayedDropDown)
	}
	displayedDropDown= dropDownId;
	getObj(dropDownId).style.display="block";
}

function hideDropDown(){
	if (displayedDropDown) {
		if (firstClick) {
			getObj(displayedDropDown).style.display = "none";
			displayedDropDown = null;
			firstClick = false;
		} else {
			firstClick = true;
		}
	}
}

function getObj(id) {
	if (id != "") {
		return document.getElementById(id);
	}
}		

function changeUnits(rangeType)
{
	var smallRangeValue = new Array(100, 1000, 2500, 5000, 10000, 25000, 50000, 100000, 500000, 1000000);
	var smallRangeText = new Array("100", "1,000", "2,500", "5,000", "10,000", "25,000", "50,000", "100,000", "500,000", "1,000,000");
	var bigRangeValue = new Array(1, 5, 10, 25, 50, 100, 1000, 10000);
	var bigRangeText = new Array("1", "5", "10", "25", "50", "100", "1,000", "10,000");
	
	ddlMinArea = document.getElementById("ddlMinArea");
	ddlMaxArea = document.getElementById("ddlMaxArea");
	
	while (ddlMinArea.options.length > 0) {
		ddlMinArea.options[0] = null;
	}

	while (ddlMaxArea.options.length > 0) {
		ddlMaxArea.options[0] = null;
	}

	ddlMinArea.options[0]=new Option("minimum","0");
	ddlMaxArea.options[0]=new Option("maximum","0");

	if (rangeType == 'big')
	{
		for (i=0;i<bigRangeValue.length;i++)
		{
			ddlMinArea.options[i+1]=new Option(bigRangeText[i],bigRangeValue[i]);
			ddlMaxArea.options[i+1]=new Option(bigRangeText[i],bigRangeValue[i]);
		}
	}
	else
	{
		for (i=0;i<smallRangeValue.length;i++)
		{
			ddlMinArea.options[i+1]=new Option(smallRangeText[i],smallRangeValue[i]);
			ddlMaxArea.options[i+1]=new Option(smallRangeText[i],smallRangeValue[i]);
		}
	}						
}

function goMicro(elem)
{
	if(elem.selectedIndex != 0)
	{
		document.location.href = elem.options[elem.selectedIndex].value;
	}
}

function openPrinterFriendly(id)
{
	window.open('../PrintContent.aspx?id=' + id)
}			
		
function openPrinterFriendlyResearch(id)
{
	window.open('../PrintContent.aspx?mode=research&id=' + id)
}		

function viewAsset(SiteRef, modeIndex)
{
	window.open("PropertyAssets.aspx?siteref=" + SiteRef + "&mode=" + modeIndex,"","width=620,height=540,location=0,toolbar=0");
}