﻿// Reference a file-based JavaScript 
/// <reference path="~/content/js/jquery/jquery-1.4.2.js" />
/// <reference path="~/content/js/danskit/danskit.notifier.js" />
/// <reference path="~/content/js/danskit/danskit.common.js" />

$(document).ready(function () {
    InitSearch();
});

function InitSearch() {
    var button = $("#searchbox-icon");
    var searchInput = $("#search-input");

    $(button).click(function (event) {
        Search();
    });

    $(searchInput).keypress(function (e) {
        if (e.which === 13) {
            Search();
            e.preventDefault();
        }
    });

    function Search() {
        var searchText = $(searchInput).val().replace(/^[\s\*]+|[\s\*\?]+$/g, "").replace(/\*{2,}/g, "*");
        $(searchInput).val(searchText);

        var searchUrl = "/Search.aspx?searchStr=" + searchText;

        if (searchText !== "") {
            if (searchText.length > 1) {
                window.location = searchUrl;
                return false;
            }
            else {
                $.notify({ text: "Søg på mindst to tegn!", type: "error", clear: true });
            }
        }
        else {
            $.notify({ text: "Tom søgning!", type: "error", clear: true });
        }
    }

}


