﻿// JScript File

var CanMove = false;
var SecondYearCanMove = false;
var BeginXOffset = 0;
var NextXOffset = 0;
var BeginYOffset = 0;
var NextYOffset = 0;
var HasMoved = false;
var ProblemOffset = 0;
var SkipTransition = false;
var ChangeToZoom = false;
var UseZoomIn = false;
var OldGrid = '';
var TilesLoaded = 0;
var TilesLoading = 0;
var CountyLocation = '';
var MaximumProgress = 0;
var Comparing = false;
var TempYearsLeft = '';
var t2 = 0;
var NoAnimation = true;
var GridToChangeYear = '';
var MoveCompare = false;

function CloseComparisonHelp() {
    document.getElementById(SecondYearPanelHelp).style.display = 'none';
}

function ToggleComparing() {
    if (Comparing) {
        Comparing = false;
        document.getElementById(CurrentInfo).style.display = '';
        document.getElementById(Tools).style.display = '';
        document.getElementById(ComparePurchasePanel).style.display = '';
        document.getElementById(GridTwoYearComparison).style.display = 'none';
        document.getElementById(PanelTwoYearComparison).style.display = 'none';
        document.getElementById(YearsComparePanel).style.display = 'none';
        document.getElementById(ComparisonControls).style.display = 'none';
        document.getElementById(SecondYearPanelHelp).style.display = 'none';
        document.getElementById(SourcePanel).style.display = '';
        document.getElementById(YearsPanel).style.left = TempYearsLeft;
        if (document.getElementById(YearsComparePanel).getElementsByTagName('table').length > 0) document.getElementById(YearsComparePanel).removeChild(document.getElementById(YearsComparePanel).getElementsByTagName('table')[0]);
        // clear contents...it wont be needed anymore
        while (document.getElementById(GridTwoYearComparison).rows.length > 0) {
            document.getElementById(GridTwoYearComparison).getElementsByTagName('tbody')[0].removeChild(document.getElementById(GridTwoYearComparison).rows[0]);
        }
        NoAnimation = true;
        t2 = 0;
    }
    else
    {
        Comparing = true;
        // disable fading and what not because it is not needed here
        NoAnimation = true;
        TilesLoaded = 0;
        document.getElementById(CurrentInfo).style.display = 'none';
        document.getElementById(Tools).style.display = 'none';
        document.getElementById(ComparePurchasePanel).style.display = 'none';
        document.getElementById(SourcePanel).style.display = 'none';
        document.getElementById(GridTwoYearComparison).style.display = '';
        document.getElementById(PanelTwoYearComparison).style.display = '';
        document.getElementById(ComparisonControls).style.display = '';
        document.getElementById(PanelTwoYearComparison).style.opacity = '1.0';
        document.getElementById(PanelTwoYearComparison).style.filter = 'alpha(opacity=100)';
        document.getElementById(PanelTwoYearComparison).style.height = document.getElementById(Main).style.height;
        document.getElementById(PanelTwoYearComparison).style.width = document.getElementById(Main).style.width.replace('px','') + 'px';
        document.getElementById(PanelTwoYearComparison).style.left = CompareTwoYearsBuffer + 'px';
        document.getElementById(SecondYearSizeArrow).style.left = (CompareTwoYearsBuffer - (document.getElementById(SecondYearArrowAndYears).style.width.replace('px','') / 2) + 1) + 'px';
        // also subtract the one to make up for the one pixel border line between the two images
        document.getElementById(GridTwoYearComparison).style.left = (document.getElementById(Grid).style.left.replace('px','') - (CompareTwoYearsBuffer-0+1)) + 'px';
        document.getElementById(GridTwoYearComparison).style.top = document.getElementById(Grid).style.top.replace('px','') + 'px';
        TempYearsLeft = document.getElementById(YearsPanel).style.left;
        document.getElementById(YearsPanel).style.left = '1px';
        // display the current year in a second panel
        DefineImageTwoPanel(document.getElementById(t).value);
    }
}

function ToggleFade() {
    if (Comparing) {
        Comparing = false;
        document.getElementById(CurrentInfo).style.display = '';
        document.getElementById(Tools).style.display = '';
        document.getElementById(ComparePurchasePanel).style.display = '';
        document.getElementById(GridTwoYearComparison).style.display = 'none';
        document.getElementById(PanelTwoYearComparison).style.display = 'none';
        document.getElementById(YearsComparePanel).style.display = 'none';
        document.getElementById(FadeControls).style.display = 'none';
        document.getElementById(SecondYearPanelHelp).style.display = 'none';
        document.getElementById(SourcePanel).style.display = '';
        document.getElementById(YearsPanel).style.left = TempYearsLeft;
        if (document.getElementById(YearsComparePanel).getElementsByTagName('table').length > 0) document.getElementById(YearsComparePanel).removeChild(document.getElementById(YearsComparePanel).getElementsByTagName('table')[0]);
        // clear contents...it wont be needed anymore
        while (document.getElementById(GridTwoYearComparison).rows.length > 0) {
            document.getElementById(GridTwoYearComparison).getElementsByTagName('tbody')[0].removeChild(document.getElementById(GridTwoYearComparison).rows[0]);
        }
        NoAnimation = true;
        t2 = 0;
    }
    else
    {
        Comparing = true;
        // disable fading and what not because it is not needed here
        NoAnimation = true;
        TilesLoaded = 0;
        document.getElementById(CurrentInfo).style.display = 'none';
        document.getElementById(Tools).style.display = 'none';
        document.getElementById(ComparePurchasePanel).style.display = 'none';
        document.getElementById(SourcePanel).style.display = 'none';
        document.getElementById(GridTwoYearComparison).style.display = '';
        document.getElementById(PanelTwoYearComparison).style.display = '';
        document.getElementById(FadeControls).style.display = '';
        document.getElementById(PanelTwoYearComparison).style.height = document.getElementById(Main).style.height;
        document.getElementById(PanelTwoYearComparison).style.width = document.getElementById(Main).style.width.replace('px','') + 'px';
        document.getElementById(PanelTwoYearComparison).style.left = '0px'; //document.getElementById(Main).style.left; //CompareTwoYearsBuffer + 'px';
        document.getElementById(PanelTwoYearComparison).style.opacity = '0.5';
        document.getElementById(PanelTwoYearComparison).style.filter = 'alpha(opacity=50)';
        document.getElementById(FadeArrow).style.left = (CompareTwoYearsBuffer - (document.getElementById(SecondYearArrowAndYears).style.width.replace('px','') / 2) + 1) + 'px';
        // lay the two grids exactly on top of each other
        document.getElementById(GridTwoYearComparison).style.left = document.getElementById(Grid).style.left.replace('px','') + 'px';
        document.getElementById(GridTwoYearComparison).style.top = document.getElementById(Grid).style.top.replace('px','') + 'px';
        TempYearsLeft = document.getElementById(YearsPanel).style.left;
        document.getElementById(YearsPanel).style.left = '1px';
        // display the current year in a second panel
        DefineImageTwoPanel(document.getElementById(t).value);
    }
}

function SwitchSearchBoxes(Show) {
    document.getElementById(AddressSearch).style.display = 'none';
    document.getElementById(LatLongSearch).style.display = 'none';
    document.getElementById(Show).style.display = '';
    document.getElementById(SearchFormAddress).value = '';
    document.getElementById(SearchFormCity).value = '';
    document.getElementById(SearchFormState).value = '';
    document.getElementById(SearchFormZip).value = '';
    document.getElementById(LatitudeSearch).value = '';
    document.getElementById(LongitudeSearch).value = '';
}

function GetInnerText(object) {
    if (object.innerText != undefined) return object.innerText; 
        else return object.textContent;
}

function SetInnerText(object, text) {
    if (object.innerText != undefined) object.innerText = text; 
        else object.textContent = text;
}

function FlipDissolve() {
    var StatusText = GetInnerText(document.getElementById(CurrentDissolveStatus));
    if (StatusText == '-on-') {
        SetInnerText(document.getElementById(CurrentDissolveStatus), '-off-');
    }    
    else
    {
        SetInnerText(document.getElementById(CurrentDissolveStatus), '-on-');
    }
}

function StreetsDropDown() {

    if (CheckWait() == false) 
    { 
        alert('Please wait until your current request has finished loading');
        return false;
    }

    document.getElementById(StreetsPanelChoose).style.display = '';
    return true;
}

function CheckLayerStatus()
{
  // a layer just got turned off so we need to figure out
  // whether we need to turn on the red gem
  if( GetInnerText(document.getElementById(CurrentStreetsStatus)).indexOf('off') >= 0 
   && document.getElementById(countyBoundaryStatus).src.indexOf('Grey') >= 0 
   && document.getElementById(cityOverlayStatus).src.indexOf('Grey') >= 0 )
  {
    document.getElementById(overlaysOffStatus).src = '/images/gemRed.png';
  }
}

function OverlaysOff()
{
    if (CheckWait() == false) return false;

    // if at least one layer is on
    if( GetInnerText(document.getElementById(CurrentStreetsStatus)).indexOf('off') < 0 
     || document.getElementById(countyBoundaryStatus).src.indexOf('Green') >= 0 
     || document.getElementById(cityOverlayStatus).src.indexOf('Green') >= 0 )
    {
        document.getElementById(majorRoadsStatus).src = '/images/gemGrey.png';
        document.getElementById(allRoadsStatus).src = '/images/gemGrey.png';
        document.getElementById(countyBoundaryStatus).src = '/images/gemGrey.png';
        document.getElementById(cityOverlayStatus).src = '/images/gemGrey.png';

        document.getElementById(overlaysOffStatus).src = '/images/gemRed.png';
        SetInnerText(document.getElementById(CurrentStreetsStatus), 'off');
    
        MaximumProgress = 0;
        UpdateImage(document.getElementById(t).value);
    }
}

