﻿/** @class TNRIS.NhdXmlShapeLayer
*/

TNRIS.NhdXmlShapeLayer = function(config) {
    Ext.applyIf(this, {
        id: Ext.id(),
        shapeLineColor: new VEColor(100,0,0,0.6),
        shapeFillColor: new VEColor(100,0,0,0.6),
        shapeIcon: '<div class="globePushpin"><img src="images/pushPins/greenGlobePin.png" /></div>'
    });
    TNRIS.NhdXmlShapeLayer.superclass.constructor.call(this, config);
};

Ext.extend(TNRIS.NhdXmlShapeLayer, TNRIS.XmlShapeLayer, {
    hasRestrictedEdit: function() {
        return true;
    },

    getShapeEditor: function() {
        var editor = Ext.getCmp('NhdShapeEditorWindow');
        if (null == editor) {
            editor = new TNRIS.NhdXmlLayerUserDataWindow({id: 'NhdShapeEditorWindow', layer: this});
        }
        return editor;
    },

    gridColumnSpecs: function() {
        var gridStore = this.getGridStore();
        if (null == gridStore || null == gridStore.fields) {
            return [];
        }
        
        var fields = [];
        Ext.each(this.getColumnConfigs(), function(config) {
            fields.push( { header: config.guiName, dataIndex: config.dbName});
        }, this);
    
        return fields;
    },
    
    getLayerExportWindow: function() {
        var winTitle = 'Exporting ' + this.name();
        var exportWin = new TNRIS.NHDExportWindow({title: winTitle, layer: this});
        exportWin.load();
        return exportWin;
    }
    
});

/** @class Dialog box for exporting NHD layer features to the database
@constructor
@param {object} config
*/
TNRIS.NHDExportWindow = function(config) {
    Ext.apply(this,config);
   
    this.form = new Ext.form.FormPanel({
        layout: 'fit',
        labelAlign:'top',
        items: [
            { id: 'nhdFeatureCount', cls: 'nhdFeatureCount', xtype: 'label' },
            { id: 'nhdSelectedCount', cls: 'nhdSelectedCount', xtype: 'label' },
            { id: 'nhdExportCount', cls: 'nhdExportCount', xtype: 'label' },
            { id: 'nhdFailedCount', cls: 'nhdFailedCount', xtype: 'label' }
        ]
    });
    
    this.nhdStore = this.layer.getGridStore();
    this.sm = new Ext.grid.CheckboxSelectionModel({singleSelect:false,sortable:true});
    this.layer.on({
        'loadGrid': {
            scope: this,
            fn: function(s, r, o) {
                this.featureCount = this.nhdStore.getCount();
                var columns = this.layer.gridColumnSpecs();
                columns = [this.sm].concat(columns);
                columns = columns.concat([{header:'Record Status',renderer: this.validateNhdRecord.bind(this)}]);

                this.exportGrid = new Ext.grid.GridPanel({
                    store: this.nhdStore,
                    columns: columns,
                    stateful: false,
                    autoShow: true,
                    sm: this.sm
                });
                
                this.form.add(this.exportGrid);
                this.form.doLayout();
            },
            single: true
        }
    });
    
    TNRIS.NHDExportWindow.superclass.constructor.call(this, {
        id: 'nhdExportWindow',
        cls: 'nhdExportWindow',
        layout: 'form',
        width: 500,
        height: 400,
        modal: true,
        resizable: false,
        stateful: false,
        closeAction: 'close',
        items: [this.form],
        buttonAlign: 'center',
        buttons: [
            {
                text: 'Export',
                scope: this,
                handler: this.onExportClick
            },
            {
                text: 'Cancel',
                scope: this,
                handler: function() {
                    this.close();
                }   
            }
        ]
    });
};

