function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var hawksworthText = "<span class='hmlTextSmall'>hml</span><span class='notHmlTextSmall'>hawksworth</span><br /><br />Established in 1991, HML Hawksworth now has a significant presence in London and manages a variety of properties from mansion flats and private estates to large mixed-use developments with leisure facilities and site staff.<br /><br />Go to <strong><a href='http://www.hmlhawksworth.com'>www.hmlhawksworth.com</a></strong>";
var andertonsText = "<span class='hmlTextSmall'>hml</span><span class='notHmlTextSmall'>andertons</span><br /><br />Established for 40 years, HML Andertons operates from a base in Croydon and provides expert property and estate management services to developments in south London, Kent, Surrey, Sussex and surrounding areas. Satellite offices in Aldershot and Bristol cover the southern Home Counties, South Coast and the West Country.<br /><br />Go to <strong><a href='http://www.hmlandertons.com'>www.hmlandertons.com</a></strong>";
var shawText = "<span class='hmlTextSmall'>hml</span><span class='notHmlTextSmall'>shaw</span><br /><br />Established for 30 years, HML Shaw is based in Richmond and offers a personal and bespoke service to clients, with attention to detail being fundamental to our management operation. Our client base extends from west and south-west London to Surrey, Buckinghamshire, Berkshire and Oxfordshire.<br /><br />Go to <strong><a href='http://www.hmlshaw.com'>www.hmlshaw.com</a></strong>";
var hathawaysText = "<span class='hmlTextSmall'>hml</span><span class='notHmlTextSmall'>hathaways</span><br /><br />HML Hathaways has been established for 30 years and provides expert property and estate management services to developments in north London, Hertfordshire, Buckinghamshire, Middlesex and Bedfordshire, from offices in north London and New Barnet. We pride ourselves on offering a personal and bespoke management service, with attention to detail being fundamental to our operations.<br /><br />Go to <strong><a href='http://www.hmlhathaways.com'>www.hmlhathaways.com</a></strong>";

function changeTextBox(whichOne, hideBox) {
	if (whichOne == "London") {
		showId('postcodeBox');
		showId('londonPostcode');
		resetDropdown('londonPostcode');
		document.getElementById('postcodeText').innerHTML = whichOne;
		hideId('bucksPostcode');
		hideId('surreyPostcode');
		return;
	} else if (whichOne == "Bucks") {
		showId('postcodeBox');
		showId('bucksPostcode');
		resetDropdown('bucksPostcode');
		document.getElementById('postcodeText').innerHTML = whichOne;
		hideId('londonPostcode');
		hideId('surreyPostcode');
		return;
	} else if (whichOne == "Surrey") {
		showId('postcodeBox');
		showId('surreyPostcode');
		resetDropdown('surreyPostcode');
		document.getElementById('postcodeText').innerHTML = whichOne;
		hideId('londonPostcode');
		hideId('bucksPostcode');
		return;
	} else {
		if (hideBox) {
			hideId('postcodeBox');
			hideId('londonPostcode');
			hideId('bucksPostcode');
			hideId('surreyPostcode');
		}
	}
	document.getElementById('textBox').className = "textBox" + whichOne;
	if (whichOne == "Hawksworth") document.getElementById('textBox').innerHTML = hawksworthText;
	else if (whichOne == "Andertons") document.getElementById('textBox').innerHTML = andertonsText;
	else if (whichOne == "Shaw") document.getElementById('textBox').innerHTML = shawText;
	else if (whichOne == "Hathaways") document.getElementById('textBox').innerHTML = hathawaysText;
}


 var viewportwidth;
 var viewportheight;

 function getScreenDims() {
     // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

     if (typeof window.innerWidth != 'undefined') {
         viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
     }

     // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

     else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0) {
         viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
     }

     // older versions of IE

     else {
         viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
     }
     //alert("Your viewport width is "+viewportwidth+"x"+viewportheight);
 }

 getScreenDims();
var myVar;
var myXOffset = (((viewportwidth - 959) / 2) + 390); //550;    390 + 
var myYOffset = 344;
//alert((((viewportwidth - 959) / 2) + 390));

