﻿/****************************************************
*                                                   *
*   Description:     JScript File for ANZ app       *
*       to control the Dragable Map. Currently      *
*       using VE as the map.                        *
*   Date: 29/02/2008 Peter Acevski Created.
*         05/03/2008 George Petrakis Added AJAX handler for the Virtual Earth (VE) map so 
*         that a search undertaken in the code-behind form, could directly add POIs to the map.
*                                                   *
****************************************************/

var map = null;
var IsMapSearchActive = true;
var AustraliaZoomLevel = 4; //All of Australia
var StreetZoomLevel = 14; //Distance bar is set to 1km
var AustraliaCentre = new VELatLong(-28.5, 133.5); //Centre coordinates for Australia

var FoundStreet = "";
var FoundSuburb = "";

var DEFAULT_STREET_TEXT = "Enter a street";
var DEFAULT_SUBURB_POSTCODE_TEXT = "Enter a suburb or postcode";
var DEFAULT_STATE_TEXT = "Select state";
var DEFAULT_BSB_TEXT = "Enter BSB number";
var NO_ADDRESS_OR_BSB_TEXT = "Error: Please enter either a suburb, postcode or BSB number."
var NO_STATE_TEXT = "Error: Please select a state."
var INVALID_BSB = "Error: The BSB number that was entered is not valid. Please try again.";

function LoadDefaultText()
{
    if (document.getElementById('InputStreet').value.length < 1){
     document.getElementById('InputStreet').value = DEFAULT_STREET_TEXT;
    }
    if (document.getElementById('InputSuburbPostcode').value.length < 1){
     document.getElementById('InputSuburbPostcode').value = DEFAULT_SUBURB_POSTCODE_TEXT; 
    }
 
   // if (document.getElementById('InputState').selectedIndex < 0){
   //     document.getElementById('InputState').selectedIndex = 0;
  //   }

    if (document.getElementById('InputBSB').value.length < 1){
        document.getElementById('InputBSB').value = DEFAULT_BSB_TEXT;
    }
  }



//Initial call to create map
function GetMap()
{
    LoadDefaultText();
      
    var token = document.getElementById('hdToken').value;    
    map = new VEMap('myMap');
    map.AttachEvent('ontokenexpire', MyHandleTokenExpire);
    map.AttachEvent('ontokenerror', MyHandleTokenError);
    map.SetClientToken(token);

    try{
        map.SetDashboardSize(VEDashboardSize.Small);
    
        //map.LoadMap(new VELatLong(-33.94578085758696, 151.18131637573242), 6 ,'r' ,false); //Sydney center
        map.LoadMap(AustraliaCentre, AustraliaZoomLevel); 
        map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
    } catch(e){
        alert(e)
    }
    //map.AttachEvent("onstartpan",OnStartPan);
    map.AttachEvent("onendzoom",MapMove);
    map.AttachEvent("onendpan",MapMove);
    
    var CmbMultipleAddress=document.getElementById("CmbMultipleAddress");
    CmbMultipleAddress.style.visibility='hidden';
    
    var street=document.getElementById("InputStreet");

    //if url parameter has been passed attempt to search the map
    if (document.getElementById('InputSuburbPostcode').value != DEFAULT_SUBURB_POSTCODE_TEXT){
        SearchClick();
        __doPostBack('ButtonLocate','OnClick');
    }
      //if bsb parameter has been passed attempt bsb search
    else if (document.getElementById('InputBSB').value != DEFAULT_BSB_TEXT){
         SearchClick();
        __doPostBack('ButtonLocate','OnClick');
    }
}

function MyHandleTokenExpire()
{
   // insert code here to handle token expiration
   alert('Your session has expired. Please refresh your browser to continue');
}

function MyHandleTokenError()
{
   // insert code here to handle token errors
   alert('Invalid Virtual Earth Platform token. Please contact support.');
}

