﻿/// <reference path="~/Resources/js/jquery-1.2.6-intellisense.js" />

//Utöka Array-objektet med en funktion som kollar om en viss sträng finns
Array.prototype.exists = function(val) {
    for (var i = 0; i < this.length; i++)
        if (this[i] === val)
        return true;
    return false;
}

$(function() {
    $("#proceed").click(function() {
        if ($(".shop-select option:selected").val() == "") {
            $(".shop-select ~ span[id$='requiredStoreValidator']").css("display", "inline");
            return false;
        }

        $(".popup-container").modalPopup2();
        $(".popup-container .semi-optional img").remove();
        $(".popup-container .semi-optional").prepend($('#' + document.HomeDeliveryId).is(":checked") ? "<img src='/Resources/images/required-dot.gif' alt='Obligatorisk' /> " : "");
        $(".popup-container .selected-store").text(
            $(".shop-select option:selected").text());

        $(window).keyup(function(e) {
            var esc = 27;
            if (e.keyCode == esc) {
                $(".popup-container").hide();
                $(".background").remove();
                return false;
            }
        });

        return false;
    });

    if ($("#inquiry-error input").val() == "yes") {
        $("#proceed").click();
    }

    $(".shop-select").change(function() {
        var selectedShop = $(".shop-select option:selected").val();

        if (selectedShop != "") {
            $(".shop-select ~ span[id$='requiredStoreValidator']").hide();
            document.cookie = "EelStore=storeId=" + selectedShop.substring(1, selectedShop.length - 1) + "; path=/;";
        }
    });
});