function showBranch(mouseX, mouseY) {
    getScreenDims();
    if (viewportwidth > 959) myXOffset = (((viewportwidth - 959) / 2) + 390);
    else myXOffset = 390;
    //alert(mouseX);
    //alert("myXOffset = " + myXOffset + "\nmouseX - xOffset = " + (mouseX - myXOffset));
    
    //alert(mouseY);
    //alert(isPointInPoly(AndertonsPoints, { x: mouseX - 625, y: mouseY - 340}) ? "In" : "Out");
    if (isPointInPoly(AndertonsPoints, { x: mouseX - myXOffset, y: mouseY - myYOffset })) changeTextBox('Andertons', true);
    if (isPointInPoly(HawksworthPoints, { x: mouseX - myXOffset, y: mouseY - myYOffset })) changeTextBox('Hawksworth', true);
    if (isPointInPoly(HathawaysPoints, { x: mouseX - myXOffset, y: mouseY - myYOffset })) changeTextBox('Hathaways', true);
    if (isPointInPoly(ShawPoints, { x: mouseX - myXOffset, y: mouseY - myYOffset })) changeTextBox('Shaw', true);
    if (isPointInPoly(SurreyPoints, { x: mouseX - myXOffset, y: mouseY - myYOffset })) changeTextBox('Surrey', false);
    if (isPointInPoly(BucksPoints, { x: mouseX - myXOffset, y: mouseY - myYOffset })) changeTextBox('Bucks', false);
    if (isPointInPoly(LondonPoints, { x: mouseX - myXOffset, y: mouseY - myYOffset })) changeTextBox('London', false);
}

function isPointInPoly(poly, pt) {
    for (var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i)
        ((poly[i].y <= pt.y && pt.y < poly[j].y) || (poly[j].y <= pt.y && pt.y < poly[i].y))
		&& (pt.x < (poly[j].x - poly[i].x) * (pt.y - poly[i].y) / (poly[j].y - poly[i].y) + poly[i].x)
		&& (c = !c);
    return c;
}

AndertonsPoints = [
	{ x: 233, y: 110 },
	{ x: 247, y: 137 },
	{ x: 287, y: 137 },
	{ x: 294, y: 160 },
	{ x: 340, y: 153 },
	{ x: 349, y: 136 },
	{ x: 374, y: 125 },
	{ x: 426, y: 131 },
	{ x: 422, y: 158 },
	{ x: 394, y: 175 },
	{ x: 352, y: 192 },
	{ x: 273, y: 186 },
	{ x: 239, y: 190 },
	{ x: 195, y: 205 },
	{ x: 157, y: 183 },
	{ x: 140, y: 171 },
	{ x: 122, y: 163 },
	{ x: 114, y: 151 },
	{ x: 110, y: 121 },
	{ x: 107, y: 86 },
	{ x: 236, y: 66 }
];
HawksworthPoints = [
	{ x: 305, y: 18 },
	{ x: 309, y: 55 },
	{ x: 330, y: 80 },
	{ x: 344, y: 81 },
	{ x: 347, y: 89 },
	{ x: 340, y: 103 },
	{ x: 336, y: 113 },
	{ x: 351, y: 114 },
	{ x: 351, y: 120 },
	{ x: 347, y: 135 },
	{ x: 367, y: 127 },
	{ x: 345, y: 137 },
	{ x: 374, y: 122 },
	{ x: 382, y: 125 },
	{ x: 396, y: 113 },
	{ x: 419, y: 87 },
	{ x: 434, y: 71 },
	{ x: 444, y: 31 }
];
HathawaysPoints = [
	{ x: 310, y: 56 },
	{ x: 328, y: 82 },
	{ x: 344, y: 83 },
	{ x: 337, y: 104 },
	{ x: 335, y: 109 },
	{ x: 322, y: 112 },
	{ x: 305, y: 121 },
	{ x: 302, y: 107 },
	{ x: 301, y: 87 },
	{ x: 299, y: 69 },
	{ x: 301, y: 62 }
];
ShawPoints = [
	{ x: 235, y: 110 },
	{ x: 238, y: 64 },
	{ x: 256, y: 68 },
	{ x: 283, y: 124 },
	{ x: 305, y: 124 },
	{ x: 293, y: 139 },
	{ x: 246, y: 137 }
];
SurreyPoints = [
	{ x: 291, y: 143 },
	{ x: 305, y: 128 },
	{ x: 320, y: 142 },
	{ x: 343, y: 142 },
	{ x: 337, y: 154 },
	{ x: 313, y: 156 },
	{ x: 296, y: 158 }
];
BucksPoints = [
	{ x: 263, y: 82 },
	{ x: 298, y: 67 },
	{ x: 304, y: 122 },
	{ x: 284, y: 121 },
	{ x: 266, y: 95 }
];
LondonPoints = [
	{ x: 307, y: 128 },
	{ x: 311, y: 117 },
	{ x: 332, y: 110 },
	{ x: 339, y: 115 },
	{ x: 350, y: 115 },
	{ x: 347, y: 126 },
	{ x: 342, y: 140 },
	{ x: 326, y: 143 },
	{ x: 318, y: 138 }
];

