﻿//global varialble to parcel results
var parcelResults;          //results from the search - JSON object
var parcelResultsCount;     //number of parcel records returned from the search
var parcelIDSearched;       //parcel ID that has been searched
var parcelMapID;            //parcel mapID from the mapLayers variable in js_Themes.js
var parcelMapServiceName;   //parcel map service name
var parcelLayerName;        //parcel layer name in the MXD document
var parcelLayerSearchField; //field to search for parcel ID
var parcelLayerID = -1;     //id for the parcel layer in the map service (not the map document)
var parcelLayerQueryField;  //field in the parcel layer used for queries - different from
                            //parcelLayerSearchField because it must be fully qualified
                            //(e.g. KGIS.CAD_Parcels_KNO.PARCELID)
var zoomToParcels = true;   //flag used to determine when the highlight routine should zoom to parcels
                            //this is mostly used to disable zooming when the user simply identifies
                            //a parcel on the map - this keeps the extents from changing

//function used to setup parcel layer information
//for searching and locating - MUST be done before
//any parcels can be located on the map
function setParcelInfo (mapID, layerName) {
    //mapID from the mapLayers variable in js_Themes.js
    parcelMapID = mapID;
    
    //parcel layer name in the MXD document
    parcelLayerName = layerName;
    
    //field name that contains the parcel ID
    parcelLayerSearchField = "KGIS.CAD_Parcels_KNO.PARCELID";
    //parcelLayerSearchField = "PARCELID";
    
    //loop through the maplayers and set the service name
    for (i=0, lCount=mapLayers.length; i<lCount; i++) {
        var thisLayer = mapLayers[i];
        var layer;
                
        //get the mapservice name and concatinate with the base url
        if (thisLayer.mapID.toUpperCase() == mapID.toUpperCase()) {
            parcelMapServiceName = baseMapServiceURL + thisLayer.mapService;
        }        
    }
}

//  findParcel function will search for the incoming parcel id.
//  This function will use the map service and attempt to find
//  an exact match.  If an exact match isn't found then switch
//  to a database query to avoid long delays for searches that
//  return a large number of records - e.g. parcelid like '048D%'
function findParcel_old(parcelID, findExactMatch) {
    //debugger;
    //create find task with url to map service
    var findParcelTask = new esri.tasks.FindTask(parcelMapServiceName);

    //get parcel layer id from list of layers
    var parcelLayerID = getLayerIDFromMapDoc(parcelMapID, parcelLayerName);

    //create find parameters and define known values
    findParams = new esri.tasks.FindParameters();
    //contains property does a substring match when set to TRUE (this is the default)
    //therefore we need to use the opposite of findExactMatch for the contains property
    //i.e. to find an exact match set the contains property to FALSE or NOT findExactMatch
    findParams.contains = !findExactMatch;
    findParams.returnGeometry = true;
    findParams.layerIds = [parcelLayerID];
    findParams.searchFields = [parcelLayerSearchField];
    findParams.searchText = parcelID.toUpperCase();

    //set the zoomToParcels flag to true
    zoomToParcels = true;
    
    //execute the search
    if (findExactMatch==true) {
        findParcelTask.execute(findParams,checkForExactMatch);
    } else {
        findParcelTask.execute(findParams,OnParcelSearchComplete);
    }
}

function setParcelLayerID() {
    //find the parcel layer within the parcel map service
    var parcelLayer = map.getLayer(parcelMapID);
    var allLayerInfo = parcelLayer.layerInfos;
    var thisLayerInfo;
    for (var i=0, il=allLayerInfo.length; i<il; i++) {
        thisLayerInfo = allLayerInfo[i];
        if (thisLayerInfo.name.toUpperCase() == parcelLayerName.toUpperCase()) parcelLayerID = thisLayerInfo.id;
    }
}

function findParcel(parcelID, findExactMatch) {
    //if we haven't set the parcelLayerID then do so
    if (parcelLayerID < 0) setParcelLayerID();

    //be sure the parcelLayerID was set properly
    if (parcelLayerID < 0) { 
        alert("Unable to determine the parcel layer id.\nSearch will not be performed.");
        return false;
    }
    
    //set the zoomToParcels flag to true
    zoomToParcels = true;

    //create query task with url to map service
    var qtURL = parcelMapServiceName + "/" + parcelLayerID.toString();
    var queryParcelTask = new esri.tasks.QueryTask(qtURL);

    //build query filter
    var query = new esri.tasks.Query();
    query.returnGeometry = true;
    query.outFields = ["KGIS.CAD_Parcels_KNO.PARCELID",
                       "KGIS.VIEW_PARCEL_ADDR_OWNER.ADDRESS_NUM",
                       "KGIS.VIEW_PARCEL_ADDR_OWNER.ADDRESS_NUM_SUF",
                       "KGIS.VIEW_PARCEL_ADDR_OWNER.STREET_NAME",
                       "KGIS.VIEW_PARCEL_ADDR_OWNER.UNIT",
                       "KGIS.VIEW_PARCEL_ADDR_OWNER.OWNER",
                       "KGIS.CAD_Parcels_KNO.OBJECTID",
                       "KGIS.CAD_Parcels_KNO.SHAPE"
                      ];
    
    //if we are looking for an exact match then use an equal otherwise do a LIKE query
    if (findExactMatch == true) {
        query.where = "KGIS.CAD_Parcels_KNO.PARCELID = '" + parcelID + "'";

        //execute the query task
        queryParcelTask.execute(query, checkForExactMatch, parcelSearchError);
    } else {
        query.where = "KGIS.CAD_Parcels_KNO.PARCELID LIKE '" + parcelID + "%'";

        //execute the query task
        queryParcelTask.execute(query, OnParcelSearchComplete, parcelSearchError);
    }
}

function parcelSearchError(err) {
    var searchError = err;
    
}

function getParcels() {
    var parcelID = dojo.byId("txtParcelID").value;
    var params = {"parcelID":'"' + parcelID + '"'}
    parcelIDSearched = parcelID.toUpperCase();

    if (parcelIDSearched == "") {
        alert("Please eneter a parcel id.");
        return;
    }
    
    //change the parcel format from city/county to KGIS format
    parcelIDSearched = FormatKGISParcelID(parcelIDSearched);
    
    //show the busy indicator
    showBusy();
    
    //debugger;
    findParcel(parcelIDSearched, true);
}

/************************************
/  This function takes a standard City/County parcel id and transforms
/  it into a KGIS standard parcel id.  City/County parcel ids include
/  a "-" infront of the parcel number.  The KGIS standard does not include
/  the "-" symbol.
************************************/
function FormatKGISParcelID(sID) {
    var sNewParcel = "";
    var i = 0;
    
    //look for the "-" character in the string
    var pos = sID.indexOf("-");
    if  (pos > 0) {
        if (pos == 3) {
            //this parcel id does not include the group and insert (e.g. 108-001)
            //insert two spaces between the CLT Number and Parcel Number
            sNewParcel = sID.replace("-", "  ");  // sID.substring(0,3) + "  " + sID.substring(4);
        } else if (pos == 5) {
            sNewParcel = sID.replace("-","");
        } else {
            alert("Invalid parcel id format.");
        }
    } else {
        sNewParcel = sID;
    }    
    return sNewParcel;
}

