﻿
function showMessage(message, closeCallback) {
    var div = '<div class="popup" style="display: none; width: 339px;" id="network_login_confirm">';
    div += '<div class="popup_close jqmClose"><a href="#">Close</a></div>';
    div += '<div class="popup_t" style="width: 331px;">';
    div += '<div class="popup_inner">';
    div += '<div class="vbox login_popup" style="width: 275px;">';
    div += '<p style="padding: 15px 0;">' + message + '</p>';
    div += '</div></div></div><div class="popup_b"><div class="popup_br"></div></div></div>';
    var $dialog = $(div).appendTo('body');
    $dialog.center().jqm({ modal: true, onHide: function (hash) { hash.w.hide().remove(); hash.o.remove(); closeCallback && closeCallback(); } }).jqmShow();
    return $dialog;
}

jQuery.fn.center = function () {
    this.css("position", "absolute");
    var top = ($(window).height() - this.height()) / 2 + $(window).scrollTop();
    if (top <= 10) top = 10;
    var left = ($(window).width() - this.width()) / 2 + $(window).scrollLeft();
    this.css("top", top + "px");
    this.css("left", left + "px");
    return this;
}

jQuery.fn.waterMark = function (txt) {
    if (this.is('input:text, textarea')) {
        if (this.val() == '')
            this.val(txt);
        this.focus(function () {
            if ($(this).val() == txt)
                $(this).val('');
        });
        this.blur(function () {
            if ($(this).val() == '')
                $(this).val(txt);
        });
    }
    return this;
}