function dropdown(mySel, whichOne) {
	var myVal = mySel.options[mySel.selectedIndex].value;
	if(myVal) {
		doPostcode(myVal);
	}
	return false;
}

function resetDropdown(dropdownId) {
	var mySel = document.getElementById(dropdownId);
	mySel.selectedIndex = 0; //mySel.options[mySel.selectedIndex].value;
}

//shows/hides an id
function showhide(myId) {
	if (document.getElementById) {
		var state = document.getElementById(myId).style.visibility;
		if (state == 'visible') {
			hideId(myId);
			//return false;
		} else {
			showId(myId);
			//return false;
		}
	} else {
		;//return true;
	}
}

//hides an id
function hideId(myId) {
	if (document.getElementById) {
		document.getElementById(myId).style.visibility = 'hidden';
		if (myId == "searchPopup") setCookie("searchWinVis", "hidden", 1);
	}
}

//shows an id
function showId(myId) {
	if (document.getElementById) {
		document.getElementById(myId).style.visibility = 'visible';
		if (myId == "searchPopup") setCookie("searchWinVis", "visible", 1);
	}
}

function getCookie(Name){ //get cookie value
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return ""
}

function setCookie(name, value, days){ //set cookie value
//alert("setCookie!");
var expireDate = new Date()
//set "expstring" to either future or past date, to set or delete cookie, respectively
var expstring=expireDate.setDate(expireDate.getDate()+parseInt(days))
document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
}


