﻿$(document).ready(function () {
    if ($("#loginEnterToSite").val() != '') {
        $("#loginEnterToSite").prev().text('');
        $("#passwordEnterToSite").prev().text('');
    }

    $("#loginEnterToSite, #passwordEnterToSite").focus(function (e) {
        $(this).prev().text('');
    });

    $("#loginEnterToSite").blur(function (e) {
        if ($(this).val() == '') $(this).prev().text('Gebruikersnaam');
    });

    $("#passwordEnterToSite").blur(function (e) {
        if ($(this).val() == '') $(this).prev().text('Wachtwoord');
    });


    var fTrim = function (s) {
        return s.replace(/^\s*(.*?)\s*$/, "$1");
    };
    $('input.inputtext:not(#loginEnterToSite, #passwordEnterToSite), textarea').each(function (i) {
        if ($(this).attr('title') && fTrim($(this).val()).length === 0) {
            //console.log(fTrim($(this).val()));
            $(this).val($(this).attr('title'));
        }
    });

    $('input.inputtext:not(#loginEnterToSite, #passwordEnterToSite), textarea').blur(function () {
        var sValue = fTrim(this.value);
        if (sValue.length === 0) {
            $(this).val($(this).attr('title'));
        }
    });
    $('input.inputtext:not(#loginEnterToSite, #passwordEnterToSite), textarea').focus(function () {
        var sValue = fTrim(this.value);
        if (sValue == $(this).attr('title')) {
            $(this).val("");
        }
    });


    $('.content_sponsors a').tooltip({
        track: true,
        delay: 10,
        showURL: false,
        showBody: " - ",
        extraClass: "pretty",
        left: -120
    });

    /*$('.site_form input[type=text], textarea').tooltip({
    track: true,
    delay: 10,
    showURL: false,
    showBody: " - ",
    extraClass: "form_pretty",
    left: 30,
    top: 0
    });*/

    $(".faqs_list h5").addClass('closed');
    $(".faqs_list div").css('display', 'none');
    $(".faqs_list h5").click(function () {
        $(this).toggleClass('closed');
        $(this).next().slideToggle(300, function () {
            $(this).focus();
        });
    });
    $(".rating_chooser span").addClass("rate" + (($(".rating_chooser input:checked").index()) + 1));
    $(".rating_chooser").removeClass("noscript");
    starRating();


    $(".calendar_img").datepicker({
        nextText: '',
        prevText: '',
        showOtherMonths: true,
        buttonImage: '/images/voermanonline/calendar_img.gif',
        showOn: 'button',
        buttonImageOnly: true,
        dateFormat: 'mm/dd/yy',
        onSelect: function datepicker_actions(dateText, inst) {
            $('#' + inst.id).prevAll(".datum_day").val(inst.selectedDay);
            $('#' + inst.id).prevAll(".datum_month").val(inst.selectedMonth + 1);
            $('#' + inst.id).prevAll(".datum_year").val(inst.selectedYear);
        }
    });

    $('.datum_year, .datum_month, .datum_day').change(function () {
        $(this).parent().children('input').val($(this).parent().children('select.datum_month').val() + "/" + $(this).parent().children('select.datum_day').val() + "/" + $(this).parent().children('select.datum_year').val());
    });

    dateObj = new Date();

    $(".calendar_img").each(function (i) {
        if (!$(this).val()) {
            $(this).val((dateObj.getMonth() + 1) + "/" + dateObj.getDate() + "/" + dateObj.getFullYear());
            $(this).prevAll(".datum_day").val(dateObj.getDate());
            $(this).prevAll(".datum_month").val((dateObj.getMonth() + 1));
            $(this).prevAll(".datum_year").val(dateObj.getFullYear());
        }
    });


    /*$(".slider_div").slider({
    value: 5,
    min: 0,
    max: 10
    });*/
});

function starRating() {

    var starBox = $(".rating_chooser span");
    var rateButton = $(".rating_chooser input");
    rateButton.each(function (index) {
        $(this).click(function () {
            var oldClass = starBox.attr("class");
            var newClass = "rate" + (index + 1);
            starBox.removeClass(oldClass);
            starBox.addClass(newClass);
        });
        $(this).dblclick(function () {
            var oldClass = starBox.attr("class");
            starBox.removeClass(oldClass);
            starBox.addClass("rate0");
            rateButton.attr("checked", "");
        });
        $(this).hover(
			function () {
			    var newClass = "rateH" + (index + 1);
			    starBox.addClass(newClass);
			},
			function () {
			    var newClass = "rateH" + (index + 1);
			    starBox.removeClass(newClass);
			}
		);
    });
}

function initAddThis() {
    addthis.init();
}

$(document).ready(initAddThis);


