﻿/// <reference path="jquery-1.4.1-vsdoc.js" />

$(document).ready(function () {
    initForhandlerMeny();
    $("#postnrClick").click(function () {
        var postnr = $("#postNrSearch").val();
        var reg = new RegExp("^\\d{4}$", "g");
        if (reg.test(postnr)) {
            $.ajax({ url: "PostalHandler.asmx/FindDealer",
                type: "POST",
                data: "{postalCode:" + postnr + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    if (data.d.Message != "OK") {
                        alert("Fant ikke postnr");
                    } else {
                        var resBox = $("#PostSearchResult");
                        resBox.find(".Navn").text(data.d.Forhandler.forhandlere_navn);
                        resBox.find(".Adresse").text(data.d.Forhandler.forhandlere_adresse);
                        resBox.find(".Post").text(data.d.Forhandler.forhandlere_postnr + " " + data.d.Forhandler.forhandlere_poststed);
                        resBox.find(".Telefon").text("Telefon:" + data.d.Forhandler.forhandlere_tlf);
                        resBox.find(".Faks").text("Faks:" + data.d.Forhandler.forhandlere_faks);
                        resBox.find(".Epost").text("Epost:" + data.d.Forhandler.forhandlere_epost);
                        resBox.fadeIn("normal");
                       
                    }
                },
                error: function () { }
            });
        } else {
            alert("Ugyldig postnr");
        }
    });
});

function initForhandlerMeny() {
    $("#sverige").slideToggle(0);
    $("#sverigeDiv").click(function () {
        $("#norge").slideUp("slow");
        $("#sverige").slideDown("slow");
    });
    $("#norgeDiv").click(function () {
        $("#norge").slideDown("slow");
        $("#sverige").slideUp("slow");
    });
    if (navigator.appVersion.indexOf("MSIE 6") == -1) {
        $("#FylkeMeny ul li ul li a").hover(function () {
            $(this).stop(true, true).animate({ backgroundColor: "#ececec", color: "#000000" }, 400);
        },
function () {
    $(this).stop(true, true).animate({ backgroundColor: "#808080", color: "#ffffff" }, 400);

});
    } else {
        $("#FylkeMeny ul li ul li a").css({ height: "20px", margin: "0px" });
        $("#FylkeMeny ul li ul li").css({ height: "20px", margin: "0px" });
        $("#FylkeMeny ul li ul li a").hover(function () {
            $(this).css("backgroundColor", "#ececec");
            $(this).css("color", "#000000");
        }, function () {
            $(this).css("backgroundColor", "#808080");
            $(this).css("color", "#ffffff");
        });
    }
    var qstr = window.location + "";
    if (qstr.indexOf("Sverige") > 0) {
        $("#norge").slideUp(0);
        $("#sverige").slideDown(0);
    }
}