//On a map move event we undertake a search by calling the respective WS to grab the POIs.
function MapMove(e)
{

    //map.Clear();
   
    if(IsMapSearchActive){
        var center = map.GetCenter(), 
        centPix = map.LatLongToPixel(center); 
    
        var isBranchSelected = document.getElementById("CheckBoxBranch").checked,
        isBusinessCentreSelected = document.getElementById("CheckBoxBusinessCentre").checked, 
        isATMSelected = document.getElementById("CheckBoxATM").checked, 
        isNightSafeSelected = document.getElementById("CheckBoxNightSafe").checked;
   
      FindSearchedMapCriteriaLocation(center.Longitude, center.Latitude, isBranchSelected, isBusinessCentreSelected, isATMSelected, isNightSafeSelected);
         
      //update gridview with closest 50 POI's to the new map center     
      document.getElementById('SearchBSB').value = "";
      document.getElementById('SearchX').value = center.Longitude;
      document.getElementById('SearchY').value = center.Latitude;
      __doPostBack('ButtonLocate','OnClick');
        
  
    }else{
    IsMapSearchActive =true
    //Do nothing as we are currently undertaking a non-map (via BSB/address selection) search.
    }
}

function SearchAgainClick()
{

  IsMapSearchActive = false;
  document.getElementById("LabelError").innerText= "";
  
    //Clear search fields of values.
    document.getElementById("CheckBoxBranch").checked = false;
    document.getElementById("CheckBoxBusinessCentre").checked = false;
    document.getElementById("CheckBoxATM").checked = false; 
    document.getElementById("CheckBoxNightSafe").checked = false;
    
    document.getElementById("InputState").options.selectedIndex = 0; 
    //Me.InputState.SelectedIndex = 0

    document.getElementById('InputStreet').value = DEFAULT_STREET_TEXT;
    document.getElementById('InputSuburbPostcode').value = DEFAULT_SUBURB_POSTCODE_TEXT;
    document.getElementById('InputState').value = DEFAULT_STATE_TEXT;
    document.getElementById('InputBSB').value = DEFAULT_BSB_TEXT;

    document.getElementById('SearchX').value = "";
    document.getElementById('SearchY').value = "";

    document.getElementById('SearchStreet').value = "";
    document.getElementById('SearchSuburbPostcode').value = "";
    document.getElementById('SearchState').value = "";
    document.getElementById('SearchBSB').value = "";

    //Clear the (select) combo box of all values, and then make invisible.
    //We clear the select starting from the last position till the first one position, as our length will
    //decrement every time we remove an option item.
    var CmbMultipleAddress=document.getElementById("CmbMultipleAddress");
    for(var count = CmbMultipleAddress.options.length - 1; count >= 0; count--)
    {
        CmbMultipleAddress.options[count] = null;
    }
    CmbMultipleAddress.style.visibility="hidden";
    
    //Reset map to default
    FindNoResultsCallback(null);

    //Hide the panel holding the GridView, as the gridview, when empty does not render.
    document.getElementById("PanelGridViewResults").style.visibility="hidden";
    ClearResultsGridView();
}

//We attempt to clear the grid view of results. This is needed for when we clear the form,
//to prepare for a new search, and also when we are undertaking an interactive map search
//triggerred by the firing of a map event.
function ClearResultsGridView()
{
    //Clear grid view results
    var gridView = document.getElementById('GridViewResults')
    if (null != gridView )
    {
        for(var count = gridView.rows.length - 1; count >= 0; count--)
        {
            gridView.deleteRow(count);
        }
    }
}

