﻿///
///
///
var map;
var tpmap;
var tripmap;
var blogmap;
var blogmapview;
///
// Initialise a map with a small map control on it
///
function init(elementname, latitude, longitude, zoomlevel) {      
if (GBrowserIsCompatible()) 
    {        
    initMap (elementname, latitude, longitude, zoomlevel);
    map.addControl(new GSmallMapControl());    
    }    
}  
/// 
//Refreshes the map if it is not displaying fully (used for popup maps)
///
function resize()
{
    map.checkResize();
    //TODO check for the home point and Centre on it!
}
///
// initialises a map with no zoom control
///
function initMap (elementname, latitude, longitude, zoomlevel) 
{      
if (GBrowserIsCompatible()) 
    {
    try
    {        
        map = new GMap2(document.getElementById(elementname));  
        map.setMapType(G_HYBRID_MAP);      
        centerMap(latitude, longitude, zoomlevel);
        var point = new GLatLng(latitude, longitude);
        var marker = new GMarker(point);
        map.addOverlay(marker);         
    }
    catch (err)
    {}
    }    
}
///   
// Adds a large map control to the map in memory
///
function AddLargeControl()
{
    map.addControl(new GLargeMapControl());    
}
///
//Adds a small map control in memory
function AddSmallControl()
{
    map.addControl(new GSmallMapControl());
}
///
// Adds an event listener to the map to pick up your clicks
///

//var messId = $get(sender.get_ExpandControlID().replace(/pnlTopGMaps/g,"txtLatLngTop")).value;

function addSelectLocation()
{  
    GEvent.addListener(map, "click", function(overlay,latlng)
    {
    map.clearOverlays();
    var marker = new GMarker(latlng);
    map.addOverlay(marker);
//    document.getElementById("txtLatLng").setAttribute("value",latlng.lat() +"," + latlng.lng());
    document.getElementById("txtLatLng").setAttribute("value",latlng);
    //$get(sender.get_ExpandControlID().replace(/pnlTopGMaps/g,'txtLatLngTop')).setAttribute("value",latlng);
    if (document.getElementById("ctl07$txtLatLngTop") != null)
    {
        document.getElementById("ctl07$txtLatLngTop").setAttribute("value",latlng);
    }
    if (document.getElementById("ctl07$txtLatLngBlog") != null)
    {
        document.getElementById("ctl07$txtLatLngBlog").setAttribute("value",latlng);    //TODO find a way so as the control isn't explicitally named and also set based on which map is showing
    }
    });
}
///
//Centres the map on the point specified
///
function centerMap(latitude, longitude, zoomlevel) 
{
    map.setCenter(new GLatLng(latitude, longitude), zoomlevel);
}
///
// Gets a string reprensenting the latlong point clicked on the map by the user
///
function selectBlogLocation()
{  
    GEvent.addListener(map, "click", function(overlay,latlng)
    {
    map.clearOverlays();
    var marker = new GMarker(latlng);
    map.addOverlay(marker);
//    document.getElementById("txtLatLng").setAttribute("value",latlng.lat() +"," + latlng.lng());
    if (document.getElementById("ctl08$txtLatLngBlog") != null)
        {
        document.getElementById("ctl08$txtLatLngBlog").setAttribute("value",latlng);
        }
    //$get(sender.get_ExpandControlID().replace(/pnlTopGMaps/g,'txtLatLngTop')).setAttribute("value",latlng);
    if (document.getElementById("ctl07$txtLatLngTop") != null)
    {
        document.getElementById("ctl07$txtLatLngTop").setAttribute("value",latlng);
    }
    if (document.getElementById("ctl07$txtLatLngBlog") != null)
    {
        document.getElementById("ctl07$txtLatLngBlog").setAttribute("value",latlng);    //TODO find a way so as the control isn't explicitally named and also set based on which map is showing
    }
    });
}

function getLatLong()
{
    return "test";
}
//
//
//
function test()
{
    var car ="saab";
}
//Map functions for Trips!!
function initTripMap (elementname, latitude, longitude, zoomlevel) 
{      
if (GBrowserIsCompatible()) 
    {        
    tripmap = new GMap2(document.getElementById(elementname));      
    tripmap.setMapType(G_HYBRID_MAP);
    tripmap.addControl(new GLargeMapControl());
    tripmap.addControl(new GOverviewMapControl());
    tripmap.addControl(new GMapTypeControl());
    centerTripMap(latitude, longitude, zoomlevel); 
    //GEvent.addListener(marker, 'click', function() {marker.openInfoWindowHtml('You are in Ashtown!!!')});
    }    
}
function addTripMarker(latitude, longitude)
{
    var marker = new GMarker(new GLatLng(latitude, longitude));
    //GEvent.addListener(marker, 'click', function(){marker.openInfoWindowHtml(description);});
    tripmap.addOverlay(marker);
}
function AddTripPolyLine(line)
{
    var polyline = new GPolyline(line, "#000000", 5, 1);
    tripmap.addOverlay(polyline);
}
function centerTripMap(latitude, longitude, zoomlevel) 
{
    tripmap.setCenter(new GLatLng(latitude, longitude), zoomlevel);
}
//Map functions for Blogs!!
function initBlogMap (elementname, latitude, longitude, zoomlevel) 
{      
if (GBrowserIsCompatible()) 
    {        
    blogmap = new GMap2(document.getElementById(elementname));      
    blogmap.setMapType(G_HYBRID_MAP);
    centerBlogMap(latitude, longitude, zoomlevel); 
    var point = new GLatLng(latitude, longitude);
    var marker = new GMarker(point);
    //GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(location);  });
    blogmap.addOverlay(marker); 
    blogmap.addControl(new GSmallMapControl());
    }    
}
function centerBlogMap(latitude, longitude, zoomlevel) 
{
    blogmap.setCenter(new GLatLng(latitude, longitude), zoomlevel);
}
function selectMyBlogLocation()
{  
    GEvent.addListener(blogmap, "click", function(overlay,latlng)
    {
    blogmap.clearOverlays();
    var marker = new GMarker(latlng);
    blogmap.addOverlay(marker);
//    document.getElementById("txtLatLng").setAttribute("value",latlng.lat() +"," + latlng.lng());
    if (document.getElementById("PageContentmyblogs.ascx0$txtLatLngBlog") != null)
        {
        document.getElementById("PageContentmyblogs.ascx0$txtLatLngBlog").setAttribute("value",latlng);
        }
    });
}
function initTpMap (elementname, latitude, longitude, zoomlevel) 
{      
if (GBrowserIsCompatible()) 
    {        
    tpmap = new GMap2(document.getElementById(elementname));      
    tpmap.setMapType(G_HYBRID_MAP);
    tpmap.addControl(new GSmallMapControl());
    centerTPMap(latitude, longitude, zoomlevel); 
    var point = new GLatLng(latitude, longitude);
    var marker = new GMarker(point);
    tpmap.addOverlay(marker); 
    }    
}
function centerTPMap(latitude, longitude, zoomlevel) 
{
    tpmap.setCenter(new GLatLng(latitude, longitude), zoomlevel);
}
function addSelectTPLocation()
{  
    GEvent.addListener(tpmap, "click", function(overlay,latlng)
    {
    tpmap.clearOverlays();
    var marker = new GMarker(latlng);
    tpmap.addOverlay(marker);
    if (document.getElementById("txtLatLngBlog") != null)
        {
        document.getElementById("txtLatLngBlog").setAttribute("value",latlng);
        }
    });
}