﻿$("#search-form").submit(function (event) {
    var query = $("#search-box").val();
    var path = window.location.pathname;
    //Split path, removing empty entries
    var splitPath = path.split('/');
    splitPath = splitPath.filter(function (v) { return v !== '' });

    if (splitPath.length <= 1) {
        searchSite(query);
    }
    else if (splitPath.length >= 2)
    {
        var username = splitPath[1];
        console.log(username);
        var repository = splitPath[2];
        console.log(repository);
        searchRepository(username, repository, query);
    }
    console.log(splitPath.length);

    return false;
});


function searchRepository(username, repository, query) {
    console.log("search repo");

    data = JSON.stringify({
        "username": username,
        "repository": repository,
        "query": query
    });

    $.ajax({
        type: "POST",
        url: "/Search/Repository/",
        //TODO: If anyone knows a better way to do this, please share it.
        //My Javascript is not strong...
        data: "username=" + username + "&repository=" + repository + "&query="+ query,
        success: results
    });
}

function results(e) {
    $("#tree-view").hide();
    $("#search-results").show();

    if(e.length == 0)
    {
        $("#no-results").show();
        return;
    }

    $("#no-results").hide();

}

function searchSite(query) {
    console.log("search site");
    console.log(query);
}


@@ -423,101 +423,37 @@
     
-console.log(username);%0A        var repository = splitPath%5B2%5D;%0A        console.log(repository)
+var repository = splitPath%5B2%5D
 ;%0A  
@@ -514,43 +514,8 @@
    %7D
-%0A    console.log(splitPath.length);
 %0A%0A  
@@ -596,40 +596,8 @@
 y) %7B
-%0A    console.log(%22search repo%22);
 %0A%0A  
@@ -1008,23 +1008,28 @@
 uccess: 
-results
+handleSearch
 %0A    %7D);
@@ -1045,17 +1045,28 @@
 ion 
+handleSearch(
 results
-(e
 ) %7B%0A
@@ -1133,18 +1133,25 @@
 %0A%0A    if
-(e
+ (results
 .length 
@@ -1155,20 +1155,16 @@
 th == 0)
-%0A   
  %7B%0A     
@@ -1199,27 +1199,25 @@
     
+%7D%0A
     
-return;
+else %7B
 %0A    
-%7D%0A%0A
     
@@ -1245,41 +1245,189 @@
 ();%0A
-%0A%7D%0A%0Afunction searchSite(query) %7B%0A
+        var htmlResults = buildResults(results);%0A    %7D%0A%7D%0A%0Afunction buildResults(results) %7B%0A    for (var i = 0; i %3C results.length; i++) %7B%0A        var searchResult = results%5Bi%5D;%0A    
     
@@ -1442,47 +1442,61 @@
 log(
-%22
 search
- site%22
+Result
 );%0A    
-console.log
+%7D%0A%7D%0A%0A%0Afunction searchSite
 (query)
-;
+ %7B
 %0A%7D%0A%0A

Remove old logging statements. Set up structure to build HTML