//Performed when the 'Locate' button is clicked.
//Checks to make sure a value is in both text boxes
//if the location combo is visible use it for location instead of the text box
//and move the map to the lat/long stored in its value
//if its not visible, we search for the location.
function SearchClick()
{
    //if 4 digit bsb has been entered pad it with 01
    if (document.getElementById("InputBSB").value.length == 4) {
    document.getElementById("InputBSB").value = '01' + document.getElementById("InputBSB").value
    }
    //if a hyphen has been entered remove it
    document.getElementById("InputBSB").value = document.getElementById("InputBSB").value.replace(/-/g,"") 

    IsMapSearchActive = false;
    document.getElementById("LabelError").innerText= "";
 
    var streetValue=document.getElementById("InputStreet").value,
        suburbPostcodeValue=document.getElementById("InputSuburbPostcode").value,
        bsbValue=document.getElementById("InputBSB").value,
        state=document.getElementById("InputState"),
        CmbMultipleAddress=document.getElementById("CmbMultipleAddress");
        
    //var errorPanel=document.getElementById("PanelError");
    //var errorLabel=document.getElementById("LabelError");
    
    var isBranchSelected = document.getElementById("CheckBoxBranch").checked,
        isBusinessCentreSelected = document.getElementById("CheckBoxBusinessCentre").checked, 
        isATMSelected = document.getElementById("CheckBoxATM").checked, 
        isNightSafeSelected = document.getElementById("CheckBoxNightSafe").checked;

    document.getElementById('SearchX').value = "";
    document.getElementById('SearchY').value = "";

    document.getElementById('SearchStreet').value = "";
    document.getElementById('SearchSuburbPostcode').value = "";
    document.getElementById('SearchState').value = "";
    document.getElementById('SearchBSB').value = "";
    
    if ((bsbValue==""||bsbValue==DEFAULT_BSB_TEXT) && (suburbPostcodeValue==""||suburbPostcodeValue==DEFAULT_SUBURB_POSTCODE_TEXT)){
        //alert(NO_ADDRESS_OR_BSB_TEXT);
        document.getElementById("LabelError").innerText= NO_ADDRESS_OR_BSB_TEXT;
        return false;
    }
               
    if(bsbValue==""||bsbValue==DEFAULT_BSB_TEXT){
        //alert('..' + bsbValue + '..');
    }
    else
    {
    
        FindSearchedBSB(bsbValue, isBranchSelected, isBusinessCentreSelected, isATMSelected, isNightSafeSelected);
        return true;
    }
    
    if((suburbPostcodeValue==""||suburbPostcodeValue==DEFAULT_SUBURB_POSTCODE_TEXT)&&(streetValue==""||streetValue==DEFAULT_STREET_TEXT)){
    }
    else
    {
        if(suburbPostcodeValue==""||suburbPostcodeValue==DEFAULT_SUBURB_POSTCODE_TEXT){
            suburbPostcodeValue = "";
        }
        
        if(streetValue==""||streetValue==DEFAULT_STREET_TEXT){
            streetValue = "";
        }
    
        //Check for a selected state first.
        //var stateValue = state.options[state.selectedIndex].value;
       // var stateIndex = document.getElementById('InputState').selectedIndex;
       // if(stateIndex==0){;
        //    document.getElementById("LabelError").innerText= NO_STATE_TEXT;
       //     return false;
      //  }
        var stateValue= "a";
        
        if(CmbMultipleAddress.style.visibility=="visible"){
            CmbMultipleAddress.style.visibility="hidden";

            var text = CmbMultipleAddress.options[CmbMultipleAddress.selectedIndex].text;
            if(text.indexOf(", ") > 0){
                var splitMessage = text.split(", ");
            
                document.getElementById("InputStreet").value = splitMessage[0];
                document.getElementById("InputSuburbPostcode").value = splitMessage[1];
            }else{
                document.getElementById("InputStreet").value = "";
                document.getElementById("InputSuburbPostcode").value = text;
            }
            
            //document.getElementById("InputStreet").value = CmbMultipleAddress.options[CmbMultipleAddress.selectedIndex].text;            
            //document.getElementById("InputSuburbPostcode").value = CmbMultipleAddress.options[CmbMultipleAddress.selectedIndex].text;
            var stuffs=CmbMultipleAddress.options[CmbMultipleAddress.selectedIndex].value.split("***");
            
            FindSearchedLocation(stuffs[0], stuffs[1], isBranchSelected, isBusinessCentreSelected, isATMSelected, isNightSafeSelected);
        }else{
            //We do not have multiple defined addresses, so it is the first time that we are searching.
        //alert("Street: '" + streetValue + "', SuburbPostcode: '" + suburbPostcodeValue + "', State: '" + stateValue + "'");

        // Mark Sharman - this IS the first time geocode and is ok
        //alert('FindAddress ... ');
            FindAddress(streetValue, suburbPostcodeValue, stateValue);
        }
        //errorLabel.innerText="";
        //errorLabel.style.visibility="hidden";
        CmbMultipleAddress.style.visibility="hidden";
        
        return true;
    }
}

