function SearchFieldlist() {

    var fields = [];
    var categories = [];
    var categoryTemplateID;
    this.setCategory = function(template) {
        categoryTemplateID = !template ? null : $.grep(fields, function(field) {
            return (field.templateName.toUpperCase().indexOf(template.toUpperCase()) > -1);
        });
    }

    this.loadData = function(filter) {

        if (fields.length === 0) {
            initdb_();
        }


        data = $.grep(fields, function(field) {
            field.categoryTemplates = $.grep(field.categoryTemplates, function(field2) {
                return (!categoryTemplateID || field2 == categoryTemplateID);
            });
            return (
                (!categoryTemplateID || field.categoryTemplates.length > 0) &&
               // (!filter.mdpLabel || field.label.toUpperCase().indexOf(filter.label.toUpperCase()) > -1) &&
                (!filter.group || field.group.toUpperCase().indexOf(filter.group.toUpperCase()) > -1) &&
                (!filter.label || field.label.toUpperCase().indexOf(filter.label.toUpperCase()) > -1) &&
                (!filter.help || field.help.toUpperCase().indexOf(filter.help.toUpperCase()) > -1) &&
                (!filter.type || field.type.toUpperCase().indexOf(filter.type.toUpperCase()) > -1)
            );
        });

        return data;

    };

    this.insertItem = function(insertingField) {
        fields.push(insertingField);
    };

    this.updateItem = function(updatingField) {};

    this.deleteItem = function(deletingField) {
        var fieldIndex = $.inArray(deletingField, this.fields);
        fields.splice(fieldIndex, 1);
    };

    function initdb_() {
        $.ajax({
            url: 'data/fieldFinder2.json',
            dataType: 'json',
            async: false,
            success: function(data) {
                fields = data.DataDictionary;
            }
        });
        $.ajax({
            url: 'data/categories.json',
            dataType: 'json',
            async: false,
            success: function(data) {
                categories = data.categories;
            }
        });
    }



}
@@ -149,34 +149,103 @@
         
+if (
 categor
-yT
+ies.length === 0) %7B%0A            initdb_();%0A        %7D%0A%0A%0A        var t
 emplate
-ID
+s
  = !temp
@@ -257,37 +257,41 @@
 ? null : $.grep(
-field
+categorie
 s, function(fiel
@@ -278,37 +278,40 @@
 ories, function(
-field
+category
 ) %7B%0A            
@@ -318,21 +318,24 @@
 return (
-field
+category
 .templat
@@ -401,24 +401,142 @@
         %7D);%0A
+        if (templates && templates.length %3E 0) %7B%0A            categoryTemplateID = templates%5B0%5D.templateID;%0A        %7D%0A%0A
     %7D%0A%0A    t
@@ -967,24 +967,25 @@
 gth %3E 0) &&%0A
+ 
             

add category id search logic