/* Minification failed. Returning unminified contents.
(1,13): run-time error CSS1031: Expected selector, found ';'
(1,13): run-time error CSS1025: Expected comma or open brace, found ';'
(2,25): run-time error CSS1031: Expected selector, found ';'
(2,25): run-time error CSS1025: Expected comma or open brace, found ';'
(3,22): run-time error CSS1031: Expected selector, found ';'
(3,22): run-time error CSS1025: Expected comma or open brace, found ';'
(4,8): run-time error CSS1031: Expected selector, found ';'
(4,8): run-time error CSS1025: Expected comma or open brace, found ';'
(5,13): run-time error CSS1031: Expected selector, found ';'
(5,13): run-time error CSS1025: Expected comma or open brace, found ';'
(6,11): run-time error CSS1031: Expected selector, found ';'
(6,11): run-time error CSS1025: Expected comma or open brace, found ';'
(7,16): run-time error CSS1031: Expected selector, found ';'
(7,16): run-time error CSS1025: Expected comma or open brace, found ';'
(8,13): run-time error CSS1031: Expected selector, found ';'
(8,13): run-time error CSS1025: Expected comma or open brace, found ';'
(9,17): run-time error CSS1031: Expected selector, found ';'
(9,17): run-time error CSS1025: Expected comma or open brace, found ';'
(10,14): run-time error CSS1031: Expected selector, found ';'
(10,14): run-time error CSS1025: Expected comma or open brace, found ';'
(11,11): run-time error CSS1031: Expected selector, found ';'
(11,11): run-time error CSS1025: Expected comma or open brace, found ';'
(12,11): run-time error CSS1031: Expected selector, found ';'
(12,11): run-time error CSS1025: Expected comma or open brace, found ';'
(13,8): run-time error CSS1031: Expected selector, found ';'
(13,8): run-time error CSS1025: Expected comma or open brace, found ';'
(14,11): run-time error CSS1031: Expected selector, found ';'
(14,11): run-time error CSS1025: Expected comma or open brace, found ';'
(15,12): run-time error CSS1031: Expected selector, found ';'
(15,12): run-time error CSS1025: Expected comma or open brace, found ';'
(16,12): run-time error CSS1031: Expected selector, found ';'
(16,12): run-time error CSS1025: Expected comma or open brace, found ';'
(17,11): run-time error CSS1031: Expected selector, found ';'
(17,11): run-time error CSS1025: Expected comma or open brace, found ';'
(18,13): run-time error CSS1031: Expected selector, found ';'
(18,13): run-time error CSS1025: Expected comma or open brace, found ';'
(19,19): run-time error CSS1031: Expected selector, found '='
(19,19): run-time error CSS1025: Expected comma or open brace, found '='
(20,15): run-time error CSS1031: Expected selector, found '='
(20,15): run-time error CSS1025: Expected comma or open brace, found '='
(21,18): run-time error CSS1031: Expected selector, found '='
(21,18): run-time error CSS1025: Expected comma or open brace, found '='
(22,10): run-time error CSS1031: Expected selector, found '='
(22,10): run-time error CSS1025: Expected comma or open brace, found '='
(23,1): run-time error CSS1019: Unexpected token, found '/'
(23,2): run-time error CSS1019: Unexpected token, found '/'
(24,1): run-time error CSS1031: Expected selector, found '/'
(24,1): run-time error CSS1025: Expected comma or open brace, found '/'
(73,10): run-time error CSS1031: Expected selector, found 'identifyForAddressSearch('
(73,10): run-time error CSS1025: Expected comma or open brace, found 'identifyForAddressSearch('
(90,10): run-time error CSS1031: Expected selector, found 'markMap('
(90,10): run-time error CSS1025: Expected comma or open brace, found 'markMap('
(108,10): run-time error CSS1031: Expected selector, found 'highlightParcel('
(108,10): run-time error CSS1025: Expected comma or open brace, found 'highlightParcel('
(157,10): run-time error CSS1031: Expected selector, found 'addAddressMarker('
(157,10): run-time error CSS1025: Expected comma or open brace, found 'addAddressMarker('
(201,1): run-time error CSS1019: Unexpected token, found '/'
(201,2): run-time error CSS1019: Unexpected token, found '/'
(202,10): run-time error CSS1031: Expected selector, found 'CreateGeocoder('
(202,10): run-time error CSS1025: Expected comma or open brace, found 'CreateGeocoder('
(219,1): run-time error CSS1019: Unexpected token, found '/'
(219,2): run-time error CSS1019: Unexpected token, found '/'
(220,10): run-time error CSS1031: Expected selector, found 'CreateIntersectionGeocoder('
(220,10): run-time error CSS1025: Expected comma or open brace, found 'CreateIntersectionGeocoder('
(238,1): run-time error CSS1019: Unexpected token, found '/'
(238,2): run-time error CSS1019: Unexpected token, found '/'
(239,1): run-time error CSS1031: Expected selector, found '/'
(239,1): run-time error CSS1025: Expected comma or open brace, found '/'
(310,1): run-time error CSS1019: Unexpected token, found '/'
(310,2): run-time error CSS1019: Unexpected token, found '/'
(311,10): run-time error CSS1031: Expected selector, found 'IsSuffix('
(311,10): run-time error CSS1025: Expected comma or open brace, found 'IsSuffix('
(466,1): run-time error CSS1019: Unexpected token, found '/'
(466,2): run-time error CSS1019: Unexpected token, found '/'
(468,1): run-time error CSS1031: Expected selector, found '/'
(468,1): run-time error CSS1025: Expected comma or open brace, found '/'
(617,1): run-time error CSS1019: Unexpected token, found '/'
(617,2): run-time error CSS1019: Unexpected token, found '/'
(618,10): run-time error CSS1031: Expected selector, found 'showResultsIntersection('
(618,10): run-time error CSS1025: Expected comma or open brace, found 'showResultsIntersection('
 */
