// JScript File
var RoutePlanningPopup; // Moved out here so we can use it in multiple functions
var Postcode;

function ContentPageLoad()
{
    //=================
    // Popup Sample Map
    //=================
    // Create a new map associated with the map view div.
    RoutePlanningPopup = new ISYSMap( document.getElementById("RoutePlanningPopupSampleDiv"), 0, 0, 600, 600, 0 ); // Div, X, Y, Width, Height, Map
    
    // Get the map view element
    var RoutePlanningPopupDiv = document.getElementById("RoutePlanningPopupSampleDiv")
    
    // Wire up the mouse listeners to do dragging, scrolling and zooming
    RoutePlanningPopupDiv.onmousedown = function(event){RoutePlanningPopup.ISYSStartMoveMouse(event); };
    RoutePlanningPopupDiv.onmousemove = function(event){RoutePlanningPopup.ISYSProcessMoveMouse(event); };
    RoutePlanningPopupDiv.onmouseup = function(event){RoutePlanningPopup.ISYSStopMoveMouse(event); };  // Optional use with compass scroll
    RoutePlanningPopupDiv.ondblclick = function(event){RoutePlanningPopup.ISYSZoomInMouse(event); };
    RoutePlanningPopupDiv.oncontextmenu = function(event){RoutePlanningPopup.ISYSContextMenu(event); return false;}; // return false prevents standard browser context menu from showing

    // necessary to enable dragging on IE
    RoutePlanningPopupDiv.ondragstart = function(event) { return false; }
    
    // Set the mouse scroll method
    RoutePlanningPopup.ISYSScrollMethodCompass();  // Only works on IE, defaults to ISYSScrollMethodDrag for other browsers

    // Set the context menus we want to show
    RoutePlanningPopup.ISYSContextMenuRouteEnable();
    RoutePlanningPopup.ISYSContextMenuZoomEnable();

    RoutePlanningPopup.ISYSDivContextMenuRouteEnable();
    RoutePlanningPopup.ISYSDivContextMenuZoomEnable();

    // Centre map somewhere near Heathrow
    var myCoordinateLatLong = new ISYSCoordinate();
    myCoordinateLatLong.Latitude = 3088325;
    myCoordinateLatLong.Longitude = -25971;
    RoutePlanningPopup.ISYSCentreMapOnLatLong( myCoordinateLatLong );
    
    // Quick zoom
    RoutePlanningPopup.ISYSZoomLevel(4);

	// Draw the map
    RoutePlanningPopup.ISYSDrawMap();
}

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;

    // Centre map
    var Result = RoutePlanningPopup.ISYSCentreMapOnLatLong( myCoordinateLatLong );

    // Check result as this map covers a limited area and the location may not be on the map
    if( Result )
    {
        // Quick zoom
        RoutePlanningPopup.ISYSZoomLevel(12);

        // 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", "MyDiv"+Postcode);
        RoutePlanningPopup.MapDiv.appendChild(MyDiv);
        MyImg = document.createElement("img");
        MyImg.src="pircle.png";
        MyImg.width="45";
        MyImg.height="45";
        MyImg.alt=""+Postcode;
        MyDiv.appendChild(MyImg);
        MyDiv.oncontextmenu = function(event){RoutePlanningPopup.ISYSDivContextMenu(event); return false;}; // return false prevents standard browser context menu from showing
        RoutePlanningPopup.ISYSAddDivLatLong( "MyDiv"+Postcode, 23, 23, myCoordinateLatLong );
    }
    else
    {
        alert( "Postcode location is not on this map." );
    }
}
