﻿/// <reference path="~/Resources/js/jquery-1.2.6-intellisense.js" />
var VVM = {
    searchPath: "/sok/",

    toInt: function(string) {
        if (!string) return 0;
        return (string + "").replace(/ *kr| *:-| |\.|,/g, "") * 1;
    },

    formatPrice: function(price) {
        if (!price) return "0 kr";

        var priceString = this.toInt(price) + "";
        var out = "";
        var j = 1;
        for (var i = priceString.length - 1; i >= 0; i--) {
            out = priceString.charAt(i) + out;
            if (i > 0 && j++ % 3 == 0)
                out = "." + out;
        }
        return out + " kr";
    },

    getCookieValue: function(name) {
        var cookies = document.cookie.split("; ");
        for (i = 0; i < cookies.length; i++) {
            var values = cookies[i].split("=");
            if (values.length >= 2) {
                if (values[0] == name) {
                    return values[1];
                }
            }
        }
        return null;
    },

    searchOptions: {},
    productListOptions: {}
};

$(function() {
    $("#main-menu .panel").hide();
    var title = $("#search-panel legend").text();
    $("#query").val(title).click(function() {
        if ($(this).val() === title) {
            $(this).val("");
        }
    }).blur(function() {
        if ($(this).val() === "") {
            $(this).val(title);
        }

        return false;
    });

    $("button").focus(function() {
        $(this).blur();
    });
});