$(function(){
    $(".searchButton").button();
})

function showErrorDialog(message)
{
    $("#errorDialog").html(message);
    
    $("#errorDialog").dialog({
        title: ":(",
        modal: true,
        dialogClass: "ui-state-error",
        draggable: false,
        minHeight: 100,
        minWidth: 600,
        buttons:
        {
            "OK": function()
            {
                $(this).dialog("close");
            }
        }
    });
}	

function getURLParameter(name) {
    return decodeURI(
        (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
        );
}

function searchKeyPressed(event)
{
    var code = event.keyCode ? event.keyCode : event.which;
        
    if(code == 13)
        doSearch();
}

function doSearch()
{
    var searchText = $.trim($(".searchText").val());
    
    if(searchText.length == 0)
        $(".searchText").addClass("invalid");
    else
        window.location.href = "/browse.html?search=" + searchText;
}

function clearSearchResultsFromStorage()
{
    //notice that the remove function fails in IE so setting to empty string is used
    $.Storage.set("searchResults", "");
    $.Storage.set("searchResultsTime", "");
    $.Storage.set("searchResultsSelectedCategoryId", "");
}
