﻿function doLogin() {

    Sys.Services.AuthenticationService.login(
    "fthornton_01",
    "maasai_04",
    false,
    null,
    null,
    OnLoginComplete,
    OnAuthenticationFailed,
    "UserContext"
    );
}
function OnLoginComplete(validCredentials, userContext, methodName) {

    if (validCredentials == true) {
        window.location.reload(true);

    }
    else {

    }
}
function OnAuthenticationFailed(error_object, userContext, methodName) {
    alert("failed authentication with this message:" + error_object.getMessage());
}

var map = null;
var layer = null;
var cities = null;
function GetMap() {
    try {
        map = new VEMap('myMap');
        
        map.LoadMap();
        
        getFriendCities();
     
    } catch (e) {
        return;

    }
    
   // try { map.Find(null, txtWhere.value); } catch (e) { alert(e.message); }
   
}
// This function calls the Web service method 
// that returns an ArrayOfStrings.
function getFriendCities() {
    
    UjimanetSolutions_web.WebServices.FacebookFriends.getFriendLocations(
        SucceededCallbackWithContext, FailedCallback,
        "XmlDocument")
    
}
// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object, the user context, and the 
// calling method name as parameters.
function SucceededCallbackWithContext(result, userContext, methodName) {
    
    //Creating the layer   
    layer = new VEShapeLayer(); 
    map.AddShapeLayer(layer);  
 for( counter=0;counter<result.length;counter++){
     try {
     map.Find("", result[counter], null, layer, 0, 10, true, true, true, false,addPinToMap)

 } catch (e) { 
    
     }
 }

                       
}
function addPinToMap(layer, resultsArray, places, hasMore, veErrorMessage) {
    //Add a pushpin to the new layer
   try{
    shape = new VEShape(VEShapeType.Pushpin, places[0].LatLong);
         shape.SetTitle(places[0].Name);
         shape.SetDescription('Friend in this city');
         layer.AddShape(shape);
     } 
     catch (e) {
         
         }
}
// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameter.
function FailedCallback(error) {
    
   alert( "Service Error: " + error.get_message());
}

function CreateLayer() {
    layer = new VEShapeLayer();
    map.AddShapeLayer(layer);
}

if (typeof (Sys) !== undefined) Sys.Application.notifyScriptLoaded();