var geocoder;
var IntersectionGeocoder;
var MarkMapParameters;
var pin;
var permitid;
var userid;
var PCIS_bld_id;
var bldgType;
var streetnumber;
var direction;
var street;
var suffix;
var zip;
var LOG_ID;
var POINT_X;
var POINT_Y;
var LogExt;
var Group_ID;
var graphicsArray = [];
var ParcelIDs = [];
var featureLogID = "";
var PIND = "";
// This functioanlity is created
//for maximum zoom level after address search
function showLocation(evt) {    
    MarkMapParameters = new Object();
    MarkMapParameters.showLocationEvent = evt;
    MarkMapParameters.attributes = MarkMapParameters.showLocationEvent.result.feature.attributes;
    MarkMapParameters.PINDFound = false;
    MarkMapParameters.IdentifyCompleted = false;
    MarkMapParameters.IsRunning = true;
    MarkMapParameters.sessionid = evt.result.sessionid;
    if (IsRequestFromPCIS == true) {
        MarkMapParameters.pin = evt.result.pin;
        MarkMapParameters.userid = evt.result.userid;
        MarkMapParameters.permitNo = evt.result.permitNo;
        MarkMapParameters.PCIS_bld_id = evt.result.buildingid;
    }
    // Set zoom on address search
    setTimeout(function () {
        //if (map.getLevel() != 14) {        
        map.centerAndZoom(MarkMapParameters.showLocationEvent.result.feature.geometry, 14);
        //}
    }, 100);

    //Query for address PIND

    setTimeout(function () {
        var address = new Object();
        address.StreetNumber = MarkMapParameters.attributes.House;
        address.Direction = MarkMapParameters.attributes.PreDir;
        address.StreetName = MarkMapParameters.attributes.StreetName;
        address.Suffix = MarkMapParameters.attributes.SufType;
        address.Zip = MarkMapParameters.attributes.ZIP;
        address.HSE_NBR = MarkMapParameters.attributes.HSE_NBR;
        address.HSE_FRAC_NBR = MarkMapParameters.attributes.HSE_FRAC_NBR;
        address.HSE_DIR_CD = MarkMapParameters.attributes.HSE_DIR_CD;
        address.STR_NM = MarkMapParameters.attributes.STR_NM;
        address.STR_SFX_CD = MarkMapParameters.attributes.STR_SFX_CD;
        address.UNIT_RANGE = MarkMapParameters.attributes.UNIT_RANGE;
        address.PIND = PIND;        
        if (IsRequestFromPCIS == true) {
            address.PIN = MarkMapParameters.pin;
        }
        getAddressPoint(address);
    }, 500);

    // Start Identify Task for address search
    // Set multi-threading to highlight parcel
    setTimeout(function () { identifyForAddressSearch(MarkMapParameters.showLocationEvent); }, 500);

}
function identifyForAddressSearch(evt) {
    highlightBOEParcelParameters.geometry = evt.result.feature.geometry;
    highlightBOEParcelParameters.mapExtent = map.extent;
    // can share identify parameters
    var deferred = highlightBOEParcel
      .execute(highlightBOEParcelParameters)
      .addCallback(function (response) {          
          MarkMapParameters.IdentifyCompleted = true;
          MarkMapParameters.identifyForAddressSearchResults = response;
          if (MarkMapParameters.IdentifyCompleted && MarkMapParameters.PINDFound) {              
              markMap();

          }
      });
}

