/* Minification failed. Returning unminified contents.
(2,10): run-time error CSS1031: Expected selector, found 'showAddress('
(2,10): run-time error CSS1025: Expected comma or open brace, found 'showAddress('
(82,10): run-time error CSS1031: Expected selector, found 'AddressSearch('
(82,10): run-time error CSS1025: Expected comma or open brace, found 'AddressSearch('
(166,10): run-time error CSS1031: Expected selector, found 'showAddressOnMap('
(166,10): run-time error CSS1025: Expected comma or open brace, found 'showAddressOnMap('
(191,10): run-time error CSS1031: Expected selector, found 'IntersectionSearch('
(191,10): run-time error CSS1025: Expected comma or open brace, found 'IntersectionSearch('
(201,10): run-time error CSS1031: Expected selector, found 'BuildingIDSearch('
(201,10): run-time error CSS1025: Expected comma or open brace, found 'BuildingIDSearch('
(216,10): run-time error CSS1031: Expected selector, found 'PINSearch('
(216,10): run-time error CSS1025: Expected comma or open brace, found 'PINSearch('
(227,10): run-time error CSS1031: Expected selector, found 'APNSearch('
(227,10): run-time error CSS1025: Expected comma or open brace, found 'APNSearch('
(298,10): run-time error CSS1031: Expected selector, found 'LegalSearch('
(298,10): run-time error CSS1025: Expected comma or open brace, found 'LegalSearch('
 */
/********function called on clicking of search/Go button************/
function showAddress() {
    var parseXml;
    var messageText = document.getElementById("addresses");
    var divErrorMsgText = document.getElementById("divErrorMsg");
    var searchText = document.getElementById("txtSearch").value;
    var searchTypes = $("#SearchTypes");
    var searchTextLength = trim(searchText).length;

    /***********Hide Parcel quick view popup******************/
    hideSlidingWindow('divParcelQuckiView');
    /***********Hide partial address search popup******************/
    hideDialog();

    /**********Do not apply following validations for the Legal search***********/
    if ($(searchTypes).val() != 5) {
        /*Check if search text is entered or not*/
        if (searchText == "" || searchTextLength == 0) {
            messageText.innerHTML = "";
            divErrorMsgText.innerHTML = "";
            confirmDialog(ValidationMessages.requiredSearchText, "ok", false)
            return;
        }

        /*If number of characters is less than three*/
        if (searchTextLength < 3) {
            messageText.innerHTML = "";
            divErrorMsgText.innerHTML = "";
            confirmDialog(ValidationMessages.validMinLenForSearchText, "ok", false)
            return;
        }
    }


    /************Show progress bar**************/
    showProgress();


    /*Case for different search types*/
    switch ($(searchTypes).val()) {
        case "1":
            /*Address Search*/
            AddressSearch(searchText, divErrorMsgText, messageText);
            break;
        case "2":
            /*Intersection Search*/
            IntersectionSearch(searchText);
            break;
        case "3":
            /*APN Search*/
            APNSearch(searchText);
            break;
        case "4":
            /*PIN Search*/
            PINSearch(searchText);
            break;
        case "5":
            /*Legal Search*/
            LegalSearch();
            break;
        case "6":
            /*Building ID Search*/
            BuildingIDSearch(searchText);
            break;
        default:
            if (App == "Grading") {
                showGradingQuickView();
            }

    }


}