function ToggleCountyOverlay()
{
    if (CheckWait() == false) return false;
    
    // if county boundaries are on
    if( document.getElementById(countyBoundaryStatus).src.indexOf('Green') >= 0 )
    {
        document.getElementById(countyBoundaryStatus).src = '/images/gemGrey.png';

        CheckLayerStatus();
        
        MaximumProgress = 0;
        UpdateImage(document.getElementById(t).value);
    }
    // if county boundaries are off
    else
    {
        document.getElementById(countyBoundaryStatus).src = '/images/gemGreen.png';
        document.getElementById(overlaysOffStatus).src = '/images/gemGrey.png';

        CheckLayerStatus();
        
        MaximumProgress = 0;
        UpdateImage(document.getElementById(t).value);
    }
}

function ToggleCityOverlay()
{
    if (CheckWait() == false) return false;
    
    // if county boundaries are on
    if( document.getElementById(cityOverlayStatus).src.indexOf('Green') >= 0 )
    {
        document.getElementById(cityOverlayStatus).src = '/images/gemGrey.png';

        CheckLayerStatus();
        
        MaximumProgress = 0;
        UpdateImage(document.getElementById(t).value);
    }
    // if county boundaries are off
    else
    {
        document.getElementById(cityOverlayStatus).src = '/images/gemGreen.png';
        document.getElementById(overlaysOffStatus).src = '/images/gemGrey.png';

        CheckLayerStatus();
        
        MaximumProgress = 0;
        UpdateImage(document.getElementById(t).value);
    }
}

function FlipStreets(Assign) {

    if (CheckWait() == false) return false;

    var Current = GetInnerText(document.getElementById(CurrentStreetsStatus));
    Assign = '-' + Assign + '-';

    // if the clicked layer is off
    if (Assign != Current) 
    {
        document.getElementById(majorRoadsStatus).src = '/images/gemGrey.png';
        document.getElementById(allRoadsStatus).src = '/images/gemGrey.png';
        document.getElementById(overlaysOffStatus).src = '/images/gemGrey.png';

        document.getElementById(CheckStreetsOff).style.display = 'none';
        document.getElementById(CheckStreetsMain).style.display = 'none';
        document.getElementById(CheckStreetsAll).style.display = 'none';
        if (Assign.indexOf('all') >= 0) {
            document.getElementById(allRoadsStatus).src = '/images/gemGreen.png';
            document.getElementById(CheckStreetsAll).style.display = '';
        }
        else if (Assign.indexOf('main') >= 0) {
            document.getElementById(majorRoadsStatus).src = '/images/gemGreen.png';
            document.getElementById(CheckStreetsMain).style.display = '';
        }
        else
        {
            document.getElementById(CheckStreetsOff).style.display = '';
        }
        SetInnerText(document.getElementById(CurrentStreetsStatus), Assign);
        MaximumProgress = 0;
        UpdateImage(document.getElementById(t).value);
    }
    // the clicked layer os already on. turn it off
    else
    {
        document.getElementById(majorRoadsStatus).src = '/images/gemGrey.png';
        document.getElementById(allRoadsStatus).src = '/images/gemGrey.png';
        SetInnerText(document.getElementById(CurrentStreetsStatus), 'off');
        
        CheckLayerStatus();
        
        MaximumProgress = 0;
        UpdateImage(document.getElementById(t).value);
    }
    
    document.getElementById(StreetsPanelChoose).style.display = 'none';
    
}

function CancelEvent() {
    window.event.cancel = true;
    return false;
}

function ChangeTool(NewTool, ImageToHilite, Description) {
    document.getElementById(CurrentTool).value = NewTool;
    document.getElementById(PanTool).src = document.getElementById(PanTool).src.replace('_selected','');
    document.getElementById(ZoomInTool).src = document.getElementById(ZoomInTool).src.replace('_selected','');
    document.getElementById(ZoomOutTool).src = document.getElementById(ZoomOutTool).src.replace('_selected','');
    document.getElementById(MeasureTool).style.color = '#FFFFFF';
    document.getElementById(AreaTool).style.color = '#FFFFFF';
    document.getElementById(PlotTool).style.color = '#FFFFFF';
    PickColor('Yellow');
    
    document.getElementById(plotStatus).src = '/images/gemGrey.png';
    document.getElementById(distanceStatus).src = '/images/gemGrey.png';
    document.getElementById(areaStatus).src = '/images/gemGrey.png';
    if( NewTool == Measure )
    {
        SetTool('MEASURE');
        document.getElementById(distanceStatus).src = '/images/gemGreen.png';
    }
    else if( NewTool == Area )
    {
        SetTool('AREA');
        document.getElementById(areaStatus).src = '/images/gemGreen.png';
    }
    else if( NewTool == Plot )
    {
        SetTool('PLOT');
        document.getElementById(plotStatus).src = '/images/gemGreen.png';
    }
//alert( typeof( document.getElementById(ImageToHilite).src ) );
    if( typeof( document.getElementById(ImageToHilite).src ) == 'undefined' )
        document.getElementById(ImageToHilite).style.color = '#AA0000';
    else
        document.getElementById(ImageToHilite).src = document.getElementById(ImageToHilite).src.replace('.jpg','_selected.jpg');
    SetInnerText(document.getElementById(CurrentToolDescription), Description);

}

function CheckButton(e) {

    if (CheckWait() == false) return false;
    
    e = e || window.event;
    var src = e.srcElement || e.target;
    var target = src;
    
    //if( e.button == 2 )
    //  return false;

    var root = document.documentElement||document.body;
    var LoopTries = 0;
    var quit = false;
    while (target.tagName != 'BODY' && target.tagName != 'HTML' && target.id != Main && target.id != CoverageMap && target.id != HICoverageMap && target.id != SecondYearSizeArrow && target.id != FadeArrow && LoopTries < 15 && BadElement(target) == false) {
        target = target.parentElement || target.parentNode;
        LoopTries = LoopTries + 1;
    }
    //alert( e.button );
    //alert( target.id );
    if (BadElement(target)) return false;
    if (Comparing) 
    {
        if ((e.button == 0 || e.button == 1) && (target.id == SecondYearSizeArrow || target.id == FadeArrow)) 
        {
            BeginXOffset = (e.clientX + root.scrollLeft) - document.getElementById(Main).offsetLeft - ProblemOffset;
            MoveCompare = true;
        }

        if (e.preventDefault) e.preventDefault();
        return false;

    }
    else if (quit == false && (e.button == 0 || e.button == 1) && (target.id == Main || target.id == CoverageMap || target.id == HICoverageMap)) {
        if (document.getElementById(CoverageMap).style.display == '') 
        {
            if( target.id == HICoverageMap )
            {
                // we are coming from the Hawaii coverage map
                if( root.scrollLeft != 0 || root.scrollTop != 0 )
                {
                  BeginXOffset = (e.clientX + root.scrollLeft) - document.getElementById(Main).offsetLeft - document.getElementById(HIInsert).style.left.replace('px','') - ProblemOffset;
                  BeginYOffset = (e.clientY + root.scrollTop) - document.getElementById(Main).offsetTop - document.getElementById(HIInsert).style.top.replace('px','') - ProblemOffset;
                }
                else //if( document.body.scrollLeft != 0 || document.body.scrollTop != 0 )
                {
                  BeginXOffset = (e.clientX + document.body.scrollLeft) - document.getElementById(Main).offsetLeft - document.getElementById(HIInsert).style.left.replace('px','') - ProblemOffset;
                  BeginYOffset = (e.clientY + document.body.scrollTop) - document.getElementById(Main).offsetTop - document.getElementById(HIInsert).style.top.replace('px','') - ProblemOffset;
                }
                //alert( BeginXOffset + "," + BeginYOffset  );
                ZoomInHawaii(BeginXOffset, BeginYOffset);
            }
            else
            {
                // we are coming from the coverage map
                if( root.scrollLeft != 0 || root.scrollTop != 0 )
                {
                  BeginXOffset = (e.clientX + root.scrollLeft) - document.getElementById(Main).offsetLeft - ProblemOffset;
                  BeginYOffset = (e.clientY + root.scrollTop) - document.getElementById(Main).offsetTop - ProblemOffset;
                }
                else //if( document.body.scrollLeft != 0 || document.body.scrollTop != 0 )
                {
                  BeginXOffset = (e.clientX + document.body.scrollLeft) - document.getElementById(Main).offsetLeft - ProblemOffset;
                  BeginYOffset = (e.clientY + document.body.scrollTop) - document.getElementById(Main).offsetTop - ProblemOffset;
                }
                //alert(document.body.scrollTop);
                //alert( BeginXOffset + "," + BeginYOffset  );
                ZoomInClick(BeginXOffset, BeginYOffset);
            }
        }
        else
        {
            if( root.scrollLeft != 0 || root.scrollTop != 0 )
            {
              BeginXOffset = (e.clientX + root.scrollLeft) - target.offsetLeft - ProblemOffset;
              BeginYOffset = (e.clientY + root.scrollTop) - target.offsetTop - ProblemOffset;
            }
            else //if( document.body.scrollLeft != 0 || document.body.scrollTop != 0 )
            {
              BeginXOffset = (e.clientX + document.body.scrollLeft) - target.offsetLeft - ProblemOffset;
              BeginYOffset = (e.clientY + document.body.scrollTop) - target.offsetTop - ProblemOffset;
            }
                        
            if (document.getElementById(CurrentTool).value == Pan) {
                HasMoved = false;
                CanMove = true;
                ChangeToZoom = false;
            }
            else if (document.getElementById(CurrentTool).value == ZoomIn) 
            {
                ZoomInClick(BeginXOffset - document.getElementById(Grid).style.left.replace('px',''), BeginYOffset - document.getElementById(Grid).style.top.replace('px',''));
                //UseZoomIn = true;
                //CanMove = false;
            }
            else if (document.getElementById(CurrentTool).value == ZoomOut) {
                ZoomOutClick(BeginXOffset - document.getElementById(Grid).style.left.replace('px',''), BeginYOffset - document.getElementById(Grid).style.top.replace('px',''));
            }
            else if (document.getElementById(CurrentTool).value == 'MEASURE') 
            {
                CheckButtonForDraw( e );
                //ZoomOutClick(BeginXOffset - document.getElementById(Grid).style.left.replace('px',''), BeginYOffset - document.getElementById(Grid).style.top.replace('px',''));
            }
            else if (document.getElementById(CurrentTool).value == 'AREA') 
            {
                CheckButtonForDraw( e );
                //ZoomOutClick(BeginXOffset - document.getElementById(Grid).style.left.replace('px',''), BeginYOffset - document.getElementById(Grid).style.top.replace('px',''));
            }
            else if (document.getElementById(CurrentTool).value == 'PLOT') 
            {
                CheckButtonForDraw( e );
                //ZoomOutClick(BeginXOffset - document.getElementById(Grid).style.left.replace('px',''), BeginYOffset - document.getElementById(Grid).style.top.replace('px',''));
            }
        }

        if (e.preventDefault) e.preventDefault();
        return false;

    }
    else
    {
        CanMove = false;
    }
}