/***********Function for highlighting Parcel and adding address marker on map for address search*******************/
function markMap() {

    /************Hide progress bar**************/
    hideProgress();

    /*********Highlight Parcel on the map********/
    highlightParcel();

    /****************Adds Address marker on map*******************/
    if (App != "Grading") {
        addAddressMarker(MarkMapParameters.showLocationEvent.result.feature.geometry);
    }

    MarkMapParameters = null;

}

/**********Function for highlighting the parcel on map*******************************/
function highlightParcel() {    
    parcelSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
                   new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
                     new Color([0, 255, 255]), 2),
                   new Color([0, 255, 255, 0.25]));
    //alert(MarkMapParameters.GetAddressPointResult.length);
    arrayUtils.map(MarkMapParameters.identifyForAddressSearchResults, function (result) {
        
        for (var t = 0; t < MarkMapParameters.GetAddressPointResult.length; t++) {
            
            if (result.value == MarkMapParameters.GetAddressPointResult[t].PIND) {                
                var feature = result.feature;
                var layerName = result.layerName;

                feature.attributes.layerName = layerName;
                /************Show Parcel Quick View**********************/
                /****Call following function from Common.js file**********/
                //Commenting for production release
                if (App != "Grading") {
                    showParcelQuickViewDetail(feature, false);
                }
                else {
                    /*Set feature layer symbol*/
                    if ($.inArray(feature.attributes.PIN, gradingParcels) == -1) {
                        feature.setSymbol(parcelSymbol);
                        //gradingParcels.push(feature.attributes.PIN);
                        lastSelectedParcelFeature = feature;
                        isAddGradingPointClicked = false;
                        /*add feature in the graphics of the map*/
                        map.graphics.add(feature);

                        $("#selectedParcelCount").html(gradingParcels.length);
                        if (POINT_X == "" && POINT_Y == "") {
                            showParcelQuickViewDetail(feature, false);
                            if (Group_ID == "") {
                                showGradingQuickView();
                            }
                        }
                    }
                }


            }
        }
    });
}


/*********************Function to add address marker on map**************************************/
function addAddressMarker(point) {
    //map.graphics.clear();

    //if (App != "Grading") {

    var symbol = new SimpleMarkerSymbol().setStyle(
      SimpleMarkerSymbol.STYLE_SQUARE).setColor(
      new Color([255, 0, 0, 0.70])
    );



    if (isGradingPointAdded) {
        symbol = new SimpleMarkerSymbol().setStyle(
      SimpleMarkerSymbol.STYLE_SQUARE).setColor(
      new Color([255, 201, 178, 0.70])
    );
    }

    if (isGradingPointClicked) {
        if (featureLogID == LOG_ID) {
            symbol = new SimpleMarkerSymbol().setStyle(
        SimpleMarkerSymbol.STYLE_SQUARE).setColor(
        new Color([255, 0, 0, 0.70])

    );
        }
        else {

            symbol = new SimpleMarkerSymbol().setStyle(
         SimpleMarkerSymbol.STYLE_SQUARE).setColor(
         new Color([255, 301, 278, 0.70])
       );
        }

    }

    graphic = new Graphic(point, symbol);
    map.graphics.add(graphic);

    graphicsArray.push(graphic);
    //}
}

