﻿
//require("Scripts/jquery.ui.position.min.js");
require("Scripts/jquery.ui.autocomplete.js");



$(document).ready(function () {

    $("input[id$=btnGo]").click(function (e) {
        e.preventDefault();

        var strTerm = $('input[id$=txtSearch]').val();

        strTerm = escape(strTerm);

        document.location = "search.aspx?term=" + strTerm;
    });

    // SEARCH

    $(".search_box").autocomplete({
        source: "suggestions.ashx",
        minLength: 3,
        delay: 500,
        select: function (event, ui) {
            //search for ui.item.value

            var strProduct = MakeURL(ui.item.value);

            document.location = strProduct;
        }
    });

    $(".search_watermark").each(function () {
        $tb = $(this);
        if ($tb.val() != this.title) {
            $tb.removeClass("search_watermark");
        }
    });

    $(".search_watermark").focus(function () {
        $tb = $(this);
        if ($tb.val() == this.title) {
            $tb.val("");
            $tb.removeClass("search_watermark");

        }
    });

    $(".search_watermark").blur(function () {
        $tb = $(this);
        if ($.trim($tb.val()) == "") {
            $tb.val(this.title);
            $tb.addClass("search_watermark");
        }
    });





    $(".line_filter a").click(function () {

        var strTitle = $(this).text();

        if (strTitle == "All") {
            $(".line").css("display", "block");
        }
        else {
            $(".line").css("display", "none");
            $("." + strTitle).css("display", "block");
        }

    });







});


function MakeURL(strText) {

    // rewrite product name to be like the rewrite url

    var strProduct;

    strProduct = strText.replace(/ /g, "-");
    strProduct = strProduct.replace(/:/g, "-");


    strProduct = strProduct.replace(/'/g, "");


    strProduct = strProduct.replace("&", "and");

    return strProduct;
}
