﻿// JScript File
var QueryText= new Array();
QueryText[0] = "";
QueryText[1] = "";
var ProcessQuery = false;
var selected6thField;
var add6thWatershed = false;
//var sType;
var FamilySource;
var Text;
var isQuery = false;
var AlternateName;
var QuerySciName;
var PushPinShape = null;
var InnerHTML= '';
var placeID = 0;
var PlaceInfo = '';
var Description = '';
var QueryText;
var shapeID = 0;
var ReferenceTab = "";
var divSelectPlacesDefaultText = '<input type="text" value="No places selected" style="font-size: 10px; color: Gray; width: 200px;" />';
var PolyShape = 0;
var isLayer = false;
var Count = 0;
var PlaceBin = new Array();
//var TractID = "";
var STFID = " ";
var PartOf = " ";
var Contains = " ";
var QueryResultPlaceBinArray = new Array();
var InfoQueryAddedShapes = new Array();
var InfoQueryDisplayInfo = new Array();
var divQueryResultsScript = "";


function goToSelection(source, eventArgs)
{
    isLoadingPlaceToBin = true;
    if (source != null)
    {
        if (!infoBtnStatus)
        {
            var divLoadingPlaceBin = $get('divLoadingPlaceBin');
            divLoadingPlaceBin.style.display = 'block';  
        }  
        else //clear info layers
        {
            deleteInfoLayers();                
            PlaceShapeInfoOnlyTEMPLayer.DeleteAllShapes();
            QueryResultPlaceBinArray.clear();
            var divQueryResultsDisplay = $get('divQueryResultsDisplay');
            divQueryResultsDisplay.innerHTML = "";
            divQueryResultsScript = "";
            //InfoQueryDisplayInfo.clear();
        }
        var Value = "";
        var ValueArray= "";
        var geoType = "";    
        if (eventArgs != null || source != null)
        {
            if (eventArgs == null && source.length > 0)
            {                
                for (var i=0;i<source.length;i++)//process for onclick
                {
                    if (source[i][0] != undefined && source[i][0] != "{")
                    {
                    Value = source[i][0];
                    }
                    else if (source[i] != undefined)
                    {
                    Value = source[i];
                    }
                    if (Browser == "Netscape")//MOZILLA
                    {
                        var rbtnCommunites = $get('rbtnCommunites');
                        if (rbtnCommunites.checked)
                        {
                        geoType = Value.split(/\:/)[3].split(";")[1];
                        }
                        else
                        {
                        geoType = Value.split(/\:/)[2].split(";")[1];
                        }
                        ValueArray = Value.split(/\,/)[1].split(/\"/)[3].split(/\;/)[0];
                        QueryText = Value.split(/\:/)[1].split(/\"/)[1];
                        
                    }
                    else//IE
                    {
                        ValueArray = Value.split(/\,/)[1].split(/\"/)[2].split(/\;/)[0];
                        QueryText = Value.split(/\:/)[1].split(/\,/)[0].split(/\"/)[0];
                        geoType = Value.split(/\;/)[1];
                    }                  
                    SendDrawRequest(ValueArray,QueryText,geoType);
                }//end for loop    
            }        
            else if(eventArgs != null)                //process for autocomplete
            {
                Value = eventArgs.get_value();
                ValueArray = Value.split(/\;/);
                QueryText = eventArgs.get_text();    
                geoType = ValueArray[1];
                ValueArray = Value.split(/\;/)[0];
                SendDrawRequest(ValueArray,QueryText,geoType);
            }
            else
            {
                //turn off loading indicator
                var divLoadingPlaceBin = $get('divLoadingPlaceBin');
                divLoadingPlaceBin.style.display = 'block';
                divLoadingPlaceBin.innerHTML = 'No results found for area selected';
                setTimeout(resetLoadingDiv,5000);                 
            }
        } 
    }          
    else//
    {
        if (infoBtnStatus)
        {
            var divQueryResults = $get('divQueryResults');
            var divQueryResultsDisplay = $get('divQueryResultsDisplay');                
            divQueryResultsDisplay.innerHTML = '<div align=center><span style="display:block">No data available for selected place.</div>';
        }
        else
        {   
            var divLoadingPlaceBin = $get('divLoadingPlaceBin');
            divLoadingPlaceBin.style.display = 'block';
            divLoadingPlaceBin.innerHTML = 'No results found for area selected';
            setTimeout(resetLoadingDiv,5000);  
        }
    }
}

function SendDrawRequest(ValueArray,QueryText,geoType)
{
    var ParamGeoType = {"GeoType": geoType};
        if (geoType == "Communities")
        {
            var CommunityInfo = ValueArray.split(/\:/);
            ReferenceTab = CommunityInfo[0];
            var PlaceType = CommunityInfo[1];           
            var ParamQueryText = {"QueryText": QueryText};   
            var ParamReferenceTab = {"Reference": ReferenceTab};
            var ParamPlaceType = {"PlaceType": PlaceType};                      
            if (infoBtnStatus)
            {
             InfoQueryDisplayInfo.push(QueryText+";"+ReferenceTab+";"+PlaceType);
            }
            WebServices.GetFeatureWebService.GetFeatureCommunity(ParamGeoType.GeoType, ParamQueryText.QueryText, ParamReferenceTab.Reference, ParamPlaceType.PlaceType, OnSucceededCommunity, OnFailedCommunity);            
            
        }
        else //geoType = "Counties"
        {
            var ParamGeoType = {"GeoType": geoType};
             var ParamQueryText = {"QueryText": QueryText};                    
            WebServices.GetFeatureWebService.GetFeatureCounty(ParamGeoType.GeoType, ParamQueryText.QueryText, OnSucceededCounty, OnFailedCounty); 
        }
}

function OnSucceededCommunity(result)
{
    var isTract, isPlace, isCity = "";   
    var isInfoOnly = false; 
    if (result != null){
    var polyRings = result.getElementsByTagName("RING").length;    
    for (var h=polyRings-1; h > -1; h--)
    {
        PolyShape = h;
        Count++;
        var isLast = false;
        var PolyCoords = result.getElementsByTagName("RING")[h].text;
        var Points = PolyCoords.split(/\;/);
        var polyPoints = new Array();
        var LatLong = new Array();
        for (var i=0; i< Points.length; i++)
        {
            LatLong = Points[i].split(/\ /);
            LatLong[1] = parseFloat(LatLong[1]);
            LatLong[0] = parseFloat(LatLong[0]);
            polyPoints.push(new VELatLong(LatLong[1],LatLong[0]));
        }
        try{isTract = result.getElementsByTagName("FIELDS")[0].getAttribute("SDE.SDE.OREGON_2000CENSUSTRACTS_WGS84.ID");if (isTract != null){setDescriptionTract(result);}}catch(e){}       
        try{isPlace = result.getElementsByTagName("FIELDS")[0].getAttribute("SDE.SDE.OREGON_2000CENSUSPLACES_WGS84.NAME"); if (isPlace != null){setDescriptionPlace(result);}}catch(e){}
        try{isCity = result.getElementsByTagName("FIELDS")[0].getAttribute("SDE.SDE.ORE_CITYLIMITS_2005_WGS84.CITY_NAME"); if (isCity != null){setDescriptionCity(result)}}catch(e){}
        var ReferenceTabTrans = referenceTabTranslation(ReferenceTab);
        var CommunityTitle = QueryText + '  <br><span style="font-size:10px; display:block; text-indent:10px; padding-top:5px;">(' + ReferenceTabTrans + ')</span>';
        if (h == 0)
        {
        isLast = true;
        }
        if (infoBtnStatus)
        {
        isInfoOnly = true;
        }
        AddFeaturePoly(polyPoints, CommunityTitle, Description, isLast, isInfoOnly)
        }
    }   
}

function OnFailedCommunity(result)
{
//    var divLoadingPlaceBin = $get('divLoadingPlaceBin');
//    divLoadingPlaceBin.innerHTML = 'No results found for area selected';
//    setTimeout(resetLoadingDiv(),5);      
}

function resetLoadingDiv()
{   
    var divLoadingPlaceBin = $get('divLoadingPlaceBin');
    divLoadingPlaceBin.style.display = 'none';  
    divLoadingPlaceBin.innerHTML = 'Loading...';
}

function OnSucceededCounty(result)
{
    if (result != null)
    {
    var isInfoOnly = false; 
    var polyRings = result.getElementsByTagName("RING").length;
    for (var h=polyRings-1; h > -1; h--)
    {
        var PolyCoords = result.getElementsByTagName("RING")[h].text;
        var Points = PolyCoords.split(/\;/);
        var polyPoints = new Array();
        var LatLong = new Array();
        for (var i=0; i< Points.length; i++)
        {
            LatLong = Points[i].split(/\ /);
            LatLong[1] = parseFloat(LatLong[1]);
            LatLong[0] = parseFloat(LatLong[0]);
            polyPoints.push(new VELatLong(LatLong[1],LatLong[0]));
        }
        var title = QueryText + ' County';
        var sDescription = '';
        ReferenceTab = "County";
        if (infoBtnStatus)
        {
        isInfoOnly = true;
        }
        AddFeaturePoly(polyPoints, title, sDescription, true, isInfoOnly)        
        }
    }
}
function OnFailedCounty(result)
{
}
function setDescriptionTract(result)
{
    ReferenceTab = "Census Tracts 2000";
    //QueryText =
    var County = result.getElementsByTagName("FIELDS")[0].getAttribute("SDE.SDE.OREGON_2000CENSUSTRACTS_WGS84.COUNTY");    
    Contains = result.getElementsByTagName("FIELDS")[0].getAttribute("SDE.SDE.OREGON_2000CENSUSTRACTS_WGS84.INCLUDES");
    PartOf = result.getElementsByTagName("FIELDS")[0].getAttribute("SDE.SDE.OREGON_2000CENSUSTRACTS_WGS84.PARTOF");
    TractID = result.getElementsByTagName("FIELDS")[0].getAttribute("SDE.SDE.OREGON_2000CENSUSTRACTS_WGS84.TRACTID");
    STFID = result.getElementsByTagName("FIELDS")[0].getAttribute("SDE.SDE.OREGON_2000CENSUSTRACTS_WGS84.STFID");
    if (infoBtnStatus)
    {
     QueryText = "Census Tract "+TractID+ "  ("+County+" County)";
    }
    Description = "<table>";
    if (TractID != "")
    {Description += "<tr><td>Tract ID:  "+TractID+"</td></tr>";} 
    if (Contains == "")
    {Contains = " ";}    
    else if (Contains != " ")
    {Description += "<tr><td>Contains:  "+Contains+"</td></tr>";}     
    if (PartOf =="")
    {PartOf = " ";}
    else if (PartOf != " ")
    {Description += "<tr><td>Part of:  "+PartOf+"</td></tr>";}     
    Description += "</table>";
    //Contains = '';
    //PartOf = '';
}

function setDescriptionPlace(result)
{
    Description = ""; 
    ReferenceTab = "Census Desig Places 2000";  
    QueryText = result.getElementsByTagName("FIELDS")[0].getAttribute("SDE.SDE.OREGON_2000CENSUSPLACES_WGS84.NAME"); 
}
function setDescriptionCity(result)
{
    Description = "";  
    ReferenceTab = "Incoporated Cities 2005";  
    QueryText = result.getElementsByTagName("FIELDS")[0].getAttribute("SDE.SDE.ORE_CITYLIMITS_2005_WGS84.CITY_NAME"); 
}

function setPolyLayer(QueryTextNoSpace)
{
    var PolygonLayersCache = $get('PolygonLayersCache');
    var PolygonLayersCacheInnerHTML = PolygonLayersCache.innerHTML;   
    PolygonLayersCacheInnerHTML += '<div id="'+QueryTextNoSpace+'Layer"></div>'; 
    PolygonLayersCache.innerHTML = PolygonLayersCacheInnerHTML;
    var shapeLayer =  QueryTextNoSpace+'Layer'; 
    var shapeLayer = $get(shapeLayer); 
    shapeLayer.innerHTML = "";
}
function AddFeaturePoly(polyPoints, title, sDescription, isLast, isInfoOnly)
           {     
            shape = new VEShape(VEShapeType.Polygon, polyPoints);
            var PlaceInfoAdd = '';
            var QueryTextNoSpace = QueryText.toString().replace(/\ /g,"");
            var divQueryResultsBackgroundColor = 'white';
            var divQueryResultsBorderColor = 'blue';     
            var divQueryResultsFontColor = 'black'; 
            var zIndex = '1000';
            if (isInfoOnly)
            {           
            switch (ReferenceTab)
                {
                    case "Census Tracts 2000":         
                        divQueryResultsBackgroundColor = '#91B3CF';
                        divQueryResultsBorderColor = 'black';       
                        shape.SetLineColor(new VEColor(145,179,207,1.0));
                        shape.SetFillColor(new VEColor(145,179,207,0.3));
                        zIndex =1000;
                        break;
                    case "Census Desig Places 2000":
                    case "Incorporated Cities 2005":
                        shape.SetLineColor(new VEColor(91,112,130,1.0));
                        shape.SetFillColor(new VEColor(91,112,130,0.3));
                        zIndex =5000;
                        divQueryResultsBackgroundColor = '#5B7082';
                        divQueryResultsBorderColor = 'black';
                        divQueryResultsFontColor = 'white';
                        break;
                    case "County": 
                    default:
                        shape.SetLineColor(new VEColor(207,193,145,1.0));
                        shape.SetFillColor(new VEColor(207,193,145,0.3));
                        divQueryResultsBackgroundColor = '#CFC191';
                        divQueryResultsBorderColor = 'black';
                        divQueryResultsFontColor = 'white';
                        zIndex =500;
                        break;
                    } 
                } 
                     
            if (!isLast)            
                {            
                if (PolyShape >=1 && Count == 1)
                {             
                setPolyLayer(QueryTextNoSpace); 
                isLayer = true;          
                }          
                var shapeLayer =  QueryTextNoSpace+'Layer'; 
                var shapeLayer = $get(shapeLayer); 
                var shapeLayerinnerHTML = shapeLayer.innerHTML;
                
                shape.SetCustomIcon("<div></div>");          
                shape.SetTitle('');
                shape.SetDescription('');            
                shape.SetLineWidth(3);                      
                if (!isInfoOnly)
                {
                shape.SetLineColor(new VEColor(0,150,100,1.0));
                shape.SetFillColor(new VEColor(0,150,100,0.5)); 
                }
                if (isInfoOnly)
                {
                PlaceShapeInfoOnlyTEMPLayer.AddShape(shape);
                }   
                else
                {
                map.AddShape(shape);  
                }                                             
                var shapeVEID = shape.GetID();                 
                shapeLayerinnerHTML += QueryTextNoSpace+','+shapeVEID+';';
                shapeLayer.innerHTML = shapeLayerinnerHTML;               
                }            
            else //Last
                {                            
                if (isInfoOnly)
                {                          
                icon = '<img src="img/info.gif"/>';                                  
                }              
                else
                {
                //turn off loading indicator
                var divLoadingPlaceBin = $get('divLoadingPlaceBin');
                divLoadingPlaceBin.style.display = 'none';
                shapeID ++; 
                icon = "<div class='pinStyle1'><div class='text'>"+shapeID+"</div></div>";
                shape.SetLineColor(new VEColor(0,150,100,1.0));
                shape.SetFillColor(new VEColor(0,150,100,0.5));
                }
                shape.SetCustomIcon(icon);          
                shape.SetTitle(title);
                shape.SetDescription(sDescription);            
                shape.SetLineWidth(3);                      
                var IDtoShowInBin = "";                                 
                if (ReferenceTab == "")
                {
                    ReferenceTab = '&nbsp;'
                } 
                if (Count > 1)
                {
                isLayer = true;
                }              
                else
                {
                isLayer = false;
                }         
                var shapeVEID = '';
                if (!isInfoOnly)
                { 
                PlacesShapeLayer.AddShape(shape);
                IDtoShowInBin = shapeID;
                }
                else
                {
                IDtoShowInBin = "~";       
                PlaceShapeInfoOnlyLayer.AddShape(shape);                 
                }
                var shapeVEID = shape.GetID();   
                if (isInfoOnly)
                {
                    var divQueryID = 'div'+QueryTextNoSpace+'ID';
                    sDescription += "<input type=button value=\"Add to selected place(s)\" onclick=\"addQueryResultToBin('"+shapeVEID+"',"+QueryResultPlaceBinArray.length+",'"+divQueryID+"')\" style=\"font-size:10px\"/>";
                    shape.SetDescription(sDescription);
                }
                             
            var ReferenceTabTrans = referenceTabTranslation(ReferenceTab);
            PlaceInfoAdd = '<tr id=tr'+shapeVEID+' class="trTaxLot"><td style="border-bottom:solid 0px #a7a7a7; border-left:solid 1px #a4412e; padding-left:5px; padding-top:5px;"><img src="img/listicon.gif"/></td>';
            PlaceInfoAdd += '<td style="font-size:10px; padding-top:3px;"><div class="pinStyle2"><div class="text">'+IDtoShowInBin+'</div></div></td>';
            PlaceInfoAdd += '<td width="150px" style="border-bottom:solid 0px #a7a7a7; font-size:10px; padding-top:3px; padding-left:5px;"><a href="javascript:void(0);" class=aTaxLot onclick="zoomToPlace(\''+shapeVEID+'\',\''+isInfoOnly+'\');"><b>'+QueryText+'</b></a><span style="padding-left:3px; padding-bottom:3px; font-size:9px; line-height:10px; color:gray; display:block">('+ReferenceTabTrans+')<span></td>';                
            PlaceInfoAdd += '<td style="padding-right:5px; border-right:solid 1px #a4412e; padding-top:2px; padding-bottom:2px;"><input type="button" style="width:18px; background-color:#a4412e; color:white; font-weight:bold; font-size:10px;" value="x" onclick="deletePlaceShape(\''+shapeVEID+'\',\''+isLayer+'\',\''+QueryTextNoSpace+'\',\''+isInfoOnly+'\')"/></td></tr>';                         
            
            var PlaceBinInfo = QueryText+'~'+ReferenceTab+','+STFID+','+Contains+','+PartOf+','+isLayer+','+QueryTextNoSpace;
                    if (!isInfoOnly)
                {
                    PlaceInfo = PlaceInfoAdd;                                                                    
                    PlaceBin.push(PlaceBinInfo); 
                    AddPlaceToBin(PlaceInfoAdd);                    
                    if (QueryText == "Portland")
                    {
                    map.Find(null,"Portland");
                    }
                    else
                    {
                    map.SetMapView(polyPoints);
                    }                                          
                    map.ShowInfoBox(shape);   
                }
                else //is infoquery
                {                
                var divQueryResults = $get('divQueryResults');
                var divQueryResultsDisplay = $get('divQueryResultsDisplay');
                
                divQueryResults.style.display = "block";
                var divQueryResultsScript = "<div id="+divQueryID+" style=\"border:solid 1px "+divQueryResultsBorderColor+"; background-color:"+divQueryResultsBackgroundColor+"; color:"+divQueryResultsFontColor+"; margin-top:10px\"><div style=\"padding:5px\">";                
                divQueryResultsScript += '<span style=\"display:block"><b>'+title +'</b></span>'+ sDescription;                
                QueryResultPlaceBinArray.push(PlaceInfoAdd);
                QueryResultPlaceBinArray.push(PlaceBinInfo);
                //divQueryResultsScript += "<input type=button value=\"Add to selected place(s)\" onclick=\"addQueryResultToBin('"+shapeVEID+"')\" style=\"font-size:10px\"/>";
                divQueryResultsScript += "</div></div>";
                if (ReferenceTab == "Census Desig Places 2000" || ReferenceTab == "Incorporated Cities 2005")
                {
                divQueryResultsDisplay.innerHTML = divQueryResultsScript + divQueryResultsDisplay.innerHTML;
                }
                else
                {
                divQueryResultsDisplay.innerHTML += divQueryResultsScript; 
                }
                }
                PolyShape = 0;    
                Count = 0;       
                STFID = ' ';                                                                 
                Contains = ' ';
                PartOf = ' ';
                Description = " ";
                isLoadingPlaceToBin = false;
                } 
                shape.SetZIndex(zIndex);
                //shape.Redraw(true,true,true,true);                               
         }

function referenceTabTranslation(rTab)
{
    switch (rTab)
    {
    case "Incorporated Cities 2005":
    case "Census Desig Places 2000":
        rTab = "Census Designated Place";
        break;
    case "Census Tracts 2000":
        rTab = "Census Tract 2000";
        break;
    default:
        break;        
    }
    return rTab;
}
function addQueryResultToBin(shapeVEID,index,divQueryID)
{
    if (QueryResultPlaceBinArray.length<=index)
    {
    index = 0;
    }
    shapeID ++;
    divQueryID = $get(divQueryID);
    divQueryID.style.display = 'none';
    PlaceInfo = QueryResultPlaceBinArray[index].toString().replace(/\~/,shapeID);    
    var QueryPlaceBinInfo = QueryResultPlaceBinArray[index+1];
           
    var isLayer = QueryPlaceBinInfo.split(',')[4];
    var QueryTextNoSpace = QueryPlaceBinInfo.split(',')[5];
    if (isLayer == "true")
    {
        var shapeLayer =  QueryTextNoSpace+'Layer'; 
        shapeLayer = $get(shapeLayer); 
        var shapeLayerShapeVEID = shapeLayer.innerHTML.split(';');  
        for (var r=0;r<shapeLayerShapeVEID.length-1;r++)
        {            
            var SubShape = map.GetShapeByID(shapeLayerShapeVEID[r].split(',')[1]); 
            SubShape.SetLineColor(new VEColor(0,150,100,1.0));
            SubShape.SetFillColor(new VEColor(0,150,100,0.5)); 
        }  
    }
    
    var shape = PlaceShapeInfoOnlyLayer.GetShapeByID(shapeVEID);    
    InfoQueryAddedShapes.push(shapeVEID);       
    var icon = "<div class='pinStyle1'><div class='text'>"+shapeID+"</div></div>";
    shape.SetLineColor(new VEColor(0,150,100,1.0));
    shape.SetFillColor(new VEColor(0,150,100,0.5)); 
    shape.SetCustomIcon(icon);                         
    PlaceBin.push(QueryPlaceBinInfo);   
    var TempSlice = QueryResultPlaceBinArray.splice(index,2);
    //QueryResultPlaceBinArray =    TempSlice;             
    AddPlaceToBin(QueryPlaceBinInfo); 
    if (QueryResultPlaceBinArray.length == 0)
    {  
    var divQueryResults = $get('divQueryResults');
    divQueryResults.style.display = "none";  
    }                           
//    }
//    else
//    {
//    PlaceBin.pop();
//    }
}
function AddPlaceToBin(QueryText,ReferenceTab)
{
    var divPlaceBin = $get('divPlaceBin');
    if (shapeID == 1)
    {
    InnerHTML += '<TABLE cellpadding=0 cellspacing=0 style="margin-top:5px; font-size:10px; border:solid 1px #a4412e;">';    
    //InnerHTML += '<tr><td style="border-bottom:solid 2px #a4412e;" colspan=2>&nbsp;</td><td style="border-bottom:solid 2px #a4412e;">Place(s)</td><td style="border-bottom:solid 2px #a4412e;">&nbsp;</td></tr>';
    }
    else
    {
    //NEED both for ie/mozilla issues
    InnerHTML = divPlaceBin.innerHTML.replace("</TBODY></TABLE>","");
    InnerHTML = InnerHTML.replace("</table>","");
    }    
    InnerHTML += PlaceInfo;       
    InnerHTML += '</TABLE>';
    divPlaceBin.innerHTML = InnerHTML;
    var divClear = $get('divClear');
    if (shapeID > 0)
    {    
    divClear.style.display = 'block';    
    }
    else
    {
    divClear.style.display = 'none'; 
    }   
    if (shapeID > 1)
    {
    var divCombine = $get('divCombine');
    divCombine.style.display = "block";
    var divCompare = $get('divCompare');
    divCompare.style.display = "block";
    }
}

function deleteInfoLayers()
{
    if (InfoQueryAddedShapes.length > 0)
    {
        for (var r=0;r<PlaceShapeInfoOnlyLayer.GetShapeCount();r++)
        {
            var idCheck = PlaceShapeInfoOnlyLayer.GetShapeByIndex(r).GetID();
            var isDeleteable = false;
            if (!InfoQueryAddedShapes.find(idCheck))
            {
            var ShapetoDelete = PlaceShapeInfoOnlyLayer.GetShapeByID(idCheck);
            PlaceShapeInfoOnlyLayer.DeleteShape(ShapetoDelete);
            }            
        }
    }           
    else
    {     
    PlaceShapeInfoOnlyLayer.DeleteAllShapes();
    }
}

function zoomToPlace(shapeVEID, isInfoOnly)
{
    var ShapeToZoom = "";
    if (isInfoOnly == "true")
    {
    ShapeToZoom = PlaceShapeInfoOnlyLayer.GetShapeByID(shapeVEID);
    }
    else
    {
    ShapeToZoom = PlacesShapeLayer.GetShapeByID(shapeVEID);
    }
    var ShapePoints = ShapeToZoom.GetPoints();
    map.SetMapView(ShapePoints);
    var zoomLevel = map.GetZoomLevel();
    if (zoomLevel >13)
    {
        zoomLevel = 13;
    }
    map.SetZoomLevel = zoomLevel;
}

function deletePlaceShape(shapeVEID, isLayer, LayerName, isInfoOnly)
{
    try
    {
    shapeID--;
    if (isLayer == "true")
    {
     var shapeLayerDiv = LayerName+'Layer';
     shapeLayerDiv = $get(shapeLayerDiv);
     var shapeLayerDivHTML = shapeLayerDiv.innerHTML;
     shapeLayerShapes = shapeLayerDivHTML.split(/\;/);
     //delete all of the shapes except the top from a layer.  Corvallis has five polys, this will delete 4.
     for (var i= 0; i< shapeLayerShapes.length;i++)
     {
     var shapeLayerVEID = shapeLayerShapes[i].split(/\,/);
     shapeLayerVEID = shapeLayerVEID[1];
     shapeToDelete = map.GetShapeByID(shapeLayerVEID);
     try{map.DeleteShape(shapeToDelete);}catch(ex){}
     }
     //clear the layer from the polylayercache div via shapelayerdiv parent call.
     shapeLayerDiv.innerHTML = '';
     shapeLayerDiv.parentElement.innerHTML = shapeLayerDiv.parentElement.innerHTML.replace("<DIV id="+LayerName+"Layer>&nbsp;</DIV>","");
     //shapeLayerDiv;
    }
    //Clear from display bin
    var trShapeVEID = 'tr'+shapeVEID; 
    trshapeVEID = $get(trShapeVEID);    
    trshapeVEID.style.display = 'none';  
    //  
    var ShapeToDelete = "";
    var ShapeLayerCount = "";
    //Delete the last polygon of layer, or the only polygon.
    if (isInfoOnly == "false")
    {
    ShapeToDelete = PlacesShapeLayer.GetShapeByID(shapeVEID);
    ShapeLayerCount = PlacesShapeLayer.GetShapeCount();
    }
    else
    {
    ShapeToDelete = PlaceShapeInfoOnlyLayer.GetShapeByID(shapeVEID);
    ShapeLayerCount = PlaceShapeInfoOnlyLayer.GetShapeCount();
    for (var x=0;x<InfoQueryAddedShapes.length;x++)
    {
        if (InfoQueryAddedShapes[x] == shapeVEID)
        {
            InfoQueryAddedShapes.splice(x,1);
        }
    }    
    }
    var shapeToDeleteDesc = ShapeToDelete.Notes.replace("<table id=\"PopUpTable\"><tr><td class=\"PopUpDataTitle\">Tax Lot ID:</td><td class=\"PopUpData\">","").replace("</td><tr></table>","");
    ShapeToDelete.Update();
    var ShapeIndex = ShapeToDelete.GetIndex();
    PlaceBin.splice(ShapeIndex,1);    
    var indexToDelete;
    for (var i=0; i < ShapeLayerCount; i++)
    {
        var shape = "";
        if (isInfoOnly == "false")
        {
        shape = PlacesShapeLayer.GetShapeByIndex(i);
        }
        else
        {
        shape = PlaceShapeInfoOnlyLayer.GetShapeByIndex(i);
        }        
        var shapeDesc = shape.GetDescription();
        if (shapeDesc.match(shapeToDeleteDesc))
        {
        indexToDelete = i;
        }
    }
    var ShapeCount = "";
    if (isInfoOnly == "false")
    {
    PlacesShapeLayer.DeleteShape(ShapeToDelete);        
    }
    else
    {
    PlaceShapeInfoOnlyLayer.DeleteShape(ShapeToDelete);         
    }  
    ShapeCount = PlacesShapeLayer.GetShapeCount() + PlaceShapeInfoOnlyLayer.GetShapeCount();  
    if (ShapeCount == 0)
    {
    var PlaceListDiv = $get('divPlaceBin'); 
    PlaceListDiv.innerHTML = divSelectPlacesDefaultText;    
    InnerHTML = '';
    var divClear = $get('divClear');    
    divClear.style.display = 'none';     
    shapeID = 0;     
    hideCombineCompare();
    }
    if (ShapeCount == 1)
    {
    hideCombineCompare();
    }
    }
    catch(ex)
    {
    var test = ex;
    }
}

function hideCombineCompare()
{
    var divCombine = $get('divCombine');
    divCombine.style.display = "none";
    var divCompare = $get('divCompare');
    divCompare.style.display = "none";
}

function clearAllPlaceShapes()
{
PlacesShapeLayer.DeleteAllShapes();
deleteInfoLayers();                
PlaceShapeInfoOnlyTEMPLayer.DeleteAllShapes();
QueryResultPlaceBinArray.clear();
var divQueryResultsDisplay = $get('divQueryResultsDisplay');
divQueryResultsDisplay.innerHTML = "";
divQueryResultsScript = "";
PlaceShapeInfoOnlyLayer.DeleteAllShapes();
InfoQueryAddedShapes.clear();
PlaceBin.clear();
shapeID = 0;
var PolygonLayersCache = $get('PolygonLayersCache');
var PolyLayersCacheChildren = PolygonLayersCache.childNodes.length;
for (var i=0;i<PolyLayersCacheChildren;i++)
{
    var ChildNode = PolygonLayersCache.childNodes[i];//breaking in mozilla
    var shapeLayerDivHTML = ChildNode.innerHTML;
     shapeLayerShapes = shapeLayerDivHTML.split(/\;/);
     for (var h= 0; h< shapeLayerShapes.length;h++)
     {
     var shapeLayerVEID = shapeLayerShapes[h].split(/\,/);
     shapeLayerVEID = shapeLayerVEID[1];
     shapeToDelete = map.GetShapeByID(shapeLayerVEID);
     try{map.DeleteShape(shapeToDelete);}
     catch(ex)
     {
     var test = "";
     }
     }   
     var test = "";
}
PolygonLayersCache.innerHTML = "";
var PlaceListDiv = $get('divPlaceBin'); 
PlaceListDiv.innerHTML = divSelectPlacesDefaultText;
InnerHTML = '';
var divClear = $get('divClear'); 
divClear.style.display = 'none';
hideCombineCompare();
}