// JScript File
var AddressMap; // Moved out here so we can use it in multiple functions

function ContentPageLoad()
{
    // Create a new map associated with the map view div.
    AddressMap = new ISYSMap( document.getElementById("AddressMapViewDiv"), 0, 0, 455, 300, 0 ); // Div, X, Y, Width, Height, Map
    
    // Get the map view element
    var AddressMapDiv = document.getElementById("AddressMapViewDiv")
    
    // Wire up the mouse listeners to do dragging, scrolling and zooming
    AddressMapDiv.onmousedown = function(event){AddressMap.ISYSStartMoveMouse(event); };
    AddressMapDiv.onmousemove = function(event){AddressMap.ISYSProcessMoveMouse(event); };
    AddressMapDiv.onmouseup = function(event){AddressMap.ISYSStopMoveMouse(event); };
    AddressMapDiv.ondblclick = function(event){AddressMap.ISYSZoomInMouse(event); };

    // necessary to enable dragging on IE
    AddressMapDiv.ondragstart = function() { return false; }
    
    // Set the mouse scroll method
    AddressMap.ISYSScrollMethodDrag();

    // Setup address search event handlers
    var myAddressSearchTextBox = document.getElementById("AddressSearchTextBox");
    var myAddressSearchListBox = document.getElementById("AddressSearchListBox");
    
    myAddressSearchTextBox.onkeyup = function(event){ AddressMap.ISYSFillAddressSearchList(myAddressSearchTextBox,myAddressSearchListBox,1000); };
    myAddressSearchListBox.onclick = function(event){ AddressMap.ISYSSelectAddressSearchList(); };
    
    // Centre map on a XY.
    var myCoordinateXY1 = new ISYSCoordinate();
    myCoordinateXY1.X = 1000;
    myCoordinateXY1.Y = 1008;

    // Centre map    
    AddressMap.ISYSCentreMapOnXY( myCoordinateXY1 );

    // Zoom
    AddressMap.ISYSZoomLevel(7);
}

//------------------------------------------------
// Method:  ISYSSelectAddressSearchListComplete()
// See:     ISYSSelectAddressSearchList()
//------------------------------------------------
ISYSMap.prototype.ISYSSelectAddressSearchListComplete = function(Address, myCoordinate)
{
    // Remove old circle, if there is one
    AddressMap.ISYSRemoveDiv( "MyCircleAddress1" );

    // Centre map
    var Result = AddressMap.ISYSCentreMapOnLatLong( myCoordinate );

    // Check result
    if( Result )
    {
        // Quick zoom
        AddressMap.ISYSZoomLevel(11);

        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", "MyCircleAddress1");
   
        if( browser.isIE55 || browser.isIE6x )
        {
            AddressMap.MapDiv.appendChild(MyDiv);
            new OpacityObject("MyCircleAddress1","pircle").setBackground();
        }
        else
        {
            AddressMap.MapDiv.appendChild(MyDiv);
            MyImg = document.createElement("img");
            MyImg.src="pircle.png";
            MyImg.width="45";
            MyImg.height="45";
            MyImg.alt=""+Address;
            MyDiv.appendChild(MyImg);
        }

        // Draw new circle
        AddressMap.ISYSAddDivLatLong( "MyCircleAddress1", 23, 23, myCoordinate );
        AddressMap.ISYSCentreMapOnLatLong( myCoordinate );
    }
    else
    {
        alert( "Address location is not on this map." );
    }
}