// Prakash set a custom geocoder for address search based on DBS address points
function CreateGeocoder() {
    geocoder = new Geocoder({
        arcgisGeocoder: false,
        autoComplete: true,
        geocoders: [{
            url: (getUrlByName("js_addressLocatorUrl")),   // Rest services is in SINT database
            name: "DBS Geocoder",

            placeholder: "Enter an address",
            outFields: "*"
        }],
        map: map,
        zoomScale: 51000
    }, dom.byId("search"));
    geocoder.on("select", showLocation);
}

//Intersection search
function CreateIntersectionGeocoder(intersection) {

    IsRequestFromPCIS = false;

    var singleLineAddress = {
        "Single Line Input": $('#txtIntersection').val()
    };

    var locator = new Locator(getUrlByName("js_intersectionLocatorUrl"));
    locator.on("address-to-locations-complete", showResultsIntersection);
    locator.outSpatialReference = map.spatialReference;
    var options = {
        address: singleLineAddress,
        outFields: ["txtIntersection"]
    }
    locator.addressToLocations(options);

}
// Added code to zoom user into specified address automatically
// can be used for different application with link to Map Viewer (such as PCIS)
function structuralInventory() {
    streetnumber = getURLVars()["streetnumber"] !== undefined ? getURLVars()["streetnumber"] : '';
    direction = getURLVars()["direction"] !== undefined ? getURLVars()["direction"] : '';
    street = getURLVars()["street"] !== undefined ? getURLVars()["street"] : '';
    suffix = getURLVars()["suffix"] !== undefined ? getURLVars()["suffix"] : '';
    zip = getURLVars()["zip"] !== undefined ? getURLVars()["zip"] : '';
    pin = getURLVars()["pin"] !== undefined ? decodeURI(getURLVars()["pin"].trim()) : '';
    permitid = getURLVars()["permitid"] !== undefined ? getURLVars()["permitid"] : '';
    userid = getURLVars()["userid"] !== undefined ? getURLVars()["userid"] : '';
    PCIS_bld_id = getURLVars()["buildingid"] !== undefined ? getURLVars()["buildingid"] : '';
    bldgType = getURLVars()["bldgType"] !== undefined ? getURLVars()["bldgType"] : '';
    //Commenting for production release
    App = getURLVars()["App"] !== undefined ? getURLVars()["App"] : '';
    parcelIDs = getURLVars()["ParcelIDs"] !== undefined ? getURLVars()["ParcelIDs"] : '';
    LOG_ID = getURLVars()["LogNo"] !== undefined ? getURLVars()["LogNo"] : '';
    POINT_X = getURLVars()["X"] !== undefined ? getURLVars()["X"] : '';
    POINT_Y = getURLVars()["Y"] !== undefined ? getURLVars()["Y"] : '';
    LogExt = getURLVars()["LogExt"] !== undefined ? getURLVars()["LogExt"] : '';
    Group_ID = getURLVars()["Group_ID"] !== undefined ? getURLVars()["Group_ID"] : '';


    if (PCIS_bld_id != "null" && PCIS_bld_id != "" && PCIS_bld_id != 0 && PCIS_bld_id.toLowerCase() != "na" && PCIS_bld_id.toLowerCase() != "n/a" && PCIS_bld_id.toLowerCase() !== "new") {
        /*Search by Building ID*/
        showProgress();
        doFind(PCIS_bld_id);
    }
    else if (pin != "null" && pin != "" && pin != 0) {
        /*Search by Parcel or PIN*/
        showProgress();
        doFindParcel(pin);
    }
        //Commenting for production release
    else if (parcelIDs != "") {
        showProgress();

        ParcelIDs = decodeURI(parcelIDs).split(',');

        for (var i = 0; i <= ParcelIDs.length - 1 ; i++) {

            doFindParcel(decodeURI(ParcelIDs[i]));
        }

        if (LOG_ID != "") {

            var query = new Query();
            query.where = "LOG_ID =" + LOG_ID;

            gradingFeatureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, function (features) {
                if (features.length > 0) {
                    updateFeature = features[0];
                    //Set the Feature Layer InfoWindow content and open the InfoWindow
                    getGradingFeatureLayerInfoWindowContent("", updateFeature);
                    addAddressMarker(updateFeature.geometry);

                }
                else {
                    map.infoWindow.hide();
                }
            });
        }

    }
    else {
        /*Search by Address*/
        addressLocator(streetnumber, direction, street, suffix, zip);
    }

}