function BadElement(target) {
    if (target.id == Tools || target.id == YearsPanel || target.id == CurrentInfo || target.id == StreetsPanelChoose || target.id == ComparePurchasePanel || target.id == YearsComparePanel || target.id == SourcePanel) { return true; } else { return false; }
}

function DisableMove(e) {
    
    if (CheckWait() == false) return false;
 
    // check to see if we are still over the main window
    e = e || window.event;
    var src = e.srcElement || e.target;
    var target = src;

    var root = document.documentElement||document.body;
    var LoopTries = 0;
    var quit = false;
    while (target.tagName != 'BODY' && target.tagName != 'HTML' && target.id != Main && target.id != CoverageMap && LoopTries < 15 && BadElement(target) == false) {
        target = target.parentElement || target.parentNode;
        LoopTries = LoopTries + 1;
    }
    
    if (MoveCompare) {
        if (target.id != Main) {
            MoveCompare = false;
        }
    }
    else if (CanMove && HasMoved) {
        if (target.id != Main) {
            CanMove = false;
            HasMoved = false;
            SecondYearCanMove = false;
            SkipTransition = true;
            UpdateGridAfterPan();
        }
    }
    else
    {
        CanMove = false;
    }
}

function DisableMoveMouseUp(e) {

    if (CheckWait() == false) return false;
    
    if (MoveCompare) {
        MoveCompare = false;
    }
    else if (HasMoved) 
    {
        CanMove = false;
        HasMoved = false;
        SecondYearCanMove = false;
        SkipTransition = true;
        UpdateGridAfterPan();
    }
    else
    {
        CanMove = false;
        SecondYearCanMove = false;
        if (ChangeToZoom) {
            ChangeToZoom = false;
            // the user probably meant to zoom and not pan
            ChangeTool(ZoomIn, ZoomInTool, 'Zooming In');
            CheckButton(e);
            ZoomInClick(BeginXOffset - document.getElementById(Grid).style.left.replace('px',''), BeginYOffset - document.getElementById(Grid).style.top.replace('px',''));
            UseZoomIn = false;
        }
        else if (UseZoomIn) {
            //we need to zoom
            ZoomInClick(BeginXOffset - document.getElementById(Grid).style.left.replace('px',''), BeginYOffset - document.getElementById(Grid).style.top.replace('px',''));
            UseZoomIn = false;
        }
        //ChangeMaps(e);
    }
}

function UpdateGridAfterPan() {
    // in here we will adjust for movement of the grid so that only certain portions of the screen have to be updated

    var oGrid = document.getElementById(Grid);
    
    if (OldGrid) { if (OldGrid != '') { document.getElementById(Main).removeChild(document.getElementById(OldGrid)) ; OldGrid = ''; }  }
    
    var Increments = 0;
    
    var TBody = oGrid.getElementsByTagName('tbody')[0];
    var TileHeight = (TBody.rows[0].cells[0].style.height.replace('px','') - 0);
    var YMovement = 0;
    var XMovement = 0;
    var CreatedElement;
    if ((oGrid.style.top.replace('px','') - 0) > 0) {
        // we need to move a row from the bottom of the table to the top
        Increments = (oGrid.style.top.replace('px','') - 0) / TileHeight;
        for (X = 0; X < Increments; X++) {
            TBody.insertBefore(TBody.rows[TBody.rows.length-1], TBody.rows[0]);
            YMovement = YMovement - TileHeight;
            // clear out image tiles
            for (Tile = 0; Tile < TBody.rows[0].cells.length; Tile++) {
                if (TBody.rows[0].cells[Tile].getElementsByTagName('img').length > 0) {
                    TBody.rows[0].cells[Tile].removeChild(TBody.rows[0].cells[Tile].getElementsByTagName('img')[0]);
                    CreatedElement = document.createElement('div');
                    CreatedElement.style.width = TBody.rows[0].cells[Tile].style.width;
                    CreatedElement.style.height = TBody.rows[0].cells[Tile].style.height;
                    CreatedElement.innerHTML = '&nbsp;';
                    TBody.rows[0].cells[Tile].appendChild(CreatedElement);
                }
            }
        }
        oGrid.style.top = (oGrid.style.top.replace('px','') - 0 + YMovement) + 'px';
    }
    else
    {
        // now check to see if we have moved up and the bottom is exposed
        var Bottom = (oGrid.style.top.replace('px','') - 0) + (oGrid.rows.length * TileHeight);
        if (Bottom < (document.getElementById(Main).style.height.replace('px','') - 0)) {
            // we need to move a row from the top of the table to the bottom
            Increments = ((document.getElementById(Main).style.height.replace('px','') - Bottom) / TileHeight);
            for (X = 0; X < Increments; X++) {
                TBody.appendChild(TBody.rows[0]);
                YMovement = YMovement + TileHeight;
                // clear out image tiles
                for (Tile = 0; Tile < TBody.rows[TBody.rows.length - 1].cells.length; Tile++) {
                    if (TBody.rows[TBody.rows.length - 1].cells[Tile].getElementsByTagName('img').length > 0) {
                        TBody.rows[TBody.rows.length - 1].cells[Tile].removeChild(TBody.rows[TBody.rows.length - 1].cells[Tile].getElementsByTagName('img')[0]);
                        CreatedElement = document.createElement('div');
                        CreatedElement.style.width = TBody.rows[TBody.rows.length - 1].cells[Tile].style.width;
                        CreatedElement.style.height = TBody.rows[TBody.rows.length - 1].cells[Tile].style.height;
                        CreatedElement.innerHTML = '&nbsp;';
                        TBody.rows[TBody.rows.length - 1].cells[Tile].appendChild(CreatedElement);
                    }
                }
            }
            oGrid.style.top = ((oGrid.style.top.replace('px','') - 0) + YMovement) + 'px';
        }
    }
    
    var TileWidth = (TBody.rows[0].cells[0].style.width.replace('px','') - 0);
    // now that we have taken care of the top and bottom, we need to do the left and right sides
    if ((oGrid.style.left.replace('px','') - 0) > 0) {
        // we need to move a column from the right of the table to the left
        Increments = (oGrid.style.left.replace('px','') - 0) / TileWidth;
        for (Y = 0; Y < oGrid.rows.length; Y++) {
            // move the column for each row
            for (X = 0; X < Increments; X++) {
                TBody.rows[Y].insertBefore(TBody.rows[Y].cells[TBody.rows[Y].cells.length - 1], TBody.rows[Y].cells[0]);
                if (TBody.rows[Y].cells[0].getElementsByTagName('img').length > 0) {
                    TBody.rows[Y].cells[0].removeChild(TBody.rows[Y].cells[0].getElementsByTagName('img')[0]);
                    CreatedElement = document.createElement('div');
                    CreatedElement.style.width = TBody.rows[Y].cells[0].style.width;
                    CreatedElement.style.height = TBody.rows[Y].cells[0].style.height;
                    CreatedElement.innerHTML = '&nbsp;';
                    TBody.rows[Y].cells[0].appendChild(CreatedElement);
                }
                if (Y == 0) {
                    XMovement = XMovement - TileWidth;
                }
            }
        }
        oGrid.style.left = (oGrid.style.left.replace('px','') - 0 + XMovement) + 'px';
    }
    else
    {
        // now check to see if we have moved left and the right is exposed
        var Right = (oGrid.style.left.replace('px','') - 0) + (oGrid.rows[0].cells.length * TileWidth);
        if (Right < (document.getElementById(Main).style.width.replace('px','') - 0)) {
            // we need to move a column from the left of the table to the right
            Increments = ((document.getElementById(Main).style.width.replace('px','') - Right) / TileWidth);
            for (Y = 0; Y < oGrid.rows.length; Y++) {
                // move the column for each row
                for (X = 0; X < Increments; X++) {
                    TBody.rows[Y].appendChild(TBody.rows[Y].cells[0]);
                    if (TBody.rows[Y].cells[TBody.rows[Y].cells.length - 1].getElementsByTagName('img').length > 0) {
                        TBody.rows[Y].cells[TBody.rows[Y].cells.length - 1].removeChild(TBody.rows[Y].cells[TBody.rows[Y].cells.length - 1].getElementsByTagName('img')[0]);
                        CreatedElement = document.createElement('div');
                        CreatedElement.style.width = TBody.rows[Y].cells[TBody.rows[Y].cells.length - 1].style.width;
                        CreatedElement.style.height = TBody.rows[Y].cells[TBody.rows[Y].cells.length - 1].style.height;
                        CreatedElement.innerHTML = '&nbsp;';
                        TBody.rows[Y].cells[TBody.rows[Y].cells.length - 1].appendChild(CreatedElement);
                    }
                    if (Y == 0) {
                        XMovement = XMovement + TileWidth;
                    }
                }
            }
            oGrid.style.left = ((oGrid.style.left.replace('px','') - 0) + XMovement) + 'px';
        }
    }
    if (XMovement != 0 || YMovement != 0) {
        document.getElementById(o).value = oGrid.style.left.replace('px','') + ',' + oGrid.style.top.replace('px','');
        UpdatePosition(XMovement, YMovement);
    }
}