Ext.extend(TNRIS.NHDExportWindow, Ext.Window,{
    load:function() {
        this.layer.loadGridData();
    },
    
    onExportClick: function(){
        this.selectedFeatures = this.sm.getSelections();
        this.selected = this.selectedFeatures.length;
        this.total = this.nhdStore.getCount();
        this.exported = 0;
        this.failed = 0;
        
        var featuresToExport = [];
        Ext.each(this.selectedFeatures,function(record) {
            var featureData = this.getFeatureDateFromRecord(record);
            if ((featureData.EditCategory != null) && (featureData.EditCategory != "")){
                featuresToExport.push(featureData);
            }else {
                this.failed++;
            }
        },this);
        
        this.getEl().mask('Exporting selected records to server... Please Wait!!');
        PageMethods.submitNhdFeature(featuresToExport,function(exportedResult){
            this.getEl().unmask();
            var successList = exportedResult.successItems;
            var failList = exportedResult.failureItems;
            
            Ext.each(successList, function(itemId) {
                this.exported++;
                this.layer.deletedRecords.push(itemId);
            },this);
            
            Ext.each(failList, function(itemId) {
                this.failed++;
            },this);
                
            this.layer.commitShapeData(
                function() { 
                    this.layer.reload();
                    this.updateStatus();
                    Ext.Msg.alert("Export Completed"," The export is compeleted and all successfully exported features were deleted from your NHD layer."); 
                }.bind(this));
        }.bind(this));
    },
    
    updateStatus: function() {
        Ext.getCmp('nhdExportCount').getEl().update('<br/>Exported: '+ this.exported + ' Records ');
        Ext.getCmp('nhdFailedCount').getEl().update('<br/>Failed: '+ this.failed + ' Records ');
        Ext.getCmp('nhdFeatureCount').getEl().update('Total: '+ this.total + ' Records ');
        Ext.getCmp('nhdSelectedCount').getEl().update('<br/>Selected: '+ this.selected + ' Records ');
    },
    
    validateNhdRecord: function(value,metadata,record,rIndex,colIndex,store){
        var result = "";
        var featureData = this.getFeatureDateFromRecord(record);
        if ((featureData.EditCategory == null) || (featureData.EditCategory == "")){
            result= '<font color ="red">Insufficient Data</font> ';
        }else {
            result = '<font color ="green">Ready to export</font> ';
        }
        return result;
    },
    
    getFeatureDateFromRecord: function(record) {
    
        var featureData = {
            "id" : record.id ,
            "EditCategory" : record.get('1'),
            "FeatureClass" : record.get('2'),
            "ComID" : record.get('3'),
            "FDate" : record.get('4'),
            "Resolution" : record.get('5'),
            "GNIS_ID" : record.get('6'),
            "GNIS_Name" : record.get('7'),
            "ReachCode" : record.get('8'),
            "FlowDir" : record.get('9'),
            "FType" : record.get('10'),
            "FCode" : record.get('11'),
            "Comments" : record.get('12'),
            "ShapePoints" : record.get('shapePoints'),
            "ShapeType" : record.get('shapeType')
        };
        return featureData;
    }
    
});


