/* Minification failed. Returning unminified contents.
(1,10): run-time error CSS1031: Expected selector, found 'doFind('
(1,10): run-time error CSS1025: Expected comma or open brace, found 'doFind('
(298,10): run-time error CSS1031: Expected selector, found 'showBuildingSearchResults('
(298,10): run-time error CSS1025: Expected comma or open brace, found 'showBuildingSearchResults('
 */
function doFind(PCIS_bld_id) {    
    //Set the search text to the value in the box
    //Value of variable PCIS_bld_id is set into AddressWidget.js file 
    BuildingSearchFindParameters.searchText = PCIS_bld_id; //dojo.byId("txtBuildingNumber").value;
    //Get only number part from the PCIS_bld_id
    var bldg_ID = parseInt(PCIS_bld_id);
    
    /********Check if building id is number or not*********/
    if (!isNaN(PCIS_bld_id)) {
        /*If user enters the temporary building id then open infowindow for temporary building*/
        //Check temporary building id length it should be less than 12 digit because original building id length is starting from 12 digits        
        if (bldg_ID.toString().length < 12) {

            //build query filter
            query = new esri.tasks.Query();
            query.returnGeometry = true;
            query.outFields = ["*"];
            query.where = "BLD_ID = '" + bldg_ID + "'";

            searchFeatureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, function (features) {
                
                if (features.length > 0) {
                    var resultFeatures = features[0];
                    /*Check for selected feature layer type and feature type coming from the PCIS. 
                    If both feature types are same then show the feature Infowindow otherwise show error message. 
                        If feature type is blank from PCIS then simply search for the temporary building ID and show the Infowindow*/
                    var isfeatureMatchedFound = false;
                    for (k = 0; k < features.length; k++) {

                        if (features[k].attributes.TYPE != featureType && featureType != "") {


                        }
                        else {
                            isfeatureMatchedFound = true;
                            updateFeature = features[k];
                            var date = null;
                            var formatteddate = null;
                            if (features[k].attributes.DATE_ != null) {
                                date = new Date(features[k].attributes.DATE_);
                                formatteddate = (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear()
                            }

                            var featurediv = document.createElement("div");
                            featurediv.id = "infoContDiv";

                            var content = '<table><tr><td><b>Building ID</b>:</td><td><input type="text" class="editorInput" id="txtBldId" readonly="readonly"  value=' + (features[k].attributes.BLD_ID != null ? features[k].attributes.BLD_ID : '') + '  ></td></tr>'
                                                 + '<tr><td><b>Date</b>:</td><td><input type="text" class="editorInput" id="txtDate" readonly="readonly"  value=' + (features[k].attributes.DATE_ != null ? formatteddate : '') + ' ></td></tr>'
                                                 + '<tr><td><b>Author</b>:</td><td><input type="text" class="editorInput" id="txtAuthor" readonly="readonly"  value=' + (features[k].attributes.AUTHOR != null ? features[k].attributes.AUTHOR : '') + ' ></td></tr>'
                                                 //+ '<tr><td><b>PER_FLAG</b>:</td><td><select name="txtPerFlag" id="txtPerFlag" disabled    class="editorInput"><option value="2" ></option><option value="0"  ' + (resultFeatures.attributes.PER_FLAG != null && resultFeatures.attributes.PER_FLAG == 0 ? "Selected" : '') + '>Yes</option><option value="1" ' + (resultFeatures.attributes.PER_FLAG != null && resultFeatures.attributes.PER_FLAG == 1 ? "Selected" : '') + '>No</option></select> </td></tr>'
                                                 //+ '<tr><td><b>B1_PER_ID1</b>:</td><td><input type="text" class="editorInput" id="txtPerId1" readonly="readonly"  value=' + (resultFeatures.attributes.B1_PER_ID1 != null ? resultFeatures.attributes.B1_PER_ID1 : '') + ' ></td></tr>'
                                                 //+ '<tr><td><b>B1_PER_ID2</b>:</td><td><input type="text" class="editorInput" id="txtPerId2" readonly="readonly" value=' + (resultFeatures.attributes.B1_PER_ID2 != null ? resultFeatures.attributes.B1_PER_ID2 : '') + ' ></td></tr>'
                                                 //+ '<tr><td><b>B1_PER_ID3</b>:</td><td><input type="text" class="editorInput" id="txtPerId3" readonly="readonly" value=' + (resultFeatures.attributes.B1_PER_ID3 != null ? resultFeatures.attributes.B1_PER_ID3 : '') + ' ></td></tr>'
                                                 + '<tr><td><b>Permit #</b>:</td><td><input type="text" class="editorInput" id="txtPerId" readonly="readonly"  value=' + (features[k].attributes.PERMIT_ID != null ? features[k].attributes.PERMIT_ID.match(/\d{5}(?=\d{2,5})|\d+/g).join("-") : '') + ' ></td></tr>'
                            content += '</table>';
                            //if (userid.toLowerCase() == (features[k].attributes.AUTHOR != null ? features[k].attributes.AUTHOR.toLowerCase() : "")) {
                            content += '<table><tr><td>' + (permitid != "" && IsRequestFromPCIS == true && isClickHereForExistingBldg ? '<a onclick ="AssignPermitNumberToBuilding(\'' + (features[k].attributes.BLD_ID != null ? features[k].attributes.BLD_ID : '') + '\', \'' + '' + '\', \'' + '' + '\');" class="buttonAssignPermit" title="Assign Permit to this Structure">Assign Permit</a>' : "") + '</td><td ><input type="Submit" class="buttonAssignPermit" id="btnDelete" value="Delete Building" onclick="deleteFeatureLayer(\'' + (features[k].attributes.TYPE != null ? features[k].attributes.TYPE : '') + '\');"></td></tr></table>';
                            //} else {
                            //content += '</table>';
                            //}

                            //content += '</table>';

                            //content += (permitid != "" && IsRequestFromPCIS == true && isClickHereForExistingBldg ? '<br/><a onclick ="AssignPermitNumberToBuilding(\'' + (features[k].attributes.BLD_ID != null ? features[k].attributes.BLD_ID : '') + '\', \'' + '' + '\', \'' + '' + '\');" class="buttonAssignPermit" title="Assign Permit to this Structure">Assign Permit</a>' : "");


                            /************Hide progress bar**************/
                            hideProgress();

                            /*************Highlight the building*************************/
                            //map.setExtent(resultFeatures.geometry.getExtent(), true);
                            map.centerAndZoom(features[k].geometry, 14);
                   
                            var symbol = new SimpleMarkerSymbol().setStyle(
                                             SimpleMarkerSymbol.STYLE_SQUARE).setColor(
                                             new Color([0, 255, 255, 0.25])
                                           ).setSize("35");

                            /*Clear graphics from the Map*/
                            map.graphics.clear();

                            /*Set feature layer symbol*/
                            //features[k].setSymbol(symbol);

                            graphic = new Graphic(features[k].geometry, symbol);
                            map.graphics.add(graphic);

                            /*add feature in the graphics of the map*/
                            //map.graphics.add(features[k]);

                            featurediv.innerHTML = content;
                            map.infoWindow.setTitle(features[k].attributes.TYPE);
                            map.infoWindow.setContent(featurediv);
                            map.infoWindow.resize(350, 400);
                            map.infoWindow.show(features[k].geometry);
                            setDraggableInfoWindowUsingPointers();

                        }
                    }

                    if (!isfeatureMatchedFound) {
                        map.infoWindow.hide();
                        hideProgress();
                        confirmDialog(ValidationMessages.validBuildingIDAndBuildingType, "ok", false);
                    }
                }
                else {

                    hideProgress();

                    if (IsRequestFromPCIS) {
                        map.infoWindow.hide();

                        confirmDialog(ValidationMessages.noRecordFoundBuildingSearch, "ok", false)
                    }
                    else {
                        confirmDialog(ValidationMessages.noRecordFoundBuildingSearch, "ok", false)
                    }

                }
            });

            //searchBuildingFeatureUrl.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, function (features) {                
            //    if (features.length > 0) {
            //        var resultFeatures = features[0];
            //        /*Check for selected feature layer type and feature type coming from the PCIS. 
            //        If both feature types are same then show the feature Infowindow otherwise show error message. 
            //            If feature type is blank from PCIS then simply search for the temporary building ID and show the Infowindow*/
            //        if (resultFeatures.attributes.TYPE != featureType && featureType != "") {
            //            map.infoWindow.hide();
            //            hideProgress();

            //            confirmDialog(ValidationMessages.validBuildingIDAndBuildingType, "ok", false);

            //        } else {
            //            updateFeature = resultFeatures;
            //            //Set the Feature Layer InfoWindow content and open the InfoWindow
            //            /*Set the building quick view template by using following function. This function is present in Common.js file*/
            //            showBuildingQuickViewDetail(updateFeature);
            //            //feature.setInfoTemplate(buildingTemplate);                             
            //            /*Set the parcel quick view template by using following function.  This function is present in Common.js file*/
            //            showParcelQuickViewDetail(updateFeature, true);

            //            //var date = null;
            //            //var formatteddate = null;
            //            //if (resultFeatures.attributes.DATE_ != null) {
            //            //    date = new Date(resultFeatures.attributes.DATE_);
            //            //    formatteddate = (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear()
            //            //}

            //            //var featurediv = document.createElement("div");
            //            //featurediv.id = "infoContDiv";

            //            //var content = '<table><tr><td><b>BLD_ID</b>:</td><td><input type="text" class="editorInput" id="txtBldId" readonly="readonly"  value=' + (resultFeatures.attributes.BLD_ID != null ? resultFeatures.attributes.BLD_ID : '') + '  ></td></tr>'
            //            //                     + '<tr><td><b>DATE</b>:</td><td><input type="text" class="editorInput" id="txtDate" readonly="readonly"  value=' + (resultFeatures.attributes.DATE_ != null ? formatteddate : '') + ' ></td></tr>'
            //            //                     + '<tr><td><b>AUTHOR</b>:</td><td><input type="text" class="editorInput" id="txtAuthor" readonly="readonly"  value=' + (resultFeatures.attributes.AUTHOR != null ? resultFeatures.attributes.AUTHOR : '') + ' ></td></tr>'
            //            //                     + '<tr><td><b>PER_FLAG</b>:</td><td><select name="txtPerFlag" id="txtPerFlag" disabled    class="editorInput"><option value="2" ></option><option value="0"  ' + (resultFeatures.attributes.PER_FLAG != null && resultFeatures.attributes.PER_FLAG == 0 ? "Selected" : '') + '>Yes</option><option value="1" ' + (resultFeatures.attributes.PER_FLAG != null && resultFeatures.attributes.PER_FLAG == 1 ? "Selected" : '') + '>No</option></select> </td></tr>'
            //            //                     + '<tr><td><b>B1_PER_ID1</b>:</td><td><input type="text" class="editorInput" id="txtPerId1" readonly="readonly"  value=' + (resultFeatures.attributes.B1_PER_ID1 != null ? resultFeatures.attributes.B1_PER_ID1 : '') + ' ></td></tr>'
            //            //                     + '<tr><td><b>B1_PER_ID2</b>:</td><td><input type="text" class="editorInput" id="txtPerId2" readonly="readonly" value=' + (resultFeatures.attributes.B1_PER_ID2 != null ? resultFeatures.attributes.B1_PER_ID2 : '') + ' ></td></tr>'
            //            //                     + '<tr><td><b>B1_PER_ID3</b>:</td><td><input type="text" class="editorInput" id="txtPerId3" readonly="readonly" value=' + (resultFeatures.attributes.B1_PER_ID3 != null ? resultFeatures.attributes.B1_PER_ID3 : '') + ' ></td></tr>'
            //            //                     + '<tr><td><b>PERMIT_ID</b>:</td><td><input type="text" class="editorInput" id="txtPerId" readonly="readonly"  value=' + (resultFeatures.attributes.PERMIT_ID != null ? resultFeatures.attributes.PERMIT_ID : '') + ' ></td></tr>'

            //            //if (userid.toLowerCase() == (resultFeatures.attributes.AUTHOR != null ? resultFeatures.attributes.AUTHOR.toLowerCase() : "")) {
            //            //    content += '<tr><td colspan="2"><input type="Submit" class="ui-dialog-buttonset btn" id="btnDelete" value="Delete" onclick="deleteFeatureLayerTypePoint(\'' + (resultFeatures.attributes.TYPE != null ? resultFeatures.attributes.TYPE : '') + '\');"></td></tr></table>';
            //            //} else {
            //            //    content += '</table>';
            //            //}

            //            if (IsRequestFromPCIS) {
            //                $('#divBuildingQuickView').css("display", "block");
            //            }
            //            openBuildingAccordion();
            //            $('#buildingContent').html(buildingHtmlTemplate);



            //            setDraggableInfoWindow();
            //            //map.centerAndZoom(resultFeatures.geometry, 14);
            //            /************Hide progress bar**************/
            //            hideProgress();

            //            //featurediv.innerHTML = content;
            //            //map.infoWindow.setTitle(resultFeatures.attributes.TYPE);
            //            //map.infoWindow.setContent(featurediv);
            //            //map.infoWindow.resize(350, 400);
            //            //map.infoWindow.show(resultFeatures.geometry);
            //            //setDraggableInfoWindowUsingPointers();

            //        }

            //    }
            //    else {

            //        /************Hide progress bar**************/
            //        searchFeatureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, function (features) {

            //            if (features.length > 0) {
            //                var resultFeatures = features[0];
            //                /*Check for selected feature layer type and feature type coming from the PCIS. 
            //                If both feature types are same then show the feature Infowindow otherwise show error message. 
            //                    If feature type is blank from PCIS then simply search for the temporary building ID and show the Infowindow*/
            //                if (resultFeatures.attributes.TYPE != featureType && featureType != "") {
            //                    map.infoWindow.hide();
            //                    hideProgress();

            //                    confirmDialog(ValidationMessages.validBuildingIDAndBuildingType, "ok", false);

            //                }
            //                else {
            //                    updateFeature = resultFeatures;
            //                    var date = null;
            //                    var formatteddate = null;
            //                    if (resultFeatures.attributes.DATE_ != null) {
            //                        date = new Date(resultFeatures.attributes.DATE_);
            //                        formatteddate = (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear()
            //                    }

            //                    var featurediv = document.createElement("div");
            //                    featurediv.id = "infoContDiv";

            //                    var content = '<table><tr><td><b>Building ID</b>:</td><td><input type="text" class="editorInput" id="txtBldId" readonly="readonly"  value=' + (resultFeatures.attributes.BLD_ID != null ? resultFeatures.attributes.BLD_ID : '') + '  ></td></tr>'
            //                                         + '<tr><td><b>Date</b>:</td><td><input type="text" class="editorInput" id="txtDate" readonly="readonly"  value=' + (resultFeatures.attributes.DATE_ != null ? formatteddate : '') + ' ></td></tr>'
            //                                         + '<tr><td><b>Author</b>:</td><td><input type="text" class="editorInput" id="txtAuthor" readonly="readonly"  value=' + (resultFeatures.attributes.AUTHOR != null ? resultFeatures.attributes.AUTHOR : '') + ' ></td></tr>'
            //                                         //+ '<tr><td><b>PER_FLAG</b>:</td><td><select name="txtPerFlag" id="txtPerFlag" disabled    class="editorInput"><option value="2" ></option><option value="0"  ' + (resultFeatures.attributes.PER_FLAG != null && resultFeatures.attributes.PER_FLAG == 0 ? "Selected" : '') + '>Yes</option><option value="1" ' + (resultFeatures.attributes.PER_FLAG != null && resultFeatures.attributes.PER_FLAG == 1 ? "Selected" : '') + '>No</option></select> </td></tr>'
            //                                         //+ '<tr><td><b>B1_PER_ID1</b>:</td><td><input type="text" class="editorInput" id="txtPerId1" readonly="readonly"  value=' + (resultFeatures.attributes.B1_PER_ID1 != null ? resultFeatures.attributes.B1_PER_ID1 : '') + ' ></td></tr>'
            //                                         //+ '<tr><td><b>B1_PER_ID2</b>:</td><td><input type="text" class="editorInput" id="txtPerId2" readonly="readonly" value=' + (resultFeatures.attributes.B1_PER_ID2 != null ? resultFeatures.attributes.B1_PER_ID2 : '') + ' ></td></tr>'
            //                                         //+ '<tr><td><b>B1_PER_ID3</b>:</td><td><input type="text" class="editorInput" id="txtPerId3" readonly="readonly" value=' + (resultFeatures.attributes.B1_PER_ID3 != null ? resultFeatures.attributes.B1_PER_ID3 : '') + ' ></td></tr>'
            //                                         + '<tr><td><b>Permit #</b>:</td><td><input type="text" class="editorInput" id="txtPerId" readonly="readonly"  value=' + (resultFeatures.attributes.PERMIT_ID != null ? resultFeatures.attributes.PERMIT_ID.match(/\d{5}(?=\d{2,5})|\d+/g).join("-") : '') + ' ></td></tr>'

            //                    if (userid.toLowerCase() == (resultFeatures.attributes.AUTHOR != null ? resultFeatures.attributes.AUTHOR.toLowerCase() : "")) {
            //                        content += '<tr><td colspan="2"><input type="Submit" class="ui-dialog-buttonset btn" id="btnDelete" value="Delete" onclick="deleteFeatureLayerTypePoint(\'' + (resultFeatures.attributes.TYPE != null ? resultFeatures.attributes.TYPE : '') + '\');"></td></tr></table>';
            //                    } else {
            //                        content += '</table>';
            //                    }

            //                    content += (permitid != "" && IsRequestFromPCIS == true && isClickHereForExistingBldg ? '<b><br/><a onclick ="AssignPermitNumberToBuilding(\'' + (event.graphic.attributes.BLD_ID != null ? event.graphic.attributes.BLD_ID : '') + '\', \'' + '' + '\', \'' + '' + '\');" class="buttonAssignPermit" title="Assign Permit to this Structure">Assign Permit</a>' : "");


            //                    /************Hide progress bar**************/
            //                    hideProgress();

            //                    /*************Highlight the building*************************/
            //                    map.setExtent(resultFeatures.geometry.getExtent(), true);

            //                    featurediv.innerHTML = content;
            //                    map.infoWindow.setTitle(resultFeatures.attributes.TYPE);
            //                    map.infoWindow.setContent(featurediv);
            //                    map.infoWindow.resize(350, 400);
            //                    map.infoWindow.show(resultFeatures.geometry);
            //                    setDraggableInfoWindowUsingPointers();

            //                }
            //            }
            //            else {

            //                hideProgress();

            //                if (IsRequestFromPCIS) {
            //                    map.infoWindow.hide();

            //                    confirmDialog(ValidationMessages.noRecordFoundBuildingSearch, "ok", false)
            //                }
            //                else {
            //                    confirmDialog(ValidationMessages.noRecordFoundBuildingSearch, "ok", false)
            //                }

            //            }
            //        });
            //        //hideProgress();

            //        //if (IsRequestFromPCIS) {
            //        //    map.infoWindow.hide();

            //        //    confirmDialog(ValidationMessages.noRecordFoundBuildingSearch, "ok", false)
            //        //}
            //        //else {
            //        //    confirmDialog(ValidationMessages.noRecordFoundBuildingSearch, "ok", false)
            //        //}
            //    }
            //});
            disableAddPointFutureFunctionality();
        } else {
            BuildingSearchFindTask.execute(BuildingSearchFindParameters, showBuildingSearchResults);

        }
    }
    else {
        /************Hide progress bar**************/
        hideProgress();

        confirmDialog(ValidationMessages.validBuildingID, "ok", false)

    }

}