//function compareParcelIDs(a,b) { return a.value - b.value; }
function sortByParcelID(a, b) {
    var x = a.attributes[parcelLayerSearchField];
    var y = b.attributes[parcelLayerSearchField];
    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}

function checkForExactMatch(results) {
    var features = results.features;
    if (features.length == 1) {
        clearSearchResults();
        highlightParcels(features, true);
        //locateParcel(parcelIDSearched);
    } else {
        findParcel(parcelIDSearched, false);
    }
}

function OnParcelSearchComplete(results) {
    //parse the results into an array of JSON objects
    //parcelResults = dojo.fromJson(results);
    //debugger;

    parcelResults = results.features;
    parcelResultsCount = parcelResults.length;

    //sort the records by parcel id
    parcelResults.sort(sortByParcelID);//(compareParcelIDs);

    //make sure we don't have more than 400 records
    //
    //***  IMPORTANT NOTE  ***
    //
    //As of 22 October 2008 the back end can have more
    //than 400 records in the result set.  However, the
    //list is trimmed to 401 records if more than 400
    //are returned.  A simple check on returned results
    //will let us know if we have more than 400 and we
    //can notify the user.  Future backend code may contain
    //an error object that will note when 400 record limit
    //has been exceded.
    //
    if (parcelResultsCount > 400) {
        hideBusy();
        alert("More than 400 records were returned.\nPlease refine your search.");
        return false;
        //displayParcels(0);
    } else if (parcelResultsCount == 0) {
        hideBusy();
        alert("Nothing found for: " + parcelIDSearched);
        return false;
    } else if (parcelResultsCount == 1) {
        //TODO: add code to handle only one parcel found
        clearSearchResults();
        locateParcel(parcelIDSearched);
    } else {
        //highlightParcels(results, true);
        displayParcels(0);
    }
}

function displayParcels(startAt) {
    //only highlight the parcels in this list
    var parcelsToHighlight = new Array();
    var recsToDisplay = 15;
    
    //getPagerString(firstRecord, totalRecords, recordsPerPage, pagesPerGroup, pagingFunction)
    var pagingInfo = getPagerString(startAt, parcelResultsCount, recsToDisplay, 5, "displayParcels");
    
    //looping control for the last record
    var lastRecord;
    if ((startAt + recsToDisplay) > (parcelResultsCount - 1)) {
        lastRecord = parcelResultsCount;
    } else {
        lastRecord = startAt + recsToDisplay;
    }
    
    var content = "";
    var rowClass;
    
    //add the pager
    content = "<table class='searchResults' width='240px' cellpadding='0' cellspacing='0'><tr><td align='left'>";
    content += pagingInfo["pageOf"];
    content += "</td><td align='right'>";
    content += pagingInfo["pageString"];
    content += "</td></tr><tr><td>&nbsp;</td></tr><tr><td colspan='2'>";
    //content += "<div style='overflow: auto; height: 100%;'>";
    content += "<table width='100%' cellpadding='0' cellspacing='0'><tr><td>";
        
    var n = 0;
    for (var i=startAt; i < lastRecord; i++) {
        //copy this parcel record to the parcels to highlight array
        parcelsToHighlight[n] = parcelResults[i];
        n++;
        var fullAddress = "";
        var apoInfo = parcelResults[i];
        if ((i % 2) == 0) {
            rowClass = "row1";
        } else {
            rowClass = "row2";
        }
        
        content += "<table width='240' class='" + rowClass + "' cellpadding='1' cellspacing='0'>";
        content += "  <tr><td colspan='4'><img src='./images/pixel.gif' height='3' /></td></tr>";
        content += "  <tr>";
        content += "    <td colspan='4'>" + parcelResults[i].attributes['KGIS.VIEW_PARCEL_ADDR_OWNER.OWNER'] + "</td>";
        content += "  </tr>";
        content += "  <tr>";
        
        //get the full address - with or without the unit number
        if ((parcelResults[i].attributes['KGIS.VIEW_PARCEL_ADDR_OWNER.UNIT'] == null) || (parcelResults[i].attributes['KGIS.VIEW_PARCEL_ADDR_OWNER.UNIT'] == "")) {
            fullAddress = parcelResults[i].attributes['KGIS.VIEW_PARCEL_ADDR_OWNER.ADDRESS_NUM'] + " " + parcelResults[i].attributes['KGIS.VIEW_PARCEL_ADDR_OWNER.STREET_NAME'];
        } else {
            fullAddress = parcelResults[i].attributes['KGIS.VIEW_PARCEL_ADDR_OWNER.ADDRESS_NUM'] + " " + parcelResults[i].attributes['KGIS.VIEW_PARCEL_ADDR_OWNER.UNIT'] + " " + parcelResults[i].attributes['KGIS.VIEW_PARCEL_ADDR_OWNER.STREET_NAME'];
        }               

        //get the parcelID
        var thisParcel = parcelResults[i].attributes['KGIS.CAD_Parcels_KNO.PARCELID'];

        content += "    <td colspan='4'>" + fullAddress + "</td>";
        content += "  </tr>";
        content += "  <tr>";
        content += "    <td width='192' align='left'>" + thisParcel + "</td>";
        content += "    <td width='16' align='center'><img style='cursor: hand;' src='./images/ViewDetails_12.png' onclick='getFullParcelInfo(\"" + thisParcel + "\")' /></td>";
        content += "    <td width='16' align='center'><img style='cursor: hand;' src='./images/ZoomToRecord_12.png' onclick='locateParcel(\"" + thisParcel + "\")' /></td>";
        content += "    <td width='16' align='center'><img style='cursor: hand;' src='./images/ViewDetailsAndZoom_12.png' onclick='locateParcel(\"" + thisParcel + "\");getFullParcelInfo(\"" + thisParcel + "\");' /></td>";
        content += "  </tr>";
        content += "  <tr><td colspan='4'><img src='./images/pixel.gif' height='3' /></td></tr>";
        content += "</table>";
    }
    
    //highlight these parcels
    highlightParcels(parcelsToHighlight);

    content += "</td></tr></table>";
    //content += "</div>";
    content += "</td></tr></table>";

    var resultsPane = dojo.byId("cpResults");    
    resultsPane.innerHTML = content;
    
    //besure the left panel is open to display the data
    if (g_sLeftPaneState=="CLOSED") toggleLeft();
            
    dijit.byId("mainTabContainer").selectChild("tabResults");
    dijit.byId("acSearchResults").selectChild("apResults");
}

//clean out any data in the search results pane to avoid confusion
function clearSearchResults() {
    var resultsPane = dojo.byId("cpResults");
    resultsPane.innerHTML = "";
}