//pasting
function IsSuffix(testSuffix) {
    var suffixArray = [
    'ALY',
    'ANX',
    'ARC',
    'AVE',
    'AYU',
    'BCH',
    'BND',
    'BLF',
    'BTM',
    'BLVD',
    'BR',
    'BRG',
    'BRK',
    'BG',
    'BYP',
    'CP',
    'CYN',
    'CPE',
    'CSWY',
    'CTR',
    'CIR',
    'CLFS',
    'CLB',
    'COR',
    'CORS',
    'CRSE',
    'CT',
    'CTS',
    'CV',
    'CRK',
    'CRES',
    'XING',
    'DL',
    'DM',
    'DV',
    'DR',
    'EST',
    'EXPY',
    'EXT',
    'FALL',
    'FLS',
    'FRY',
    'FLD',
    'FLDS',
    'FLT',
    'FOR',
    'FRST',
    'FGR',
    'FORK',
    'FRKS',
    'FT',
    'FWY',
    'GDNS',
    'GTWY',
    'GLN',
    'GN',
    'GRV',
    'HBR',
    'HVN',
    'HTS',
    'HWY',
    'HL',
    'HLS',
    'HOLW',
    'INLT',
    'IS',
    'ISS',
    'ISLE',
    'JCT',
    'CY',
    'KNLS',
    'LK',
    'LKS',
    'LNDG',
    'LN',
    'LGT',
    'LF',
    'LCKS',
    'LDG',
    'LOOP',
    'MALL',
    'MNR',
    'MDWS',
    'ML',
    'MLS',
    'MSN',
    'MT',
    'MTN',
    'NCK',
    'ORCH',
    'OVAL',
    'PARK',
    'PKY',
    'PASS',
    'PATH',
    'PIKE',
    'PNES',
    'PL',
    'PLN',
    'PLNS',
    'PLZ',
    'PT',
    'PRT',
    'PR',
    'RADL',
    'RNCH',
    'RPDS',
    'RST',
    'RDG',
    'RIV',
    'RD',
    'ROW',
    'RUN',
    'SHL',
    'SHLS',
    'SHR',
    'SHRS',
    'SPG',
    'SPGS',
    'SPUR',
    'SQ',
    'STA',
    'STRA',
    'STRM',
    'ST',
    'SMT',
    'TER',
    'TRCE',
    'TRAK',
    'TRL',
    'TRLR',
    'TUNL',
    'TPKE',
    'UN',
    'VLY',
    'VIA',
    'VW',
    'VLG',
    'VL',
    'VIS',
    'WALK',
    'WAY',
    'WLS',
    'ROAD',
    'LANE'];

    for (var i = 0; i < suffixArray.length; i++) {
        if (testSuffix == suffixArray[i])
            return true;
    }
    return false;
}

//end pasting

