﻿// JScript File

var MapManager;
var pinID = 0;

function Map_Load(divId)
{
    Map_Initialize(divId);
}

function Map_Initialize(divId)
{
    MapManager = new MapManagerVO();
    MapManager.Initialize(divId);
    MapManager.AttachMouseOverEvent(onMouseOverCallback);
    MapManager.FindCity('GA, United States');
    setTimeout("GetTroupes()",500);
}

function GetTroupes()
{
    WS_GetTroupes(441);
}
 
function SetCenterAndZoom(lat, lng, zoom)
{
    var LatLng = new VELatLong(lat, lng);
    MapManager.SetCenterAndZoom(LatLng, zoom);
}

function AddRow(Troupe, index)
{
    var table = $get("TroupeTable"); 
    
    var row = table.insertRow(table.rows.length);
    var idCell = row.insertCell(0);
    idCell.appendChild(document.createTextNode(index));
    idCell.style.display = "none";
    
    var numberCell = row.insertCell(0);
    numberCell.appendChild(document.createTextNode(Troupe.TroupeId));
    
    var schoolCell = row.insertCell(1);
    schoolCell.appendChild(document.createTextNode(Troupe.School));
    
    //var addressCell = row.insertCell(2);
    //addressCell.appendChild(document.createTextNode(Troupe.StreetAddress));
    $addHandler(row,"click", RowClick);
}

var shape = null;

function RowClick(e)
{
    MapManager.HideInfoBox();
    shape = MapManager.GetShapeByID(e.target.parentElement.cells[0].innerText);
    MapManager.SetCenter(shape.GetPoints()[0]);
    setTimeout("ShowInfoBox()", 500);
}

function ShowInfoBox()
{
    MapManager.ShowInfoBox(shape);

}

function onMouseOverCallback(e)
{
    // check to see if we have hovered over a pushpin
    if(e.elementID != null)
    {
        var pts = MapManager.GetShapeByID(e.elementID).GetPoints();
   }
}

function ReplaceApostrophe(str)
{
    str = str.replace("'","\'");
    return str;
}