//**************************************
//  IMPORTANT NOTE:
//  The locateParcel function has been changed to use the query task.
//  This will allow the result set to be a featureSet which is what is
//  returned from the parcel search function at the top of the page.
//  Therefore, we can use the same functions to display the results.
//  Original code is listed at the bottom of this function in case we
//  need to refer back to it at some time.
//**************************************
function locateParcel(parcelID) {
    //if we haven't set the parcelLayerID then do so
    if (parcelLayerID < 0) setParcelLayerID();

    //be sure the parcelLayerID was set properly
    if (parcelLayerID < 0) { 
        alert("Unable to determine the parcel layer id.\nSearch will not be performed.");
        return false;
    }
    
    //set the zoomToParcels flag to true
    zoomToParcels = true;

    //create query task with url to map service
    var qtURL = parcelMapServiceName + "/" + parcelLayerID.toString();
    var queryParcelTask = new esri.tasks.QueryTask(qtURL);

    //build query filter
    var query = new esri.tasks.Query();
    query.returnGeometry = true;
    query.where = "KGIS.CAD_Parcels_KNO.PARCELID = '" + parcelID + "'";
    

//    query.outFields = ["KGIS.CAD_Parcels_KNO.PARCELID",
//                       "KGIS.VIEW_PARCEL_ADDR_OWNER.ADDRESS_NUM",
//                       "KGIS.VIEW_PARCEL_ADDR_OWNER.ADDRESS_NUM_SUF",
//                       "KGIS.VIEW_PARCEL_ADDR_OWNER.STREET_NAME",
//                       "KGIS.VIEW_PARCEL_ADDR_OWNER.UNIT",
//                       "KGIS.VIEW_PARCEL_ADDR_OWNER.OWNER",
//                       "KGIS.CAD_Parcels_KNO.OBJECTID",
//                       "KGIS.CAD_Parcels_KNO.SHAPE"
//                      ];
    
//    //should only be here if we have an exact match
//    if (findExactMatch == true) {
//        query.where = "KGIS.CAD_Parcels_KNO.PARCELID = '" + parcelID + "'";

//        //execute the query task
//        queryParcelTask.execute(query, checkForExactMatch, parcelSearchError);
//    } else {
//        query.where = "KGIS.CAD_Parcels_KNO.PARCELID LIKE '" + parcelID + "%'";

    //execute the query task
    queryParcelTask.execute(query, function(results) {
            //highlight the identified parcel
            highlightParcels(results.features, false);
        } , parcelSearchError);
    //*****************************
    //  ORIGINAL IDENTIFY TASK CODE
    //*****************************
    //    //create find task with url to map service
    //    findParcelTask = new esri.tasks.FindTask(parcelMapServiceName);

    //    //get parcel layer id from list of layers
    //    var parcelLayerID = getLayerIDFromMapDoc(parcelMapID, parcelLayerName);

    //    //create find parameters and define known values
    //    findParams = new esri.tasks.FindParameters();
    //    findParams.contains = false;
    //    findParams.returnGeometry = true;
    //    findParams.layerIds = [parcelLayerID];
    //    findParams.searchFields = [parcelLayerSearchField];
    //    findParams.searchText = parcelID.toUpperCase();

    //    //set the zoomToParcels flag
    //    zoomToParcels = true;
    //    
    //    findParcelTask.execute(findParams, function(results) {
    //            var feature = results[0].feature;
    //            highlightParcels(feature);
    //        });
    //*****************************

}

//function ParcelSearch() {
//    debugger;
//    
//    var parcelID = dojo.byId("txtParcelID").value.toUpperCase();

//    //create find task with url to map service
//    findParcelTask = new esri.tasks.FindTask(parcelMapServiceName);

//    //get parcel layer id from list of layers
//    var parcelLayerID = getLayerIDFromMapDoc("parcels", "parcels");
//    
//    //create find parameters and define known values
//    findParams = new esri.tasks.FindParameters();
//    findParams.returnGeometry = true;
//    findParams.layerIds = [parcelLayerID];
//    findParams.searchFields = ["PARCELID"];
//    findParams.searchText = parcelID;
//    
//    findParcelTask.execute(findParams,showParcelResults);
//}

function getLayerIDFromMapDoc(mapLayerName, layerNameInMapDoc) {
    var layerID = -1;
    for(var j = 0; j <= map.layerIds.length - 1; j++) {
        var layer = map.getLayer(map.layerIds[j]);
        if (typeof(layer != "undefined")) {
            if (layer != null) {
                if (layer.id == mapLayerName) {
                    var mapDocLayers = layer.layerInfos;
                    for (var n = 0; n <= mapDocLayers.length - 1; n++) {
                        if (mapDocLayers[n].name.toUpperCase() == layerNameInMapDoc.toUpperCase()) {
                            layerID = n;
                            n = mapDocLayers.length;
                        }
                    }
                    j = map.layerIds.length;
                }
            }
        }
    }
    return layerID;        
}


function getLayerID(mapLayerName) {
    var layerID = -1;
    
    for(var j = 0; j < map.layerIds.length; j++) {
        var layer = map.getLayer(map.layerIds[j]);
        if (layer.id == mapLayerName) {
            layerID = j;
            j = map.layerIds.length;
        }
    }
    return layerID;        
}

function highlightParcels(results) {
    map.graphics.clear();
                
    //set the graphic symbology
    var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NULL, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([128,0,0,1]), 3), new dojo.Color([255,255,0,0.1]));
        
    //add each of the parcels to the graphics layers and adjust the extent
    for (var i=0, il=results.length; i<il; i++) {
        var graphic = results[i];
        
        graphic.setSymbol(symbol);
        map.graphics.add(graphic);
        
        //expand the extent for each parcel - if zoomMap is true
        if (zoomToParcels) {
            if (i==0) {
                var parcelExtent = new esri.geometry.Extent(graphic.geometry.getExtent().xmin, graphic.geometry.getExtent().ymin, graphic.geometry.getExtent().xmax, graphic.geometry.getExtent().ymax, map.spatialReference)
            } else {
                var thisExtent = new esri.geometry.Extent(graphic.geometry.getExtent().xmin, graphic.geometry.getExtent().ymin, graphic.geometry.getExtent().xmax, graphic.geometry.getExtent().ymax, map.spatialReference)
                if (thisExtent.xmin < parcelExtent.xmin)
                    parcelExtent.xmin = thisExtent.xmin;
                                            
                if (thisExtent.ymin < parcelExtent.ymin)
                    parcelExtent.ymin = thisExtent.ymin;

                if (thisExtent.xmax > parcelExtent.xmax)
                    parcelExtent.xmax = thisExtent.xmax;
                    
                if (thisExtent.ymax > parcelExtent.ymax)
                    parcelExtent.ymax = thisExtent.ymax;
            }
        }
    }
        
    //zoom to the parcel(s) extent if requested
    if (zoomToParcels)
        map.setExtent(parcelExtent.expand(2));
        
    //remove the busy indicator
    hideBusy();
}

function displaySimpleParcelDetails(results) {
    //get the info to be displayed
    //var parcelResults = dojo.fromJson(results);
    //var apoInfo = parcelResults[0];
    var info = getAddrParcelOwner_InfoWindowContent(results);

    //get the detail information and put it in the details pane
    //getFullParcelInfo(apoInfo.ParcelID);
    
    //show the basic parcel information
    map.infoWindow.setTitle("Parcel Info:");
    map.infoWindow.setContent(info);
    map.infoWindow.show(g_evt.screenPoint, map.getInfoWindowAnchor(g_evt.screenPoint));
}

