function createRequestObject()
{
	var request_o;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer")
	{
	request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else
	{
	request_o = new XMLHttpRequest();
	}
	return request_o;
}
var http = createRequestObject(); 

var reqPATH = reqPATH;

function getListingDetail(id)
{
	var id = id;
	reqPATH = reqPATH;
	var ts = (new Date()).getTime();
	document.getElementById('DetailResult').innerHTML = "<img alt=\"Spinner\" id=\"search_spinner\" src=\"./images/spinner.gif\" />";
	http.open('get', reqPATH + '=' + ts + '&action=getListingDetail&id=' + id);
	http.onreadystatechange = handlerC; 
	http.send(null);
}

function showLocation(id)
{
	var id = id;
	reqPATH = reqPATH;
	var ts = (new Date()).getTime();
	document.getElementById('unitLocation').innerHTML = "<img alt=\"Spinner\" id=\"search_spinner\" src=\"./images/spinner.gif\" />";
	http.open('get', reqPATH + '=' + ts + '&action=showLocation&id=' + id);
	http.onreadystatechange = handlerM; 
	http.send(null);
}

function showDirectory()
{
	document.getElementById('DetailResult').innerHTML = '';
	document.getElementById('unitLocation').style.height='0px';
	document.getElementById('unitLocation').innerHTML = '';
}


function handlerA()
{
if(http.readyState == 4)
	{
	var response = http.responseText;
	document.getElementById('ajax_results').innerHTML = response;
	}
}

function handlerB() 
{

    if(http.readyState == 4)
    {
        var response = http.responseText;
        var update = new Array();
            
        if(response.indexOf('||' != -1)) 
        {
        update = response.split('||');
        var div_id = update[0];
        document.getElementById(+div_id).innerHTML = update[1];
        }
	}
}

function createMarker(point, name, address, phone, grade) {
      var marker = new GMarker(point, markerOptions);
      var html = "<b>" + name + "</b> (" + grade + ")<br/>" + address
+ "<br />" + phone;
      GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html);
      });
      return marker;
    }

function handlerC()
{
if(http.readyState == 4)
	{
	if (GBrowserIsCompatible()) 
		{	 
		function createMarker(point,html){
	    var marker = new GMarker(point);
	    GEvent.addListener(marker, "click", function() 
			{
	    	marker.openInfoWindowHtml(html);
	        });
       	return marker;
		}
		// Display the map, with some controls and set the initial location 
		var response = http.responseText;
		var update = new Array();
	    update = response.split('||');
	    var details = update[0]
		var lat = update[1];
		var lng = update[2];
		var tel = update[3];
		var shop = update[4];
		document.getElementById('DetailResult').innerHTML = details;
		document.getElementById('unitLocation').style.height='545px';	
		map = new GMap2(document.getElementById("unitLocation"));
		map.setCenter(new GLatLng(53.2895,-6.2003), 18);
		var boundaries = new GLatLngBounds(new GLatLng(53.2886,-6.2018 ), new GLatLng(53.2904,-6.1988));
	    var oldmap = new GGroundOverlay("http://www.stillorgan-sc.ie/documents-and-resources/kml/stillorgan-centre-layout.jpg", boundaries);
	    map.setUIToDefault();
	    map.addOverlay(oldmap);
    
		// Set up three markers with info windows 
	    var point = new GLatLng(lat,lng);
	    var marker = createMarker(point,''+ shop + '<br/>Tel: 01 '+ tel +'')
		map.addOverlay(marker);
		// debugalert("<" + lat + "-" + lng + ">");
		}
		// display a warning if the browser was not compatible
		else 
		{
		alert("Sorry, the Google Maps API is not compatible with this browser");
		}
		//document.getElementById('unitLocation').innerHTML = location;
	}
}

function enableButton()
{
document.payment.submit.disabled=false;
}

function Disable(form) 
{
if (document.getElementById) 
	{
	for (var i = 0; i < form.length; i++) 
		{
		if (form.elements[i].type.toLowerCase() == "submit")
		form.elements[i].disabled = true;
		form.elements.submit.value = 'Please wait..';
		}
	}
return true;
}

function reload()
{
window.location.reload(true);
}

function back() 
	{
    if (window.opener) 
    	{
        window.close();
        }
        else
        {
        if(history.length == 0)
        {
        window.close();
        }
      history.go(-1);
    }
}