﻿/// <reference path="jquery-1.5-vsdoc.js" />

var selectItemHtml = "<option value=\"{VALUE}\">{NAME}</option>";

$(function () {
    var navigationLinks = $(".topNavigationItem");

    navigationLinks.hover(
      function () {
          $(this).addClass("hover");
      },
      function () {
          $(this).removeClass("hover");
      }
    );

    $('.dataTable tr:even').addClass("gridrow");
    $('.dataTable tr:odd').addClass("gridrow_alternate");
});

function FillCategories(categorySelect) {
    categorySelect.html(selectItemHtml.replace("{VALUE}", "").replace("{NAME}", "Loading..."));

    $.ajax({
        type: "GET",
        url: "/Home/GetCategories/",
        success: function (data) {
            categorySelect.html(selectItemHtml.replace("{VALUE}", "").replace("{NAME}", "Category"));

            $.each(data, function (index, value) {
                categorySelect.append(selectItemHtml.replace("{NAME}", value.name).replace("{VALUE}", value.id));
            });
        },
        error: function (msg) {

        }
    });
}

function FillProductLines(categoryId, productLineSelect) {
    if (categoryId == "0" || categoryId == "") {
        productLineSelect.html(selectItemHtml.replace("{VALUE}", "").replace("{NAME}", "All"));
    }
    else {
        productLineSelect.html(selectItemHtml.replace("{VALUE}", "").replace("{NAME}", "Loading..."));

        $.ajax({
            type: "GET",
            url: "/Home/GetProductLines/",
            data: { categoryId: categoryId },
            success: function (data) {
                productLineSelect.html(selectItemHtml.replace("{VALUE}", "").replace("{NAME}", "All"));

                $.each(data, function (index, value) {
                    productLineSelect.append(selectItemHtml.replace("{NAME}", value.name).replace("{VALUE}", value.id));
                });
            },
            error: function (msg) {

            }
        });
    }
}

function SearchCategories(categoryId, productLineId) {
    if (productLineId != "0" && productLineId != "") {
        window.location = "/Store/BrowseProductLines?productLineId=" + productLineId;
    }
    else if (categoryId != "0" && categoryId != "") {
        window.location = "/Store/BrowseCategories?categoryId=" + categoryId;
    }
    else {
        return false;
    }
}

function FillManufacturers(manufacturerSelect) {
    manufacturerSelect.html(selectItemHtml.replace("{VALUE}", "").replace("{NAME}", "Loading..."));

    $.ajax({
        type: "GET",
        url: "/Home/GetAllManufacturers/",
        success: function (data) {
            manufacturerSelect.html(selectItemHtml.replace("{VALUE}", "").replace("{NAME}", "Manufacturer"));

            $.each(data, function (index, value) {
                manufacturerSelect.append(selectItemHtml.replace("{NAME}", value.name).replace("{VALUE}", value.id));
            });
        },
        error: function (msg) {

        }
    });
}

function SearchManufacturers(manufacturerId) {
    if (manufacturerId != "0" && manufacturerId != "") {
        window.location = "/Store/BrowseManufacturers?manufacturerId=" + manufacturerId;
    }
    else {
        return false;
    }
}

function GetParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return decodeURIComponent(results[1].replace(/\+/g, " "));
}
