//<![CDATA[

var map_loading;
var map_notfound;
var map = null;
var gdir;

var is_ie6 = (document.implementation != null) && (document.implementation.hasFeature != null) && typeof window.XMLHttpRequest == "undefined";
var geocoder  = null;

var area = "Australia";
var opt;

function load() 
{
  if (GBrowserIsCompatible()) 
  {
    map = new GMap2(document.getElementById("google-map"));
	map.setCenter(new GLatLng(-25.165173,134.296875), 3);  
   
    map.addControl(new GMapTypeControl());
    map.addControl(new GSmallMapControl());

  }
}
function showPointLatLng(point)
{
	if(document.getElementById("latitude")){
    	document.getElementById("latitude").value = point.lat();
	}
    if(document.getElementById("longitude")){
		document.getElementById("longitude").value = point.lng();
	}
}

function geocodeAddress(address,longitude,latitude) 
{	
	if(!longitude || !latitude)
    {
		geocoder = new GClientGeocoder();
		geocodearea = new GClientGeocoder();
	
		map_notfound = 0;
		map_loading = 1;
		if (geocoder) 
		{
			geocoder.getLatLng(address,function(point) 
			{
				if(!point) 
				{
					geocodearea.getLatLng(area,function(point2) 
					{
						if(point2)
						{
							if(document.getElementById("message"))
                            { 
                                var elem = document.getElementById("message");
                                elem.innerHTML = 'The address you provided was not successfully located. Please correct any mistakes and update the map'; 
                        		elem.className = 'error';
                                elem.style.height = '50px';
                                elem.style.width = '450px';
                                elem.style.padding = '35px 0 0 10px';
                            }	
                            map_notfound = 1;
							map_loading = 0;
						}	
						map.setCenter(point2, 18);
					});
				} 
                else 
				{
					map.clearOverlays();
                    map.setCenter(point,18);
					
					var icon = new GIcon();

                    if(is_ie6)
                    {
                       icon.image = 'http://www.lovethatplace.com.au/images/map/icon-google-off-ie6.gif';
                       icon.iconAnchor = new GPoint(10.0, 35.0);
                    }
                    else
                    {
                    	icon.image = "http://www.lovethatplace.com.au/images/map/icon-google-off.png";
                        icon.iconAnchor = new GPoint(10.0, 35.0);
                    }
                    
                    
                    opts = 
                    {
                        "icon": icon,
                        "clickable": false,
                        "draggable": false,
                        "labelID": 'marker1',
                        "labelText": '',
                        "labelOffset": new GSize(-9, -37)
                    };
                    var marker = new GMarker(point, opts);
            
                    showPointLatLng(point);
					map.addOverlay(marker);
					if(document.getElementById("message"))
                    { 
                    	var elem = document.getElementById("message");
                       	elem.innerHTML = '<p style="font-weight:normal;">We successfully found <strong>' + address + '</strong></p><p style="font-weight:normal;">Note: If the current location marker is incorrect, please click here to <a href="report-bug.php?problem_address='+address+'&amp;p_report=/includes/mapscripts/map_functions.php">report the problem</a></p>'; 
                        elem.className = 'success';
                        elem.style.height = '70px';
                        elem.style.width = '450px';
                        elem.style.padding = '35px 0 0 10px';
                    }
                    map_loading = 0;
				}
			});
		  }	    
	}
    else 
    {
        var point = new GLatLng(latitude,longitude);
		showPointLatLng(point);
	
        var icon = new GIcon();
        icon.iconAnchor = new GPoint(22.0, 15.0);
        opts = 
        {
            "icon": icon,
            "clickable": false,
            "draggable": false,
            "labelID": 'marker1',
            "labelText": '',
            "labelOffset": new GSize(-9, -37)
        };
        var marker = new LabeledMarker(point, opts);
        
		map.addOverlay(marker);
        map.setCenter(point);
		
        if(document.getElementById("message")){ document.getElementById("message").innerHTML = address; }
		map_loading = 0;
	}
}
//]]>