function CheckWait() {
    if (document.getElementById(Wait).style.display == '') {
        return false;
    }
    else
    {
        return true;
    }
}

function ShowWait() {
    document.getElementById(Wait).style.display = '';
}

function HideWait() {
    document.getElementById(Wait).style.display = 'none';
}

function ChangeStatus(Status) {
    if (window.status != Status) {
        window.status = Status;
    }
}

function FollowMap(e) {

    if (CheckWait() == false) return false;
    
    var root = document.documentElement||document.body;
    e = e || window.event;
    var src = e.srcElement || e.target;
    CheckToCloseDiscussionPreview(src);
    var CurrentLeft;
    var CurrentTop;
    var DiffX;
    var DiffY;
    var target = document.getElementById(Main);

    if (MoveCompare) 
    {
        // the user is comparing two years
    
        target = document.getElementById(Main);

        MoveCompare = false;
        
        //if( root.scrollLeft != 0 )
          NextXOffset = (e.clientX + root.scrollLeft) - target.offsetLeft - ProblemOffset;
        //else if( document.body.scrollLeft != 0 )
          //NextXOffset = (e.clientX + document.body.scrollLeft) - target.offsetLeft - ProblemOffset;

        DiffX = NextXOffset - BeginXOffset;

        if( document.getElementById(FadeControls).style.display == 'none' )
        {
            if ((e.button == 0 || e.button == 1) && DiffX != 0) {
                // if the button is still down
                if ((document.getElementById(PanelTwoYearComparison).style.left.replace('px','') - 0 + DiffX) < 25 || 
                        (document.getElementById(PanelTwoYearComparison).style.left.replace('px','') - 0 + DiffX) > (document.getElementById(Main).style.width.replace('px','') - 25)) {
                    DiffX = 0;
                }
                else
                {
                    BeginXOffset = NextXOffset;
                }
                document.getElementById(PanelTwoYearComparison).style.left = (document.getElementById(PanelTwoYearComparison).style.left.replace('px','') - 0 + DiffX) + 'px';
                document.getElementById(SecondYearSizeArrow).style.left = (document.getElementById(SecondYearSizeArrow).style.left.replace('px','') - 0 + DiffX) + 'px';
                document.getElementById(GridTwoYearComparison).style.left = (document.getElementById(GridTwoYearComparison).style.left.replace('px','') - DiffX) + 'px';
                HasMoved = true;
            }
        }
        else
        {
            if ((e.button == 0 || e.button == 1) && DiffX != 0) 
            {
                // if the button is still down
                if ((document.getElementById(FadeArrow).style.left.replace('px','') - 0 + DiffX) < 25 || 
                        (document.getElementById(FadeArrow).style.left.replace('px','') - 0 + DiffX) > (document.getElementById(PanelTwoYearComparison).style.width.replace('px','') - 50)) {
                    DiffX = 0;
                }
                else
                {
                    BeginXOffset = NextXOffset;
                }
                document.getElementById(FadeArrow).style.left = (document.getElementById(FadeArrow).style.left.replace('px','') - 0 + DiffX) + 'px';

                var newOpacity = (document.getElementById(FadeArrow).style.left.replace('px','') - document.getElementById(PanelTwoYearComparison).style.left.replace('px','')) / document.getElementById(PanelTwoYearComparison).style.width.replace('px','');
                //var newFilter = (newOpactiy * 100).split(".",1);
                //alert( newOpacity);
            
                document.getElementById(PanelTwoYearComparison).style.opacity = newOpacity;
                document.getElementById(PanelTwoYearComparison).style.filter = 'alpha(opacity=' + Math.floor(newOpacity * 100) + ')';
            }
        }
        
        MoveCompare = true;
        
    }
    else if (CanMove) // || UseZoomIn) 
    {
        // it may be possible the user is trying to pan but has the zoom tool clicked
        if (UseZoomIn) {
            UseZoomIn = false;
        }
        ChangeToZoom = false;
        CanMove = false;

        target = document.getElementById(Main);

        if( root.scrollLeft != 0 || root.scrollTop != 0 )
        {
          NextXOffset = (e.clientX + root.scrollLeft) - target.offsetLeft - ProblemOffset;
          NextYOffset = (e.clientY + root.scrollTop) - target.offsetTop - ProblemOffset;
        }
        else //if( document.body.scrollLeft != 0 || document.body.scrollTop != 0 )
        {
          NextXOffset = (e.clientX + document.body.scrollLeft) - target.offsetLeft - ProblemOffset;
          NextYOffset = (e.clientY + document.body.scrollTop) - target.offsetTop - ProblemOffset;
        }

        CurrentLeft = document.getElementById(Grid).style.left.replace('px','');        
        CurrentTop = document.getElementById(Grid).style.top.replace('px','');        
        DiffX = NextXOffset - BeginXOffset;
        DiffY = NextYOffset - BeginYOffset;
        if ((e.button == 0 || e.button == 1) && (DiffX != 0 || DiffY != 0)) {
            // if the button is still down
            document.getElementById(Grid).style.left = (CurrentLeft - 0 + DiffX) + 'px';
            document.getElementById(Grid).style.top = (CurrentTop - 0 + DiffY) + 'px';
            document.getElementById(o).value = (CurrentLeft - 0 + DiffX) + ',' + (CurrentTop - 0 + DiffY);
            if (OldGrid) {
                if (OldGrid != '') {
                    CurrentLeft = document.getElementById(OldGrid).style.left.replace('px','');        
                    CurrentTop = document.getElementById(OldGrid).style.top.replace('px','');        
                    document.getElementById(OldGrid).style.left = (CurrentLeft - 0 + DiffX) + 'px';
                    document.getElementById(OldGrid).style.top = (CurrentTop - 0 + DiffY) + 'px';
                }
            }
            BeginXOffset = NextXOffset;
            BeginYOffset = NextYOffset;
            HasMoved = true;
        }

        CanMove = true;
    }
}

function ShowUserHelpBubble() {
    if (document.getElementById(MapNavGoToPoint).value.length > 0 && document.getElementById(MapNavGoToYear).value.length > 0 && document.getElementById(MapNavGoToScale).value.length > 0 ) {
        document.getElementById(UserStartInfo).style.display = 'none';
        document.getElementById(MapNavAddress).value = '';
        SkipTransition = true;
        StartWait();
        setTimeout("document.getElementById(ZoomToPointMethod).click();",10);
    }
    else
    {
        if (document.getElementById(MapName).value == 'COVER') {
            document.getElementById(UserStartInfo).style.display = '';
        }
        else
        {
            document.getElementById(UserStartInfo).style.display = 'none';
        }
    }
}

function CheckToCloseDiscussionPreview(src) {
    if (DiscussionMasterPanel != '') {
        if (document.getElementById(DiscussionPreview)) {
            if (document.getElementById(DiscussionPreview).style.display == '') {
                if (src.id == DiscussionMasterPanel) {
                    return false;
                }
                while (src.tagName != 'BODY') {
                    src = src.parentElement || src.parentNode;
                    if (src != null) {
                        if (src.id == DiscussionMasterPanel) {
                            return false;
                        }
                    }
                }
                // if we made it here then we are not in the discussion area any more and we need to close the discussion preview panel
                if (Closing == false) {
                    CloseDiscussionPreview();
                }
            }
        }
    }
    
}






//*******************************************************************************************************
//*******************************************************************************************************
//*******************************************************************************************************
//*******************************************************************************************************
//*******************************************************************************************************
//*******************************************************************************************************
//*******************************************************************************************************
//*******************************************************************************************************







function GetStreetStatus() {
    if (GetInnerText(document.getElementById(CurrentStreetsStatus)) == '-on-') {
        return true;
    }
    else
    {
        return false;
    }
}