/** @class Dialog box for adding/editing fields through the map for NHD xml layer
@constructor
@param {object} config
@config {TNRIS.ShapeLayer} layer A layer to query against
*/
TNRIS.NhdXmlLayerUserDataWindow = function(config) {
    Ext.apply(this, config);

    Ext.applyIf(this,{
        shim: false,
        shapeLineColor: new VEColor(0, 150, 150, 0.6),
        shapeFillColor: new VEColor(0, 150, 150, 0.6),
        shapeIcon: '<div class="globePushpin"><img src="images/pushPins/greenGlobePin.png"></div>',
        shapeHighlightLineColor: new VEColor(0, 255, 0, 0.6),
        shapeHighlightFillColor: new VEColor(0, 255, 0, 0.6),
        shapeHighlightIcon: '<div class="globePushpin"><img src="images/pushPins/ochreGlobePin.png"></div>',
        shapeWidth: 2
    });
    
    Ext.apply(Ext.QuickTips.getQuickTip(), {
        showDelay: 50,
        trackMouse: true
    });
    
    // fields to validate for each category
    this.newFeatureFields = ['FDate','Resolution','FlowDir','FType','FCode'];
    this.existingFeatureFields = ['ComID','FDate','Resolution','ReachCode','FlowDir','FType','FCode'];
    
        
    this.fieldRecordConstructor = Ext.data.Record.create(['dbName', 'guiName', 'order', 'dbType', 'isId', 'isName', 'isHidden', 'isGeometry', 'value']);

    //syntax must be similar to XmlLayerUserDataWindow
    this.fieldStore = new Ext.data.Store({
        reader: new Ext.data.JsonReader({}, this.fieldRecordConstructor)
    });

    this.fClassStore = new Ext.data.Store({
        reader: new Ext.data.ArrayReader({}, ['FClass'])
    });

    this.fTypeStore = new Ext.data.Store({
        reader: new Ext.data.ArrayReader({}, ['FTypeDesc','FType'])
    });

    this.fCodeStore = new Ext.data.Store({
        reader: new Ext.data.ArrayReader({}, ['FCode', 'FDescription'])
    });

    this.nhdMappingStore = new Ext.data.Store({
        reader: new Ext.data.ArrayReader({}, ['FClass','FType',  'FCode', 'FTypeDesc','FDescription']),
        listeners: {
            'load': { scope: this, fn: function(store, records, options) { this.loadFClassStore(); } }
        }
    });

    this.nhdTabPanel =new Ext.TabPanel({
        xtype: 'tabpanel', cls: 'nhdTabPanel',
        layoutOnTabChange: true,
        enableTabScroll: true,
        autoHeight: true, width: 360, autoShow: true,
        bodyStyle:'padding:5px; background-color: transparent',
        hideMode: 'offsets', hidden: true,
        listeners: {
            'remove': { scope: this, fn: this.onTabPanelRemove }
        }
    });
    
    this.form = new Ext.FormPanel({
        bodyStyle: 'padding:5px; background-color: transparent',
        defaultType: 'textfield',
        layout: 'form',
        autoScroll: true,
        defaults: { maxLength: 100 },
        items: [
            {
                xtype: 'fieldset',
                title: 'Edit Category & Feature Class',
                id: 'nhdEditCategoryOptions',
                cls: 'nhdEditCategoryOptions',
                autoHeight: true,
                defaults: { xtype: 'radio', hideLabel: true },
                items: [
                    { id: 'radioBtnNew', name: 'EditCategory', value: 'New', boxLabel: "New" ,
                        listeners: {
                            'check': {
                                scope: this,
                                fn: function (chkBx, checked) {
                                    if (checked) {
                                        this.form.findById('ComID').disable();
                                        this.form.findById('ReachCode').disable();
                                    } else {
                                        this.form.findById('ComID').enable();
                                        this.form.findById('ReachCode').enable();
                                    }
                                }
                            }
                        }
                    },
                    { id: 'radioBtnExisting', name: 'EditCategory', value: 'Existing', boxLabel: "Existing" },
                    { id: 'radioBtnComment', name: 'EditCategory', value: 'Commentary', boxLabel: "Commentary"},
                    {
                        id: 'FeatureClass', xtype: 'combo', fieldLabel: "Feature Class", hideLabel: false,
                        allowBlank: true, editable: false, forceSelection: true, mode: 'local',
                        triggerAction: 'all', store: this.fClassStore, displayField: 'FClass', selectOnFocus: true,
                        listeners: {
                            'select': {
                                scope: this,
                                fn: function(combo, record, index) {
                                    var fClassSelected = record.get('FClass');
                                    this.loadFTypeStore(fClassSelected);
                                    this.form.findById('FType').reset();
                                }
                            }
                        }
                    }
                ]
            },

            this.nhdTabPanel,

            { id: 'ComID', fieldLabel: "ComID" },
            { id: 'FDate', xtype: 'datefield', fieldLabel: "FDate", format: 'Ymd' },

            { id: 'Resolution', fieldLabel: "Resolution", xtype: 'combo',
                allowBlank: true, width: 75, editable: false, forceSelection: true, mode: 'local',
                hiddenName: 'f_resolution', triggerAction: 'all', displayField: 'resValue',valueField: 'resValue',
                tpl: '<tpl for="."><div ext:qtip="{resValue}" class="x-combo-list-item">{resName}</div></tpl>', 
                store: new Ext.data.SimpleStore({fields: ['resValue','resName'], data: [["1","Local"],["2","High"],["3","Medium"]] })
            },

            { id: 'GNIS_ID', fieldLabel: "GNIS_ID" },
            { id: 'GNIS_Name', fieldLabel: "GNIS_Name" },
            { id: 'ReachCode', fieldLabel: "ReachCode" },

            { id: 'FlowDir', xtype: 'combo', fieldLabel: "FlowDir",
                allowBlank: true, width: 125, editable: false, forceSelection: true, mode: 'local',
                hiddenName: 'flow_dir', triggerAction: 'all',
                displayField: 'flowValue',valueField: 'flowValue',
                tpl: '<tpl for="."><div ext:qtip="{flowValue}" class="x-combo-list-item">{flowName}</div></tpl>', 
                store: new Ext.data.SimpleStore({fields: ['flowValue','flowName'], data: [["1","WithDigitized"],["2","Uninitialized"]] })
            },

            {
                id: 'FType', xtype: 'combo', fieldLabel: "FType", width: 200,
                allowBlank: true, editable: false, forceSelection: true, mode: 'local',
                triggerAction: 'all', store: this.fTypeStore, displayField: 'FType', valueField: 'FType', selectOnFocus: true,
                tpl: '<tpl for="."><div ext:qtip="{FType}" class="x-combo-list-item">{FTypeDesc}</div></tpl>',
                listeners: {
                    'select': {
                        scope: this,
                        fn: function(combo, record, index) {
                            var fTypeSelected = record.get('FType');
                            var fClassSelected = this.form.findById('FeatureClass').getValue();
                            this.loadFcodeStore(fTypeSelected,fClassSelected);
                            this.form.findById('FCode').reset();
                        }
                    }
                }
            },
            {
                id: 'FCode', xtype: 'combo', fieldLabel: "FCode", width: 200,
                allowBlank: true, editable: false, forceSelection: true, mode: 'local',
                tpl: '<tpl for="."><div ext:qtip="{FCode}" class="x-combo-list-item">{FDescription}</div></tpl>',
                triggerAction: 'all', store: this.fCodeStore, displayField: 'FCode', valueField: 'FCode'
            },

            {
                id: 'Comments', xtype: 'textarea', fieldLabel: "Comments",
                maxLength: 1000, width: 200
            }]
    });


    TNRIS.NhdXmlLayerUserDataWindow.superclass.constructor.call(this, {
        title: 'NHD Shape Properties',
        height: 600,
        width: 400,
        anchor: '90%',
        layout: 'fit',
        closable: false, 
        closeAction: 'close',
        buttonAlign: 'center',
        stateful: false,
        items: this.form,
        buttons: [
            {
                id: 'okButton',
                text: 'Ok',
                scope: this,
                handler: this.onOK
            }, {
                id: 'cancelButton',
                text: 'Cancel',
                scope: this,
                handler: function() {this.onClose(); }
            }
        ],
        listeners: {
            'show': {
                scope: this,
                fn: this.onShow
            }
        }
    });
    
    this.mapPanel = this.layer.mapPanel();

    this.mapPanel.on('map-change', function(){this.onClose();}, this);
    this.form.doLayout();
};

