	var feed_content = null;
	var googleHttp = null;
	var chooseoption = 'parking';
	var storedx;
	var storedy;
	var icon;
	//var map = null;

	function gping (id) {
		var divIdValue = $('selectedValue').value;
		var divId = $('selectedValue');
		if (divIdValue !='none')
			{
				$('div_'+divIdValue).className ='map_none'; 
			}
			
			divId.value = id;
		if ($('div_'+id))
			$('div_'+id).className ='map_orange'; 
		}

	
	function map_hover (id) {
		if ($('div_'+id).className !='map_orange')
			$('div_'+id).className ='map_green'; 
	}
	
	function map_out (id) {
		if ($('div_'+id).className !='map_orange')
		$('div_'+id).className ='map_none'; 
	}
	
function genInfoWindow1(name,line1,line2,url, urlText, icon){
	var text = '<div class="infwin"><div style="float:right; margin-right:18px; background:url(/images/icons/'+icon+'.gif) left center no-repeat; height:25px; width:25px;"></div><span class="green"><strong>'+name+'</strong></span><br /><span class="orange">'+line1+'</span><br />'+line2+'<br /><p><a href="'+url+'">'+urlText+'</a></p></div>';
	return text;
}

function genInfoWindow2(description,url, urlText){
	var text = '<div class="infwin">'+description+'<p><a href="'+url+'">'+urlText+'</a></p></div>';	
	return text;
}

    if (GBrowserIsCompatible()) {
		
var polyline =  new GPolyline.fromEncoded({
  color: "#0000ff",
  weight: 4,
  opacity: 0.8,
  points: "asmyHlh_@zCz@lCdAjEbHzUoa@fF}JM}H|MqGzDqCjIgL~P{RvEGx@\\~CeALyCpAw@tDfHt@RrHyMdJkJp@wRhAeIzDkBh@hC~@B`IuErC{D`Ou`@~Oqb@jL{^t@qNmCif@?GIcM_EaI}EcEuBuL}CoI_BqEoBkQ_I_LqIP}ApAcAo@KoBd@yAv@UdE{`@?EUgo@{BmCb@eEqJeQkEgMc\\uLcDjDj@sFwX{PeMwBqDzEkEp@q@oLcNtAgCjBqCaLqRdOwJDwNrQmHlPsKvVnBtPbAzBo@nBeAUuFpAmKpk@aIde@vD|D_KhRCxLlAvc@xH~KpAF~CfU}IhI?C[zIjLh_@bOhl@n@vCfEiElDlMeF|DpDd_@IfHtBbApBrDyAdKz@jXtDt`@dFuAlAxKcFpBnEfb@",
  levels: "P?DEGEFHDFGICDECFCGEFGHCDEFGJFGH?EFEGEDHIECFCDCF?HDEFGHDJGFEDHFDEGHIFGEFCDEHFGIEJEFGE?FHGCEFEIDEDFGHEEEP",
  zoomFactor: 2,
  numLevels: 18
});
 
var polylineext = new GPolyline.fromEncoded({
  color: "#FF0000",
  weight: 4,
  opacity: 0.8,
  points: "_kgyHnhXxKpIhIfp@eD~l@S`V?CvEtb@Fp@pD~i@lAvUIxCn@hC~Fxd@bA|JvFhKn@tJiPvQcRlW}SpT}HzEeIdMiSlRxDpPqBhRwRvTsBjHkA~@k@xLuQnX}GhKgBq@iAnD{QjJeX~GgJtCo@FPnEmKdH{JnIkHjJgHlImDeJSeAmLOSqHaCJa@kLjCki@j@g@O_CVuEuVhK~CcSvAcW~AwT|JuV@?xOqAn@eR~Gg^fAeh@nFyAnB}JdBgCeCcQzOiYeS{c@pEeImCaGn\\ok@xEyJ|PeMhPgUhFcDhFt@nDsExAnFjIuHlNyRvB{Ct@mTvA{FtDo@ZnBdJyDzOi_@bTcj@",
  levels: "P?GHF?GBIFCDGEHEFGJEFGEHFGCEIEFDGHEBFGJEFEBGDEFGBCHFEFGF?GHIFGEDFHGEJGEHFGEIDEGDFDHCEGP",
  zoomFactor: 2,
  numLevels: 18
});

      var gmarkers = [];
      var html1 = [];
	  var html2 = [];
	  var tab1 ='';
	  var tab2 ='';
	  
      var i = 0;
	  var j = 0;
	  
	  var map;
	  var icon;

	  G_NORMAL_MAP.getErrorMessage = function() {
         var z=map.getZoom();
         if (z > 14) {
           map.setZoom(z-1);
           return "";
         }
         return "No data available at this zoom level.";
       } 
	  
	  var baseIcon = new GIcon();
		baseIcon.iconAnchor = new GPoint(6, 6);
		baseIcon.infoWindowAnchor = new GPoint(9, 2);

      function createMarker(point,name,firstline,secondline,url,description,icon_name,icon_width,icon_height,label) {
	   			icon = new GIcon(baseIcon);
  				icon.image = "/images/icons/" + icon_name + ".gif";
  				icon.iconSize = new GSize(icon_width, icon_height);
		var urlText;		
        var marker = new GMarker(point, icon);
         
		if ((icon_name=='city') || (icon_name=='postcode'))
			urlText = '';
		else if (icon_name=='parking')
		  	urlText = 'Find out more details about this space';
		else
		 	urlText = 'View more Information';
		 
		 
        GEvent.addListener(marker, "click", function() {
		  if (icon_name=='parking')
		  	marker.openInfoWindowTabsHtml([new GInfoWindowTab('Summary',genInfoWindow1(name,firstline,secondline,url, urlText, icon_name)), new GInfoWindowTab('Description',genInfoWindow2(description,url, urlText))]);
		else
			marker.openInfoWindowHtml(genInfoWindow1(name,firstline,secondline,url,urlText, icon_name));
		
		if (label!=0)
		  gping (label);
		  //document.location.href = '#div_'+label;
		  //document.location.href = '#top';

        });
		
        gmarkers[label] = marker;
        html1[label] 	= genInfoWindow1(name,firstline,secondline,url, urlText, icon_name);
		html2[label] 	= genInfoWindow2(description,url, urlText);

        return marker;
      }


      // This function picks up the click and opens the corresponding info window
      function myclick(i) {
        gmarkers[i].openInfoWindowHtml(htmls[i]);

      }
      
	  
function readMap(getoption,getitem,choice,first,sortby,sortorder)
	{	
		$('selectedValue').value = 'none';
		feed_content='';
		

		chosen_div = $('list_space');
		showLoader('list_space');

		
					if ($("static_form")){
						document.static_form.oid.value = 'check';
					}
						
		var latLngBounds = map.getBounds();	
		var btmbnd = roundNumber(latLngBounds.getSouthWest().lng(),4);
		var topbnd = roundNumber(latLngBounds.getNorthEast().lng(),4);
		var leftbnd = roundNumber(latLngBounds.getSouthWest().lat(),4);
		var rightbnd = roundNumber(latLngBounds.getNorthEast().lat(),4);
		var center = map.getCenter();
		var centerx = roundNumber(center.x,5);
		var centery = roundNumber(center.y,5);
		
		$('alert_lat').value = centery;
		$('alert_lon').value = centerx;
		$('alert_item').value = getitem;
				var query = '/index.php?com=maps&xml=gmaps&view='+getoption+'&item='+getitem+'&type='+choice+'&sortby='+sortby+'&sortorder='+sortorder+'&btmbnd='+btmbnd+'&topbnd='+topbnd+'&leftbnd='+leftbnd+'&rightbnd='+rightbnd+'&centerx='+centerx+'&centery='+centery;
				
				GDownloadUrl(query, function(data, responseCode) {
  				var xml = GXml.parse(data);
   								
								// obtain the array of markers and loop through it
								var markers = xml.documentElement.getElementsByTagName("marker");
            					// hide the info window, otherwise it still stays open where the removed marker used to be
            					
								if (chooseoption != getoption)
								map.getInfoWindow().hide();
								
								
								chooseoption = getoption;
								
            					for (i=0; i<gmarkers.length; i++)
									{
              							map.removeOverlay(gmarkers[i]);
            						}

            					gmarkers = [];
								
            					for (var i = 0; i < markers.length; i++)
									
									{
              							var lat = parseFloat(markers[i].getAttribute("lat"));
              							var lng = parseFloat(markers[i].getAttribute("lng"));
              							var point = new GLatLng(lat,lng);
										var name = markers[i].getAttribute("name");
										var price = markers[i].getAttribute("price");
										var freq = markers[i].getAttribute("freq");
              							var url = markers[i].getAttribute("url");
										var description = markers[i].getAttribute("description");
              							var label = markers[i].getAttribute("label");
              							icon = markers[i].getAttribute("icon");
			  							var icon_width = parseInt(markers[i].getAttribute("width"));
			  							var icon_height = parseInt(markers[i].getAttribute("height"));
										var firstline = markers[i].getAttribute("firstline");
										var distance = markers[i].getAttribute("distance");
										var postcode = markers[i].getAttribute("postcode");
										var first_icon = markers[0].getAttribute("icon")
							
							if ((icon=='city') || (icon=='postcode'))
								var secondline =  '';
							else if (icon=='parking')
								var secondline =  '&pound;'+price+' per '+freq;
							else
								var secondline =  postcode;
								
								var new_icon = icon;
										
		var marker = createMarker(point,name,firstline, secondline, url,description,icon,icon_width,icon_height,label);
        map.addOverlay(marker);
										


if (label!=0){
feed_content += '<div class="map_none" id="div_'+label+'" title="Click here for more details" ondblclick="map.setCenter(new GLatLng( '+lat+','+lng+'), 15)" onclick="ProcessClick('+label+','+lat+','+lng+',\''+getoption+'\')" onmouseover="map_hover('+label+');" onmouseout="map_out('+label+');"><span class="infowindowtitle">'+name+'</span><br />';

if (new_icon=='parking'){
if (price!='')
feed_content +='&pound;'+price;

if (freq!='')
feed_content +=' per '+freq;

}
else
feed_content +=firstline;


if (((choice == 'business') && ((first==1) || ((storedx == map.getCenter().lat()) && (storedy == map.getCenter().lng())))) && (label!=0))
	feed_content +='<br/>'+distance;
else
	feed_content +='<br/>'+postcode;

feed_content +='</div>';


}

           		 					}
 
			var tab1_first = html1[0];
			var tab2_first = html2[0];
 									if (first==1){
										
										if (first_icon=='parking')
	map.openInfoWindowTabsHtml(map.getCenter(),[new GInfoWindowTab('Summary',tab1_first), new GInfoWindowTab('Details',tab2_first)]);
					else
						map.openInfoWindowHtml(map.getCenter(), tab1_first);
									}		
				
				
				if (feed_content !='')
							chosen_div.innerHTML = feed_content;
							
				else if ((first_icon!='city') && (first_icon!='postcode')){
							chosen_div.innerHTML = '<div class="no_results"><h4>Sorry</h4><p>We haven\'t found any <span class="blue">'+xml.documentElement.getElementsByTagName("option_value").item(0).firstChild.data+'</span> within this area. Please try searching in a different area or in a different category.</p></div>';
				}
				else
				chosen_div.innerHTML = '<div class="no_results"><h4>Sorry</h4><p>We haven\'t found any results in this area. Please try searching in a different area or in a different category.</p></div>';

        					});
							
			}
			
   


	function ShowMeTheMap(label,lat,lang,zoom,option,choice)
		{

			map = new GMap2($('map'));
      		map.addControl(new GLargeMapControl());
      		map.addControl(new GMapTypeControl());
			map.addControl(new GScaleControl());
			//var ovcontrol = new GOverviewMapControl(new GSize(100,100)); 
			//map.addControl(ovcontrol);
			//var ovmap = ovcontrol.getOverviewMap(); 
			//GEvent.addListener(ovmap, 'moveend', function() {												 
       		//readMap(chooseoption,label,choice,0,'distance','asc');
      //});

					
      		map.setCenter(new GLatLng( lat,lang), zoom);
			map.savePosition();
			map.enableContinuousZoom();
			storedx = map.getCenter().lat();
			storedy = map.getCenter().lng();
			readMap(option,label,choice,1,'distance','asc');
			GEvent.addListener(map, 'dragend', function() {
       		readMap(chooseoption,label,choice,0,'distance','asc');
      });
			GEvent.addListener(map, 'zoomend', function() {
       		readMap(chooseoption,label,choice,0,'distance','asc');
      });
			choseoption = option;

  map.addOverlay(polyline);
  map.addOverlay(polylineext);
   		}
		
		
	}

    //]]>

