﻿$(document).ready(function () {
    $(":input[value='']:visible:enabled:first").focus();

    $("a[modal]").click(function () {
        var modalHeight = $(document).height();
        var modalWidth = $(window).width();

        $(".Dialog").css({ 'width': modalWidth, 'height': modalHeight });

        $(".Dialog").fadeIn(1000);
        $(".Dialog").fadeTo("slow", 0.8);

        var windowHeight = $(window).height();
        var windowWidth = $(window).width();

        $(".DialogMessage").empty();
        $(".DialogMessage").html('');
        $(".DialogMessage").html($(this).attr('modal'));

        $(".DialogMessage").css('top', windowHeight / 2 - $(".DialogMessage").height() / 2);
        $(".DialogMessage").css('left', windowWidth / 2 - $(".DialogMessage").width() / 2);

        $(".DialogMessage").fadeIn(2000);
    });

    $("a[bekijkvoorspellingen]").click(function () {
        var modalHeight = $(document).height();
        var modalWidth = $(window).width();

        $(".Dialog").css({ 'width': modalWidth, 'height': modalHeight, 'background-color': '#000000' });

        $(".Dialog").fadeIn(1000);
        $(".Dialog").fadeTo("slow", 0.8);

        var windowHeight = $(window).height();
        var windowWidth = $(window).width();

        $(".DialogMessage").css({ 'background-image': 'none', 'background-color': 'white' });
        $(".DialogMessage").empty();
        $(".DialogMessage").html('');
        $(".DialogMessage").html("<iframe width='580px' height='" + (windowHeight - 80) + "px' src='/bekijk-voorspellingen/default.aspx" + $(this).attr('QueryString') + "' frameborder='0'></iframe><br/><ul class='FormulierButton'><li><a href='javascript:void();' class='sluit-venster'>Sluit venster</a></li></ul>");

        $(".DialogMessage").css('top', windowHeight / 2 - $(".DialogMessage").height() / 2);
        $(".DialogMessage").css('left', windowWidth / 2 - $(".DialogMessage").width() / 2);

        $(".DialogMessage").fadeIn(2000);
    });

    $(".sluit-venster").live('click', function () {
        $(".Dialog").hide();
        $(".DialogMessage").empty();
        $(".DialogMessage").html('');
        $(".DialogMessage").hide();
    });

    jQuery.fn.HighlightArea = function (iterations) {
        for (var i = 1; i <= iterations; i++) {
            $(this).effect('highlight', { color: '#6b9a28' }, 3000);
        }
    }
});

$(document).ready(function()
{
    if($.browser.msie && jQuery.browser.version < 8)
    {
        $(".Speelronde li").each(function() { $(this).css('max-width', '30px').css('float', 'left'); });
        $(".Pollvraag li").each(function() { $(this).css('max-width', '30px').css('float', 'left'); });
    }
});

//Veel gestelde vragen script

$(document).ready(function()
{
    $(document).ready(function() 
    {
        $('.FAQVraag').click(function() 
        {
            if($(this).hasClass('Active'))
            {
                $(this).removeClass('Active');
                $(".FAQAntwoord[rel='" + $(this).attr('rel') + "']").hide();
            }
            else
            {
                //Verwijder de Active-class van alle li- en a-elementen
                $('.FAQVraag').removeClass('Active');
                //Verberg alle banners
                $('.FAQAntwoord').hide();
                //Plaats de Active-class en toon de juiste banner
                $(".FAQAntwoord[rel='" + $(this).attr('rel') + "']").show();
                //Plaats de Active-class op het a-element en het bijbehorende li-element
                $(this).addClass('Active');
            }
        });
    });
});

//Tooltip script
$(document).ready(function() 
    {
        $('ul.Formulier[title], ul.Inloggen[title]').each(function()
        {
            $(this).attr('formid', $(this).attr('title'));
            $(this).attr('title', '');
        });
        
        $('ul.Wedstrijd').each(function()
        {
            $(this).attr('formid', $(this).attr('title'));
        });
        
        $('ul[title]').mouseover(function()
        {
            $(this).data('title', $(this).attr('title'));
            $(this).attr('title', '');
        });
        
        $('ul[title]').mouseout(function()
        {
            $(this).attr('title', $(this).data('title'));
            $(this).data('');
        });
    
        $('img.ToolTipStatic, img.ToolTipInfo, img.KennersPercentage, img.AantalReacties').each(function()
        {
            $(this).data('title', $(this).attr('title'));
            $(this).attr('title', '');
        });
        
        $('.ToolTipBoxStatic').each(function()
        {
            $('.ToolTipBoxStatic').css('margin-left', '0px').css('margin-top', '0px');
        });
        
        $('img.ToolTipStatic').mouseover(function(muisPositie) 
        { 
            $(this).attr('src', '../images/tooltip-open.png');
            $('.ToolTipBoxStatic').html($(this).data('title'));
            
            var leftVal = $(this).offset().left + 22;
            var topVal = $(this).offset().top;
            
            $('.ToolTipBoxStatic').css("top", ($(this).offset().top) + "px")
            $('.ToolTipBoxStatic').css("left", ($(this).offset().left + 22) + "px")
            
            $('.ToolTipBoxStatic').show();
        }).mouseout(function() 
        { 
            $(this).attr('src', '../images/tooltip-gesloten.png'); 
            
            $('.ToolTipBoxStatic').hide();
            $('.ToolTipBoxStatic').empty();
        });
        
        $("img.ToolTipInfo, img.KennersPercentage, img.AantalReacties").mouseover(function(e) 
        {
            $('.ToolTipBoxInfo').html($(this).data('title'));
            $('.ToolTipBoxInfo').css("top", (e.pageY) + "px")
            $('.ToolTipBoxInfo').css("left", (e.pageX + 30) + "px")
            $('.ToolTipBoxInfo').show();
        }).mouseout(function(e) {
            $('.ToolTipBoxInfo').html('');
            $('.ToolTipBoxInfo').hide();
        });
 
        $("img.ToolTipInfo, img.KennersPercentage, img.AantalReacties").mousemove(function(e) {
            $('.ToolTipBoxInfo').css("top", (e.pageY) + "px")
            $('.ToolTipBoxInfo').css("left", (e.pageX + 30) + "px");
        });
    });