function ChangeYears(NewYear, GridToApply) {

    if (CheckWait() == false) return false;
    
    ShowWait();

    GridToChangeYear = GridToApply;

    var ti = document.getElementById(t).value;
    
    // only change this if we are dealing with the main image
    if (GridToChangeYear == Grid) document.getElementById(t).value = 'changeyears';

    if (NoAnimation) {
    
        MaximumProgress = 25;
        setTimeout("CheckImagesForProgress(true, '" + GridToChangeYear + "');",100);

    }
    else
    {

        //copy the existing master grid for smooth transition
        var oGrid = document.getElementById(GridToChangeYear);
        var NewGrid = document.createElement('table');
        NewGrid.className = oGrid.className;
        NewGrid.style.left = oGrid.style.left;
        NewGrid.style.top = oGrid.style.top;
        NewGrid.cellSpacing = oGrid.cellSpacing;
        NewGrid.cellPadding = oGrid.cellPadding;
        NewGrid.onselectstart = oGrid.onselectstart;
        NewGrid.style.borderCollapse = 'collapse';
        var TBody = document.createElement('tbody');
        NewGrid.appendChild(TBody);

        for (RowIndex = 0; RowIndex < oGrid.rows.length; RowIndex++) {
            TBody.appendChild(document.createElement('tr'));
            for (CellIndex = 0; CellIndex < oGrid.rows[RowIndex].cells.length; CellIndex++) {
                
                NewGrid.rows[RowIndex].appendChild(document.createElement('td'));
                NewGrid.rows[RowIndex].cells[CellIndex].style.width = oGrid.rows[RowIndex].cells[CellIndex].style.width;
                NewGrid.rows[RowIndex].cells[CellIndex].style.height = oGrid.rows[RowIndex].cells[CellIndex].style.height;
                NewGrid.rows[RowIndex].cells[CellIndex].style.borderWidth = oGrid.rows[RowIndex].cells[CellIndex].style.borderWidth;
                
                if (NewGrid.rows[RowIndex].cells[CellIndex].getElementsByTagName('img').length > 0) {
                    NewGrid.rows[RowIndex].cells[CellIndex].removeChild(NewGrid.rows[RowIndex].cells[CellIndex].getElementsByTagName('img')[0]);
                }
            }
        }
        oGrid.id = GridToChangeYear + 'back';
        oGrid.name = GridToChangeYear + 'back';
        NewGrid.id = GridToChangeYear;
        NewGrid.name = GridToChangeYear;
        OldGrid = oGrid.id;

        document.getElementById(Main).insertBefore(NewGrid, document.getElementById(PanelTwoYearComparison))
    
        oGrid = document.getElementById(GridToChangeYear);
        
        // hide the new year until it has finished fully loading
        oGrid.style.display = 'none';
        if (GetInnerText(document.getElementById(CurrentDissolveStatus)) == '-on-') {
            oGrid.style.filter = 'blendTrans(duration=3)';
        }
        
        MaximumProgress = 80;
        setTimeout("CheckImagesForProgress(true, '" + GridToChangeYear + "');",100);

    }
    
    var Streets = GetInnerText(document.getElementById(CurrentStreetsStatus));
    var counties = false;
    if( document.getElementById(countyBoundaryStatus).src.indexOf('Green') >= 0 )
      counties = true;
    var cities = false;
    if( document.getElementById(cityOverlayStatus).src.indexOf('Green') >= 0 )
      cities = true;
      
    AsyncWeb.ChangeYears(ti, NewYear, Streets, counties, cities, document.getElementById(CurrentSession).value, ChangeYearsCallBack, OnFailedDoNothing);
}

function ChangeYearsCallBack(result, userContext, methodName) {
  	if (result != '') {
  	    var Arguments = result[0,0].split('=');
  	    // if we are doing this to the main grid
  	    if (GridToChangeYear == Grid) {
  	        document.getElementById(t).value = Arguments[Arguments.length-1];
  	    }
  	    else
  	    {
  	        // we are updating the second year and need to update the years list
  	        t2 = Arguments[Arguments.length-1];
  	        UpdateSecondYearsList();
  	    }
  	    if (NoAnimation) {
  	        // if we are skipping animation then that means all the imagery must be erased
  	        // because it was not done automatically for us and we wanted to wait
  	        // until the imagery was ready so there is little blank space on the screen
  	        var oGrid = document.getElementById(GridToChangeYear);
            for (Y = 0; Y < oGrid.rows.length; Y++) {
                for (X = 0; X < oGrid.rows[Y].cells.length; X++) {
                    if (oGrid.rows[Y].cells[X].getElementsByTagName('img').length > 0) {
                        oGrid.rows[Y].cells[X].removeChild(oGrid.rows[Y].cells[X].getElementsByTagName('img')[0]);
                    }
                }
            }

            // we are almost done
            MaximumProgress = 80;
            setTimeout("CheckImagesForProgress(true, '" + GridToChangeYear + "');",100);

  	    }
  	    ApplyGrid(GridToChangeYear, result, true);
  	    setTimeout("CheckProgressForYearChange();",850)
  	}
}

var YearChangeDissolveGrid = '';

function CheckProgressForYearChange() {

    // we cannot let anything else clear the temporary grid until the dissolve has taken place
    if (OldGrid != '') { 
        if (GetInnerText(document.getElementById(CurrentDissolveStatus)) == '-on-') {
            YearChangeDissolveGrid = OldGrid;
            OldGrid = '';
        }
    }
    
    if (document.getElementById(ProgressMeterWidth).style.width.replace('%','') == '100') {
        var oGrid = document.getElementById(Grid);
        if (GetInnerText(document.getElementById(CurrentDissolveStatus)) == '-on-') {
            if (oGrid.outerHTML) {
                oGrid.filters.blendTrans.Apply() 
            }
        }
        oGrid.style.display = '';
        if (GetInnerText(document.getElementById(CurrentDissolveStatus)) == '-on-') {
            if (oGrid.outerHTML) {
                oGrid.filters.blendTrans.Play()
            }
        }
        if (YearChangeDissolveGrid != '') { 
            if (GetInnerText(document.getElementById(CurrentDissolveStatus)) == '-on-') {
                setTimeout("document.getElementById(Main).removeChild(document.getElementById(YearChangeDissolveGrid)); YearChangeDissolveGrid = ''; ",4000);
            }
        }
  	    HideWait();
    }
    else
    {
        setTimeout("CheckProgressForYearChange();",550)
    }
}

function CheckImagesForProgress(reset, GridToCheck) {
    if (reset) {
        document.getElementById(ProgressMeterWidth).style.width = '0%';
        SetInnerText(document.getElementById(ProgressMeterWidth).rows[0].cells[0], '');
    }
    //update MaximumProgress
    if (TilesLoading > 0 && ((GetNumImagesLoaded(GridToCheck) / TilesLoading) * 100) > MaximumProgress) {
        MaximumProgress = ((GetNumImagesLoaded(GridToCheck) / TilesLoading) * 100);
    }
    if (((document.getElementById(ProgressMeterWidth).style.width.replace('%','') - 0) + 1) <= MaximumProgress) {
        if (MaximumProgress == 100) {
            document.getElementById(ProgressMeterWidth).style.width = '100%';
        }
        else
        {
            document.getElementById(ProgressMeterWidth).style.width = ((document.getElementById(ProgressMeterWidth).style.width.replace('%','') - 0) + 1) + '%';
        }
    }
    if (document.getElementById(ProgressMeterWidth).style.width != '100%') {
        if ((document.getElementById(ProgressMeterWidth).style.width.replace('%','')-0) > 40) {
            SetInnerText(document.getElementById(ProgressMeterWidth).rows[0].cells[0], 'Loading ' + Math.round(document.getElementById(ProgressMeterWidth).style.width.replace('%','')) + '%');
            document.getElementById(ProgressMeterWidth).rows[0].cells[0].style.fontSize = '10px';
        }
        else if ((document.getElementById(ProgressMeterWidth).style.width.replace('%','')-0) > 25) {
            SetInnerText(document.getElementById(ProgressMeterWidth).rows[0].cells[0], 'Loading');
            document.getElementById(ProgressMeterWidth).rows[0].cells[0].style.fontSize = '10px';
        }
        setTimeout("CheckImagesForProgress(false, '" + GridToCheck + "');",135);
    }
    else
    {
        if (CountyLocation != '') {
            SetInnerText(document.getElementById(ProgressMeterWidth).rows[0].cells[0], 'Loaded - ' + CountyLocation);
        }
        else
        {
            SetInnerText(document.getElementById(ProgressMeterWidth).rows[0].cells[0], 'Loaded');
        }
        document.getElementById(ProgressMeterWidth).rows[0].cells[0].style.fontSize = '10px';
        // we have loaded the image and need to get rid of the interim grid if we have one
        if (OldGrid != '') { document.getElementById(Main).removeChild(document.getElementById(OldGrid)); OldGrid = ''; }
    }
}

function GetNumImagesLoaded(GridToCheck) {
    var tempTilesLoaded = 0;
    TilesLoading = 0;
    var oGrid = document.getElementById(GridToCheck);
    for (Y = 0; Y < oGrid.rows.length; Y++) {
        for (X = 0; X < oGrid.rows[Y].cells.length; X++) {
            if (oGrid.rows[Y].cells[X].getElementsByTagName('img').length > 0) {
                if (ImageLoaded(oGrid.rows[Y].cells[X].getElementsByTagName('img')[0])) {
                    tempTilesLoaded = tempTilesLoaded + 1;
                }
                TilesLoading = TilesLoading + 1;
            }
        }
    }
    return tempTilesLoaded;
}

function ImageLoaded(img) {
    if (!img.complete) {
        return false;
    }
    if (typeof img.naturalWidth != 'undefined' && img.naturalWidth == 0) {
        return false;
    }
    return true;
}

function TileLoaded() {
    TilesLoaded = TilesLoaded + 1;
}

