﻿// JScript File
var map = null;
var isFox = false;
var pinID = 1;
var xmlDoc = null;
var ideal = null;
var findl = null;
var gblPinImg = null;
var gblImgPath = null;

gblPinImg = "pin_blue.png"
gblImgPath = "/vCommon/Apps/Idea-Micro/VirtualEarth/images/";
        
function MouseHandler(e)
{
     var msg;
     if (e.eventName == "onclick")
     {
        // Right Click Functionality Removed 12/4/07 - gtw
     }
}// end MouseHandler()
        
function MouseOverHandler(e)
{
    var pixel = new VEPixel(e.mapX, e.mapY);
    var LL = map.PixelToLatLong(pixel);
    loadDiv('divLatLong', "Longitude = " + Dec2DMS(LL.Longitude) + ", Latitude = " + Dec2DMS(LL.Latitude));
}// end MouseOverHandler()

function loadDiv(id, data)
{
    var el = document.getElementById(id);
    if (el != undefined) el.innerHTML = data;
} // end loadDiv()

function Credits()
{
    alert("The Virtual Earth map was created for Idea Texas by GIS Technology Architect Costas Kotzabassis, Ph.D.");
} // end Credits()
        
function FindLoc()      
{         
    try         
    {
        findl.DeleteAllShapes();
        var what = document.getElementById("txtWhat");
        var where = document.getElementById("txtWhere");
        map.Find(what.value, where.value, null, findl);         
    }         
    catch(e)         
    {            
        alert(e.message);         
    }      
} // end FindLoc()     
              
function CreateLayers()
{
    ideal = new VEShapeLayer();
    map.AddShapeLayer(ideal);

    findl = new VEShapeLayer();
    map.AddShapeLayer(findl);
} // CreateLayers()
        
function AddPin(index, lat, lon, pinimage, image, home, title, desc)
{
     var shape;
     var sid = (index ? index+1 : "");
     var simage = (!image ? "" : "<img src=\"" + gblImgPath +  "/" + image + "\" onclick=\"Credits();\" /><br /><br />");
     var shome = (!home ? "" : "<br /><br /><a href=\"" + home + "\" target=\"_blank\"><em>Home Page</em></a>");
     
     shape = new VEShape(VEShapeType.Pushpin, new VELatLong(lat, lon));
     shape.SetTitle(title);
     shape.SetDescription(simage + desc + shome);
     //shape.SetCustomIcon("<img class=\"vePin\" src=\"" + gblImgPath +  pinimage + "\" />");
     shape.SetCustomIcon("<div class=\"vePin\"></div>");
     ideal.AddShape(shape);
 } // end AddPin()
        
function ShowSites()
{
    for (var i=0; i<IdeaSites.length; i++)
    {
        var s = IdeaSites[i];
        AddPin(i, s.Latitude, s.Longitude, gblPinImg, null, null, s.Office, s.Address);
    }
} // end ShowSites()
        
function Dec2DMS(Angle)
{
    var Sign = (Angle >=0 ? 1 : -1);
    var posAngle = Math.abs(Angle);
    var Degrees = Math.floor(posAngle);
    var Minutes = Math.floor((posAngle - Degrees) * 60);
    var Seconds=Math.floor(((posAngle - Degrees) * 3600 - Minutes * 60) * 100 / 100);
    var DMS = (Degrees * Sign) + "° " + Minutes + "' " + Seconds + "\"";
    return DMS;
} // end Dec2DMS()
        
function showMessage(Msg)
{
    document.getElementById("Message").innerHTML = Msg;
} // end showMessage()

function GetMap()
{
    map = new VEMap('IdeaMap');
    map.LoadMap(new VELatLong(39, -98), 4 ,'r' ,false);
    map.AttachEvent("onclick",MouseHandler);
    map.AttachEvent("onmousemove",MouseOverHandler);
    CreateLayers();
    ShowSites();
} // end GetMap()