//Calls the webservice to find the BSB entered into the text box.
function FindSearchedBSB(bsbValue, isBranchSelected, isBusinessCentreSelected, isATMSelected, isNightSafeSelected)
{

    //alert("Hello World BSB");
    document.Form1.SearchBSB.value = bsbValue;

    //if( map.GetZoomLevel != StreetZoomLevel){
        //map.DetachEvent("onendpan",MapMove);
        //map.DetachEvent("onendzoom",MapMove);
        //map.SetZoomLevel(StreetZoomLevel);
        //map.AttachEvent("onendzoom",MapMove);
        //map.AttachEvent("onendpan",MapMove);
    //}
    
    ANZFindWebService.FindSearchedBSB(bsbValue, isBranchSelected, isBusinessCentreSelected, isATMSelected, isNightSafeSelected, FindSearchedBSBResultsCallback, FindNoResultsCallback);
}

//Calls the webservice to find the address entered into the text box.
//FindCallBack is run when the result is returned.
function FindAddress(RawStreet, RawSuburbPostcode, RawState)
{
    IsMapSearchActive = false;
    
    //document.Form1.SearchX.value = "";
    //document.Form1.SearchY.value = "";
    
    document.Form1.SearchStreet.value = RawStreet;
    document.Form1.SearchSuburbPostcode.value = RawSuburbPostcode;
    document.Form1.SearchState.value = RawState;
    
    //alert("RawStreet: '" + RawStreet + "', RawSuburbPostcode: '" + RawSuburbPostcode + "'");
    ANZFindWebService.FindAddress(RawStreet, RawSuburbPostcode, RawState, FindAddressResultsCallback, FindNoResultsCallback);
}

function FindSearchedMapLocation(X, Y){
    //alert("ZoomLevel" + map.GetZoomLevel() + ", X = " + X + ", Y = " + Y);
    //if(IsMapSearchActive){
        ANZFindWebService.FindSearchedMapLocation(map.GetZoomLevel(), X, Y, FindSearchedMapResultsCallback, FindNoResultsCallback);
    //}
}
function FindSearchedMapCriteriaLocation(X, Y, isBranchSelected, isBusinessCentreSelected, isATMSelected, isNightSafeSelected){
    //if(IsMapSearchActive){
        //alert("FindSearchedMapCriteriaLocation() X: " + X + ", Y: " + Y + ", branch: " +isBranchSelected + ", business centre: " + isBusinessCentreSelected + ", ATM: " + isATMSelected + ", Nightsafe: " + isNightSafeSelected);
        ANZFindWebService.FindSearchedMapCriteriaLocation(map.GetZoomLevel(), X, Y, isBranchSelected, isBusinessCentreSelected, isATMSelected, isNightSafeSelected, FindSearchedMapResultsCallback, FindNoResultsCallback);
    //}
}

//Calls the webservice to find the Location returned from the geocoded address.
function FindSearchedLocation(X, Y, isBranchSelected, isBusinessCentreSelected, isATMSelected, isNightSafeSelected)
{

    IsMapSearchActive = false;
   
    document.Form1.SearchX.value = X;
    document.Form1.SearchY.value = Y;
    
    //document.Form1.SearchStreet.value = "";
    //document.Form1.SearchSuburbPostcode.value = "";
    //document.Form1.SearchState.value = "";
    //document.Form1.SearchBSB.value = "";
    
    //alert("Find Location - Begin");
    //alert("X = " + X + ", Y = " + Y);
//    //25/03/2008 George P. The following is a fix necessary for when calling the FindResultsCallback
//    //so that the requires zoom level is already set.
//    if(IsMapSearch){
//        //Do nothing, just continue.        
//    }else{
//        //if( map.GetZoomLevel != StreetZoomLevel){
//            //map.DetachEvent("onendpan",MapMove);
//            //map.DetachEvent("onendzoom",MapMove);
//            map.SetZoomLevel(StreetZoomLevel);
//            //map.AttachEvent("onendzoom",MapMove);
//            //map.AttachEvent("onendpan",MapMove);
//        //}
//    }
    
    //alert("FindLocation(). ZoomLevel: " + ZoomLevel + ", X: " + X + ", Y: " + Y + ", branch: " +isBranchSelected + ", business centre: " + isBusinessCentreSelected + ", ATM: " + isATMSelected + ", Nightsafe: " + isNightSafeSelected);
    ANZFindWebService.FindSearchedLocation(X, Y, isBranchSelected, isBusinessCentreSelected, isATMSelected, isNightSafeSelected, FindSearchedResultsCallback, FindNoResultsCallback);
}

