﻿$(document).ready(function () {
    $(".fancyBox").fancybox();
    addTabs();

    $("#brosjyre_click").click(function () {
        $("#brosjyreLoader").css("display", "block");
        var navnS = $("#brosjyre_navn").attr("value");
        var adresseS = $("#brosjyre_adresse").attr("value");
        var poststedS = $("#brosjyre_poststed").attr("value");
        var postnrS = $("#brosjyre_postnr").attr("value");
        var epostS = $("#brosjyre_epost").attr("value");
        var tlfS = $("#brosjyre_tlf").attr("value");
        if (epostS == "" || navnS == "" || adresseS == "" || poststedS == "" || postnrS == "") {

            $("#brosjyreLoader").css("display", "none");
            $("#brosjyre_status").html("Vennligst fyll ut alle feltene");
            $("#brosjyre_status").fadeIn();
            return false;
        }
        $.get("BestillBrosjyre.aspx", { navn: navnS, adresse: adresseS, poststed: poststedS, postnr: postnrS, epost: epostS, tlf: tlfS }, function (data) {
            $("#brosjyreLoader").css("display", "none");
            if (data == "OK") {

                $("#brosjyre_status").html("Takk for din bestilling!");
                $("#brosjyre_status").fadeIn();
            } else if (data == "FAIL") {

                $("#brosjyre_status").html("Det oppstod en feil,vennligst prøv igjen senere. Sjekk at epostadressen er gyldig.");
                $("#brosjyre_status").fadeIn();
            }

        });

        /*$.ajax({
        url: "BestillBrosjyre.aspx",
        type: "POST",
        contentType: "application/x-www-form-urlencoded;charset=utf-8",
        data: ({ navn: navnS, adresse: adresseS, poststed: poststedS, postnr: postnrS, epost: epostS }),
        success: function (data) {
        $("#brosjyreLoader").css("display", "none");
        if (data == "OK") {
        alert("Takk for din bestilling!");
        } else if (data == "FAIL") {
        alert("Det oppstod en feil,vennligst prøv igjen senere. Sjekk at epostadressen er gyldig.");
        }

        }
        });*/
        //alert(navn + " " + adresse + " " + poststed + " " + postnr + " " + epost);
        return false;
    });
});


function addTabs() {
    var t = 0;
    $(".myTabs .myTabsPanel").each(function () {
        if (t != 0) {
            $(this).css("display", "none");
        }
        t = t + 1;
    });
    $(".myTabs ul li a").each(function () {

        var id = $(this).attr("id").substring(1);

        $(this).click(function () {

            $(".myTabs .myTabsPanel").each(function () {
                if ($(this).attr("id") == id) {
                    $(this).css("display", "block");
                    //$(this).slideDown();
                } else {
                    $(this).css("display", "none");
                    //$(this).slideUp();
                }

            });
        });
    });
}