$(function () {
    $('.vtip').bt && $('.vtip').bt({ fill: '#F5DEEE', strokeStyle: '#fff' });    
    
    $("label:has(.ico_checkbox)").bind("click", function (evt) {
        var $chk = $(this).find('input:checkbox');
        $(this).find('.ico_checkbox').toggleClass('checked', $chk.is(':checked'));
    });

    $('label:has(.ico_radio)').bind("click", function (evt) {
        var $this = $(this);
        var $radio = $this.find('input:radio');
        var name = $radio.attr('name');
        $(":radio[name='" + name + "']").not($radio).each(function () {
            $(this).removeAttr('checked').parent('.ico_radio').removeClass('checked');
        });
        $this.find('.ico_radio').addClass('checked');
    });

    $.validator.setDefaults({
        errorElement: "span",
        wrapper: 'div',
        errorPlacement: function (error, element) {
            error.appendTo(element.closest('dd,div'));
            $(error).attr("class", "error_tip");
        },
        highlight: function (element, errorClass, validClass) {
            $(element).closest('dd,div').addClass("valid_error");
        },
        unhighlight: function (element, errorClass, validClass) {
            $(element).closest('.valid_error').find('.error_tip').remove();
            $(element).closest('.valid_error').removeClass("valid_error");
        }
    });

    $.validator.addMethod("email", function (value, element, param) {
        var reg = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
        return this.optional(element) || reg.test(value);
    }, "Incorrect email format");

    $.validator.addMethod("notag", function (value, element, param) {
        var reg = /^.*<.*$/;
        return this.optional(element) || !reg.test(value);
    }, "Invalid content");

    function getDateFromBirthday(birthday) {
        var day;
        var month;
        var year;

        if (birthday.indexOf('-') > 0) {
            var myDate = birthday.split('-');

            day = parseInt(myDate[0], 10);
            month = parseInt(myDate[1], 10);
            year = parseInt(myDate[2], 10);
        } else {
            day = parseInt(birthday.substring(0, 2), 10);
            month = parseInt(birthday.substring(2, 4), 10);
            year = parseInt(birthday.substring(4, 8), 10);
        }

        return {
            day: day,
            month: month,
            year: year
        };
    }

    function getAge(birthday) {
        var date = new Date();
        var day = date.getDate();
        var month = date.getMonth() + 1;
        var year = date.getFullYear();

        var myDate = getDateFromBirthday(birthday);
        var myDay = myDate.day;
        var myMonth = myDate.month;
        var myYear = myDate.year;

        var age = year - myYear;
        if (myMonth > month || (myMonth == month && myDay > day)) {
            age = age - 1;
        }

        return age;
    }

    $.validator.addMethod("dateNL", function (value, element) { // dd-mm-yyyy or ddmmyyyy
        if (this.optional(element)) return true;
        var valid = /^(((0?[1-9])|([12][0-9])|(3[01]))-((0?[1-9])|(1[012]))-(((19)|(20))[0-9]{2}))?$/.test(value) || /^(((0[1-9])|([12][0-9])|(3[01]))((0[1-9])|(1[012]))(((19)|(20))[0-9]{2}))?$/.test(value);
        if (!valid) return false;
        var dmy = getDateFromBirthday(value);
        var d = new Date();
        d.setFullYear(dmy.year);
        d.setMonth(dmy.month - 1, dmy.day);
        valid = valid && (d.getMonth() == (dmy.month - 1));
        if (valid)
            $(element).val(dmy.day + "-" + dmy.month + "-" + dmy.year);
        return valid;
    }, "Incorrect date format");

    $.validator.addMethod("birthdayNL", function (value, element) { // dd-mm-yyyy or ddmmyyyy
        var valid = this.optional(element) || $.validator.methods.dateNL.call(this, value, element);
        valid = valid && getAge(value) >= 0;
        return valid;
    }, "Invalid birthday");

    $.validator.addMethod("housenumber", function (value, element) {
        return this.optional(element) || /^[a-zA-Z0-9]{0,6}$/.test(value);
    }, "ongeldig");

    $.validator.addMethod("postcode", function (value, element) {
        return this.optional(element) || /^([0-9]{4}(\s)?[a-zA-Z]{2})?$/.test(value);
    }, "ongeldig");

    $.validator.addMethod("telephone", function (value, element) {
        return this.optional(element) || /^(\+)?([0-9\s\-]{5,12})?$/.test(value);
    }, "ongeldig");

    $.extend($.validator.messages, window.bloemen.errorMessages.common);

    Cufon.replace('.btn_cyan a, .btn_lightcyan a, .btn_green a,.btn_lightpink a, .mijnpagina_l01_text h3,h4.twitter_leading,.home_twitter h4, .about_item h4,.mainCont .vbox h3, .btn_pink a, .btn_blue a, .srch_form h3, .btn_yellow a,.home_mr01 h3, .home_share_code h3, .home_bl h4, .home_bm h4, .home_br h4,.block_r h3, .block_l h3, .block_m h3', { fontFamily: 'CaeciliaLTStd' });
    Cufon.replace('.content_in h2, .my_info_item h3,.sitemap, .tab_uit h3, .T2_sheet_bl a', { fontFamily: 'BaskervilleClassico' });
    Cufon.replace('.nav li a, .subNav li a, .register .register_form h4, .home_bl h3,.campaign2 h2, .campaign2 p', { fontFamily: 'CaeciliaLTStd-Roman', hover: true });

    var $loader = $('<div style="display:none;" id="preloader"><img src="/bloemencontent/images/preloader_1.gif"/></div>').appendTo('body');
    $loader.jqm({ modal: true });
    $loader.ajaxError(function () { $(this).jqmHide(); });

    var m_timeoutid = 0;
    var s_timeoutid = 0;
    $('.nav li').mouseenter(function () {
        $('.nav li:not(.current)').not($(this)).removeClass('on').find('a').css({ color: '#000' });
        $(this).addClass('on');
        $('.subNav').hide();
        $('#s' + $(this).attr('id')).show();
        fixNavCufon();
        clearTimeout(m_timeoutid);
        clearTimeout(s_timeoutid);
    }).click(function () {
        var smid = 's' + $(this).attr('id');
        var $firstSub = $('#' + smid + ' li a:first');
        if ($firstSub.length > 0 && $firstSub.attr('href').indexOf('/') == 0)
            document.location = $firstSub.attr('href');
    });

    $('.nav li:not(.current)').mouseleave(function (evt) {
        if (!$(evt.relatedTarget).hasClass('subNav')) {
            var $c_menu = $(this);
            m_timeoutid = setTimeout(function () {
                $c_menu.removeClass('on');
                $('.subNav').hide();
                $('.subNav.current').show();
                $c_menu.find('a').css({ color: '#000' });
                fixNavCufon();
            }, 10);
        }
    });

    $('.subNav:not(.current)').mouseleave(function () {
        var $cs_menu = $(this);
        s_timeoutid = setTimeout(function () {
            $cs_menu.hide();
            $('.subNav.current').show();
            $('#' + $cs_menu.attr('id').replace('sm_', 'm_')).removeClass('on').find('a').css({ color: '#000' });
            fixNavCufon();
        }, 10);
    }).mouseenter(function () {
        clearTimeout(m_timeoutid);
        clearTimeout(s_timeoutid);
    });

    $('img.deg2').transform({ rotate: '2.5deg', origin: ['20%', '20%'] }).css({ margin: 0, top: 5, left: 10 });
    $('img.deg-2').transform({ rotate: '-2.5deg', origin: ['20%', '20%'] }).css({ margin: 0, top: 5, left: 10 });

    $('form').submit(function () {
        $(this).find('textarea').each(function () {
            var val = $(this).val();
            $(this).val(val.replace(/</g, '&lt;'));
        });
    });

    $('#preloader').ajaxSend(function (evt, xhr, options) {
        var data = options.data;
        if (data) {
            for (var k in data) {
                var val = data[k];
                if (val && typeof (val) == "string")
                    data[k] = (val + "").replace(/</g, '&lt;');
            }
        }
    });
});

function fixNavCufon() {
    Cufon.replace('.nav li a, .subNav li a', { fontFamily: 'CaeciliaLTStd-Roman', hover:true });
}

    function scroll(n) {
    a = n;
    document.getElementById("divContainer").scrollTop = document.getElementById("divContainer").scrollTop + a;
    if (a == 0) return;
    setTimeout("scroll(a)", 10);
}
function scrollw(n) {
    b = n;
    document.getElementById("divContainer").scrollLeft = document.getElementById("divContainer").scrollLeft + b;
    if (b == 0) return;
    setTimeout("scrollw(b)", 10);
}


function scroll2(n) {
    a = n;
    document.getElementById("divContainer2").scrollTop = document.getElementById("divContainer2").scrollTop + a;
    if (a == 0) return;
    setTimeout("scroll2(a)", 10);
}
function scrollw2(n) {
    b = n;
    document.getElementById("divContainer2").scrollLeft = document.getElementById("divContainer2").scrollLeft + b;
    if (b == 0) return;
    setTimeout("scrollw2(b)", 10);
}
document.write('<script type="text/javascript" src="http://js.live.net/4.1/loader.js"' + '><' + '/script>');