// show results of custom URL address search
function showResults(evt) {
    var candidate;
    var geom;
    var mockEvent = new Object();

    
    arrayUtils.every(evt.addresses, function (candidate) {        
        console.log(candidate.score);
        if (candidate.score > 70) {            
            console.log(candidate.location);
            var address = new Object();
            var addressParts = candidate.address.split(',');
            addressline = addressParts[0].split(' ');
            address.StreetName = '';
                        
            /************Logic to handle fraction number and unit range present in address**********************/
            address.HSE_NBR = addressline[0];

            var res = parseFloat(addressline[1]);
            
            if (isNaN(res)) {
                if (addressline.length == 3) {
                    if (addressline[1].length > 1) {
                        address.STR_NM = addressline[1];
                        address.StreetName = addressline[1];

                        if (IsSuffix(addressline[2])) {
                            address.STR_SFX_CD = addressline[2];
                        }
                    }
                    else {
                        address.HSE_DIR_CD = addressline[1];
                        address.STR_NM = addressline[2];
                        address.StreetName = addressline[2];

                        if (IsSuffix(addressline[3])) {
                            address.STR_SFX_CD = addressline[3];
                        }
                    }

                }
                else {

                    address.HSE_DIR_CD = addressline[1];
                    address.STR_NM = addressline[2];
                    if (IsSuffix(addressline[3])) {
                        address.STR_SFX_CD = addressline[3];
                    }
                    else {
                        address.STR_SFX_CD = addressline[4];
                    }
                   
                    
                }
            }
            else {
                address.HSE_FRAC_NBR = addressline[1];
                address.HSE_DIR_CD = addressline[2];
                address.STR_NM = addressline[3];
                if (IsSuffix(addressline[4])) {
                    address.STR_SFX_CD = addressline[4];
                }
                else {
                    address.STR_SFX_CD = addressline[5];
                }

                //address.STR_SFX_CD = addressline[4];

            }


            if (addressline.length > 5) {
                if (addressline[5].indexOf("-") > -1) {
                    address.UNIT_RANGE = addressline[5];

                }

            }
            /************Logic to handle fraction number and unit range present in address**********************/

            //address.STR_NM = addressline[3];
            //address.STR_SFX_CD = addressline[4];
            //address.UNIT_RANGE = addressline[5];



            address.House = addressline[0];
            address.PreDir = addressline[1];
            
            if (IsSuffix(addressline[addressline.length - 1])) {

                address.SufType = addressline[addressline.length - 1]
                if (address.StreetName == "" ) {
                    for (var i = 2; addressline.length - 1 > i; i++) {
                        address.StreetName += addressline[i] + ' ';
                    }
                }
            } else {
                if (address.StreetName == "") {
                    for (var i = 2; addressline.length - 1 >= i; i++) {
                        address.StreetName += addressline[i] + ' ';
                    }
                }
            }
            address.StreetName = address.StreetName.trim();




            address.ZIP = addressParts[addressParts.length - 1].trim();

            geom = candidate.location;

            // Creating mark map parameters

            mockEvent = new Object();
            mockEvent.result = new Object();
            mockEvent.result.name = candidate.address;
            mockEvent.result.feature = new Object();
            mockEvent.result.feature.geometry = geom;
            mockEvent.result.feature.attributes = address;
            mockEvent.result.sessionid = getURLVars()["sessionid"] !== undefined ? getURLVars()["sessionid"] : 0;
            if (IsRequestFromPCIS == true) {
                mockEvent.result.pin = getURLVars()["pin"] !== undefined ? getURLVars()["pin"] : '';
                mockEvent.result.userid = getURLVars()["userid"] !== undefined ? getURLVars()["userid"] : '';
                mockEvent.result.permitNo = getURLVars()["permitid"] !== undefined ? getURLVars()["permitid"] : '';
                mockEvent.result.buildingid = getURLVars()["buildingid"] !== undefined ? getURLVars()["buildingid"] : '';
            }

            return false; //break out of loop after one candidate with score greater  than 80 is found.
        }
    });

    if (geom !== undefined) {
        showLocation(mockEvent);
    }
    else {
        /************Hide progress bar**************/
        hideProgress();
        if (App != "Grading") {
            confirmDialog(ValidationMessages.noSearchResultFound, "ok", false);
        }
        else {
            confirmDialog("Building, parcel, address couldn't be found. <br/> Please use the Search box on the top to look for a<br/> nearby/related address to associate the Log to", "ok", false);
        }
    }
}

// Renamed function for intersection search
function showResultsIntersection(evt) {
    var result;
    var geom;
    var mockEvent = new Object();
    arrayUtils.every(evt.addresses, function (candidate) {
        console.log(candidate.score);
        if (candidate.score > 80) {
            console.log(candidate.location);
            result = candidate;
            geom = candidate.location;
            return false; //break out of loop after one candidate with score greater  than 80 is found.
        }
    });

    /************Hide progress bar**************/
    hideProgress();

    if (geom !== undefined) {

        map.centerAndZoom(geom, 14); // changed to improve initial search display
        addAddressMarker(geom);
        // map.infoWindow.setFeatures([feature]);
        map.infoWindow.setTitle("Intersection");
        map.infoWindow.setContent(result.address.replace(/[, ]+$/, ''));
        map.infoWindow.show(geom);
        setDraggableInfoWindow();

    }
    else {
        /*If intersection result is not found then show error message in confirm box*/
        confirmDialog(ValidationMessages.noRecordFoundIntersectionSearch, "ok", false);
    }
}