function ZoomOutClick(X, Y)
{
    // first expand all images double
    
    var oGrid;
    
    if (OldGrid != '') {
        // we already have a grid and the new one hasn't loaded yet
        oGrid = document.getElementById(OldGrid);
        var AdjustedX = X + (document.getElementById(Grid).style.left.replace('px','') - oGrid.style.left.replace('px',''));
        var AdjustedY = Y + (document.getElementById(Grid).style.top.replace('px','') - oGrid.style.top.replace('px',''));
        oGrid.style.left = (((document.getElementById(Main).style.width.replace('px','') / 2) - (AdjustedX / 2))) + 'px';
        oGrid.style.top = (((document.getElementById(Main).style.height.replace('px','') / 2) - (AdjustedY / 2))) + 'px';
        for (row = 0; row < oGrid.rows.length; row++) {
            for (cell = 0; cell < oGrid.rows[row].cells.length; cell++) {
                oGrid.rows[row].cells[cell].style.width = (oGrid.rows[row].cells[cell].style.width.replace('px','') / 2) + 'px';
                oGrid.rows[row].cells[cell].getElementsByTagName('img')[0].style.width = oGrid.rows[row].cells[cell].style.width;
                oGrid.rows[row].cells[cell].style.height = (oGrid.rows[row].cells[cell].style.height.replace('px','') / 2) + 'px';
                oGrid.rows[row].cells[cell].getElementsByTagName('img')[0].style.height = oGrid.rows[row].cells[cell].style.height;
            }
        }
        ShowWait();
    }
    else
    {
        oGrid = document.getElementById(Grid);
        var NewGrid = document.createElement('table');
        NewGrid.className = oGrid.className;
        NewGrid.style.left = oGrid.style.left;
        NewGrid.style.top = oGrid.style.top;
        NewGrid.cellSpacing = oGrid.cellSpacing;
        NewGrid.cellPadding = oGrid.cellPadding;
        NewGrid.onselectstart = oGrid.onselectstart;
        NewGrid.style.borderCollapse = 'collapse';
        var TBody = document.createElement('tbody');
        NewGrid.appendChild(TBody);

        oGrid.style.left = (((document.getElementById(Main).style.width.replace('px','') / 2) - (X / 2))) + 'px';
        oGrid.style.top = (((document.getElementById(Main).style.height.replace('px','') / 2) - (Y / 2))) + 'px';
        for (row = 0; row < oGrid.rows.length; row++) {
            TBody.appendChild(document.createElement('tr'));
            for (cell = 0; cell < oGrid.rows[row].cells.length; cell++) {
            
                NewGrid.rows[row].appendChild(document.createElement('td'));
                NewGrid.rows[row].cells[cell].style.width = oGrid.rows[row].cells[cell].style.width;
                NewGrid.rows[row].cells[cell].style.height = oGrid.rows[row].cells[cell].style.height;
                NewGrid.rows[row].cells[cell].style.borderWidth = oGrid.rows[row].cells[cell].style.borderWidth;
            
                oGrid.rows[row].cells[cell].style.width = (oGrid.rows[row].cells[cell].style.width.replace('px','') / 2) + 'px';
                oGrid.rows[row].cells[cell].getElementsByTagName('img')[0].style.width = oGrid.rows[row].cells[cell].style.width;
                oGrid.rows[row].cells[cell].style.height = (oGrid.rows[row].cells[cell].style.height.replace('px','') / 2) + 'px';
                oGrid.rows[row].cells[cell].getElementsByTagName('img')[0].style.height = oGrid.rows[row].cells[cell].style.height;
            }
        }

        ShowWait();
        oGrid.id = Grid + 'back';
        oGrid.name = Grid + 'back';
        NewGrid.id = Grid;
        NewGrid.name = Grid;
        OldGrid = oGrid.id;
        document.getElementById(Main).insertBefore(NewGrid, document.getElementById(PanelTwoYearComparison));
    }
    var ti = document.getElementById(t).value;
    document.getElementById(t).value = 'zoomout';

    MaximumProgress = 25;
    setTimeout("CheckImagesForProgress(true, '" + Grid + "');",100);

    var Streets = GetInnerText(document.getElementById(CurrentStreetsStatus));
    var sessionID = document.getElementById(CurrentSession).value;
    AsyncWeb.Zoom(X, Y, ti, 2, Streets, sessionID, ZoomCallBack, OnFailedDoNothing);
}

// zooms in
function ZoomInHawaii(X, Y)
{
    ShowWait();
    //var ti = document.getElementById(t).value;
    document.getElementById(t).value = 'zoomin';
    
    MaximumProgress = 25;
    setTimeout("CheckImagesForProgress(true, '" + Grid + "');",100);

    var Streets = GetInnerText(document.getElementById(CurrentStreetsStatus));
    var sessionID = document.getElementById(CurrentSession).value;
    AsyncWeb.ZoomHawaii(X, Y, 0, 1, Streets, sessionID, ZoomCallBack, OnFailedDoNothing);
}

function ZoomInClick(X, Y)
{
    // check to make sure we aren't coming from the coverage map
    if (document.getElementById(CoverageMap).style.display != '') {
        // first expand all images double
        
        var oGrid;
        
        if (OldGrid != '') {
            // we already have a grid and the new one hasn't loaded yet
            oGrid = document.getElementById(OldGrid);
            var AdjustedX = X + (document.getElementById(Grid).style.left.replace('px','') - oGrid.style.left.replace('px',''));
            var AdjustedY = Y + (document.getElementById(Grid).style.top.replace('px','') - oGrid.style.top.replace('px',''));
            oGrid.style.left = (((document.getElementById(Main).style.width.replace('px','') / 2) - (AdjustedX * 2))) + 'px';
            oGrid.style.top = (((document.getElementById(Main).style.height.replace('px','') / 2) - (AdjustedY * 2))) + 'px';
            for (row = 0; row < oGrid.rows.length; row++) {
                for (cell = 0; cell < oGrid.rows[row].cells.length; cell++) {
                    oGrid.rows[row].cells[cell].style.width = (oGrid.rows[row].cells[cell].style.width.replace('px','') * 2) + 'px';
                    oGrid.rows[row].cells[cell].getElementsByTagName('img')[0].style.width = oGrid.rows[row].cells[cell].style.width;
                    oGrid.rows[row].cells[cell].style.height = (oGrid.rows[row].cells[cell].style.height.replace('px','') * 2) + 'px';
                    oGrid.rows[row].cells[cell].getElementsByTagName('img')[0].style.height = oGrid.rows[row].cells[cell].style.height;
                }
            }
            ShowWait();
        }
        else
        {
            oGrid = document.getElementById(Grid);
            var NewGrid = document.createElement('table');
            NewGrid.className = oGrid.className;
            NewGrid.style.left = oGrid.style.left;
            NewGrid.style.top = oGrid.style.top;
            NewGrid.cellSpacing = oGrid.cellSpacing;
            NewGrid.cellPadding = oGrid.cellPadding;
            NewGrid.onselectstart = oGrid.onselectstart;
            NewGrid.style.borderCollapse = 'collapse';
            var TBody = document.createElement('tbody');
            NewGrid.appendChild(TBody);

            oGrid.style.left = (((document.getElementById(Main).style.width.replace('px','') / 2) - (X * 2))) + 'px';
            oGrid.style.top = (((document.getElementById(Main).style.height.replace('px','') / 2) - (Y * 2))) + 'px';
            for (row = 0; row < oGrid.rows.length; row++) {
                TBody.appendChild(document.createElement('tr'));
                for (cell = 0; cell < oGrid.rows[row].cells.length; cell++) {
                
                    NewGrid.rows[row].appendChild(document.createElement('td'));
                    NewGrid.rows[row].cells[cell].style.width = oGrid.rows[row].cells[cell].style.width;
                    NewGrid.rows[row].cells[cell].style.height = oGrid.rows[row].cells[cell].style.height;
                    NewGrid.rows[row].cells[cell].style.borderWidth = oGrid.rows[row].cells[cell].style.borderWidth;
                
                    oGrid.rows[row].cells[cell].style.width = (oGrid.rows[row].cells[cell].style.width.replace('px','') * 2) + 'px';
                    oGrid.rows[row].cells[cell].getElementsByTagName('img')[0].style.width = oGrid.rows[row].cells[cell].style.width;
                    oGrid.rows[row].cells[cell].style.height = (oGrid.rows[row].cells[cell].style.height.replace('px','') * 2) + 'px';
                    oGrid.rows[row].cells[cell].getElementsByTagName('img')[0].style.height = oGrid.rows[row].cells[cell].style.height;
                }
            }
            ShowWait();

            oGrid.id = Grid + 'back';
            oGrid.name = Grid + 'back';
            NewGrid.id = Grid;
            NewGrid.name = Grid;
            OldGrid = oGrid.id;
            document.getElementById(Main).insertBefore(NewGrid, document.getElementById(PanelTwoYearComparison));
        }
    }
    else
    {
        ShowWait();
    }
    var ti = document.getElementById(t).value;
    document.getElementById(t).value = 'zoomin';
    
    MaximumProgress = 25;
    setTimeout("CheckImagesForProgress(true, '" + Grid + "');",100);

    var Streets = GetInnerText(document.getElementById(CurrentStreetsStatus));
    var sessionID = document.getElementById(CurrentSession).value;
    AsyncWeb.Zoom(X, Y, ti, 1, Streets, sessionID, ZoomCallBack, OnFailedDoNothing);
}

function ZoomCallBack(result, userContext, methodName) {
  	var CreatedNode;
  	if (result > 0) {
  	    var oGrid = document.getElementById(Grid);
  	    if (result == 1) {
  	        // no sense in zooming out beyond this point
  	        CountyLocation = '';
  	        MaximumProgress = 100;
            if (document.getElementById(CoverageMap).style.display == 'none') 
                document.getElementById(CoverageMap).style.display = '';
            if (document.getElementById(HIInsert).style.display == 'none') 
                document.getElementById(HIInsert).style.display = '';
                
            ChangeTool(ZoomIn, ZoomInTool, 'Zooming In');

            // erase all images
            for (Y = 0; Y < oGrid.rows.length; Y++) {
                for (X = 0; X < oGrid.rows[Y].cells.length; X++) {
                    if (oGrid.rows[Y].cells[X].getElementsByTagName('img').length > 0) {
                        oGrid.rows[Y].cells[X].removeChild(oGrid.rows[Y].cells[X].getElementsByTagName('img')[0]);
                    }
                }
            }
            // erase the temp grid if we need to
            if (OldGrid != '') { document.getElementById(Main).removeChild(document.getElementById(OldGrid)); OldGrid = ''; }
  	        HideWait();
  	        document.getElementById(t).value = 0;
  	        document.getElementById(CurrentInfo).style.display = 'none';
  	        document.getElementById(YearsPanel).innerHTML = '';
  	        document.getElementById(ComparePurchasePanel).style.display = 'none';
  	    }
  	    else
  	    {
            MaximumProgress = 80;
  	        document.getElementById(t).value = result;
            oGrid.style.left = (-(((oGrid.rows[0].cells.length * oGrid.rows[0].cells[0].style.width.replace('px','')) - document.getElementById(Main).style.width.replace('px','')) / 2)) + 'px';
            oGrid.style.top = (-(((oGrid.rows.length * oGrid.rows[0].cells[0].style.height.replace('px','')) - document.getElementById(Main).style.height.replace('px','')) / 2)) + 'px';
            document.getElementById(o).value = oGrid.style.left.replace('px','') + ',' + oGrid.style.top.replace('px','');
  	        UpdateImage(result)
  	        document.getElementById(ComparePurchasePanel).style.display = '';

            AsyncWeb.GetCoordinates( BeginXOffset - document.getElementById(Grid).style.left.replace('px',''), BeginYOffset - document.getElementById(Grid).style.top.replace('px',''), document.getElementById(t).value, CoordinatesCallBack, OnFailedDoNothing);
  	    }
  	}
}