function doPostcode(postcode) {
	
	if (postcode == "E1" || postcode == "E2" || postcode == "E3" || postcode == "E4" || postcode == "E5" || postcode == "E6" || postcode == "E7" || postcode == "E8" || postcode == "E9" || 
			postcode == "E10" || postcode == "E11" || postcode == "E12" || postcode == "E13" || postcode == "E14" || postcode == "E15" || postcode == "E16" || postcode == "E17" || postcode == "E18" || 
			postcode == "EC1" || postcode == "EC2" || postcode == "EC3" || postcode == "EC4" || postcode == "NW1" || postcode == "SE1" || postcode == "SW1" || postcode == "SW2" || postcode == "SW3" || postcode == "SW4" || 
			postcode == "SW5" || postcode == "SW7" || postcode == "SW8" || postcode == "SW9" || postcode == "SW10" || postcode == "SW11" || postcode == "SW12" || postcode == "W1" || postcode == "W2" || 
			postcode == "W3" || postcode == "W8" || postcode == "W9" || postcode == "W10" || postcode == "W11" || postcode == "W12" || postcode == "W14" || postcode == "WC1" || postcode == "WC2") {
		 changeTextBox("Hawksworth");
	}
	else if (postcode == "HA0" || postcode == "HA1" || postcode == "HA2" || postcode == "HA3" || postcode == "HA4" || postcode == "HA5" || postcode == "HA6" || postcode == "HA7" || postcode == "HA8" || 
			 postcode == "HA9" || postcode == "N1" || postcode == "N2" || postcode == "N3" || postcode == "N4" || postcode == "N5" || postcode == "N6" || postcode == "N7" || postcode == "N8" || 
			 postcode == "N9" || postcode == "N10" || postcode == "N11" || postcode == "N12" || postcode == "N13" || postcode == "N14" || postcode == "N15" || postcode == "N16" || postcode == "N17" || 
			 postcode == "N18" || postcode == "N19" || postcode == "N20" || postcode == "N21" || postcode == "N22" || postcode == "NW1" || postcode == "NW2" || postcode == "NW3" || postcode == "NW4" || 
			 postcode == "NW5" || postcode == "NW6" || postcode == "NW7" || postcode == "NW8" || postcode == "NW9" || postcode == "NW10" || postcode == "NW11" || postcode == "HP1" || 
			 postcode == "HP2" || postcode == "HP3" || postcode == "HP4" || postcode == "HP5" || postcode == "HP22" || postcode == "HP23" || postcode == "HP27" || postcode == "LU6" || 
			 postcode == "LU7" || postcode == "MK17" || postcode == "MK18" || postcode == "MK19" || postcode == "NN13" || postcode == "WD3" || postcode == "SL9" || postcode == "EN1" || postcode == "EN2" || postcode == "EN3") {
			 changeTextBox("Hathaways");
	}
	else if (postcode == "SE2" || postcode == "SE3" || postcode == "SE4" || postcode == "SE5" || postcode == "SE6" || postcode == "SE7" || postcode == "SE8" || postcode == "SE9" || postcode == "SE10" || 
			 postcode == "SE11" || postcode == "SE12" || postcode == "SE13" || postcode == "SE14" || postcode == "SE15" || postcode == "SE16" || postcode == "SE17" || postcode == "SE18" || postcode == "SE19" || 
			 postcode == "SE20" || postcode == "SE21" || postcode == "SE22" || postcode == "SE23" || postcode == "SE24" || postcode == "SE25" || postcode == "SE26" || postcode == "SE27" || postcode == "SE28" || 
			 postcode == "SW16" || postcode == "SW17" || postcode == "CR0" || postcode == "CR1" || postcode == "CR2" || postcode == "CR3" || postcode == "CR4" || postcode == "CR5" || 
			 postcode == "CR6" || postcode == "CR7" || postcode == "CR8" || postcode == "CR9" || postcode == "KT17" || postcode == "KT18" || postcode == "KT19" || postcode == "KT20" || 
			 postcode == "KT21" || postcode == "KT22" || postcode == "KT23" || postcode == "KT24" || postcode == "RH1" || postcode == "RH2" || postcode == "RH3" || postcode == "RH4" || 
			 postcode == "RH5" || postcode == "RH6" || postcode == "RH7" || postcode == "RH8" || postcode == "RH9" || postcode == "RH10" || postcode == "RH11" || postcode == "RH12" || 
			 postcode == "RH13" || postcode == "RH14" || postcode == "SM1" || postcode == "SM2" || postcode == "SM3" || postcode == "SM4" || postcode == "SM5" || postcode == "SM6" || 
			 postcode == "SM7" || postcode == "GU1" || postcode == "GU2" || postcode == "GU3" || postcode == "GU4" || postcode == "GU5" || postcode == "GU6" || postcode == "GU7" || 
			 postcode == "GU8" || postcode == "GU9" || postcode == "GU10" || postcode == "GU14" || postcode == "GU15" || postcode == "GU16" || postcode == "GU17" || postcode == "GU18" || 
			 postcode == "GU19" || postcode == "GU20" || postcode == "GU21" || postcode == "GU22" || postcode == "GU23" || postcode == "GU24" || postcode == "GU25" || postcode == "GU26" || 
			 postcode == "GU27" || postcode == "GU95") {
			 changeTextBox("Andertons");
	}
	else if (postcode == "SW6" || postcode == "SW13" || postcode == "SW14" || postcode == "SW15" || postcode == "SW18" || postcode == "SW19" || postcode == "SW20" || postcode == "TW1" || 
			 postcode == "TW2" || postcode == "TW3" || postcode == "TW4" || postcode == "TW5" || postcode == "TW6" || postcode == "TW7" || postcode == "TW8" || postcode == "TW11" || 
			 postcode == "TW12" || postcode == "TW13" || postcode == "TW14" || postcode == "UB1" || postcode == "UB2" || postcode == "UB3" || postcode == "UB4" || postcode == "UB5" || 
			 postcode == "UB6" || postcode == "UB7" || postcode == "UB8" || postcode == "UB9" || postcode == "UB10" || postcode == "UB11" || postcode == "UB18" ||  postcode == "W4" || 
			 postcode == "W5" || postcode == "W6" || postcode == "W7" || postcode == "W13" || postcode == "HP6" || postcode == "HP7" || postcode == "HP8" || postcode == "HP9" || 
			 postcode == "HP10" || postcode == "HP11" || postcode == "HP12" || postcode == "HP13" || postcode == "HP14" || postcode == "HP15" || postcode == "HP16" || postcode == "HP17" || 
			 postcode == "HP18" || postcode == "HP19" || postcode == "HP20" || postcode == "HP21" || postcode == "OX6" || postcode == "RG9" || postcode == "SL0" || postcode == "SL1" || 
			 postcode == "SL2" || postcode == "SL3" || postcode == "SL4" || postcode == "SL5" || postcode == "SL6" || postcode == "SL7" || postcode == "SL8" || 
			 postcode == "UB9" || postcode == "KT1" || postcode == "KT2" || postcode == "KT3" || postcode == "KT4" || postcode == "KT5" || postcode == "KT6" || postcode == "KT7" || 
			 postcode == "KT8" || postcode == "KT9" || postcode == "KT10" || postcode == "KT11" || postcode == "KT12" || postcode == "KT13" || postcode == "KT14" || postcode == "KT15" || 
			 postcode == "KT16" || postcode == "TW9" || postcode == "TW15" || postcode == "TW16" || postcode == "TW17" || postcode == "TW18" || postcode == "TW19" || postcode == "TW20") {
			 changeTextBox("Shaw");
	}
}
