var mapstatus = 0;
var i;
document.getElementById('login-drop-fixed').style.top='-360px'
			
function openmenu() {
if (document.getElementById('login-drop-fixed').style.top=='-360px')
{
mapstatus = 1;
i = -360;
menuexpand();
document.getElementById('login-drop-acc').innerHTML = document.getElementById('login-drop-up').innerHTML;
}
else if (document.getElementById('login-drop-fixed').style.top=='0px')
{
mapstatus = 0;
i = 0;
menushrink();
document.getElementById('login-drop-acc').innerHTML = document.getElementById('login-drop-down').innerHTML;
}
}
			
function menuexpand() {
i = i + 20;
document.getElementById('login-drop-fixed').style.top = (i+'px');
if (i != 0) { setTimeout("menuexpand()", 20); }
}
			
function menushrink() {
i = i - 20;
document.getElementById('login-drop-fixed').style.top = (i+'px');
if (i != -360) { setTimeout("menushrink()", 20); }
}
			
function getpassword() {
document.logintop.action="password-forgot.html";
document.logintop.submit();
}

function showlayer(buildingid, colour) {
if (mapstatus==0) { openmenu(); }
document.getElementById('map-layer-' + colour + '-' + buildingid).style.display = 'inline'
}

function hidelayer(buildingid, colour) {
document.getElementById('map-layer-' + colour + '-' + buildingid).style.display = 'none'
}

function hidealllayers(colour) {
for (a=1;a<=31;a++) {
hidelayer(a, colour);
}
if (colour=='red') {
document.getElementById('postbox').checked = false;
document.getElementById('recycling').checked = false;
document.getElementById('bus').checked = false;
}
}

 if (window.XMLHttpRequest) {
 //if not IE6 change map dropdown position to fixed
 document.getElementById('login-drop-fixed').style.position='fixed';
 }
 
 document.getElementById('map-label').style.width = "auto"; //Needs to be set to auto so that offsetWidth works in ff
 function showmaplabel() {
 var tempx = mouseX;
 var labelwidth = parseInt(document.getElementById('map-label').offsetWidth);
 var mapedge = (((document.body.clientWidth-995)/2)+995);
 if (tempx+labelwidth>mapedge-20) { tempx = tempx - labelwidth - 35 }
  
 document.getElementById('map-label').style.left = tempx + 20 + 'px';
 document.getElementById('map-label').style.top = mouseY - 10 + 'px';
 document.getElementById('map-label').style.display = 'inline';
 }
 
 function hidemaplabel(building) {
 document.getElementById('map-label').style.display = 'none';
 document.getElementById('map-label').innerHTML = '';
 }
 
var isIE = document.all;
var mouseX = 0;
var mouseY = 0;

function getMouseXY(e)
{ 
  if (!e) e = window.event;
  if (e)
  { 
  	mouseX = e.clientX;
  	mouseY = e.clientY;
  }
}

document.onmousemove = getMouseXY;

var xmlhttp=false;
var xmlhttp2=false;
var xmlhttp3=false;
var xmlhttp4=false;

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
      xmlhttp = new XMLHttpRequest();
      xmlhttp2 = new XMLHttpRequest();
      xmlhttp3 = new XMLHttpRequest();
      xmlhttp4 = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
      xmlhttp2 = false;
      xmlhttp3 = false;
      xmlhttp4 = false;
    }
}

function getcompanies(buildingid) {
if (xmlhttp) {
	xmlhttp.open("GET", 'getcompanies.aspx?buildingid=' + buildingid,true);
	 xmlhttp.onreadystatechange=function() {
	  if (xmlhttp.readyState==4) {
	   document.getElementById('map-label').innerHTML = xmlhttp.responseText;
	  }
	 }
	 xmlhttp.send(null)
	 }
}

function advert() {
if (xmlhttp2) {
	xmlhttp2.open("GET", 'company-random.aspx?q=' + Math.random(),true);
	 xmlhttp2.onreadystatechange=function() {
	  if (xmlhttp2.readyState==4) {
	   document.getElementById('advert-ajax').innerHTML = xmlhttp2.responseText;
	  }
	 }
	 xmlhttp2.send(null)
	 }
}

function directory(range) {
if (xmlhttp3) {
	xmlhttp3.open("GET", 'directory-ajax.aspx?range=' + range,true);
	 xmlhttp3.onreadystatechange=function() {
	  if (xmlhttp3.readyState==4) {
	   document.getElementById('directory').innerHTML = xmlhttp3.responseText;
	  }
	 }
	 xmlhttp3.send(null)
	 }
}

function showcontact(businessid) {
if (xmlhttp4) {
	xmlhttp4.open("GET", 'company-contact.aspx?businessid=' + businessid,true);
	 xmlhttp4.onreadystatechange=function() {
	  if (xmlhttp4.readyState==4) {
	   document.getElementById('contact').innerHTML = xmlhttp4.responseText;
	   var contactx = (document.body.clientWidth - 400) / 2;
       var contacty = 200;
	   document.getElementById('contact').style.left = contactx + 'px';
	   document.getElementById('contact').style.top = contacty + 'px';
	   document.getElementById('overlay').style.display='inline';
	   document.getElementById('contact').style.display='inline';
	  }
	 }
	 xmlhttp4.send(null)
	 }
}