﻿// JScript File

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();

//********************************************************************
//***************** Web Service Functionality ************************
//********************************************************************

    function WS_GetTroupes(ModuleId)
    {   
        try
        {
            Georgia.Troupes.WebService.GetTroupes(ModuleId,WS_GetTroupes_CallBack);
        }
        catch(ex)
        {
            OnError(null);
        }
    }

    function WS_GetTroupes_CallBack(Troupes, eventArgs)
    {
        var IconTag = null;
        if (Troupes != null)
        {
            for (var i=0;i<Troupes.length;i++)
            {
                var title = Troupes[i].School + ' (' + Troupes[i].TroupeId +')';
                var description = ReplaceApostrophe(Troupes[i].StreetAddress) + '<br>';
                description += ReplaceApostrophe(Troupes[i].City) + ', ' + Troupes[i].State + ' ' + Troupes[i].ZipCode + '<br>';
                description += 'Director: ' + ReplaceApostrophe(Troupes[i].Sponsor) + '<br>';
                if (Troupes[i].Email != '')
                {
                    description += Troupes[i].Email + '<br>';
                }
                
                if (Troupes[i].Website != '')
                {
                    description += ReplaceApostrophe(Troupes[i].Website)+ '<br>';
                }
                
                description += '<br>';
                var url = "http://www.google.com/maps?q=" + ReplaceApostrophe(Troupes[i].StreetAddress) + "," + ReplaceApostrophe(Troupes[i].City) + "," + Troupes[i].State + " " + Troupes[i].ZipCode + ",USA&sa=X&oi=map&ct=title";               
                description += '<a href="' + url + '" target="newWin">Directions To</a>';
                description += ' || ';
                description += "<a href='' onclick=' SetCenterAndZoom(" + Troupes[i].Latitude + ", " + Troupes[i].Longitude + ", 15); return false;'>Zoom In</a>";       
                
                var newShape = MapManager.AddPushPin(Troupes[i].TroupeId, Troupes[i].Latitude, Troupes[i].Longitude, title, description, imgSchoolIconTag)
                AddRow(Troupes[i], newShape.GetID());
            }
        }  
    }
    
    function OnTimeOut(args)
    {
        alert('Service call timed out.');
    }

    function OnError(args)
    {
        alert('Service call errored out.');
    }
    
    
    