Ext.extend(TNRIS.NhdXmlLayerUserDataWindow, Ext.Window,
/** @scope TNRIS.NhdXmlLayerUserDataWindow */
    {
    load: function(shapeId, array) {
        this.shapeId = shapeId;
        this.fieldStore.loadData(array);

        var emptyFeature = false;
        Ext.each(array, function(field) {
            if (field.guiName == 'EditCategory') {
                if (null != field.value) {
                    this.setEditCategory(field.value);
                } else {
                    emptyFeature = true;
                }
            } else {
                var fieldCmp = this.form.findById(field.guiName);
                if (null != fieldCmp) {
                    fieldCmp.setValue(field.value);
                }
            }
        }, this);
        
        if (emptyFeature) {
            this.form.findById('Resolution').setValue('2');
            this.form.findById('FlowDir').setValue('1');
            this.form.findById('FDate').setValue(new Date());
        }

        PageMethods.getNhdDropDownInfo(function(value) {
            this.nhdMappingStore.loadData(value);
        } .bind(this));
    },
    
    onShow: function() {
        var existingRadio = this.form.findById('radioBtnExisting');
        existingRadio.on({
            'check' : {scope: this,fn:this.onExistingRadioBtnCheck}
        });
    },
    
    onExistingRadioBtnCheck: function (chkBx, checked) {
        if (checked) {
            if (this.searchCompleted) {
                if (this.nhdTabPanel.items.getCount() > 0) {
                    this.nhdTabPanel.show();
                }
            }else {
                this.searchNhdFeatures();
            }
        }
        else {
            this.nhdTabPanel.hide();
            this.resetFormValues();
        }
    },
    
    resetFormValues: function() {
        var resetFields = ['ComID','FDate','Resolution','GNIS_ID','GNIS_Name','ReachCode','FlowDir','FType','FCode'];
        Ext.each(resetFields,function(field) {this.form.findById(field).reset(); }, this);
        this.form.findById('FDate').setValue(new Date());
    },
    
    searchNhdFeatures: function() {
        this.form.getEl().mask('<span id="nhdLayerBusy">Searching existing features from server...</span>');
        var points = this.layer.getShapeStore().getById(this.shapeId).get('shapePoints');
        var pointType = this.layer.getShapeStore().getById(this.shapeId).get('shapeType');
        PageMethods.searchNhdFeatures({ points: points, type: pointType }, function(searchResult) {
            this.loadNhdTabPanel(searchResult);
            this.form.getEl().unmask();
        }.bind(this));
        
        this.searchCompleted = true;
    },

    onOK: function() {
        if (!this.validateFormFields()) {
            return;
        }

        this.fieldStore.each(function(record) {
            var field = record.get('guiName');
            switch(field) {
                case 'EditCategory':
                    record.set('value', this.getEditCategory());
                    break;
                case 'FDate':
                    record.set('value', Ext.get('FDate').getValue());
                    break;
                default:
                    var formComp = this.form.findById(field);
                    if (null != formComp) {
                        record.set('value', formComp.getValue());
                    }
                    break;
            }
        }, this);

        var fields = this.fieldStore.getRange();
        this.layer.updateShapeData(this.shapeId, fields);
        this.onClose();
    },

    onClose: function() {
        this.deleteTabPanelShapes();
        this.close();
    },

    validateFormFields: function() {
        var fieldsToValidate;
        var validationStatus = true;

        switch (this.getEditCategory()) {
            case "Existing":
                fieldsToValidate = this.existingFeatureFields;
                break;
            case "New":
                fieldsToValidate = this.newFeatureFields;
                break;
            default:
                fieldsToValidate = [];
                break;
        }

        if (fieldsToValidate.length > 0) {
            Ext.each(fieldsToValidate, function(field) {
                var result = this.validateField(field);
                if (!result) {
                    Ext.Msg.alert("Validation Failed", "The '" + field + "' can not be empty for this edit category");
                    validationStatus = false;
                    return false;
                }
            }, this);
        }
        
        if (validationStatus) {
            var dt= Ext.getCmp('FDate').getValue();
            var mt = new Date();
            if (dt > mt ) {
                Ext.Msg.alert("Date Error", "The 'FDate' can not be a future date");
                validationStatus = false;
            }
        }
        
        return validationStatus;
    },

    validateField: function(fieldName) {
        var cmp = this.form.findById(fieldName);
        var value = cmp.getValue();
        if ((null != value) && (value != "")) {
            return true;
        }

        return false;
    },

    setEditCategory: function(value) {
        switch (value) {
            case "New":
                this.form.findById('radioBtnNew').setValue(true);
                break;
            case "Existing":
                this.form.findById('radioBtnExisting').setValue(true);
                break;
            case "Commentary":
                this.form.findById('radioBtnComment').setValue(true);
                break;
            default:
                break;
        }
    },

    getEditCategory: function() {
        var result = null;
        if (this.form.findById('radioBtnNew').getValue()) {
            result = "New";
        }
        else if (this.form.findById('radioBtnExisting').getValue()) {
            result = "Existing";
        }
        else if (this.form.findById('radioBtnComment').getValue()) {
            result = "Commentary";
        }
        return result;
    },

    //drop down functionalities
    loadFClassStore: function() {
        var fClassArray = [];
        this.nhdMappingStore.each(function(record) {
            var fClass = record.get('FClass');
            var duplicateFound = false;

            Ext.each(fClassArray, function(_fClass) {
                if (_fClass[0] == fClass) {
                    duplicateFound = true;
                    return false;
                }
            }, this);

            if (!duplicateFound) {
                fClassArray.push([fClass]);
            }
        }, this);
        this.fClassStore.loadData(fClassArray);
    },

    loadFTypeStore: function(fClassSelected) {
        var fTypesArray = [];
        this.nhdMappingStore.each(function(record) {
            var fClass = record.get('FClass');
            var fType = record.get('FType');
            var fTypeDesc = record.get('FTypeDesc');
            var duplicateFound = false;

            if (fClass == fClassSelected) {
                Ext.each(fTypesArray, function(_fType) {
                    if (_fType[0] == fTypeDesc) {
                        duplicateFound = true;
                        return false;
                    }
                }, this);

                if (!duplicateFound) {
                    fTypesArray.push([fTypeDesc, fType]);
                }
            }
        }, this);
        this.fTypeStore.loadData(fTypesArray);
    },

    loadFcodeStore: function(fTypeSelected,fClassSelected) {
        var fCodesArray = [];
        this.nhdMappingStore.each(function(record) {
            var fClass = record.get('FClass');
            var fType = record.get('FType');
            var fCode = record.get('FCode');
            var fDesc = record.get('FDescription');

            if ((fType == fTypeSelected)&& (fClass == fClassSelected )) {
                fCodesArray.push([fCode, fDesc]);
            }
        }, this);
        this.fCodeStore.loadData(fCodesArray);
    },

    // tab panel
    tabTemplate: new Ext.XTemplate(
        '<tpl for=".">',
        '   <div class="nameValuePair"><span class="fieldName">{fieldName}</span>:<span class="fieldValue">{fieldValue}</span></div>',
        '</tpl>' ),

    loadNhdTabPanel: function(dataArray) {
        if (!dataArray.length > 0) {
            return;
        }

        dataArray.each(function(data) {
            var layerId, featureType, featureArray, featureId, displayFields = [];
            data.each(function(item, index) {
                switch (item.fieldName) {
                    case 'shapeType':
                        featureType = item.fieldValue;
                        break;
                    case 'shapePoints':
                        featureArray = item.fieldValue;
                        break;
                    case 'layerId':
                        layerId = item.fieldValue;
                        break;
                    case 'id':
                        featureId = item.fieldValue;
                        break;
                    case 'name':
                        featureName = item.fieldValue;
                        break;
                    default:
                        displayFields.push({ 'fieldName': item.fieldName, 'fieldValue': item.fieldValue });
                        break;
                }
            });

            var shape = (new TNRIS.ShapeLayer()).veShapeFromPoints(featureType, featureArray);
            this.mapPanel.getMap().AddShape(shape);
            shape.SetLineColor(this.shapeLineColor);
            shape.SetFillColor(this.shapeFillColor);
            if (shape.GetType() != VEShapeType.Pushpin) {
                shape.HideIcon();
            } else {
                shape.SetCustomIcon(this.shapeIcon);
            }

            this.nhdTabPanel.add({
                xtype: 'panel',
                html: this.tabTemplate.applyTemplate(displayFields),
                title: featureName,
                autoScroll: true,
                shape: shape,
                autoHeight: true,
                autoShow: true,
                layoutOnTabChange: true,
                reziseTabs: true,
                shapeData: displayFields,
                isNhdLayerInformation: true,
                listeners: {
                    'activate': { scope: this, fn: this.activatePanel },
                    'deactivate': { scope: this, fn: this.deactivatePanel }
                }
            });
            this.nhdTabPanel.show();
            this.nhdTabPanel.doLayout();
        } .bind(this));
        this.nhdTabPanel.activate(0);

    },

    activatePanel: function(panel) {
        panel.shape.SetLineColor(this.shapeHighlightLineColor);
        panel.shape.SetFillColor(this.shapeHighlightFillColor);
        if (panel.shape.GetType() != VEShapeType.Pushpin) {
            panel.shape.HideIcon();
        } else {
            panel.shape.SetCustomIcon(this.shapeHighlightIcon);
        }

        this.loadSelectedPanelData(panel.shapeData);
    },

    deactivatePanel: function(panel) {
        panel.shape.SetLineColor(this.shapeLineColor);
        panel.shape.SetFillColor(this.shapeFillColor);
        if (panel.shape.GetType() != VEShapeType.Pushpin) {
            panel.shape.HideIcon();
        } else {
            panel.shape.SetCustomIcon(this.shapeIcon);
        }
    },

    loadSelectedPanelData: function(dataArray) {
        Ext.each(dataArray, function(data) {
            var fieldCmp = this.form.findById(data.fieldName);
            if (null != fieldCmp) {
                fieldCmp.setValue(data.fieldValue);
            }
        }, this);
    },
    
    deleteTabPanelShapes:function() {
        var map = this.mapPanel.getMap();
        this.find('isNhdLayerInformation', true).each(function(panel) {
            map.DeleteShape(panel.shape);
        }, this);
    }
});

if (typeof(Sys) !== "undefined") { Sys.Application.notifyScriptLoaded(); }
