function searchFavorites (query){
    var feedback = [];
    var resultList = localStorage.getItem("results");
    _.each(resultList.businesses, function(x){
        if(x.name.search(query) > -1 || x.tag.search(query) > -1 || x.notes.search(query) > -1){
            feedback.push(x);
        }
    });
    return feedback;
}

function getFavoriteCategories(){
    var feedback = [];
    var resultList = localStorage.getItem("results");
    //returns the list of lists (of categories);
    _.each(resultList.businesses, function(x){
       feedback.push(x.categories);
    }
 );
    var answer = []; //a temp variable used in getBroadCategories which will be filled which a business's category hierachy
    var cats = [];   //a list of 'answer' lists; each element in cats is a list containing the hierachy for each business

    _.each(feedback, function(innerCat){
        cats.push(getBroadCategories(answer, innerCat, categories));
        answer =[];
    });
    return cats;
}
//this function needs testing

function getBroadCategories(answers, innerCat, globalCategories){
    for(var ky in globalCategories){
        if(typeof globalCategories == 'object'){
            answers.push(globalCategories);
            getBroadCategories(answers, globalCategories[ky]);
        }else if(typeof globalCategories == 'string'){
            if(globalCategories == innerCat){
                 return answers; //return the list which contains the hierachy of categories for this business
                 //first element in the list is the inner most category and the last element is the broad category
            }//else, the category of the item is not this one.
        }
        answers = [];  //clear the array and look at the next category in the global list
    }
}

function getFavoritesWithinCategory (query){
    var feedback = [];
    var resultList = localStorage.getItem("results");

   _.each(resultList.businesses, function(x){
        if(x.categories == query){
            feedback.push(x);
        }
    });
    return feedback;
}

function addBusinessToFavorite (business){
    var resultList =[];
    if(typeof localStorage.getItem("results") != 'undefined' ){
        resultList = localStorage.getItem("results");
        resultList.push(business);
   }else{
       resultList[0] = business;
   }
     localStorage.setItem("results", resultList);
}

function deleteBusinessFromStorage(business){
    var resultList = localStorage.getItem("results");
    removeA(resultList, business);
    localStorage.setItem("results", resultList);
}

function removeA(arr) {
    var what, a = arguments, L = a.length, ax;
    while (L > 1 && arr.length) {
        what = a[--L];
        while ((ax= arr.indexOf(what)) !== -1) {
            arr.splice(ax, 1);
        }
    }
    return arr;
}
function saveBookmark(business, tags, notes){
    business.tags = tags;
    business.notes = notes;
    var d = new Date();
    var day = d.getDate();
    var month = d.getMonth() + 1;
    var time = d.getTime();
    var year = d.getFullYear();
    business.dateAdded = time + " " + month + "/" + day +"/"+ year;
    addBusinessToFavorite(business);
}
@@ -489,24 +489,25 @@
 categories);
+ 
 %0D%0A    _.each
@@ -1516,18 +1516,19 @@
 business
+ 
 %0D%0A
-
         
@@ -1806,16 +1806,20 @@
 t%0D%0A    %7D
+    
 %0D%0A%7D%0D%0A%0D%0Af
@@ -2235,16 +2235,73 @@
 efined' 
+%7C%7C localStorage.getItem(%22results%22) != 'undefined' != null
 )%7B%0D%0A    
@@ -2398,16 +2398,16 @@
 %7Delse%7B%0D%0A
-
        r
@@ -2430,16 +2430,17 @@
 usiness;
+ 
 %0D%0A   %7D%0D%0A

fix to the addBusinessToFav