/****Function for searching address on map*********/
/*<param name="Address">address to be searched on map.</param>
<param name="divErrorMsgText">element Error message text.</param>
<param name="messageText">element message text.</param>
<returns>If finds exact match for the address then it points that address on map otherwise shows list of address in popup </returns>
*/
function AddressSearch(Address, divErrorMsgText, messageText) {

    var urlAddress = streetnumber + " " + direction + " " + street + " " + suffix + " " + zip;

    $.ajax({
        type: 'POST',
        url: addressSearch,   /* Specify Action and Controller for doing task */
        data: { address: Address, app: App },               /* Specify data to pass */
        dataType: 'html'

    }).success(function (ReturnedData) {
        var xmlstring = JSON.stringify(ReturnedData).replace(/\"/g, "");
        var liCount = xmlstring.split("<li");
        var noOfRecords = liCount.length - 1;

        if (xmlstring != "") {
            if (noOfRecords == 1) {

                /*********Parse html string for getting the address value************/
                html = $.parseHTML(xmlstring),

                $.each(html, function (i, el) {
                    /*******Get the address value from the html nodes*******/
                    Address = el.textContent;

                });

                if (Address.replace(/\s\s+/g, ' ').toLowerCase() != urlAddress.replace(/\s\s+/g, ' ').toLowerCase() && App == "Grading") {
                    //Multiple addresses, return multiple address hence show in popup
                    divErrorMsgText.style.visibility = "hidden";
                    divErrorMsgText.innerHTML = "";

                    messageText.style.visibility = "visible";
                    messageText.innerHTML = xmlstring;

                    /************Hide progress bar**************/
                    hideProgress();

                    showDialog(true);

                }
                else {
                    //Exact Match, return only one address hence point to address on map.
                    addressLocatorByAddress(Address, false);
                }
            }
            else {
                if (noOfRecords > 10) {
                    $("#addresses").css("height", "300px");
                }
                //Multiple addresses, return multiple address hence show in popup
                divErrorMsgText.style.visibility = "hidden";
                divErrorMsgText.innerHTML = "";

                messageText.style.visibility = "visible";
                messageText.innerHTML = xmlstring;

                /************Hide progress bar**************/
                hideProgress();

                showDialog(true);
            }
        }
        else {

            /************Hide progress bar**************/
            hideProgress();

            messageText.style.visibility = "hidden";
            messageText.innerHTML = "";

            divErrorMsgText.style.visibility = "visible";
            divErrorMsgText.innerHTML = ValidationMessages.noRecordFoundPartialAddressSearch;

            showDialog(true);
        }
    });

}

/************************ Function to show address on map when user selects any one address from the partial search result popup ******************************/
/*<param name="objectid">unique number assigned from the lucent search call.</param>
<returns>locate the selected address and highlight the respective parcel from partial search result on Map</returns>
*/
function showAddressOnMap(objectid) {
    /**This function present in common.js file*/
    hideDialog();
    var parameters = [];
    parameters = document.getElementById(objectid).value.split(',');
    var address = "";
    if (parameters.length > 0) {
        if (parameters[0] != "") {
            address = parameters[0];
        }

        if (parameters[1] != "") {
            PIND = parameters[1];
        }
    }


    $("#txtSearch").val(address);
    addressLocatorByAddress(address, false);
}

/************************ Function to show address on map using intersection search ******************************/
/*<param name="searchInterSectText">contains strret name or street name followed by any other street name.</param>
<returns>locate the entered intersection text on Map</returns>
*/
function IntersectionSearch(searchInterSectText) {
    /*Call the following function from Common.js file and pass Intersection search text as first parameter and true for second parameter for intesection search
    otherwise pass false in second parameter for address search.*/
    addressLocatorByAddress(searchInterSectText, true);
}

/************************ Function to show highligh building on map ******************************/
/*<param name="building_ID">Building ID which is to be search on map.</param>
<returns>Highlight the Building entered in the search textbox on Map</returns>
*/
function BuildingIDSearch(building_ID) {
    /*Call the function doFind present in the BuildingSearch.js file and pass building id to this function*/
    /*Setting IsRequestFromPCIS to false for displaying error message for incorrect PIN*/

    if (bldgType == "" || buildingid == "") {
        IsRequestFromPCIS = false;
    }
    doFind(building_ID);
}


/************************ Function to show parcel on map ******************************/
/*<param name="PIN">Parcel ID or PIN to be search on map.</param>
<returns>Highlight the Parcel entered in the search textbox on Map</returns>
*/
function PINSearch(PIN) {
    /*Call the function doFindParcel present in the ParcelSearch.js file and pass pin or parcel id to this function*/
    /*Setting IsRequestFromPCIS to false for displaying error message for incorrect PIN*/
    IsRequestFromPCIS = false;
    doFindParcel(PIN);
}

/************************ Function to show parcel on map associated with APN ******************************/
/*<param name="APN">APN.</param>
<returns>Search all parcels present under APN and highlight them on map.</returns>
*/
function APNSearch(APN) {
    var BOOK;
    var PAGE;
    var PARCEL;

    BOOK = APN.substring(0, 4);
    PAGE = APN.substring(4, 7);
    PARCEL = APN.substring(7, 10);



    if (BOOK != "" && PAGE != "" && PARCEL != "") {
        query = new esri.tasks.Query();
        query.returnGeometry = true;
        query.outFields = ["*"];
        query.where = "BOOK = '" + BOOK + "' AND PAGE = '" + PAGE + "' AND PARCEL = '" + PARCEL + "'";

        map.graphics.clear();

        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]));

        parcelFeatureLayer = new esri.layers.FeatureLayer(getUrlByName("js_parcelsFeatureLayerUrl"), {
            outFields: ["*"]
        });

        parcelFeatureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, function (features) {
            var i = 0;

            /************Hide progress bar**************/
            hideProgress();

            if (features.length > 0) {

                /*************If there is only one parcel present in APN then highlight the parcel and open parcel quick view*****************/
                if (features.length == 1) {
                    /************Show Parcel Quick View**********************/
                    /****Call following function from Common.js file**********/
                    showParcelQuickViewDetail(features[0], false);

                    /************Zooming to the map**********************/
                    map.setExtent(features[0].geometry.getExtent(), true);
                }
                    /**************If there are multiple parcels for a APN then only highlight all the parcels *****************/
                else {
                    /****Call following function from Common.js file**********/
                    /***********Show first parcel information*************/
                    showParcelQuickViewDetail(features[0], false);
                    /************Zooming to the map**********************/
                    map.setExtent(features[0].geometry.getExtent(), true);
                    /***********Show remaining parcel information on paging*************/
                    showParcelQuickViewDetail(features, false);
                }

            }
            else {
                confirmDialog(ValidationMessages.noRecordFoundForAPNSearch, "ok", false)
            }
        });
    }
    else {
        /************Hide progress bar**************/
        hideProgress();
        confirmDialog(ValidationMessages.validAPNText, "ok", false)
    }

}

/************************ Function to show Legal Search Dialog ******************************/
function LegalSearch() {
    /************Hide progress bar**************/
    hideProgress();
    openLeaglSearchDialog();
}









