function setupLatLongCollection(postcode_el,lat_el,long_el)
{
	jQuery(postcode_el).change(function ()
	{
		if (GBrowserIsCompatible())
                {
                	var localSearch = new GlocalSearch();
                        localSearch.setSearchCompleteCallback(null,
                        	function() {
                                	if (localSearch.results[0]) {
                                        	jQuery(lat_el).val(localSearch.results[0].lat);
                                                jQuery(long_el).val(localSearch.results[0].lng);
                                        }
                                });
			localSearch.execute(jQuery(postcode_el).val() + ", UK");
                }
      });
}

function saveToBasket(type,eid,desc,url)
{
	jQuery.post("/ajax/basket.php", 
		{ action:"save",
			type: type, 
			eid:eid, 
			description:desc, 
			url:url
		},
		function(data)
		{
			basketResponse(data);
			jQuery('.' + type + eid).hide();
		}
	);
}
function removeFromBasket(id,type,refreshtype)
{
	jQuery.post("/ajax/basket.php",{action:"remove",type:type,id:id,refreshtype:refreshtype},
		function(data)
		{
			basketResponse(data);
			jQuery('li#fav_' + type + '_' + id).remove();
		}
	);
}
function basketResponse(data)
{
	var dat = eval("(" + data + ")");
	if(dat["basket"])
	{
		jQuery(".my_favourites .inner").html(dat["basket"]);
		jQuery(".my_favourites .collapsible-heading-collapsed").click();
	}
	if(dat["msg"])
	{
		alert(dat["msg"]);
	}
	if(dat["error"])
	{
		alert("ERROR: " + dat["error"]);
	}
	if(dat["showclass"])
	{
		jQuery('.' + dat["showclass"]).show();
	}		
	return false;
}

$(document).ready(function(){
	$('body').removeClass('js_disabled').addClass('js_enabled');
	$('a[href^="http://"]')
	  .attr({
	    target: "_blank", 
	    title: "Opens in a new window"
	  });
	
	$('a[href$=".pdf"]')
	  .attr({
	    target: "_blank", 
	    title: "Opens in a new window"
	  });
});