function getAddrParcelOwner_InfoWindowContent(parcelResults) {
    var fullAddress;
    //get the full address - with or without the unit number
    if ((parcelResults[0].attributes['KGIS.VIEW_PARCEL_ADDR_OWNER.UNIT'] == null) || (parcelResults[0].attributes['KGIS.VIEW_PARCEL_ADDR_OWNER.UNIT'] == "")) {
        fullAddress = parcelResults[0].attributes['KGIS.VIEW_PARCEL_ADDR_OWNER.ADDRESS_NUM'] + " " + parcelResults[0].attributes['KGIS.VIEW_PARCEL_ADDR_OWNER.STREET_NAME'];
    } else {
        fullAddress = parcelResults[0].attributes['KGIS.VIEW_PARCEL_ADDR_OWNER.ADDRESS_NUM'] + " " + parcelResults[0].attributes['KGIS.VIEW_PARCEL_ADDR_OWNER.UNIT'] + " " + parcelResults[0].attributes['KGIS.VIEW_PARCEL_ADDR_OWNER.STREET_NAME'];
    }    
    
    var thisParcel = parcelResults[0].attributes['KGIS.CAD_Parcels_KNO.PARCELID'];
    
    //create the content to display
    var content;
    content = "";
    content += "<table cellpadding='2' cellspacing='0'>";
    content += " <colgroup>";
    content += "    <col align='left' valign='top' width='75'  class='iwCellHeading' />";
    content += "    <col align='left' valign='top' width='127' class='iwCellText' />";
    content += "    <col align='center' valign='middle' width='16' />";
    content += "    <col align='center' valign='middle' width='16' />";
    content += "    <col align='center' valign='middle' width='16' />";
    content += "  </colgroup>";
    content += "  <tr>";
    content += "    <td>Owner:</td>";
    content += "    <td colspan='4'>" + parcelResults[0].attributes['KGIS.VIEW_PARCEL_ADDR_OWNER.OWNER'] + "</td>";
    content += "  </tr>";
    content += "  <tr>";
    content += "    <td>Address:</td>";
    content += "    <td colspan='4'>" + fullAddress + "</td>";
    content += "  </tr>";
    content += "  <tr>";
    content += "    <td>Parcel ID:</td>";
    content += "    <td>" + thisParcel + "</td>";
    content += "    <td><a href='" + ownerCardApp + thisParcel + "' target='blank'><img style='border: none;' alt='Show Owner Card Report' src='./images/OwnerCard_12.png' /></a></td>";
    content += "    <td><a href='" + propertyMapReport + thisParcel + "' target='blank'><img style='border: none;' alt='Show Map and Details Report' src='./images/MapAndDetailsReport_12.png' /></a></td>";
    content += "    <td><img class='linkImage' alt='Get full parcel details' src='./images/ViewDetails_12.png' onclick='getFullParcelInfo(\"" + thisParcel + "\");' /></td>";
    content += "  </tr>";
    content += "</table><br />";

    return content;
}

//function showDetails() {
//    alert("in showDetails!")
//}

//function showParcelResults(results) {
//    map.graphics.clear();
//                
//    //set the graphic symbology
//    var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NONE, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.25]));
//    
//    var curFeature;
//    var graphic;
//    if (results.length == 1)
//    {
//        //get the feature for highlighting
//        curFeature = results[0];
//        graphic = curFeature.feature;

//        //get first point in the polygon to ancor info window
//        var firstPoint = new esri.geometry.Point();
//        firstPoint = graphic.getPoint(0,0);

//        //get the extent for zooming
//        var parcelExtent = new esri.geometry.Extent(graphic.geometry.getExtent().xmin, graphic.geometry.getExtent().ymin, graphic.geometry.getExtent().xmax, graphic.geometry.getExtent().ymax, map.spatialReference)                
//        
//        //


//        var parcelID = curFeature.attributes['PARCELID'];
//        var params = {"parcelID":'"' + parcelID + '"'}

//        //call the webservice to get the data

//            //url: "./wsSearches.asmx/GetAddrParcelOwner_ByParcelID",
//            //url: "./wsSearches.asmx/GetParcelInfo_ByParcelID",

//        dojo.xhrGet(
//        {
//            url: "./wsSearches.asmx/GetParcelInfo_ByParcelID",
//            handleAs: "json",
//            contentType: "application/json; charset=utf-8",
//            content: params,
//            load: showFullParcelInfo,
//            error: function(error,args){console.warn("error!",error);}
//        });
//    } else {
//        for (var i=0, il=results.length; i<il; i++) {
//            var curFeature = results[i];
//            var graphic = curFeature.feature;
//            
//            graphic.setSymbol(symbol);
//            map.graphics.add(graphic);
//            
//            //expand the extent for each parcel
//            if (i==0) {
//                var parcelExtent = new esri.geometry.Extent(graphic.geometry.getExtent().xmin, graphic.geometry.getExtent().ymin, graphic.geometry.getExtent().xmax, graphic.geometry.getExtent().ymax, map.spatialReference)
//            } else {
//                var thisExtent = new esri.geometry.Extent(graphic.geometry.getExtent().xmin, graphic.geometry.getExtent().ymin, graphic.geometry.getExtent().xmax, graphic.geometry.getExtent().ymax, map.spatialReference)
//                if (thisExtent.xmin < parcelExtent.xmin)
//                    parcelExtent.xmin = thisExtent.xmin;
//                                            
//                if (thisExtent.ymin < parcelExtent.ymin)
//                    parcelExtent.ymin = thisExtent.ymin;

//                if (thisExtent.xmax > parcelExtent.xmax)
//                    parcelExtent.xmax = thisExtent.xmax;
//                    
//                if (thisExtent.ymax > parcelExtent.ymax)
//                    parcelExtent.ymax = thisExtent.ymax;
//            }
//        }
//    }
//    map.setExtent(parcelExtent.expand(1.5));            
//}

function getFullParcelInfo(parcelID) {   
    //switch to the correct tab
    setTab("tabResults");
        
    var detailsPane = dojo.byId("cpDetails");    
//    detailsPane.style.visibility = "visible";
//    detailsPane.style.display = "block";
    dijit.byId("acSearchResults").selectChild("apDetails");

    //clear the info in the box
    detailsPane.innerHTML = "";

    showBusyDetails();

    var params = {"parcelID":'"' + parcelID + '"'}
    dojo.xhrGet(
    {
        url: "./wsSearches.asmx/GetParcelInfo_ByParcelID",
        handleAs: "json",
        contentType: "application/json; charset=utf-8",
        content: params,
        load: loadFullParcelInfo,
        error: function(error,args){console.warn("error!",error);}
    });
}