function CoordinatesCallBack(result, userContext, methodName)
{
    //alert( result );
    document.getElementById(_Latitude).value = result.split( "," )[0];
    document.getElementById(_Longitude).value = result.split( "," )[1];
    document.getElementById(_Scale).value = result.split( "," )[2];
    //HideWait();
}

function UpdateImage(t) {
    TilesLoading = 0;
    if (MaximumProgress == 0) {
        MaximumProgress = 80;
        setTimeout("CheckImagesForProgress(true, '" + Grid + "');",100);
    }
    // just in case
    ShowWait();
    //now get the images
    var Streets = GetInnerText(document.getElementById(CurrentStreetsStatus));
    var counties = false;
    if( document.getElementById(countyBoundaryStatus).src.indexOf('Green') >= 0 )
      counties = true;
    var cities = false;
    if( document.getElementById(cityOverlayStatus).src.indexOf('Green') >= 0 )
      cities = true;
      
    AsyncWeb.UpdateImage(t, Streets, counties, cities, UpdateICallBack, OnFailedDoNothing);
}

function DefineImageTwoPanel(t) {
    ShowWait();
    //now get the new t value
    var oGrid = document.getElementById(Grid);
    // define the rows and columns
    var TwoYearGrid = document.getElementById(GridTwoYearComparison);
    var TBody;
    if (document.getElementById(GridTwoYearComparison).getElementsByTagName('tbody').length == 0) {
        TBody = document.createElement('tbody');
        document.getElementById(GridTwoYearComparison).appendChild(TBody);
    }
    else
    {
        TBody = document.getElementById(GridTwoYearComparison).getElementsByTagName('tbody')[0];
    }
    for (Y = 0; Y < oGrid.rows.length; Y++) {
        TBody.appendChild(document.createElement('tr'));
        for (X = 0; X < oGrid.rows[Y].cells.length; X++) {
            TwoYearGrid.rows[Y].appendChild(document.createElement('td'));
            TwoYearGrid.rows[Y].cells[X].style.width = oGrid.rows[Y].cells[X].style.width;
            TwoYearGrid.rows[Y].cells[X].style.height = oGrid.rows[Y].cells[X].style.height;
            TwoYearGrid.rows[Y].cells[X].style.borderWidth = oGrid.rows[Y].cells[X].style.borderWidth;
        }
    }
    var Streets = GetInnerText(document.getElementById(CurrentStreetsStatus));
    AsyncWeb.GetNextYear(t, document.getElementById(CurrentSession).value, DefineImageTwoPanelCallBack, OnFailedDoNothing);
}

function DefineImageTwoPanelCallBack(result, userContext, methodName) {
  	if (result > 0) {
  	    
  	    // now that we have the new coordinates
  	    t2 = result;
  	    MaximumProgress = 25;
        // check the second panel for the images that are loaded
        setTimeout("CheckImagesForProgress(true, '" + GridTwoYearComparison + "');",100);
  	    UpdateImageTwoPanel(t2);
  	    
  	}
  	else
  	{
  	    alert('This feature is not available for the region you are currently in.');
  	    
  	    if( document.getElementById(FadeControls).style.display == 'none' )
    	    ToggleComparing();
    	else
    	    ToggleFade();
  	    
      	HideWait();
    }
}

function UpdateImageTwoPanel(t) {
    TilesLoading = 0;
    MaximumProgress = 80;
    // just in case
    ShowWait();
    //now get the images
    var Streets = GetInnerText(document.getElementById(CurrentStreetsStatus));
    var counties = false;
    if( document.getElementById(countyBoundaryStatus).src.indexOf('Green') >= 0 )
      counties = true;
    var cities = false;
    if( document.getElementById(cityOverlayStatus).src.indexOf('Green') >= 0 )
      cities = true;
      
    AsyncWeb.UpdateImage(t, Streets, counties, cities, UpdateITwoPanelCallBack, OnFailedDoNothing);
//    AsyncWeb.UpdateImage(t, Streets, UpdateITwoPanelCallBack, OnFailedDoNothing);
}

var NoErase = false;

function UpdateICallBack(result, userContext, methodName) {
  	if (result != '') {
  	    var Arguments = result[0,0].split('=');
  	    // make sure we are still dealing with the same t-value
  	    if (Arguments[Arguments.length-1] == document.getElementById(t).value) {
  	        if (!NoErase) {
  	            // first lets clear out all existing images
                var oGrid = document.getElementById(Grid);
                for (Y = 0; Y < oGrid.rows.length; Y++) {
                    for (X = 0; X < oGrid.rows[Y].cells.length; X++) {
                        if (oGrid.rows[Y].cells[X].getElementsByTagName('img').length > 0) {
                            oGrid.rows[Y].cells[X].removeChild(oGrid.rows[Y].cells[X].getElementsByTagName('img')[0]);
                        }
                    }
                }
                // now recenter the grid
                //oGrid.style.left = (-(((oGrid.rows[0].cells.length * oGrid.rows[0].cells[0].style.width.replace('px','')) - document.getElementById(Main).style.width.replace('px','')) / 2)) + 'px';
                //oGrid.style.top = (-(((oGrid.rows.length * oGrid.rows[0].cells[0].style.height.replace('px','')) - document.getElementById(Main).style.height.replace('px','')) / 2)) + 'px';
                //document.getElementById(o).value = oGrid.style.left.replace('px','') + ',' + oGrid.style.top.replace('px','');
            }
            else
            {
                NoErase = false;
            }
            
  	        ApplyGrid(Grid, result, true);
  	    }
  	}
  	HideWait();
}

function UpdateITwoPanelCallBack(result, userContext, methodName) {
  	if (result != '') {
  	    var Arguments = result[0,0].split('=');
  	    // make sure we are still dealing with the same t-value
  	    if (Arguments[Arguments.length-1] == t2) {
  	        if (!NoErase) {
  	            // first lets clear out all existing images
                var oGrid = document.getElementById(GridTwoYearComparison);
                for (Y = 0; Y < oGrid.rows.length; Y++) {
                    for (X = 0; X < oGrid.rows[Y].cells.length; X++) {
                        if (oGrid.rows[Y].cells[X].getElementsByTagName('img').length > 0) {
                            oGrid.rows[Y].cells[X].removeChild(oGrid.rows[Y].cells[X].getElementsByTagName('img')[0]);
                        }
                    }
                }
            }
            else
            {
                NoErase = false;
            }
            
            // we want to update the second grid this time
  	        ApplyGrid(GridTwoYearComparison, result, false);
  	        
  	        // we want to show the years list
  	        UpdateSecondYearsList();
  	        
  	        
            if (document.getElementById(FadeControls).style.display == 'none' && document.getElementById(SecondYearPanelHelp).style.display == 'none') document.getElementById(SecondYearPanelHelp).style.display = '';
  	    }
  	}
  	HideWait();
}

function Back() {
    var ti = document.getElementById(t).value;
    if (ti.length > 0 && ti != '0') {
        ShowWait();
        var Streets = GetInnerText(document.getElementById(CurrentStreetsStatus));
        AsyncWeb.Back(ti, Streets, BackCallBack, OnFailedDoNothing);
    }
    else
    {
        alert('There are no images to which you can go back.');
    }
}

function BackCallBack(result, userContext, methodName) {
    if (result == 0) {
        alert('There are no images to which you can go back.');
      	HideWait();
    }
    else
    {
        document.getElementById(t).value = result;
        NoErase = true;
        MaximumProgress = 0;
        var oGrid = document.getElementById(Grid);
        // now recenter the grid
        oGrid.style.left = (-(((oGrid.rows[0].cells.length * oGrid.rows[0].cells[0].style.width.replace('px','')) - document.getElementById(Main).style.width.replace('px','')) / 2)) + 'px';
        oGrid.style.top = (-(((oGrid.rows.length * oGrid.rows[0].cells[0].style.height.replace('px','')) - document.getElementById(Main).style.height.replace('px','')) / 2)) + 'px';
        document.getElementById(o).value = oGrid.style.left.replace('px','') + ',' + oGrid.style.top.replace('px','');
        NoErase = false;
        UpdateImage(result)
    }
}

// updates the current position
function UpdatePosition(XMovement, YMovement)
{
    ShowWait();
    var ti = document.getElementById(t).value;
    
    document.getElementById(t).value = 'updateposition';
     
    MaximumProgress = 10;
    setTimeout("CheckImagesForProgress(true, '" + Grid + "');",100);
    
    var oGrid = document.getElementById(Grid);
    var Streets = GetInnerText(document.getElementById(CurrentStreetsStatus));
    AsyncWeb.UpdatePosition(XMovement, YMovement, ti, Streets, oGrid.style.left.replace('px',''), oGrid.style.top.replace('px',''), document.getElementById(CurrentSession).value, UpdateGridCallBack, OnFailedDoNothing);
}

function UpdateGridCallBack(result, userContext, methodName) {
  	if (result > 0) {
        NoErase = true;
        MaximumProgress = 80;
        document.getElementById(t).value = result;
        UpdateImage(result)
        AsyncWeb.GetCoordinates( BeginXOffset - document.getElementById(Grid).style.left.replace('px',''), BeginYOffset - document.getElementById(Grid).style.top.replace('px',''), document.getElementById(t).value, CoordinatesCallBack, OnFailedDoNothing);
  	}
  	else
      	HideWait();
}

