﻿
function PopulateMap(divMapId, home, locations) {
    if (GBrowserIsCompatible()) {
        var x;
        var map = new GMap2(document.getElementById(divMapId));

        //center the map
        var lat = home.latitude;
        var lon = home.longitude;
        map.setCenter(new GLatLng(lat, lon), 13);
        
        //place home marker
        var blueIcon = new GIcon(G_DEFAULT_ICON);
        blueIcon.image = 'http://maps.google.com/mapfiles/kml/pal2/icon10.png';
        blueIcon.shadow = 'http://maps.google.com/mapfiles/kml/pal2/icon10s.png';
        blueIcon.iconSize = new GSize(32, 32); blueIcon.shadowSize = new GSize(32, 32);
        markerOptions = { icon: blueIcon, title: 'You are here!' };
        x = new GMarker(new GLatLng(home.latitude, home.longitude), markerOptions);
        map.addOverlay(x);
        
        //place locations
        blueIcon = new GIcon(G_DEFAULT_ICON);
        blueIcon.image = 'http://maps.google.com/mapfiles/kml/pal3/icon47.png';
        blueIcon.shadow = 'http://maps.google.com/mapfiles/kml/pal3/icon47.png';
        blueIcon.iconSize = new GSize(20, 20);
        blueIcon.shadowSize = new GSize(20, 20);

        if (locations != null) {
            $.each(locations, function(j, small) {
                markerOptions = { icon: blueIcon, title: small.name };
                x = new GMarker(new GLatLng(small.latitude, small.longitude), markerOptions);
                map.addOverlay(x);
            });
        }

        map.setUIToDefault();
        map.disableScrollWheelZoom();
    }
}

















function CreateEvent() 
{
    $('.facebookShare').hide();
    $('.processing').empty();
    $('.processing').html('<span>. . . P r O c E s S i N g . . .</span>');
    FB.Connect.requireSession();
    FB.Connect.showPermissionDialog("create_event", CreateEventStep2, false, null);
}
function CreateEventStep2(result) 
{
    if (result == null) 
    {
        $('.processing').empty();
        $('.processing').html('<span>You must accept these permissions to create an event in facebook!</span>');
        $('.facebookShare').show();
        return;
    }

    $.get('/Services/CreateFacebookEvent?scheduleEventId=' + $('#scheduledEventId').val(), null, CreateEventStep3, 'text');
}
function CreateEventStep3(result) 
{
    if (result == 1) 
    {
        $('.processing').empty();
        $('.processing').html('<span>Your event was successfully created in your facebook account. Please go into facebook and under profile->events invite your friends to this event</span>');
        window.open("http://www.facebook.com");
    }
    else 
    {
        $('.facebookShare').show();
        $('.processing').empty();
        $('.processing').html('<span>Sorry but we could not create an event in your facebook account; facebook rejected the request. Please try again.</span>');
    }
}