function showBuildingSearchResults(results) {
    map.graphics.clear();
    var point;
    /********************Variable declared for inserting multiple building feature in an array for displaying parcel quick view for external user*************/
    var buildingFeature = [];


    var symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
              new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
                new Color([255, 0, 0]), 2),
              new Color([255, 255, 0, 0.25]));


    if (results != undefined) {
        if (results.length > 0) {

            /***********If building belongs to multiple parcel then add building feature in the buildingFeature array*************/
            for (var i = 0; i < results.length; i++) {
                buildingFeature.push(results[i].feature);
            }

            if (results[0] != undefined) {
                /***********Get the point to highlight the building*********************/
                point = new esri.geometry.Point(results[0].feature.attributes.LON, results[0].feature.attributes.LAT, new esri.SpatialReference({ wkid: 4326 }));
                results[0].feature.setSymbol(symbol);
                map.graphics.add(results[0].feature);
            }


            /******************Show parcel quick view for internal and external user on building id search and highlight the building*************************/


            /***********pass this buildingFeature array to the showparcelquickview function to display multiple parcel quick view**********/

            if (buildingFeature.length > 0) {

                /***********Show Single parcel information on Parcel quick view detail************/
                if (buildingFeature.length == 1) {
                    showParcelQuickViewDetail(buildingFeature[0], false);
                }
                    /***********Show multiple parcel information on Parcel quick view detail************/
                else {
                    /***********Show first parcel information*************/
                    showParcelQuickViewDetail(buildingFeature[0], false);
                    /***********Show remaining parcel information on paging*************/
                    showParcelQuickViewDetail(buildingFeature, false);
                }
            }


            /*If user is normal user then don't show the building quick view show only parcel quick view*/
            /*Show building quick view to internal user*/

            /******************Show building quick view for internal user on building id search and highlight the building*************************/

            showBuildingQuickViewDetail(results[0].feature)
            openBuildingAccordion();
            $('#buildingContent').html(buildingHtmlTemplate);
            if ($('#collapseTwo').css('display') == 'block') {
                $("#collapseTwo").scrollTop(function () { return this.scrollHeight; });
            }
            if (IsRequestFromPCIS) {
                $('#divBuildingQuickView').css("display", "block");
            }
            setDraggableInfoWindow();



            /*************Highlight the building*************************/
            map.setExtent(results[0].feature.geometry.getExtent(), true);

        }
        else {
            confirmDialog(ValidationMessages.noRecordFoundBuildingSearch, "ok", false)
        }



        /************Hide progress bar**************/
        hideProgress();
    }
    else {
        doFindParcel(pin);
    }


}


