﻿var SiteUrl = "http://localhost:1040/amberloup/";

$(document).ready(function() {
    getSiteUrl(); //alle functies die siteurl gebruiken in de functie WaitForSiteUrl() zetten!

    if ($.browser.msie) {
        if ($.browser.version < 7) {

            $(".ButtonLarge").hover(
                function() {
                    $(this).attr('style', 'background-image: url(../images/button-bg-selected.jpg);');
                    $(this).css('cursor', 'pointer');
                },
                function() {
                    $(this).attr('style', 'background-image: url(../images/button-bg.jpg);');
                }
            );

           $(document).pngFix();
        }
    }

    $("#menu img").hover(
        function() {
            $(this).attr("src", $(this).attr("src").replace(".jpg", "-over.jpg"));
        },
        function() {
            $(this).attr("src", $(this).attr("src").replace("-over", ""));
        }
    );

    $(function() {
        $('#ctl00_cphContentRight_ctlFotoboek_dlFotos a').lightBox({
            imageLoading: '../images/lightbox-ico-loading.gif',
            imageBtnPrev: '../images/lightbox-btn-prev.gif',
            imageBtnNext: '../images/lightbox-btn-next.gif',
            imageBtnClose: '../images/lightbox-btn-close.gif',
            imageBlank: '../images/lightbox-blank.gif'
        });
    });

    contactFormValidation();

    //Jquery UI -> datepickers
    var arrMonthNames = ['Januari', 'Februari', 'Maart', 'April', 'Mei', 'Juni', 'Juli', 'Augustus', 'September', 'Oktober', 'November', 'December'];
    var arrDayNames = ['Zondag', 'Maandag', 'Dinsdag', 'Woensdag', 'Donderdag', 'Vrijdag', 'Zaterdag']; //let op, beginnen met zondag!
    var arrShortDayNames = ['Zo', 'Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za']; //let op, beginnen met zondag!

    $("#ctl00_cphContentRight_ctlContact_txtPeriodeGewenstVan").datepicker({ dateFormat: "dd/mm/yy", monthNames: arrMonthNames, dayNames: arrDayNames, dayNamesMin: arrShortDayNames, firstDay: 1, showWeeks: true });
    $("#ctl00_cphContentRight_ctlContact_txtPeriodeGewenstTot").datepicker({ dateFormat: "dd/mm/yy", monthNames: arrMonthNames, dayNames: arrDayNames, dayNamesMin: arrShortDayNames, firstDay: 1, showWeeks: true });

    $("#ctl00_cphContentRight_ctlContact_kalenderButton").click(function() {

        PopupKalender();

    });
});

function contactFormValidation() {
    $("#aspnetForm").validate({
        rules: {
            ctl00$cphContentRight$ctlContact$txtVerenigingNaam: {
                required: true
            },
            ctl00$cphContentRight$ctlContact$txtVerenigingPostcode: {
                required: true
            },
            ctl00$cphContentRight$ctlContact$txtVerenigingPlaats: {
                required: true
            },
            ctl00$cphContentRight$ctlContact$txtVerenigingEmail: {
                required: true,
                email: true
            },
            ctl00$cphContentRight$ctlContact$txtContactpersoonNaam: {
                required: true
            },
            ctl00$cphContentRight$ctlContact$txtContactpersoonPostcode: {
                required: true
            },
            ctl00$cphContentRight$ctlContact$txtContactpersoonPlaats: {
                required: true
            },
            ctl00$cphContentRight$ctlContact$txtContactpersoonEmail: {
                required: true,
                email: true
            }
        },

        messages: {
            ctl00$cphContentRight$ctlContact$txtVerenigingNaam: {
                required: "Verplicht veld"
            },
            ctl00$cphContentRight$ctlContact$txtVerenigingPostcode: {
                required: "Verplicht veld"
            },
            ctl00$cphContentRight$ctlContact$txtVerenigingPlaats: {
                required: "Verplicht veld"
            },
            ctl00$cphContentRight$ctlContact$txtVerenigingEmail: {
                required: "Verplicht veld",
                email: "Ongeldig formaat"
            },
            ctl00$cphContentRight$ctlContact$txtContactpersoonNaam: {
                required: "Verplicht veld"
            },
            ctl00$cphContentRight$ctlContact$txtContactpersoonPostcode: {
                required: "Verplicht veld"
            },
            ctl00$cphContentRight$ctlContact$txtContactpersoonPlaats: {
                required: "Verplicht veld"
            },
            ctl00$cphContentRight$ctlContact$txtContactpersoonEmail: {
                required: "Verplicht veld",
                email: "Ongeldig formaat"
            }
        },

        errorPlacement: function(error, element) {
            element.parent().children("em").html(error);
            //element.parent().children("input").attr("class", "TextBoxError");
            element.parent().children("input").attr("class", element.parent().children("input").attr("class") + "Error"); //nieuw voor verschillende types button
            element.parent().children("textarea").attr("class", "TextBoxLargeError");
        },

        success: function(label) {
            label.html("<img src=\"../images/ok.png\" alt=\"ok\" />");
            var bijhorendeElement = "#" + $(label).attr("htmlFor");

            if ($(bijhorendeElement).attr("class").indexOf("Error") > -1) {
                $(bijhorendeElement).attr("class", $(bijhorendeElement).attr("class").replace("Error", ""));
            }
        },

        highlight: function(element, errorClass) {

        }
    });
}

/* Opvragen SiteUrl */
function getSiteUrl() {
    realtime.GetSiteUrl(onSucceededSiteUrl, OnFailedSiteUrl);
}

function onSucceededSiteUrl(result, userContext, methodName) {
    // SiteUrl haalt asynchroon de SiteUrl uit de web.config.
    // Omdat de slideshows pas mag gestart worden als SiteUrl goed
    // opgehaald is, starten we hier de slideshows.
    SiteUrl = result;

    WaitForSiteUrl();
}

function OnFailedSiteUrl(error, userContext, methodName) {
    //alert("Er was een probleem bij het ophalen van de siteurl. Probeer opnieuw aub");
    WaitForSiteUrl();
}

function WaitForSiteUrl() {
    if ($("#noFlash").length > 0) {
        var flashvars = {};
        flashvars.url = SiteUrl;
        var params = {};
        var attributes = {};
        swfobject.embedSWF("" + SiteUrl + "SWF/frame.swf", "noFlash", "707", "173", "9.0.0", false, flashvars, params, attributes);
    }
}

function PopupKalender() {
    window.open("kalender.aspx", "", "width=400,height=520,scrollbars=no,status=0");
}