function ApplyGrid(GridToApply, URLArray, UpdateYears) {

    //check if coming from coverage map
    if (document.getElementById(CoverageMap).style.display == '') 
      document.getElementById(CoverageMap).style.display = 'none';
    if (document.getElementById(HIInsert).style.display == '') 
      document.getElementById(HIInsert).style.display = 'none';

    var CreatedNode;
    TilesLoading = 0;
    SetInnerText(document.getElementById(ProgressMeterWidth).rows[0].cells[0], ' ');
    document.getElementById(ProgressMeterWidth).rows[0].cells[0].style.fontSize = '0px';
    var oGrid = document.getElementById(GridToApply);
    for (Y = 0; Y < oGrid.rows.length; Y++) {
        for (X = 0; X < oGrid.rows[Y].cells.length; X++) {
            if (oGrid.rows[Y].cells[X].getElementsByTagName('div').length > 0) {
                oGrid.rows[Y].cells[X].innerHTML = '';
            }
            if (oGrid.rows[Y].cells[X].getElementsByTagName('img').length <= 0) {
                CreatedNode = document.createElement('img');
                CreatedNode.src = URLArray[(Y * oGrid.rows[Y].cells.length) + X];
                CreatedNode.style.width = oGrid.rows[Y].cells[X].style.width;
                CreatedNode.style.height = oGrid.rows[Y].cells[X].style.height;
                oGrid.rows[Y].cells[X].appendChild(CreatedNode);
                TilesLoading = TilesLoading + 1;
            }
        }
    }
    
    if (UpdateYears) UpdateYearsList(false);
    
    if (document.getElementById(CurrentInfo).style.display == 'none' && Comparing == false) document.getElementById(CurrentInfo).style.display = '';
    if (document.getElementById(Legend).style.display == '') document.getElementById(Legend).style.display = 'none';
    
    
}
var ForceYearsUpdate = true; //false;

function UpdateSecondYearsList() {
    var oGrid = document.getElementById(Grid);
    AsyncWeb.GetYears(((document.getElementById(Main).style.width.replace('px','') / 2) - oGrid.style.left.replace('px','')), ((document.getElementById(Main).style.height.replace('px','') / 2) - oGrid.style.top.replace('px','')), t2, GridTwoYearComparison, GetSecondYearsCallBack, OnFailedDoNothing);
}

function GetSecondYearsCallBack(result, userContext, methodName) {
  	var CreatedNode;
    var ti = document.getElementById(t).value;
  	if (result != '') {
  	    var resultArray = result.split('|');
  	    var ProceedWithYears = false;
        if (resultArray[0] == t2 && resultArray.length > 1) {
            document.getElementById(YearsComparePanel).innerHTML = resultArray[1];

            var Years = document.getElementById(YearsComparePanel).getElementsByTagName('table')[0].getElementsByTagName('table');
            // if we are skipping animation, then it doesn't matter, go ahead and show
            for (X = 0; X < Years.length; X++) {
                Years[X].style.left = '1px';
            }
            
            document.getElementById(YearsComparePanel).style.display = '';
            
  	    }
  	}
}

function UpdateYearsList(force) {
    if ((document.getElementById(ProgressMeterWidth).style.width.replace('%','')-0) > 70) {
        var oGrid = document.getElementById(Grid);
        var ti = document.getElementById(t).value;
        ForceYearsUpdate = true; //force;
        AsyncWeb.GetYears(((document.getElementById(Main).style.width.replace('px','') / 2) - oGrid.style.left.replace('px','')), ((document.getElementById(Main).style.height.replace('px','') / 2) - oGrid.style.top.replace('px','')), ti, Grid, GetYearsCallBack, OnFailedDoNothing);
    }
    else
    {
        setTimeout("UpdateYearsList(" + force + ")",500);
    }
}

function GetYearsCallBack(result, userContext, methodName) {
  	var CreatedNode;
    var ti = document.getElementById(t).value;
  	if (result != '') {
  	    var resultArray = result.split('|');
  	    var ProceedWithYears = false;
  	    // check first to see if the years are different...if they are not, don't bother
        var MainYearTable = document.getElementById(YearsPanel).getElementsByTagName('table');
  	    if (MainYearTable.length > 0 && ForceYearsUpdate == false) {
            var tables = MainYearTable[0].getElementsByTagName('table')
            var YearText = '';
  	        if (resultArray[2] == tables.length) {
  	            for (TableIndex = 0; TableIndex < tables.length; TableIndex++) {
  	                YearText = GetInnerText(tables[TableIndex].rows[0].cells[0]);
  	                if (resultArray[1].indexOf(YearText) <= 0) {
  	                    ProceedWithYears = true;
  	                }
  	            }
  	        }
  	        else
  	        {
  	            ProceedWithYears = true;
  	        }
        }
        else
        {
            ProceedWithYears = true;
        }
  	    if (ProceedWithYears) {
      	    document.getElementById(YearsPanel).innerHTML = '';
  	        if (resultArray[0] == ti && resultArray.length > 1) {
  	            document.getElementById(YearsPanel).innerHTML = resultArray[1];
  	            MoveInYears();
      	    }
      	}
      	// this will update the county location and other things such as scale
      	GetInfo();
  	}
}

function MoveInYears() {

    //document.getElementById(YearsPanel).style.left = '1px';
    return;
    
    var Years = document.getElementById(YearsPanel).getElementsByTagName('table')[0].getElementsByTagName('table');
    if (Years.length > 0) {
        if (NoAnimation) {
            // if we are skipping animation, then it doesn't matter, go ahead and show
            for (X = 0; X < Years.length; X++) {
                Years[X].style.left = '1px';
            }
        }
        // if we have loaded at least half of the images
        else if ((document.getElementById(ProgressMeterWidth).style.width.replace('%','')-0) > 80) {
            for (X = 0; X < Years.length; X++) {
                if ((Years[X].style.left.replace('px','') - 0) >= 10 && (Years[X].style.left.replace('px','') - 0) != 1) {
                    Years[X].style.left = (Years[X].style.left.replace('px','') - 10) + 'px';
                    setTimeout("MoveInYears()",10);
                    return true;
                }
                else
                {
                    Years[X].style.left = '1px';
                }
            }
        }
        else
        {
            setTimeout("MoveInYears()",500);
        }
    }
    
}

function GetInfo() {
    var ti = document.getElementById(t).value;
    AsyncWeb.GetInfo(ti, GetInfoCallBack, OnFailedDoNothing);
}

function GetInfoCallBack(result, userContext, methodName) {
    var ti = document.getElementById(t).value;
  	if (result != '') {
  	    var resultArray = result.split('|');
  	    if (resultArray[0] == ti) {
  	        if (resultArray.length >= 2) {
                CountyLocation = resultArray[1];  	 
                if (document.getElementById(ProgressMeterWidth).style.width == '100%') {
                    document.getElementById(ProgressMeterWidth).rows[0].cells[0].innerHTML = 'Loaded - ' + CountyLocation;
                }   
            }
  	        if (resultArray.length >= 3) {
                document.getElementById(CurrentScale).innerHTML = resultArray[2];
            }
  	        if (resultArray.length >= 4) {
                document.getElementById(Source).innerHTML = resultArray[3];
            }
  	    }
  	}
}

// Gets the progress of a currently processing request
function GetMostRecentUserView(ActionID, IPAddress)
{
    AsyncWeb.GetMostRecentUserView(ActionID, IPAddress, UpdateMostRecentUserView, OnFailedDoNothing);
}

// Gets the progress of a currently processing request
function GetProgress(SessionID)
{
    AsyncWeb.GetProgress(SessionID, OnSucceededWithContext, OnFailed);
}

// Gets the progress of a currently processing request
function GetAddressPoint(Address)
{
    AsyncWeb.GetProgress(SessionID, OnSucceededWithContext, OnFailed);
}

function OnSucceededWithContext(result, userContext, methodName)
{
	// Page element to display the feedback message.    
    var RsltElem = 
        document.getElementById(ProgressLabel);
    
  	RsltElem.innerHTML =  result;
 	
}

function OnFailed(error)
{
    // Display the error.    
    var RsltElem = 
        document.getElementById(ProgressLabel);
    RsltElem.innerHTML = 
        "Service Error: " + error.get_message();
}

function OnFailedDoNothing(error)
{
    // This is an error handler for things that are honestly not important
    // enough to report, for example if the user previews cannot be updated
    window.status = 'Error' + error.get_message();   
}

function UpdateMostRecentUserView(result, userContext, methodName)
{
	// Page element to display the feedback message.    
  	// alert(result);
  	if (result != '') {
  	    // let's update the most recent user view
  	    var items;
  	    items = result.split('|');
  	    var ActionID = items[0];
  	    var Year = items[1];
  	    var PreviewLocation = items[2];
  	    var Link = items[3];
  	    var o = new Image();
  	    o.src = '/preview.aspx?ActionID=' + ActionID;
  	    
  	    if (document.getElementById(PreviewImage).filters) document.getElementById(PreviewImage).filters.blendTrans.Apply();
  	    document.getElementById(PreviewImage).src = '/preview.aspx?ActionID=' + ActionID;
  	    if (document.getElementById(PreviewImage).filters) document.getElementById(PreviewImage).filters.blendTrans.Play();
  	    SetInnerText(document.getElementById(PreviewYear), Year);
  	    SetInnerText(document.getElementById(PreviewCountyLocation), PreviewLocation);
        document.getElementById(PreviewIDs).value = ActionID;
        if (PreviewLink) document.getElementById(PreviewLink).href = Link;
  	}
}

function FindPoint()
{
    document.getElementById(spinningGlobe).style.display = '';
    document.getElementById(LocatePointPostbackRow).style.display = 'none';
}

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();





















