/*  == Bing site search
== Include this js file in your search page (after jQuery)
== Get an app ID from the following URL (Live Id): http://bing.com/developers and paste it in below
== Call searchSite from your search page = Example:
    
==              <script type="text/javascript">
==                  $(document).ready(function() {
==                          searchSite('883A47204671286ECDD3CFA1AFA378AE93864A3E', 'www.cadivorce.com','<%=ViewData["searchTerms"] %>');
==                  });
==              </script>

== Make sure you have a ordered list in the search page: <ol id="result"></ol> the results are appened to it

*/

function searchSite(appId, siteDomain, keyword) {

    var bingUrl = 'http://api.search.live.net/json.aspx?JsonType=callback&JsonCallback=?&Appid=' + appId + '&query=' + keyword + ' site:' + siteDomain + '&sources=web&Web.Count=50';
    $.ajax
        ({
            type: "GET",
            url: bingUrl,
            dataType: "jsonp",
            success: function(response) {
                $("#result").html('');
                if (response.SearchResponse.Web.Results != null) {
                    $.each(response.SearchResponse.Web.Results, function(i, data) {
                        var title = data.Title;
                        var summary = data.Description;
                        var url = data.Url;

                        var output = "<li><a href='" + url + "'>" + title + "</a><p>" + summary + "</p></li>";

                        $("#result").append(output);

                    });
                }
                else {

                    $("#result").html("<li id='no'>No Results</li>");
                    $("#no-results").show();
                }
            }
        });

}
