﻿// JScript File
var PostcodeMap; // Moved out here so we can use it in multiple functions
var Postcode;

function ContentPageLoad()
{
    // Create a new map associated with the map view div.
    PostcodeMap = new ISYSMap( document.getElementById("PostcodeMapViewDiv"), 0, 0, 455, 300, 0 ); // Div, X, Y, Width, Height, Map
    
    // Get the map view element
    var PostcodeMapDiv = document.getElementById("PostcodeMapViewDiv")
    
    // Wire up the mouse listeners to do dragging, scrolling and zooming
    PostcodeMapDiv.onmousedown = function(event){PostcodeMap.ISYSStartMoveMouse(event); };
    PostcodeMapDiv.onmousemove = function(event){PostcodeMap.ISYSProcessMoveMouse(event); };
    PostcodeMapDiv.onmouseup = function(event){PostcodeMap.ISYSStopMoveMouse(event); };
    PostcodeMapDiv.ondblclick = function(event){PostcodeMap.ISYSZoomInMouse(event); };

    // necessary to enable dragging on IE
    PostcodeMapDiv.ondragstart = function(event) { return false; }
    
    // Set the mouse scroll method
    PostcodeMap.ISYSScrollMethodDrag();
    
    // Centre map on a XY.
    var myCoordinateXY1 = new ISYSCoordinate();
    myCoordinateXY1.X = 1000;
    myCoordinateXY1.Y = 1008;

    // Centre map    
    PostcodeMap.ISYSCentreMapOnXY( myCoordinateXY1 );

    // Zoom
    PostcodeMap.ISYSZoomLevel(7);
}

function myLocatePostcode()
{
    // html text box
    Postcode = document.getElementById("TextPostcode").value.toUpperCase();
    
    ISYSGetPostcodeLatLong( Postcode ); // Callback function, calls ISYSGetPostcodeLatLongComplete() on completion
}

function ISYSGetPostcodeLatLongComplete( Latitude, Longitude )
{
    var myCoordinateLatLong = new ISYSCoordinate();
    myCoordinateLatLong.Latitude = Latitude;
    myCoordinateLatLong.Longitude = Longitude;

    // Remove old circle, if there is one
    PostcodeMap.ISYSRemoveDiv( "MyCirclePostcode1" );

    // Centre map
    var Result = PostcodeMap.ISYSCentreMapOnLatLong( myCoordinateLatLong );

    // Check result
    if( Result )
    {
        // Quick zoom
        PostcodeMap.ISYSZoomLevel(11);

        // Draw new circle
        var MyDiv = document.createElement("div");
        MyDiv.style.position = "absolute";
        MyDiv.style.width = "45px";
        MyDiv.style.height = "45px";
        MyDiv.style.left = "-45px";
        MyDiv.style.top = "-45px";
        MyDiv.style.zIndex = "3";
        MyDiv.setAttribute("id", "MyCirclePostcode1");
   
        if( browser.isIE55 || browser.isIE6x )
        {
            PostcodeMap.MapDiv.appendChild(MyDiv);
            new OpacityObject("MyCirclePostcode1","pircle").setBackground();
        }
        else
        {
            PostcodeMap.MapDiv.appendChild(MyDiv);
            MyImg = document.createElement("img");
            MyImg.src="pircle.png";
            MyImg.width="45";
            MyImg.height="45";
            MyImg.alt=""+Postcode;
            MyDiv.appendChild(MyImg);
        }
        PostcodeMap.ISYSAddDivLatLong( "MyCirclePostcode1", 23, 23, myCoordinateLatLong );
        PostcodeMap.ISYSCentreMapOnLatLong( myCoordinateLatLong );
    }
    else
    {
        alert( "Postcode location is not on this map." );
    }
}