//For a given BSB find the nearest POIs.
//results as a complex object (in this case a List(Of MapPOI))
function FindSearchedBSBResultsCallback(results){
    var locs = new Array();

    map.DeleteAllShapes();                
    if(results != null){
        FindSearchedResultsCallback(results);
    }else{
        map.SetCenterAndZoom(AustraliaCentre, AustraliaZoomLevel); //Australia centre

        //alert(INVALID_BSB);//Display message for an invalid BSB entry.    
         document.getElementById("LabelError").innerText= INVALID_BSB;
    }
    IsMapSearchActive = true;
}

function FindSearchedMapResultsCallback(results){

    var locs = new Array();
 try{
   // alert("FindSearchedMapResultsCallback");
    if(IsMapSearchActive){
        //alert("Hello MAP Searched Result Callback");
      
        //Clear the grid view of any potential previous results.
        //ClearResultsGridView();
  
        map.DeleteAllShapes();                
  
 
        if(results != null){
            if(results.length > 0){
                //map.DetachEvent("onendpan",MapMove);
                //map.DetachEvent("onendzoom",MapMove);
             
                 for(var i=0; i<results.length-1; i++)
                {
                    AddPushPin(results[i]);
                    var loc = new VELatLong(results[i].Y, results[i].X);
                    locs.push(loc);
                }
            }
        }else{
            map.SetCenterAndZoom(AustraliaCentre, AustraliaZoomLevel); //Australia centre
        }
        
        
        
    }
    
      }
catch(err)
  {
}
}

