﻿// Assists with report functions
dojo.declare("ReportHelper", null,
{
    _geometryServer: "http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer",
    _printServiceUrl: "/MapPrintingService/MapPrintingService.svc",
    _reportExportSvc: "/ReportService/DemographicsExport/",
    _driveTimeSource: null,
    _dtServiceUrl: null,
    _busyIndicatorDriveTime: null,
    _driveTimeTask: null,
    _callbackFunction: null,
    _errorFunction: null,
    _propertyReportGraphics: null,
    _propertyReportAreaSymbol: null,
    _updatePanelUniqueId: null,
    _polygonHiddenInput: null,
    _map: null,
    _driveTimeCallbackFunction: null,
    _businessGraphicsLayer: null,
    _geomTask: null,
    _bufferParams: null,
    _notifTask: null,
    _notifParams: null,
    _notifSymbol: null,
    _notifResultsDiv: null,
    _notifData: null,
    _notifForm: null,
    _logoUrl: null,

    constructor: function (map, driveTimeSource, driveTimeServiceUrl, updatePanelUniqueId, polygonHiddenInputId,
            driveTimeBusyIndicatorId, geometryServer, logoUrl) {
        this._map = map;
        this._driveTimeSource = driveTimeSource;
        this._dtServiceUrl = driveTimeServiceUrl;
        this._busyIndicatorDriveTime = $('#' + driveTimeBusyIndicatorId);
        this._updatePanelUniqueId = updatePanelUniqueId;
        //this._polygonHiddenInput = $('#' + polygonHiddenInputId);
        if (geometryServer && geometryServer != "")
            this._geometryServer = geometryServer;
        this._logoUrl = logoUrl;
    },

    clearReportGraphics: function () {
        if (this._businessGraphicsLayer)
            this._businessGraphicsLayer.clear();
        if (this._propertyReportGraphics)
            this._propertyReportGraphics.clear();
    },

    validRadius: function (radius, maxRadius) {
        if (isNaN(radius) || radius <= 0 || radius > maxRadius) {
            alert('Please enter a whole number integer value between 0 and ' + maxRadius + ' for distance');
            return false;
        }
        return true;
    },

    showReportRadiusOnMap: function (lng, lat, radius, maxRadius, busyIndicatorId) {
        /// Used by Demographic (distance) and Business reports to display report circle on map
        /// radius: radius of circle to show, in meters
        /// maxRadius: if radius exceeds this value, an alert will be displayed in instead of the circle on map
        this.initReportGraphics();
        this._propertyReportGraphics.clear();

        if (!this.validRadius(radius, maxRadius))
            return false;

        $('#' + busyIndicatorId).show();

        // Add circle for report area
        var circlePoly = this._createSmallCircle(lat, lng, radius);
        var circleWM = esri.geometry.geographicToWebMercator(circlePoly);

        this._propertyReportGraphics.add(new esri.Graphic(circleWM, this._propertyReportAreaSymbol));

        // Zoom out to circle if closer in
        this.zoomToShowGeometry(circleWM, this._map, true);

        return true;
    },

    showBusinessesOnMap: function (naics) {
        // Get businesses from report. NOTE: tied to BusinessReport.ascx class names & structure.
        this.initReportGraphics();
        this._businessGraphicsLayer.clear();
        this._busNaics = naics; // used in details report export

        var busData, geoPt, wmPt, busTypeRow, color, sym, attr;
        var sr = this._map.spatialReference;
        var busGraphics = this._businessGraphicsLayer;
        var infoTempl = new esri.InfoTemplate("<span style='float:right;font-size:7pt;cursor:pointer' onclick='map.infoWindow.hide()'>Close</span>${BusinessName}",
             "Business name:<br/>&nbsp;${BusinessName}<br/><br/>Employees:<br/>&nbsp;${Employees}");

        // Get all the xy's in hidden fields in the business details table
        $('.businessDetailsTable .busLocs').each(function (data, data2) {
            busData = $(this).val().split(',');
            geoPt = new esri.geometry.Point(parseFloat(busData[0]), parseFloat(busData[1]), sr);
            wmPt = esri.geometry.geographicToWebMercator(geoPt);

            // Get color from the colorchip div for the business type
            busTypeRow = $(this).parents('tr.businessListRow').prev();
            color = busTypeRow.find('.colorchip').css('backgroundColor');

            sym = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 7,
                new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 0, 0, 1]), 1),
                new dojo.Color(color));

            // Put name & employees in attributes and add popup
            attr = { "BusinessName": busData[2], "Employees": busData[3] };

            busGraphics.add(new esri.Graphic(wmPt, sym, attr, infoTempl));
        });
        this.hideReports(); // switch to map if necessary
    },

    labelBusiness: function (lng, lat, name) {
        var newpt = esri.geometry.geographicToWebMercator(new esri.geometry.Point(lng, lat, new esri.SpatialReference({ wkid: 4326 })));

        // try to find in bus graphics - show infowindow
        var selGraphic = null;
        for (var gr, g = -1; gr = this._businessGraphicsLayer.graphics[++g]; ) {
            if (gr.geometry.x == newpt.x && gr.geometry.y == newpt.y && gr.attributes.BusinessName == name) {
                this._map.infoWindow.setContent(gr.getContent());
                this._map.infoWindow.setTitle(gr.getTitle());
                this._map.infoWindow.resize(250, 150);
                var scrnPt = esri.geometry.toScreenGeometry(this._map.extent, this._map.width, this._map.height, gr.geometry);
                this._map.infoWindow.show(scrnPt, this._map.getInfoWindowAnchor(scrnPt));
                break;
            }
        }
    },

    zoomHighlightBusiness: function (lng, lat, name) {
        var newpt = esri.geometry.geographicToWebMercator(new esri.geometry.Point(lng, lat, new esri.SpatialReference({ wkid: 4326 })));

        //        // try to find in bus graphics - show infowindow
        //        var selGraphic = null;
        //        for (var gr, g = -1; gr = this._businessGraphicsLayer.graphics[++g]; ) {
        //            if (gr.geometry.x == newpt.x && gr.geometry.y == newpt.y && gr.attributes.BusinessName == name) {
        //                this._map.infoWindow.setContent(gr.getContent());
        //                this._map.infoWindow.setTitle(gr.getTitle());
        //                var scrnPt = esri.geometry.toScreenGeometry(this._map.extent, this._map.width, this._map.height, gr.geometry);
        //                this._map.infoWindow.show(scrnPt, this._map.getInfoWindowAnchor(scrnPt));
        //                break;
        //            }
        //        }

        map.centerAndZoom(newpt, 15);
        this.hideReports(); // switch to map if necessary
    },

    createPropertyDriveTimeReport: function (lng, lat, minutes, callback) {
        this._driveTimeCallbackFunction = callback;
        this.initReportGraphics();
        this._propertyReportGraphics.clear();

        if (isNaN(minutes) || minutes <= 0 || minutes > 60) {
            alert('Please enter a whole number integer value between 1 and 60 for minutes');
            return false;
        }
        this._busyIndicatorDriveTime.show();

        if (this._driveTimeSource.toUpperCase() == "ESRI") {
            this.getDriveTimeFromEsri(new esri.geometry.Point(lng, lat, new esri.SpatialReference({ 'wkid': 4326 })), minutes);
        }
        else if (this._driveTimeSource.toUpperCase() == "SAAS") {
            this.driveTimeFromSaaS(lng, lat, minutes);
        }
    },

    getDriveTimeFromEsri: function (startPoint, minutes) {
        if (!this._driveTimeTask) {
            this._driveTimeTask = new esri.tasks.Geoprocessor(this._dtServiceUrl);
            this._driveTimeTask.outSpatialReference = startPoint.spatialReference;
        }
        var fset = new esri.tasks.FeatureSet();
        var wmGraphic = new esri.Graphic(startPoint);
        fset.features = [wmGraphic];
        var inputParams = { "Input_Location": fset, "Drive_Times": minutes };
        this._driveTimeTask.execute(inputParams, dojo.hitch(this, this.driveTimeEsriCallback), dojo.hitch(this, this.driveTimeEsriError));
    },

    driveTimeEsriCallback: function (data) {
        if (data.length > 0 && data[0].value && data[0].value.features.length > 0) {
            var geoGeom = data[0].value.features[0].geometry;
            var wmGeom = esri.geometry.geographicToWebMercator(geoGeom);
            var gr = new esri.Graphic(wmGeom, this._propertyReportAreaSymbol);
            this._propertyReportGraphics.add(gr);

            this.zoomToShowGeometry(wmGeom, map, true);

            // Insert the polygon data into the form and submit to get demographics at server
            var ring = geoGeom.rings[0];
            var polyStr = "";
            for (var pt, i = -1; pt = ring[++i]; ) {
                if (i > 0)
                    polyStr += ",";
                polyStr += pt[1].toFixed(6) + ":" + pt[0].toFixed(6);
            }
            this._driveTimeCallbackFunction(polyStr, this);
            // Hidden field is empty if set it here - do callback to orig caller and have it set the value instead
            //this._polygonHiddenInput.val(polyStr);
            // Trigger postback for report
            //__doPostBack(this._updatePanelUniqueId, "DriveTime");
        }
        else {
            this._busyIndicatorDriveTime.hide();
            alert("No drive time area is available. If problem persists, please contact Support.");
        }
    },

    driveTimeEsriError: function (msg) {
        this._busyIndicatorDriveTime.hide();
        alert("Could not obtain the drive time area. If problem persists, please contact Support.");
    },

    driveTimeFromSaaS: function (x, y, minutes) {
        var parameters = { customerId: '00000000-0000-0000-0000-000000000000', lat: y, lon: x, driveTime: minutes };
        var paramStr = dojo.toJson(parameters);
        $.ajax({
            type: "POST",
            url: "proxy.ashx?" + saasDriveTimeService,
            data: paramStr,
            contentType: "application/json",
            dataType: "json",
            success: function (msg) {
                var svcPts = msg.d;
                var wmPts = [];
                var lpt;
                var wgsSR = new esri.SpatialReference({ wkid: 4326 });
                var polyStr = "";

                // Create polygon to display, and also list for report
                for (var svcPt, i = -1; svcPt = svcPts[++i]; ) {
                    lpt = new esri.geometry.Point(svcPt.X, svcPt.Y, wgsSR);
                    wmPts.push(esri.geometry.geographicToWebMercator(lpt));
                    if (polyStr.length > 0)
                        polyStr += ",";
                    polyStr += svcPt.Y + ":" + svcPt.X;
                }

                var dtPoly = new esri.geometry.Polygon(this._map.spatialReference);
                dtPoly.addRing(wmPts);
                this._propertyReportGraphics.add(new esri.Graphic(dtPoly, this._propertyReportAreaSymbol));
                this.zoomToShowGeometry(dtPoly, this._map, true);

                this._driveTimeCallbackFunction(polyStr);
                //this._polygonHiddenInput.val(polyStr);
                //// Trigger postback for report
                //__doPostBack(this._updatePanelUniqueId, "DriveTime");
            },
            error: function (e) {
                alert("Could not obtain the drive time area. If problem persists, please contact Support.");
                this._busyIndicatorDriveTime.hide();
            }
        });
    },

    initReportGraphics: function () {
        if (!this._propertyReportGraphics) {
            this._propertyReportGraphics = this._map.addLayer(new esri.layers.GraphicsLayer(), 0);
            var outline = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 0, 255]), 2);
            this._propertyReportAreaSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, outline,
                new dojo.Color([0, 0, 255, 0.1]));
        }

        if (!this._businessGraphicsLayer) {
            this._businessGraphicsLayer = new esri.layers.GraphicsLayer();
            this._map.addLayer(this._businessGraphicsLayer);

            // show business infowindow on hover
            dojo.connect(this._businessGraphicsLayer, "onMouseMove", function (evt) {
                var g = evt.graphic;
                this._map.infoWindow.setContent(g.getContent());
                this._map.infoWindow.setTitle(g.getTitle());
                this._map.infoWindow.show(evt.screenPoint, this._map.getInfoWindowAnchor(evt.screenPoint));
            });
            //dojo.connect(this._businessGraphicsLayer, "onMouseOut", function () { this._map.infoWindow.hide(); });
        }
    },

    _createSmallCircle: function (lat, lng, radius) {
        /// Creates a circle of equal geodesic distance around the point.
        /// radius: radius of circle, in meters
        var polygon = new esri.geometry.Polygon();
        polygon.setSpatialReference(new esri.SpatialReference({ wkid: 4326 }));
        var points = [];
        var degreesToRadians = Math.PI / 180.0;
        var metersPerDegree = 111120.0;
        var latRadians = lat * degreesToRadians;
        var lngRadians = lng * degreesToRadians;
        var radiusRadians = radius / metersPerDegree * degreesToRadians; // meters to radian distance

        for (var angle = 0; angle <= 360; angle += 5) {
            points.push(this._getSmallCirclePoint(lngRadians, latRadians, angle, radiusRadians));
        }

        polygon.addRing(points);
        return polygon;
    },

    _getSmallCirclePoint: function (lngRadians, latRadians, azimuth, radiusRadians) {
        // Gets the point on earth small circle based on center, direction and radius
        // BASED ON: function directSolution() at Paul Demers http://www.acscdg.com/
        var radiansToDegrees = 180.0 / Math.PI;
        var azimuthR = azimuth / radiansToDegrees;

        var sinStartLat = Math.sin(latRadians);
        var cosStartLat = Math.cos(latRadians);

        var sinAzimuth = Math.sin(azimuthR);
        var cosAzimuth = Math.cos(azimuthR);

        var sinDistance = Math.sin(radiusRadians);
        var cosDistance = Math.cos(radiusRadians);

        var X = (cosStartLat * cosDistance) - (sinStartLat * cosAzimuth * sinDistance);
        var Y = sinDistance * sinAzimuth;

        var endLat = Math.asin((sinStartLat * cosDistance) + (cosStartLat * sinDistance * cosAzimuth));
        var endLng = lngRadians + Math.atan2(Y, X);

        return new esri.geometry.Point(endLng * radiansToDegrees, endLat * radiansToDegrees, new esri.SpatialReference({ wkid: 4326 }));
    },

    createCircleGeometry: function (pt, radius) {
        var polygon = new esri.geometry.Polygon();
        polygon.setSpatialReference(pt.spatialReference);
        var points = [];
        var radian, x, y, diffX, diffY;

        for (var i = -5; i < 360; i += 5) {
            radian = i * (Math.PI / 180.0);
            diffX = radius * Math.cos(radian);
            x = pt.x + diffX;
            diffY = radius * Math.sin(radian);
            y = pt.y + diffY;
            points.push(new esri.geometry.Point(x, y));
        }

        polygon.addRing(points);
        return polygon;
    },

    zoomToShowGeometry: function (geom, theMap, zoomIn) {
        /// zoomIn: optional parameter - if true, zooms in to extent of the geometry.
        var geomExt = null;
        switch (geom.declaredClass) {
            case "esri.geometry.Extent":
                geomExt = geom; break;
            case "esri.geometry.Polygon": case "esri.geometry.Polyline": case "esri.geometry.Multipoint":
                geomExt = geom.getExtent(); break;
            default:
                return; break;
        }
        var mapExt = theMap.extent;
        if (!mapExt.contains(geomExt))
            theMap.setExtent(mapExt.union(geomExt), true);
        else if (zoomIn) {
            theMap.setExtent(geomExt.expand(1.5));
        }
    },

    /*
    * Export
    */

    _reportMapWidth: 500,
    _reportMapHeight: 500,
    _printClient: null,
    _exportDialog: null,

    // property/parcel controls store report data for export here
    demogReportBy: null,
    demogReportParams: null,
    busReportParams: null,
    busDetailsReportParams: null,
    _currentDataType: null,
    _busNaics: null, // business details type

    showExportDialog: function (dataType, format) {
        // Display the export dialog, with settings for the selected format (pdf/etc)
        var repHlpr = this;
        this._currentDataType = dataType;
        $().colorbox({ href: "ControlsGisp/Reports/ExportDialog.htm", open: true, innerWidth: 450, innerHeight: 240,
            onComplete: function () {
                exportDialog.init(format, dojo.hitch(repHlpr, repHlpr.doReportExport));
                repHlpr._exportDialog = exportDialog;
            }
        });
        this.scrollToTop();
    },

    doReportExport: function (format, title, addMap, addLegend, addReport, emailInfo) {
        // parcel/property client stores demog or business report settings
        var dPars = (this._currentDataType === "demog") ? this.demogReportParams : this.busReportParams;

        if (dPars) {
            this._exportDialog.hideMessage();

            if (this._currentDataType == "busDet" && this._busNaics) {
                // doing business details report
                this.busDetailsReportParams = { distance: dPars.distance, x: dPars.x, y: dPars.y,
                    naics: this._busNaics, tn: dPars.tn, location: dPars.location
                };
                dPars = this.busDetailsReportParams;
            }

            dPars.format = format;
            dPars.title = title;
            dPars.logoUrl = this._logoUrl;
            dPars.showReport = addReport;
            dPars.emailInfo = emailInfo;

            if (addMap) {
                this._exportDialog.busy(true, "Creating map image...");
                if (!this._printClient) {
                    this._printClient = new PrintUtility(map, this._printServiceUrl + "/json/ExportMap");
                }

                this._printClient.exportMap(this._reportMapHeight, this._reportMapWidth,
                    dojo.hitch(this, this._exportMapCallback),
                    dojo.hitch(this, this._exportMapError));
            }
            else if (addReport) {
                this._exportDialog.busy(true, "Creating report...");
                this.doExport("");
            }
            else {  // No map or report data selected
                alert("Please select map and/or report data for export.");
            }
        }
    },

    _exportMapCallback: function (mapUrl) {
        this._exportDialog.busy(true, "Creating report...");
        this.doExport(mapUrl);
    },

    _exportMapError: function (msg) {
        // just export report data
        this._exportDialog.busy(true, "Creating report...");
        this.doExport("");
    },

    doExport: function (mapUrl) {
        try {
            if (mapUrl != "") {
                if (mapUrl.length > 0 && typeof _lbn !== "undefined") {
                    var pr = (mapUrl.indexOf("?") > 0) ? "&" : "?";
                    mapUrl += pr + "svr=" + _lbn;
                }
            }

            var dPars = null;
            var exportMethod = "";
            switch (this._currentDataType) {
                case "demog":
                    dPars = this.demogReportParams;
                    if (this.demogReportBy === "polygon")
                        exportMethod = "ExportDemographicsByPolygon";
                    else if (this.demogReportBy === "place")
                        exportMethod = "ExportDemographicsByLocation";
                    else
                        exportMethod = "ExportDemographicsByRadius";
                    break;
                case "bus":
                    dPars = this.busReportParams;
                    exportMethod = "ExportBusinessCountsByRadius";
                    break;
                case "busDet":
                    dPars = this.busDetailsReportParams;
                    exportMethod = "ExportBusinessDetailsByRadius";
                    break;
            }

            dPars.mapUrl = mapUrl;
            dPars.mapHeight = this._reportMapHeight;
            dPars.mapWidth = this._reportMapWidth;

            var jdata = dojo.toJson(dPars);
            var resCtl = this;

            $.ajax({
                url: this._reportExportSvc + exportMethod,
                type: "POST",
                contentType: "application/json",
                data: jdata,
                success: function (data) {
                    resCtl._exportDialog.busy(false, "");
                    var resultMsg = "";

                    if (data && data.Success) {
                        if (dPars.format === "email") {
                            resultMsg = "Successfully emailed the report.";
                        }
                        else {
                            resultMsg = "<a href='" + data.Url + "' target='_blank'>Click here to download your report</a>";
                        }
                    }
                    else
                        resultMsg = "Sorry, an error occurred creating the report. Please try again. If problem persists, contact Support.";

                    resCtl._exportDialog.showMessage(resultMsg);
                },
                error: function (err) {
                    resCtl._exportDialog.showMessage("Sorry, an error occurred exporting the report. If problem persists, please contact Support");
                    resCtl._exportDialog.busy(false, "");
                }
            });

        }
        catch (err) {
            alert("Error occurred creating report. If problem persists, please contact Support.");
            this._exportDialog.busy(false, "");
        }

    },

    /*
    * Notification report
    */
    createNotificationReport: function (feature, radiusMeters, resultsDivId, parcelServiceUrl, layerId, notifFields) {
        this.initReportGraphics();
        this._propertyReportGraphics.clear();
        this._initNotifTask(parcelServiceUrl, layerId, notifFields, resultsDivId);

        // Get buffer around feature
        this._bufferParams.distances = [radiusMeters];
        this._bufferParams.geometries = [feature.geometry];
        this._geomTask.buffer(this._bufferParams, dojo.hitch(this, this._notifBufferCallback),
            function (err) {
                $("#parcelNotifRepBusy").hide();
                alert('Error getting buffer around feature. If error persists, please contact Support.');
            });
    },

    _notifBufferCallback: function (polys) {
        if (polys && polys.length > 0) {
            this._propertyReportGraphics.add(new esri.Graphic(polys[0], this._propertyReportAreaSymbol));
            this._notifParams.geometry = polys[0];
            this._notifTask.execute(this._notifParams, dojo.hitch(this, this._notifQueryCallback),
                function (err) {
                    $("#parcelNotifRepBusy").hide();
                    alert("Error querying features for notification. If error persists, please contact Support.");
                });
        }
        else
            $("#parcelNotifRepBusy").hide();
    },

    _notifQueryCallback: function (featSet) {
        var graphics = featSet.features;
        var resHtml = [];

        if (graphics && graphics.length > 0) {
            // show parcels on map
            for (var g, i = -1; g = featSet.features[++i]; ) {
                g.setSymbol(this._notifSymbol);
                this._propertyReportGraphics.add(g);
            }
            this._map.setExtent(esri.graphicsExtent(featSet.features));

            // display parcel report
            resHtml.push('<div style="float:right; margin:5px;"><a href="javascript:void(0)" onclick="parcelResults._reportHelper.notifExport()" title="Export to spreadsheet">');
            resHtml.push('<img src="ControlsGisp/images/excel-file.gif"/></a></div>');
            resHtml.push('</div><div style="margin:8px 0px 10px 0px;">' + graphics.length.toString() + ' parcels found</div>');
            resHtml.push('<table width="100%"><tr>');
            var notifLine = [];
            for (var col, i = -1; col = this._notifParams.outFields[++i]; ) {
                resHtml.push('<th>' + col + '</th>');
                notifLine.push(col);
            }
            // also save data in export format
            this._notifData = [notifLine];
            resHtml.push('</tr>');
            var attrs;
            for (var gr, i = -1; gr = graphics[++i]; ) {
                resHtml.push('<tr>');
                attrs = gr.attributes;
                notifLine = [];
                for (var col, c = -1; col = this._notifParams.outFields[++c]; ) {
                    resHtml.push('<td>' + attrs[col] + '</td>');
                    notifLine.push(attrs[col]);
                }
                resHtml.push('</tr>');
                this._notifData.push(notifLine);
            }
            resHtml.push('</table>');
        }
        else {
            resHtml.push("No data available for this location.");
        }
        this._notifResultsDiv.html(resHtml.join(''));
        $("#parcelNotifRepBusy").hide();
    },

    notifExport: function () {
        if (!this._notifForm) {
            var form = document.createElement("form");
            form.setAttribute("method", "post");
            form.setAttribute("action", "NotificationExport.aspx");
            form.setAttribute("target", "_blank");
            var hiddenField = document.createElement("input");
            hiddenField.setAttribute("name", "notifyData");
            form.appendChild(hiddenField);
            this._notifForm = form;
            document.body.appendChild(form);
        }
        if (this._notifData) {
            this._notifForm.firstChild.setAttribute("value", dojo.toJson(this._notifData));
            this._notifForm.submit();
        }
    },

    _initNotifTask: function (parcelServiceUrl, layerId, notifFields, resultsDivId) {
        if (!this._notifTask) {
            this._notifTask = new esri.tasks.QueryTask(parcelServiceUrl + "/" + layerId);
            this._notifParams = new esri.tasks.Query();
            this._notifParams.outFields = notifFields.split(',');
            this._notifParams.returnGeometry = true;
            this._geomTask = new esri.tasks.GeometryService(this._geometryServer);
            this._bufferParams = new esri.tasks.BufferParameters();
            this._notifSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NULL,
                new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 200, 200]), 1),
                new dojo.Color([0, 0, 0, 0.1]));
        }
        this._notifResultsDiv = $("#" + resultsDivId);
    },

    hideReports: function () {
        // tabs for showMap in parcel-based apps only
        if (typeof showMap != "undefined")
            showMap();
    },

    scrollToTop: function () {
        $('html, body').animate({ scrollTop: 0 }, 'slow');
    }
});

/*
 * Demographic reports
 */

// ParcelResults/PropertyResults sets this
var demogReportHelper = null;

function showDemogExportDialog(format) {
    if (demogReportHelper)
        demogReportHelper.showExportDialog("demog", format);
}

/*
* BusinessReport control
*/

// ParcelResults/PropertyResults sets businessReportHelper
var businessReportHelper = null;

function showBusinessesOnMap(naics) {
    if (businessReportHelper)
        businessReportHelper.showBusinessesOnMap(naics);
}

function labelBusiness(x, y, name) {
    if (businessReportHelper)
        businessReportHelper.labelBusiness(x, y, name);
}

function zoomToBusiness(x, y, name) {
    if (businessReportHelper)
        businessReportHelper.zoomHighlightBusiness(x, y, name);
}

function showBusExportDialog(format) {
    if (businessReportHelper)
        businessReportHelper.showExportDialog("bus", format);
}

function showBusDetExportDialog(format) {
    if (businessReportHelper)
        businessReportHelper.showExportDialog("busDet", format);
}