//**************************************
//  IMPORTANT NOTE:
//  The parcelIdentify function has been changed to use the query task.
//  This will allow the result set to be a featureSet which is what is
//  returned from the parcel search function at the top of the page.
//  Therefore, we can use the same functions to display the results.
//  Original code is listed at the bottom of this function in case we
//  need to refer back to it at some time.
//**************************************
function parcelIdentify(evt) {
    //store the event point and create an identify point (idPoint) for the query function
    g_evt = evt;
    var idPoint = evt.mapPoint;
    
    //clear the details pane to avoid confusion
    clearDetails();
    
    //if we haven't set the parcelLayerID then do so
    if (parcelLayerID < 0) setParcelLayerID();

    //be sure the parcelLayerID was set properly
    if (parcelLayerID < 0) { 
        alert("Unable to determine the parcel layer id.\nSearch will not be performed.");
        return false;
    }

    //set the zoomToParcel flag
    zoomToParcels = false;

    //create query task with url to map service
    var qtURL = parcelMapServiceName + "/" + parcelLayerID.toString();
    var queryParcelTask = new esri.tasks.QueryTask(qtURL);

    //build query filter
    var query = new esri.tasks.Query();
    query.geometry = idPoint;
    query.returnGeometry = true;
    query.outFields = ["KGIS.CAD_Parcels_KNO.PARCELID",
                       "KGIS.VIEW_PARCEL_ADDR_OWNER.ADDRESS_NUM",
                       "KGIS.VIEW_PARCEL_ADDR_OWNER.ADDRESS_NUM_SUF",
                       "KGIS.VIEW_PARCEL_ADDR_OWNER.STREET_NAME",
                       "KGIS.VIEW_PARCEL_ADDR_OWNER.UNIT",
                       "KGIS.VIEW_PARCEL_ADDR_OWNER.OWNER",
                       "KGIS.CAD_Parcels_KNO.OBJECTID",
                       "KGIS.CAD_Parcels_KNO.SHAPE"
                      ];
    query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_WITHIN;


    //execute the query task
    queryParcelTask.execute(query, processIdentify, parcelSearchError);

    //*****************************
    //  ORIGINAL IDENTIFY TASK CODE
    //*****************************
    //    identifyTask = new esri.tasks.IdentifyTask(parcelMapServiceName);

    //    //get parcel layer id from list of layers
    //    var parcelLayerID = getLayerIDFromMapDoc(parcelMapID, parcelLayerName);
    //        
    //    //var identifyParams = new esri.tasks.IdentifyParameters(parcelMapID, parcelLayerName);
    //    var identifyParams = new esri.tasks.IdentifyParameters();
    //    identifyParams.tolerance = 3;
    //    identifyParams.returnGeometry = true;
    //    identifyParams.layerIds = [parcelLayerID];
    //    identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;
    //    identifyParams.geometry = evt.mapPoint;
    //    identifyParams.mapExtent = map.extent;
    //    
    //    //set the zoomToParcel flag
    //    zoomToParcels = false;
    //    
    //    //execute the identify task
    //    identifyTask.execute(identifyParams, processIdentify); // function(idResults){displaySimpleParcelDetails(idResults, evt); });
    //*****************************
}

function processIdentify(idResults) {
    //if we have only one result show info - otherwise show info for all parcels selected
    if (idResults.features.length > 1) {
        //process the search results
        OnParcelSearchComplete(idResults);    
    } else if (idResults.features.length < 1) {
        alert("Parcel not found at this location.");
    } else {
        //get the parcel id from the results
        var parcelID = idResults.features[0].attributes["KGIS.CAD_Parcels_KNO.PARCELID"];
        parcelIDSearched = parcelID;

        //display the results in the data bubble
        displaySimpleParcelDetails(idResults.features);

        //highlight the identified parcel
        highlightParcels(idResults.features, false);    

        //if the details window is open - go ahead and load the full set of data
        //to avoid confusion with info that may already be showing
        if (detailsViewState == "on") {
            //show the detail info
            getFullParcelInfo(parcelID);
        }
    }
}   