//Focus scripts
$(document).ready(function()
{    
    $("input[DataType=Date]").focus(function() 
    {
        if($(this).val().length > 0)
        {
	        $date = $(this).val().replace(/-/g, "");
	        $(this).val($date);
	        $(this).select();
        }
    });
});

$(document).ready(function()
{
    $("input[DataType=Time]").focus(function() 
    {
	    if($(this).val().length > 0)
	    {
		    $time = $(this).val().replace(/:/g, "");
		    $(this).val($time);
		    $(this).select();
	    }
    });
});

//Keyfilter scripts

$(document).ready(function()
{
    $("input[DataType=NoInput]").keypress(function(event)
    {
        return false;
    });
});

$(document).ready(function()
{
    $("input[DataType=Date], input[DataType=Time], input[DataType=Integer]").keypress(function(event)
    {
        if(event.which > 46 && event.which < 58 || event.which == 8 || event.which == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    });
});

$(document).ready(function()
{
    $("input[DataType=Score]").keypress(function(event)
    {
        if(event.which == 45 || event.which > 46 && event.which < 58 || event.which == 8 || event.which == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    });
});

$(document).ready(function()
{
    $("input[DataType=String]").keypress(function(event)
    {
        if(event.which > 96 && event.which < 123 || event.which == 8 || event.which == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    });
});

$(document).ready(function()
{
    $("input[DataType=FinishTime]").keypress(function(event)
    {
        if(event.which > 45 && event.which < 59 || event.which == 8 || event.which == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    });
});

//Blur scripts
$(document).ready(function()
{
    $("input[DataType=Date]").blur(function() 
    {
        var $maandLengtes = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

        var $dag;
        var $maand;
        var $jaar;
        var $huidigJaar = new Date().getFullYear();

        if($(this).val().length < 6)
        {
	        $(this).val("");
	        return false;
        }

        if($(this).val().length == 6)
        {
	        $dag = $(this).val().substr(0, 2);
	        $maand = $(this).val().substr(2, 2);
	        $jaar = $(this).val().substr(4, 2);
        	
	        if($jaar <= parseInt($huidigJaar.toString().substr(2,2)))
	        {
		        $jaar = "20" + $jaar;
	        }
	        else
	        {
		        $jaar = "19" + $jaar;
	        }
        }
        if($(this).val().length == 8)
        {
	        $dag = $(this).val().substr(0, 2);
	        $maand = $(this).val().substr(2, 2);
	        $jaar = $(this).val().substr(4, 4);
        }
        
        if($(this).val().length == 10)
        {
	        $dag = $(this).val().substr(0, 2);
	        $maand = $(this).val().substr(3, 2);
	        $jaar = $(this).val().substr(6, 4);
        }

        if (($jaar % 4 == 0 && $jaar % 100 != 0) || $jaar % 400 == 0)
        {
	        $maandLengtes[1] = 29;
        }

        if($dag > $maandLengtes[$maand -1] && $maand > 1 && $maand <= 12)
        {
	        $dag = $maandLengtes[$maand -1];
        }

        if($maand < 1 || $maand > 12)
        {
	        $maand = 1;
        }
        
        $(this).val($dag + "-" + $maand + "-" + $jaar);
    });
});

$(document).ready(function()
{
    $("input[DataType=Time]").blur(function() 
    {
	    var $uur;
	    var $minuut;
    	
	    if($(this).val().length < 3)
	    {
		    $(this).val("");
		    return false;
	    }
    	
	    if($(this).val().length == 3)
	    {
		    $uur = $(this).val().substr(0,1);
		    $minuut = $(this).val().substr(1,2);
	    }
    	
	    if($(this).val().length == 4)
	    {
		    $uur = $(this).val().substr(0,2);
		    $minuut = $(this).val().substr(2,2);
	    }
    	
	    if($uur > 23 || $uur == 0)
	    {
		    $uur = 0;
	    }
    	
	    if($minuut > 59)
	    {
		    $minuut = 00;
	    }
    	
	    $(this).val($uur + ":" + $minuut);
    });
});
