﻿// JScript File
mapObjID = 0;

var pushpins = null;
    
// Show Info cloud when user clicks on a pushpin
// Default behaviour of VE - to hide the cloud if it was displayed    
function MouseClick(e)
{
  if (e.elementID != null)
  {
    var shape = map.GetShapeByID(e.elementID);
    map.ShowInfoBox(shape);
  }
  else
  {
  //document.getElementById('resultDiv').innerHTML = msg;
  }
}

// Adds pushpin to the map
// Note that pinType parameter is responsible for 
// the look of the pushpin.
function AddPin(latitude, longitude, 
    img, 
    title, html, pinStyle)
{  


    var pin = new VEShape(VEShapeType.Pushpin, new VELatLong(latitude, longitude));
    icon_url = "<div class='myPushpin'><img src=" + GetPinIcon(pinStyle) + "></div>";
    pin.SetCustomIcon(icon_url);
    pin.SetTitle(title);
    pin.SetDescription("<div class='news'>" + html + "</div>");
    map.AddShape(pin);
    pushpins.push(pin);
}

// Icon can be follosing types 
// 0 - default VE red pushpin
// 1 - blue square pushpin
// 2 - red square
// 10 - default orange Google pushpin with black dot in it
function GetPinIcon(pinStyle)
{
    if (pinStyle == null)
    {
        pinStyle = 0;
    }

    switch(pinStyle)
    {
        case 1:
            // another VE icon:
            return "http://dev.live.com/virtualearth/sdk/img/poi_viewer.gif";
        break;
        case 10:
            // google style pushpin
            return "http://www.google.com/mapfiles/markerA.png";
        break;

        case 0:
        default:
            // VE style pushpin
            return "/img/pushpin-red.gif"
            return "http://dev.virtualearth.net/legacyService/i/bin/1.3.20070327220207.22/pins/poi_usergenerated.gif";
    }
}

   
function DrawAllPoints(places)
{
    pushpins = new Array();
    for (i=0; i < places.length; i++)
    {
        var pinStyle = 0;
        if (places[i][4] != null)
            pinStyle = places[i][4];
            
        AddPin(places[i][1], places[i][2], null, places[i][0], places[i][3], pinStyle);
    }
}

function MapResize(divID, offX, offY, standardWidth, standardHeight) //resize
{
    if (offX == null)
        offX = parseInt(document.getElementById(divID).style.left);
    if (offY == null)
        offY = parseInt(document.getElementById(divID).style.top);        
    
    offsetY = offY + 10;
    offsetX = offX + 10;
    if (standardWidth == null)
        standardWidth = 500;
    if (standardHeight == null)
        standardHeight = 550;
    var newWidth = 0;
    var newHeight = 0;
    if( typeof( window.innerWidth ) == 'number' )  {
        //Non-IE
        newWidth = window.innerWidth - offsetX;
        newHeight = window.innerHeight - offsetY;
    } else if( document.documentElement && 
             ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )  {
        //IE 6+ in 'standards compliant mode'
        newWidth = document.documentElement.clientWidth  - offsetX;
        newHeight = document.documentElement.clientHeight - offsetY;
    } else if (typeof(document.body.clientHeight) != "undefined") {
        newHeight = document.body.clientHeight - offsetY;
        newWidth = document.body.clientWidth - offsetX;
    }
    if (newWidth < standardWidth)
        newWidth = standardWidth;
    if (newHeight < standardHeight)
        newHeight = standardHeight;

    document.getElementById(divID).style.width = newWidth + "px";
    document.getElementById(divID).style.height = newHeight + "px";
    if (typeof(map) != "undefined" && map != null) {
        if (map.checkResize != undefined)
            map.checkResize();
        else if (typeof(map.Resize) != "undefined") 
            map.Resize(newWidth,newHeight);
    }
}