//For a given X,Y co-ordinate pair finds the nearest POIs.
//results as a complex object (in this case a List(Of MapPOI))
function FindSearchedResultsCallback(results){

IsMapSearchActive = false;
 
    var minX = 999999;
    var minY = 999999;
    var maxX = 0;
    var maxY = -999999;
    
    var xDist = 0;
    var yDist = 0;
    var maxDist = 0;
    var currZoom = 0;
    
    var locs = new Array();
    IsMapSearchActive = false;
   
    
    map.DeleteAllShapes();                
    if(results != null){
        if(results.length > 0){
            //alert("Hello Searched Result Callback");
            //map.DetachEvent("onendpan",MapMove);
            //map.DetachEvent("onendzoom",MapMove);
         
          // for(var i=0; i<50; i++)
            for(var i=0; i<results.length-1; i++)
            {
                AddPushPin(results[i]);
                var loc = new VELatLong(results[i].Y, results[i].X);
                locs.push(loc);
                if (results[i].Y < minY)
                    minY =  results[i].Y
                if (results[i].X < minX)
                    minX =  results[i].X
                if (results[i].X > maxX)
                    maxX =  results[i].X
                if (results[i].Y > maxY)
                    maxY =  results[i].Y
            }
            
            xDist = maxX - minX;
            yDist = maxY - minY;
            
            //use the greater distance to calculate zoom
            if (xDist > yDist) maxDist = xDist;
            else maxDist = yDist;
   
          //  alert('maxDist = ' + maxDist);
        
            currZoom = 4;
            
            if (maxDist < .007)
               currZoom = 15;  //.5km
            else if (maxDist < .06)
               currZoom = 14;  //1km
            else if (maxDist < .4)
               currZoom = 13;  // 2km
            else if (maxDist < .9)
               currZoom = 12;  // 4km
            else if (maxDist < 1.1)
               currZoom = 11;  // 9km
            else if (maxDist < 1.3)
               currZoom = 10;  // 15km
            else if (maxDist < 2)
               currZoom = 9;  // 30km
            else if (maxDist < 6)
               currZoom = 8;  // 70km
            else if (maxDist < 8)
               currZoom = 7; //150km
            else if (maxDist < 10)
               currZoom = 6; //300km
            else if (maxDist < 22)
               currZoom = 5; //600km
            
            
            if(document.Form1.SearchX.value != "" && document.Form1.SearchY.value != "") {
                //var shape = new VEShape(VEShapeType.Pushpin, new VELatLong(document.Form1.SearchY.value, document.Form1.SearchX.value));
    
                //shape.IconUrl="";
                //map.AddShape(shape);
    
                map.SetCenterAndZoom(new VELatLong(document.Form1.SearchY.value, document.Form1.SearchX.value), currZoom);
                
                //map.AttachEvent("onendzoom",MapMove);
                //map.AttachEvent("onendpan",MapMove);
              // IsMapSearchActive = true;
                return true;
                //alert("Centre NOT defined from results. X: " + document.Form1.SearchX.value + ", Y: " + document.Form1.SearchY.value);
            }
            
            //14/03/2008 George P. Following code is to stop a weird bug where sometimes a
            // map POI has co-ords of 0.0,0.0, so map would previously centre in the South Atlantic near Africa.
             for(var i=0; i<results.length-1; i++)
            {
                if (results[i].Y != 0 && results[i].X != 0){
                    //map.SetCenterAndZoom(new VELatLong(results[i].Y, results[i].X), StreetZoomLevel);
                    map.SetCenterAndZoom(new VELatLong(results[i].Y, results[i].X), StreetZoomLevel);

                    //map.AttachEvent("onendzoom",MapMove);
                    //map.AttachEvent("onendpan",MapMove);                        
                  //  IsMapSearchActive = true;
                    return true;
                    //alert("Centre is defined from results.");
                }
            }
        }
    }else{
        map.SetCenterAndZoom(AustraliaCentre, AustraliaZoomLevel); //Australia centre
    }
    IsMapSearchActive = true;
}

//Runs when the webservices returns nothing/null
function FindNoResultsCallback(results){
    //var errorPanel=document.getElementById("PanelError"),
    //    errorLabel=document.getElementById("LabelError");

    map.DeleteAllShapes();
    map.SetCenterAndZoom(AustraliaCentre, AustraliaZoomLevel); //Australia centre
    IsMapSearchActive = true;
}