function loadFullParcelInfo(results) {   
    //debugger;
    
    //get the feature for highlighting
    var parcelInfo = dojo.fromJson(results);

    //get individual objects for each parcel info piece
    var objParcel = ((parcelInfo.PARCEL != null)?parcelInfo.PARCEL:null);
    var objParcelPoly =((parcelInfo.PARCEL_POLY != null) ? parcelInfo.PARCEL_POLY[0]:null); 
    var objAddrPoint = ((parcelInfo.ADDRESS_POINT != null) ? parcelInfo.ADDRESS_POINT[0]:null);
    var objOwner = ((parcelInfo.OWNER != null) ? parcelInfo.OWNER[0]:null);
    var objOwnerDocs = ((parcelInfo.OWNERDOCS_RESULTS != null) ? parcelInfo.OWNERDOCS_RESULTS[0]:null);
    var objParcelDocs = ((parcelInfo.PARCELDOCS_RESULTS != null) ? parcelInfo.PARCELDOCS_RESULTS[0]:null);
    var objIncorpAreas = ((parcelInfo.IncorpAreas_POLY != null) ? parcelInfo.IncorpAreas_POLY[0]:null);
    var objWardPoly = ((parcelInfo.WardBoundary_POLY != null) ? parcelInfo.WardBoundary_POLY[0]:null);
    var objWardBlock = ((parcelInfo.WardCityBlocks_POLY != null) ? parcelInfo.WardCityBlocks_POLY[0]:null);
    var objElemSchool = ((parcelInfo.SchoolZones_ELEM != null) ? parcelInfo.SchoolZones_ELEM[0]:null);
    var objInterSchool = ((parcelInfo.SchoolZones_INTERMEDIATE != null) ? parcelInfo.SchoolZones_INTERMEDIATE[0]:null);
    var objMiddleSchool = ((parcelInfo.SchoolZones_MIDDLE != null) ? parcelInfo.SchoolZones_MIDDLE[0]:null);
    var objHighSchool = ((parcelInfo.SchoolZones_HIGH != null) ? parcelInfo.SchoolZones_HIGH[0]:null);
    var obj1990TZones = ((parcelInfo.TZones_POLY != null) ? parcelInfo.TZones_POLY[0]:null);
    var obj2000TZones = ((parcelInfo.Census2000_POLY != null) ? parcelInfo.Census2000_POLY[0]:null);
    var objSector = ((parcelInfo.Sectors_POLY != null) ? parcelInfo.Sectors_POLY[0]:null);
    var obj2000CensusTract = ((parcelInfo.Census2000Tract_POLY != null) ? parcelInfo.Census2000Tract_POLY[0]:null);
    var objVotingPrecinct = ((parcelInfo.PrecinctsAlign_POLY != null) ? parcelInfo.PrecinctsAlign_POLY[0]:null);
    var objSchoolBoard = ((parcelInfo.SchoolBoardDist_POLY != null) ? parcelInfo.SchoolBoardDist_POLY[0]:null);
    var objCountyCommission = ((parcelInfo.CountyCommDistricts_POLY != null) ? parcelInfo.CountyCommDistricts_POLY[0]:null);
    var objCityCouncil = ((parcelInfo.CityCouncilDist_POLY != null) ? parcelInfo.CityCouncilDist_POLY[0]:null);
    var objStateHouse = ((parcelInfo.StateHouseDist_POLY != null) ? parcelInfo.StateHouseDist_POLY[0]:null);
    var objStateSenate = ((parcelInfo.StateSenateDist_POLY != null) ? parcelInfo.StateSenateDist_POLY[0]:null);
    var objGISError = ((parcelInfo.GISERROR != null) ? parcelInfo.GISERROR[0]:null);

    //build the address based on presence of unit number
    var siteAddr = "";
    if(typeof(objAddrPoint) != "undefined") {
        if ((objAddrPoint.UNIT == "") || (objAddrPoint.UNIT == null)) {
            siteAddr = objAddrPoint.ADDRESS_NUM + " " + objAddrPoint.STREET_NAME;
        } else {
            siteAddr = objAddrPoint.ADDRESS_NUM + " " + objAddrPoint.UNIT + " " + objAddrPoint.STREET_NAME;        
        }
    }
    
    //build the address information section
    var content = "";
    content += "<!--Address Information Area-->";
    content += "    <table class='results' cellpadding='0' cellspacing='2' border='0' width='240'>";
    content += "      <colgroup>";
    content += "            <col width='110' align='left' />";
    content += "            <col width='125' align='left' />";
    content += "            <col width='15' align='right' />";
    content += "          </colgroup>";
    content += "          <tr>";
    content += "            <td colspan='2'>";
    content += "              <b>Address Information:</b>";
    content += "            </td>";
    content += "            <td>";
    content += "              <img src='./images/info.gif' />";
    content += "            </td>";
    content += "          </tr>";
    content += "          <tr>";
    content += "            <td bgcolor='black' colspan='3' height='2'></td>";
    content += "          </tr>";
    
    if(typeof(objAddrPoint) != "undefined") {
        content += "          <tr valign='top'>";
        content += "            <td>Site Address:</td>";
        content += "            <td colspan='2'>";
        content +=                siteAddr;
        content += "              <br />";
        content +=                objAddrPoint.CITY + " - " + objAddrPoint.ZIP_CODE;
        content += "            </td>";
        content += "          </tr>";
        content += "          <tr valign='top'>";
        content += "            <td>Address Type:</td>";
        content += "            <td colspan='2'>";
        content +=                objAddrPoint.ADDRESS_USE_TYPE;
        content += "            </td>";
        content += "          </tr>";
        content += "          <tr valign='top'>";
        content += "            <td>Site Name:</td>";
        content += "            <td colspan='2'>";
        content +=                objAddrPoint.SITE_NAME;
        content += "            </td>";
        content += "          </tr>";
    } else {
        content += "          <tr valign='top'>";
        content += "            <td>Error:</td>";
        content += "            <td colspan='2'>";
        content += "                <i>data missing</i>";
        content += "            </td>";
        content += "          </tr>";        
    }
    content += "        </table>";
    content += "        <br></br>";

    //format the owner's address - based on if addr has unit number or not
    var ownerAddr = "";
    if(typeof(objOwner) != "undefined") {
        if ((objOwner.UNIT == "") || (objOwner.UNIT == null)) {
            ownerAddr = objOwner.HOUSE_NUMBER + " " + objOwner.STREET_NAME;
        } else {
            ownerAddr = objOwner.HOUSE_NUMBER + " " + objOwner.UNIT + " " + objOwner.STREET_NAME;
        }
    }

    //build the owner information section
    content += "        <table class='results' cellpadding='0' cellspacing='1' border='0' width='240'>";
    content += "          <colgroup>";
    content += "            <col width='225' align='left' />";
    content += "            <col width='15' align='right' />";
    content += "          </colgroup>";
    content += "          <!--Owner Information Area-->";
    content += "          <tr>";
    content += "            <td>";
    content += "              <b>Owner Information:</b>";
    content += "            </td>";
    content += "            <td>";
    content += "              <img src='./images/info.gif' />";
    content += "            </td>";
    content += "          </tr>";
    content += "          <tr>";
    content += "            <td bgcolor='black' colspan='2' height='2'></td>";
    content += "          </tr>";
    if(typeof(objOwner) != "undefined") {
        content += "          <tr>";
        content += "            <td colspan='2' >";
        content +=                objOwner.OWNER;
        content += "              <br />";
        content +=                ownerAddr;
        content += "              <br />";
        content +=                objOwner.CITY + ', ' + objOwner.STATE + ' ' + objOwner.ZIPCODE;
        content += "            </td>";
        content += "          </tr>";
        content += "          <tr height='2'>";
        content += "            <td colspan='2'></td>";
        content += "          </tr>";
        content += "          <tr>";
        content += "            <td colspan='2' class='smallNotes'>";
        content += "              The owner information shown in this section does not necessarily";
        content += "              reflect the person(s) responsible for Last Year's property taxes.";
        content += "              Report any errors to the Knox County Property Assessor's office";
        content += "              at (865) 215-2365.";
        content += "            </td>";
        content += "          </tr>";
    } else {
        content += "          <tr valign='top'>";
        content += "            <td>Error:</td>";
        content += "            <td colspan='2'>";
        content += "                <i>data missing</i>";
        content += "            </td>";
        content += "          </tr>";    
    }
    content += "        </table>";
    content += "        <br></br>";

    var parcelAddr = "";
    if(typeof(objParcelPoly) != "undefined") {
        if ((objParcelPoly.LOCATION_UNIT == "") || (objParcelPoly.LOCATION_UNIT == null)) {
            parcelAddr = objParcelPoly.LOCATION_HOUSE_NUMBER + " " + objParcelPoly.LOCATION_STREET_NAME;
        } else {
            parcelAddr = objParcelPoly.LOCATION_HOUSE_NUMBER + " " + objParcelPoly.LOCATION_UNIT + " " + objParcelPoly.LOCATION_STREET_NAME;        
        }
    }
    
    //build the parcel information section
    content += "        <table class='results' cellpadding='0' cellspacing='2' border='0' width='240'>";
    content += "          <colgroup>";
    content += "            <col width='110' align='left' />";
    content += "            <col width='125' align='left' />";
    content += "            <col width='15' align='right' />";
    content += "          </colgroup>";
    content += "          <!--Parcel Information Area-->";
    content += "          <tr>";
    content += "            <td colspan='2'>";
    content += "              <b>Parcel Information:</b>";
    content += "            </td>";
    content += "            <td>";
    content += "              <img src='./images/info.gif' />";
    content += "            </td>";
    content += "          </tr>";
    content += "          <tr>";
    content += "            <td bgcolor='black' colspan='3' height='2'></td>";
    content += "          </tr>";
    
    if(typeof(objParcelPoly) != "undefined") {
        content += "          <tr>";
        content += "            <td>Location Address:</td>";
        content += "            <td colspan='2'>";
        content +=                parcelAddr;
        content += "            </td>";
        content += "          </tr>";
        content += "          <tr>";
        content += "            <td>Parcel ID:</td>";
        content += "            <td colspan='2'>";
        content +=                objParcelPoly.PARCELID;
        content += "            </td>";
        content += "          </tr>";
        content += "          <tr>";
        content += "            <td>Parcel Type:</td>";
        content += "            <td colspan='2'>";
        content +=                objParcelPoly.PARCEL_TYPE;
        content += "            </td>";
        content += "          </tr>";
        content += "          <tr>";
        content += "            <td>District:</td>";
        content += "            <td colspan='2'>";
        content +=                objParcelPoly.TAX_DISTRICT;
        content += "            </td>";
        content += "          </tr>";
        content += "          <tr>";
        content += "            <td>Ward:</td>";
        content += "            <td colspan='2'>";
        content +=                objParcelPoly.WARD;
        content += "            </td>";
        content += "          </tr>";
                             if (objParcelPoly.WARD != "") {
        content += "          <tr>";
        content += "            <td>City Block:</td>";
        content += "            <td colspan='2'>";
                                 if ((typeof (objWardBlock) != "undefined") && (objWardBlock != null))
                                     content += objWardBlock.BLOCK_NUMBER;
        content += "            </td>";
        content += "          </tr>";
                              }
        content += "          <tr valign='top'>";
        content += "            <td>Subdivision:</td>";
        content += "            <td colspan='2'>";
        content +=                objParcelPoly.SUBDIVISION_NAME;
        content += "            </td>";
        content += "          </tr>";
        content += "          <tr>";
        content += "            <td>Rec. Acreage:</td>";
        content += "            <td colspan='2'>";
        content +=                objParcelPoly.RECORDED_AREA;
        content += "            </td>";
        content += "          </tr>";
        content += "          <tr>";
        content += "            <td>Calc. Acreage:</td>";
        content += "            <td colspan='2'>";
        content +=               objParcelPoly.CALCULATED_AREA;
        content += "           </td>";
        content += "         </tr>";
        content += "         <tr>";
        content += "           <td>Recorded Plat:</td>";
        content += "            <td colspan='2'>";
                                  if ((typeof(objParcelDocs) != "undefined") && (objParcelDocs != null))
        content +=                  objParcelDocs.DEED_BOOK + "-" + objParcelDocs.DEED_PAGE;
        content += "            </td>";
        content += "          </tr>";
        content += "          <tr>";
        content += "            <td>Recorded Deed:</td>";
        content += "            <td colspan='2'>";
                                  if ((typeof(objOwnerDocs) != "undefined") && (objOwnerDocs != null))
        content += "                <a href='" + ROD_Images + objOwnerDocs.DEED_BOOK + "&page=" + objOwnerDocs.DEED_PAGE + "' target='_blank'>" + objOwnerDocs.DEED_BOOK + "-" + objOwnerDocs.DEED_PAGE + "</a>";
        content += "            </td>";
        content += "          </tr>";
        content += "          <tr>";
        content += "            <td>Deed Type:</td>";
        content += "            <td colspan='2'>";
                                  if ((typeof(objOwnerDocs) != "undefined") && (objOwnerDocs != null))
        content +=                  objOwnerDocs.ODOC_TYPE;
        content += "            </td>";
        content += "          </tr>";
        content += "          <tr>";
        content += "            <td>Deed Date:</td>";
        content += "            <td colspan='2'>";
                                  if ((typeof(objOwnerDocs) != "undefined") && (objOwnerDocs != null))
        content +=                  objOwnerDocs.RECORDED_DATE;
        content += "            </td>";
        content += "          </tr>";
    } else {
        content += "          <tr valign='top'>";
        content += "            <td>Error:</td>";
        content += "            <td colspan='2'>";
        content += "                <i>data missing</i>";
        content += "            </td>";
        content += "          </tr>";    
    }    
    content += "        </table>";
    content += "        <br></br>";

    //build MPC info section
    content += "        <table class='results' cellpadding='0' cellspacing='2' border='0' width='240'>";
    content += "          <colgroup>";
    content += "            <col width='110' align='left' />";
    content += "            <col width='125' align='left' />";
    content += "            <col width='15' align='right' />";
    content += "          </colgroup>";
    content += "          <!--MPC Information Area-->";
    content += "          <tr valign='top'>";
    content += "            <td colspan='2'>";
    content += "              <b>MPC Information:</b>";
    content += "            </td>";
    content += "            <td>";
    content += "              <img src='./images/info.gif' />";
    content += "            </td>";
    content += "          </tr>";
    content += "          <tr valign='top'>";
    content += "            <td bgcolor='black' colspan='3' height='2'></td>";
    content += "          </tr>";
    content += "          <tr valign='top'>";
    content += "            <td>Census Tract:</td>";
    content += "            <td colspan='2'>";
                            if (typeof(obj2000CensusTract) != "undefined") {
    content +=                obj2000CensusTract.TRACTID;          
                            } else {
    content += "              <i>data missing</i>";
                            }
    content += "            </td>";
    content += "          </tr>";
    content += "          <tr valign='top'>";
    content += "            <td>Planning Sector:</td>";
    content += "            <td colspan='2'>";
                            if (typeof(objSector) != "undefined") {
    content +=                objSector.SECTORNAME;
                            } else {
    content += "              <i>data missing</i>";
                            }
    content += "            </td>";
    content += "          </tr>";
    content += "          <tr valign='top'>";
    content += "            <td>1990 Traffic Zone:</td>";
    content += "            <td colspan='2'>";
                            if (typeof(obj1990TZones) != "undefined") {
    content +=                obj1990TZones.TZONE_NAME;                            
                            } else {
    content += "              <i>data missing</i>";
                            }
    content += "            </td>";
    content += "          </tr>";
    content += "          <tr valign='top'>";
    content += "            <td>2000 Traffic Zone:</td>";
    content += "            <td colspan='2'>";
                            if (typeof(obj2000TZones) != "undefined") {
                              if (obj2000TZones.TAZ != null) {
    content +=                  obj2000TZones.TAZ;
                              } else {
    content += "                <i>data missing</i>";
                              }
                            } else {
    content += "              <i>data missing</i>";
                            }
    content += "            </td>";
    content += "          </tr>";
    content += "        </table>";
    content += "        <br></br>";

    //build incorporated areas info
    content += "        <table class='results' cellpadding='0' cellspacing='2' border='0' width='240'>";
    content += "          <colgroup>";
    content += "            <col width='110' align='left' />";
    content += "            <col width='125' align='left' />";
    content += "            <col width='15' align='right' />";
    content += "          </colgroup>";
    content += "          <!-- Jurisdiction Info -->";
    content += "          <tr>";
    content += "            <td colspan='2'>";
    content += "              <b>Jurisdiction:</b>";
    content += "            </td>";
    content += "            <td>";
    content += "              <img src='./images/info.gif' />";
    content += "            </td>";
    content += "          </tr>";
    content += "          <tr>";
    content += "            <td bgcolor='black' colspan='3' height='2'></td>";
    content += "          </tr>";
    content += "          <tr valign='top'>";
    content += "            <td>County:</td>";
    content += "            <td colspan='2'>KNOX COUNTY</td>";
    content += "          </tr>";
    content += "          <tr valign='top'>";
    content += "            <td>City / Township:</td>";
    content += "            <td colspan='2'>";
                            if (typeof(objIncorpAreas) != "undefined")
    content +=                      objIncorpAreas.CITY_NAME;                            
    content += "            </td>";
    content += "          </tr>";
    content += "        </table>";
    content += "        <br></br>";

    //build school zone information
    content += "         <table class='results' cellpadding='0' cellspacing='2' border='0' width='240'>";
    content += "          <colgroup>";
    content += "            <col width='110' align='left' />";
    content += "            <col width='125' align='left' />";
    content += "            <col width='15' align='right' />";
    content += "          </colgroup>";
    content += "          <!--School Zones Area-->";
    content += "          <tr>";
    content += "            <td colspan='2'>";
    content += "              <b>School Zones:</b>";
    content += "            </td>";
    content += "            <td>";
    content += "              <img src='./images/info.gif' />";
    content += "            </td>";
    content += "          </tr>";
    content += "          <tr>";
    content += "            <td bgcolor='black' colspan='3' height='2'></td>";
    content += "          </tr>";
    content += "          <tr valign='top'>";
    content += "            <td>Elementary:</td>";
    content += "            <td colspan='2'>";
                            if ((typeof(objElemSchool) != "undefined") && (objElemSchool != null)) {
    content +=                objElemSchool.SCHOOL_NAME;
                            } else {
    content += "              <i>data missing</i>";
                            }
    content += "            </td>";
    content += "          </tr>";
    //only show the intermediate school when necessary
                          if ((typeof(objInterSchool) != "undefined") && (objInterSchool != null)) {
    content += "            <tr valign='top'>";
    content += "              <td>Intermediate:</td>";
    content += "              <td colspan='2'>";
    content +=                  objInterSchool.SCHOOL_NAME;
    content += "              </td>";
    content += "            </tr>";
                          }
    content += "          <tr valign='top'>";
    content += "            <td>Middle:</td>";
    content += "            <td colspan='2'>";
                            if ((typeof(objMiddleSchool) != "undefined") && (objMiddleSchool != null)) {
    content +=                objMiddleSchool.SCHOOL_NAME;
                            } else {
    content += "              <i>data missing</i>";
                            }
    content += "            </td>";
    content += "          </tr>";
    content += "          <tr valign='top'>";
    content += "            <td>High:</td>";
    content += "            <td colspan='2'>";
                            if ((typeof(objHighSchool) != "undefined") && (objHighSchool != null)) {
    content +=                objHighSchool.SCHOOL_NAME;
                            } else {
    content += "              <i>data missing</i>";
                            }    
    content += "            </td>";
    content += "          </tr>";
    content += "          <tr height='2'>";
    content += "            <td colspan='3'></td>";
    content += "          </tr>";
    content += "          <tr>";
    content += "            <td colspan='3' class='smallNotes'>";
    content += "              Please contact Knox County Schools Transportation and";
    content += "              Zoning Department at 594-1550 if you have questions.";
    content += "              Additional information about the individual schools can";
    content += "              be found at the <a href='" + schoolsWebsite + "' target='_blank'>";
    content += "              Knox County Schools website</a>.";
    content += "            </td>";
    content += "          </tr>";
    content += "        </table>";
    content += "        <br></br>";

    //build voting location and representative information
    content += "        <table class='results' cellpadding='0' cellspacing='2' border='0' width='240'>";
    content += "          <colgroup>";
    content += "            <col width='100' align='left' />";
    content += "            <col width='15' align='right' />";
    content += "            <col width='120' align='left' />";
    content += "            <col width='15' align='right' />";
    content += "          </colgroup>";
    content += "          <!--Voting Information Area-->";
    content += "          <tr>";
    content += "            <td colspan='3'>";
    content += "              <b>Voting Information:</b>";
    content += "            </td>";
    content += "            <td>";
    content += "              <img src='./images/info.gif' />";
    content += "            </td>";
    content += "          </tr>";
    content += "          <tr>";
    content += "            <td bgcolor='black' colspan='4' height='2'></td>";
    content += "          </tr>";
                          if (typeof(objVotingPrecinct) != "undefined") {
    content += "            <tr valign='top'>";    
    content += "              <td>Voting Precinct:</td>";
    content += "              <td>";
    content +=                  objVotingPrecinct.VOT_PRE__;
    content += "              </td>";
    content += "              <td></td>";
    content += "              <td></td>";
    content += "            </tr>";
    content += "            <tr valign='top'>";
    content += "              <td>Voting Location:</td>";
    content += "              <td></td>";
    content += "              <td colspan='2'>";
    content +=                  objVotingPrecinct.SITE_NAME;
    content += "                <br>";
    content +=                  objVotingPrecinct.HOUSE_NUMBER + " " + objVotingPrecinct.STREET_NAME;
    content += "              </td>";
    content += "            </tr>";                           
                          } else {
    content += "            <td>Voting Precinct:</td>";
    content += "            <td colspan='3'><i>data missing</i></td>";
                          }
    content += "          <tr valign='top'>";
    content += "            <td>TN State House:</td>";
                            if (typeof(objStateHouse) != "undefined") {
    content += "              <td>";
    content +=                  objStateHouse.TN_HOUSE;                            
    content += "              </td>";
    content += "              <td colspan='2'>";
    content += "                <a href='" + stateHouseWebsite + objStateHouse.WEBSITE + "' target='_blank'>" + objStateHouse.MEMBER + "</a>"; 
    content += "              </td>";
                            } else {
    content += "              <td colspan='3'>";
    content += "              <i>data missing</i>";
    content += "              </td>";
                            } 
    content += "          </tr>";
    content += "          <tr valign='top'>";
    content += "            <td>TN State Senate:</td>";
                            if (typeof(objStateSenate) != "undefined") {
    content += "              <td>";
    content +=                  objStateSenate.TN_SENATE;                           
    content += "              </td>";
    content += "              <td colspan='2'>";
    content += "                <a href='" + stateSenateWebsite + objStateSenate.WEBSITE + "' target='_blank'>" + objStateSenate.MEMBER + "</a>";
    content += "              </td>";
                            } else {
    content += "              <td colspan='3'>";
    content += "              <i>data missing</i>";
    content += "              </td>";
                            } 
    content += "          </tr>";
    content += "          <tr valign='top'>";
    content += "            <td>County Comm.:</td>";
                            if (typeof(objCountyCommission) != "undefined") {
    content += "              <td>";
    content +=                  objCountyCommission.CO_COMM;                            
    content += "              </td>";
    content += "              <td colspan='2'>";
    content += "                <a href='" + countyCommissionWebsite + objCountyCommission.WEBSITE_A + "' target='_blank'>" + objCountyCommission.MEMBER_A + "</a>"; 
    content += "                <br>";
    content += "                <a href='" + countyCommissionWebsite + objCountyCommission.WEBSITE_B + "' target='_blank'>" + objCountyCommission.MEMBER_B + "</a>"; 
    content += "                <br>";
    content += "                <a href='" + countyCommissionWebsite + objCountyCommission.WEBSITE_C + "' target='_blank'>" + objCountyCommission.MEMBER_C + "</a>"; 
    content += "              </td>";
                            } else {
    content += "              <td colspan='3'>";
    content += "              <i>data missing</i>";
    content += "              </td>";
                            } 
    content += "          </tr>";
    content += "          <tr valign='top'>";
    content += "            <td>City Council:</td>";
                            if (typeof(objCityCouncil) != "undefined") {
    content += "              <td>";
    content +=                  objCityCouncil.DISTRICT;
    content += "              </td>";
    content += "              <td colspan='2'>";
    content += "                  <a href='" + cityCouncilWebsite + objCityCouncil.WEBSITE + "' target='_blank'>" + objCityCouncil.MEMBER + "</a>"; 
    content += "              </td>";
                            } else {
    content += "              <td colspan='3'>";
    content += "              <i>data missing</i>";
    content += "              </td>";
                            } 
    content += "          </tr>";
    content += "          <tr valign='top'>";
    content += "            <td>School Board:</td>";
                            if (typeof(objSchoolBoard) != "undefined") {
    content += "              <td>";
    content +=                  objSchoolBoard.SCH_BOARD;
    content += "              </td>";
    content += "              <td colspan='2'>";
    content += "                  <a href='" + schoolBoardWebsite + "' target='_blank'>" + objSchoolBoard.MEMBER + "</a>";
    content += "              </td>";
                            } else {
    content += "              <td colspan='3'>";
    content += "              <i>data missing</i>";
    content += "              </td>";
                            } 
    content += "          </tr>";
    content += "        </table>";

    
    //get the details pane and show the data
    var detailsPane = dojo.byId("cpDetails");
    detailsPane.innerHTML = content;
    
    //imgBusySearchingDetails
    hideBusyDetails();
}