function ProcessClick(label,lat,lang,option_value)
	{
		gping (label);
		tab1 = html1[label];
		tab2 = html2[label];
		
	if (option_value=='parking')
			gmarkers[label].openInfoWindowTabsHtml([new GInfoWindowTab('Summary',tab1),new GInfoWindowTab('Description',tab2)]);
	else
        	gmarkers[label].openInfoWindowHtml(tab1);
	}
	
function validateForm()
{	
	var alert_email = $('email');
	
if (!validEmail(alert_email.value))
    {  alert("Please type a valid email address.");
	    alert_email.focus();
		alert_email.select();
		return false;
	}

	return true;
}

function postAlert (choice)
{
	if (validateForm())
		{
	
	chosen_div = $(choice);
	
AjaxRequest.submit(document.forms[1],
  {
	'onLoading':function(req){ chosen_div.innerHTML = waitLoading(); }
    ,'onSuccess':function(req){ chosen_div.innerHTML = req.responseText; }
    ,'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
  }
);

	}
}

function showHidden(type,items){
	$('hiddenSelect').style.display="block";
	
	AjaxRequest.get(
  {
    'url':'/index.php'
	,'parameters':{'com':'maps','option':'response','task':'showHidden','type':type,'item':items,'xml':1}
	,'method':'GET'
	,'onLoading':function(req){ $('hiddenSelect').innerHTML = waitLoading(); }
    ,'onSuccess':function(req){ $('hiddenSelect').innerHTML = req.responseText; }
    ,'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
  }
);
	
}