function OnComplete(args, args2) {
    
    
    var htmlMapCode = args;
    var resourceIdentifier = args2;
    
    var networkMapDivIdentifier = "#networkMap-" + resourceIdentifier;
    $(networkMapDivIdentifier).html(htmlMapCode);
  
    var tooltipDivIndex = 0;
    $(networkMapDivIdentifier + " area").each(function() {

        var tooltipDivId = "mapStudioTooltip" + resourceIdentifier + "-" + tooltipDivIndex;
        var status = this.title.substring(0, this.title.lastIndexOf("|"));
        var tooltiptext = this.title.slice(this.title.indexOf("|") + 1);
        if (tooltiptext.length > 0) {
            this.title = "";
            $.swtooltip(this, $("<div id='" + tooltipDivId + "'>" + tooltiptext + "</div>"));
            tooltipDivIndex++;
        }
    });    

}
function OnError(args, args2) {
    if(args.get_timedOut())
    {
        $("#networkMap-" + args2).html("Service call timed out.");
    }
    else
    {
        $("#networkMap-" + args2).html("An unexpected error occured.");
    }
}

$(function() {
    MapService.set_timeout(180000);
    $(".mapIdentifier").each(function(i)
    {
      //mapIdentifier contains string {mapId}|{resourceId}
      //the resource id is sent to the OnComplete function, so it can update the networkMap-{resourceId} element
      var identifiers = $(this).val().split("|");
      $("#networkMap-" + identifiers[1]).html("<div style=\"text-align:center\"><img src=\"/Orion/images/AJAX-Loader.gif\" alt=\"Loading map\"></div>");
      MapService.GetMap(identifiers[0], OnComplete, OnError, identifiers[1]);
    }
    );
    

}); 