//returned results from a webservice call to find a location
//accepts results as QuickLocate.Result
//structure: .FullResult            int, response type code
//           .Locations[]           array
//                  .ResultCode     int
//                  .Position       Object
//                          .X      float
//                          .Y      float
//                  .StreetLine     string
//                  .Suburb         string
//                  .State          string
//                  .PostCode       string
//                  .Countary       string
//                  .SDBCode        string
function FindAddressResultsCallback(results){


    var locs = new Array();
    //var cent = map.GetCenter();
        
    var isBranchSelected = document.getElementById("CheckBoxBranch").checked,
        isBusinessCentreSelected = document.getElementById("CheckBoxBusinessCentre").checked, 
        isATMSelected = document.getElementById("CheckBoxATM").checked, 
        isNightSafeSelected = document.getElementById("CheckBoxNightSafe").checked;

    //var errorPanel=document.getElementById("PanelError");
    //var errorLabel=document.getElementById("LabelError");

    var CmbMultipleAddress=document.getElementById("CmbMultipleAddress");
    
    map.DeleteAllShapes();                
    switch(results.FullResult)
    {
    case 1://one addy
        var anum=/^((\d){3})+$|^((\d){4})+$/;
        //if(anum.test(loc)){zoomlvl=11}else{zoomlvl=12}
        //if(Round(cent.Latitude,2)==Round(results.Locations[0].Position.Y,2)&&Round(cent.Longitude,2)==Round(results.Locations[0].Position.X,2))
        //{//if already at the location the map doesnt move and no event is called,
            //must call the event manually
        //    VEEvent();
        //}else{
           //map.SetCenterAndZoom(new VELatLong(results.Locations[0].Position.Y, results.Locations[0].Position.X), zoomlvl);
            //alert("FindAddressResultsCallback(). Suburb: " + results.Locations[0].Suburb + ", X: " + results.Locations[0].Position.X + ", Y: " + results.Locations[0].Position.Y);
            IsMapSearchActive = false;

            
            FindSearchedLocation(results.Locations[0].Position.X, results.Locations[0].Position.Y, isBranchSelected, isBusinessCentreSelected, isATMSelected, isNightSafeSelected);
        //}
        break;
    case 100://multi address
        map.SetCenterAndZoom(AustraliaCentre, AustraliaZoomLevel); //Australia centre
    
         //alert("Multiple results were found. Please select the best match from the list.")
         document.getElementById("LabelError").innerText= "Multiple results were found. Please select the best match from the list below.";
     
        
        CmbMultipleAddress.style.visibility="visible";
        //error.style.visibility="visible";
        //error.innerHTML="Multiple results were found. Please select the best match from the list.";
        CmbMultipleAddress.options.length=0;
        CmbMultipleAddress.options.length=results.length-1;
        for(var a=0; a<results.Locations.length; a++)//populate the combobox with locations
        {
            //var obj=new Option(results.Locations[a].StreetLine + " " + results.Locations[a].Suburb + ", " + results.Locations[a].State + ", " + results.Locations[a].Postcode, results.Locations[a].Position.X + "***" + results.Locations[a].Position.Y);
            var obj;
            if(results.Locations[a].StreetLine != ""){             
                obj=new Option(results.Locations[a].StreetLine + ", " + results.Locations[a].Suburb, results.Locations[a].Position.X + "***" + results.Locations[a].Position.Y);
            }else{
                obj=new Option(results.Locations[a].Suburb + " " + results.Locations[a].Postcode, results.Locations[a].Position.X + "***" + results.Locations[a].Position.Y);
            }
            CmbMultipleAddress[a]=obj;
        }
        break;
    default://no addy//invalid addy
        map.SetCenterAndZoom(AustraliaCentre, AustraliaZoomLevel); //Australia centre
        
        //errorLabel.innerText="We were unable to find the location specified. Please try new information.";
        //errorLabel.style.visibility="visible";
        //errorPanel.style.visibility="visible";
        
        //alert("We were unable to find the location specified. Please try new information.");
         document.getElementById("LabelError").innerText= "We were unable to find the location specified. Please try new information.";
         break;
    }
    //alert("Find Address Results");
}

//Adds a pushpin to the VE map with the given properties
//mapPOI is a POI object.
function AddPushPin(mapPOI)
{


try{
    var shape = new VEShape(VEShapeType.Pushpin, new VELatLong(mapPOI.Y, mapPOI.X));
    shape.SetTitle(mapPOI.Name);
    shape.SetDescription("<B>" + mapPOI.StreetAddress1 + "<br/>" + mapPOI.StreetAddress2 + "<br/>" + mapPOI.Suburb + "<br/>" + mapPOI.State + "<br/>" + mapPOI.Postcode + "<br/>Facilities: " + mapPOI.FacilityTypeText + "<br/></b>" + "<a href=javascript:popUp('http://www.anz.com/aus/Locateus/default.asp?AN=" + mapPOI.AgentNumber + "')>More Details</a>"); 
    shape.IconUrl=mapPOI.IconPath;
    map.AddShape(shape);
  }
catch(err)
  {
}

}

function popUp(URL)
{
    day = new Date();
    id = day.getTime();
   eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=730,height=615,left = 150,top = 150');");
}

function popitup(url) {
	newwindow=window.open(url,'name','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=730,height=615,left = 150,top = 150');
	if (window.focus) {newwindow.focus()}
	return false;
}

