// BrowserCheck
var bT = navigator.appName
var uA = navigator.userAgent
var b;
if (bT=="Netscape") b = "ns"
else if (bT=="Microsoft Internet Explorer") b = "ie"
else b=bT
var version = navigator.appVersion
var v = parseInt(this.version)
var ns = b=="ns" && v>=4
var ns4 = b=="ns" && v==4
var ns5 = b=="ns" && v==5
var ie = b=="ie" && v>=4
var ie4 = version.indexOf('MSIE 4')>0
var ie5 = version.indexOf('MSIE 5')>0
var ie55 = version.indexOf('MSIE 5.5')>0
var min = ns||ie
var isMac = (uA.indexOf("Mac")!=-1)

// browser redirection code
if (parseFloat(navigator.appVersion) < 4 || (ns4 && parseFloat(navigator.appVersion)<4.06) ) location.href="/browser.html"
if(!document.layers && !navigator.cookieEnabled) location.href="/browser.html";

//----------------------------------------------------------------------------------------------
//for opening up pdf's in a new window
	var blnRegistering
	

	function getPdf(formName){
		var sFromPage = document.location.href
		var queryStr="";
		var formObj=document[formName];
		
		if (formObj){
				if (formObj.from){
					formObj.from.value = sFromPage
				}
		
			// generate querystring from hidden form
			for(i=0;i<formObj.elements.length;i++){
				queryStr+="&"+formObj.elements[i].name+"="+escape(formObj.elements[i].value);
			}
	
			var page="/pdfstream.asp?regSite=com"+queryStr;
		
			newWin = openWin(page,"newWin",500,700)
			setTimeout("focusWin(newWin)",20)
		}



	}
	
	
	function registering(){
		blnRegistering = true
	}
	
	
	function closeWinIfLoadedPDF(oWin){
		var sPageName = oWin.document
		if(!blnRegistering){
			oWin.document.location.href = "/closewin.asp"
		}else{
			focusWin(oWin)
		}
	}
	
//----------------------------------------------------------------------------------------------
//for the 'go' button on keyword search
function keyWdSearch(){
	if (document.keywordSearch){
		document.keywordSearch.submit()
	}
}
//----------------------------------------------------------------------------------------------
//for the 'printer friendly' and 'contact savills' button on news
function doForm(sFormName){
	var newWin
	if (document[sFormName]){
		if(document[sFormName].target=="newPrintWin"){
			newWin = window.open("", "newPrintWin", "width=600,height=500,scrollbars=yes,resizable=yes,toolbar=yes,menubar=yes")
			newWin.focus()
		}
		document[sFormName].submit()
	}
}
//----------------------------------------------------------------------------------------------

function goContact(sEmail, sName){
	var sPageName
	var newWin
	sPageName = document.location.href

	//newWin = openWin("/registration/contact.asp?toName="+escape(sName)+"&toEmail="+escape(sEmail)+"&popupWin=true","newWin",417,518)
	newWin = openWin("http://www.savills.co.uk/ContactForm.aspx?toName="+escape(sName)+"&toEmail="+escape(sEmail)+"&popupWin=true")
	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

//	if(sLink.indexOf('fpdsavills.com')!=-1);


	var email_yes_regExp = /@.*\./

	// all contact emails in popups now
	if (email_yes_regExp.test(sLink)){
		goContact(sLink, sContactName);
	}else{

		if(sLink.substr(0,7)=="http://" && sLink.indexOf(getserverName())==-1){
			window.open(sLink)
		}
		else
		{
			slinkPage = "/link.asp?from="+escape(sFromPage)+"&content="+sLink
			if (sContactName){
				slinkPage += "&contactName="+sContactName
			}
			if (sSpecial){
				slinkPage += "&sp="+sSpecial
			}
			document.location.href = slinkPage
		}
	}
}

function getserverName(){
	return document.location.protocol+"//"+document.location.host
}	

//----------------------------------------------------------------------------------------------

function goReg(){
	if(document.preReg){
		newWin = openWin("/registration/new_research_reports.asp?loading=true&regSite=com","regWin")
		document.preReg.submit()
		setTimeout("focusWin(newWin)",20)
	}
}
//----------------------------------------------------------------------------------------------
//focus new windows after they are created. use on timeout, otherwsie get intermittent errors

	function focusWin(oWin){
		if (oWin){
			oWin.focus()
		}else{
			if (newWin) newWin.focus()
		}
	}
	var newWin

//----------------------------------------------------------------------------------------------

	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
	
	}
//---------------------------------------------------------------------------------------------
function openWin(filename, winname, width, height) {
	if(!winname) winname = ""
	if(!width) width = 500
	if(!height) height = 600
	return window.open(filename, winname, "width="+width+",height="+height+",scrollbars=yes,resizable=yes")
}
	
	//----------------------------------------------------------------------------------------
	
function euroOn(imgName)
{
	var docu1 = document.layers ? document.worldmapDiv.document.europeDiv.document.europemaskDiv.document : document;
	var docu2 = document.layers ? document.worldmapDiv.document.europeDiv.document : document;
	if (docu1.images[imgName])
	{
		docu2.images["europe_image"].src = europe_imageon.src;
		docu1.images[imgName].src = eval(imgName + "on.src");
	}	
}

function euroOff(imgName)
{
	var docu1 = document.layers ? document.worldmapDiv.document.europeDiv.document.europemaskDiv.document : document;
	var docu2 = document.layers ? document.worldmapDiv.document.europeDiv.document : document;
	if (docu1.images[imgName])
	{
		docu2.images["europe_image"].src = europe_imageoff.src;
		docu1.images[imgName].src = eval(imgName + "off.src");
	}	
}

function imgOn(imgName,nest)
{
 	var docu = nest&&document.layers ? eval(nest) : document;
	if (docu.images[imgName])
		docu.images[imgName].src = eval(imgName + "on.src");
}

function imgOff(imgName,nest)
{
 	var docu = nest&&document.layers ? eval(nest) : document;
 	if (docu.images[imgName])
		docu.images[imgName].src = eval(imgName + "off.src");
}

function z(){}

/* fixes recurrsive netscape onload bug */
if(document.layers)
{	
	var currHeight = window.innerHeight;
	var currWidth = window.innerWidth;
	window.onresize = function()
	{
		if((window.innerHeight!=currHeight)||(window.innerWidth!=currWidth)) location.reload(); 	
	}
}

/* corrects netscapes document.height [needs divs in page] */
function fixDocumentHeight()
{
	var allheight;
	if(document.layers&&document.layers['leftcontent']&&document.layers['rightcontent'])
	{
		allheight = Math.max(document.layers['leftcontent'].pageY,document.layers['rightcontent'].pageY);
		//alert(allheight + ", " + document.height + ", " + window.innerHeight)
		if((document.height>window.innerHeight)&&(allheight<window.innerHeight))
			document.height = window.innerHeight+1;
		else if((window.innerHeight<document.height))
			document.height = allheight;
	}
	else if(ns5&&document.getElementById("leftcontent")&&document.getElementById("rightcontent"))
	{
		allheight = Math.max(document.getElementById("leftcontent").offsetTop,document.getElementById("rightcontent").offsetTop);
	}
}