function httpget (url) {

  var objHTTPRequest = null;

  if (window.XMLHttpRequest) objHTTPRequest = new XMLHttpRequest();
  else                       objHTTPRequest = new ActiveXObject ('Microsoft.XMLHTTP');

  if (objHTTPRequest != null) {

    objHTTPRequest.open ('GET', url, false);

    objHTTPRequest.send (null);
  }


  if (objHTTPRequest.status == 200) return objHTTPRequest.responseText;

}

// detailed search

var trLocationBody;
var locationBody = true;
function switchContentTo (paramID, obj) {

  if (!trLocationBody) trLocationBody = document.getElementById('trLocationBody').firstChild.cloneNode (true);

  if (obj.className != "inactive") {

    obj.className = "inactive";
    obj.parentNode.getElementsByTagName('a')[(obj.parentNode.getElementsByTagName('a')[0] == obj ? 1 : 0)].className = "";
  }

  switch (paramID) {

    case "trLocationBody":


      if (locationBody == false) {
        document.getElementById ('tdTitle0').innerHTML = 'Available<br />locations';
        document.getElementById ('tdTitle1').innerHTML = 'Selected<br />locations';

        document.getElementById ('trLocationBody').removeChild (document.getElementById ('trLocationBody').firstChild);
        document.getElementById ('trLocationBody').appendChild (trLocationBody);



        locationBody = true;
      }

      break;

    case "trNeighbourhoodBody":

      if (locationBody == true) {

        document.getElementById ('tdTitle0').innerHTML = 'Available<br />neighbourhoods';
        document.getElementById ('tdTitle1').innerHTML = 'Selected<br />neighbourhoods';

        if (! window.addEventListener) document.getElementById ('trLocationBody').removeChild (document.getElementById ('trLocationBody').firstChild);
        else                           document.getElementById ('trLocationBody').innerHTML = "";


          document.getElementById ('trLocationBody').appendChild (document.getElementById ('trNeighbourhoodBody').firstChild.cloneNode (true));

        locationBody = false;
      }

      break;

  }
}

function doSelectAll (obj) {
    for (i in obj.childNodes) {
      if (! obj[i]) continue;

      obj[i].selected = true;
    }
}

function selectMe(mySource, myDestination)  {

	var theSource = document.getElementById(mySource);
	var theDestination = document.getElementById(myDestination);
	var boxLength = theDestination.length;
	var selectedItem = theSource.selectedIndex;
	var selectedText = theSource.options[selectedItem].text;
	var selectedValue = theSource.options[selectedItem].value;
	var i;
	var newoption;
	var isNew = true;

	if (boxLength != 0) {
		for (i = 0; i < boxLength; i++) {
			thisitem = theDestination.options[i].text;
			if (thisitem == selectedText) {
				isNew = false;
				break;
			 }
	  	}
	}
	if (isNew) {
		newoption = new Option(selectedText, selectedValue, false, false);
		theDestination.options[boxLength] = newoption;
	}

	if (newoption != null)
  	newoption.selected = true;
}

function removeMe(myDestination) {

	var theDestination = document.getElementById(myDestination);
	var boxLength = theDestination.length;
	arrSelected = new Array();
	var count = 0;

	for (i = 0; i < boxLength; i++) {
		if (theDestination.options[i].selected) {
			arrSelected[count] = theDestination.options[i].value;
		}
		count++;
	}

	var x;

	for (i = 0; i < boxLength; i++) {
		for (x = 0; x < arrSelected.length; x++) {
			if (theDestination.options[i].value == arrSelected[x]) {
				theDestination.options[i] = null;
   			}
		}
		boxLength = theDestination.length;
   	}
}

//  hilites

function hiliteMe(what) {
	document.getElementById(what).style.backgroundPosition = "top left";
}

function unhiliteMe(what) {
	document.getElementById(what).style.backgroundPosition = "top right";
}

// popup

var win=null;

function NewWindow(mypage,myname,w,h,scroll,pos)	{

	LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=window.open(mypage,myname,settings);

}

// tooltip

var tt = null;

function showTip(offset, what) {
	tt = document.getElementById('tooltip');
	tt.style.display = 'block';
	tt.innerHTML = '<div class="tt_top">' + what + '<\/div><div class="tt_bottom"><\/div>'
	followMouse(tt, offset);
}
function hideTip() {
	tt.style.display = 'none';
	tt.innerHTML = '&nbsp;';
	stopFollow();
}

function followMouse(tt, offset) {

	var offX = -130;
	var offY = offset;

	function mouseX(evt) {
		if (!evt) evt = window.event;
		if (evt.pageX) return evt.pageX;
		else if (evt.clientX) return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft);
		else return 0;
	}
	function mouseY(evt) {
		if (!evt) evt = window.event;
		if (evt.pageY) return evt.pageY;
		else if (evt.clientY) return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
		else return 0;
	}
	function follow(evt) {
		if (document.getElementById) {
			tt.style.left = (parseInt(mouseX(evt))+offX) + 'px';
			tt.style.top = (parseInt(mouseY(evt))+offY) + 'px';
		}
	}
	document.onmousemove = follow;
}

function stopFollow() {
	tt.style.left = '0px';
	tt.style.top = '0px';
}
