$(document).ready(function(){
    if ($('#secties').val() !== undefined) {
        $('#secties').pngFix();
    }	
	$("#afmeldenLink").click(function(){
						$("#afmelden").css("display", "block");			 
									 });
    
    $("#mainmenu li[class!='active']").hover(function(){
        $(this).addClass("active");
    }, function(){
        $(this).removeClass("active");
    });
    
    function redirect(resultLogin){
        if (resultLogin) {
            window.location.href = window.location + "/";
        }
        else {
            $('#error').show().html("De opgegeven combinatie van e-mailadres en wachtwoord komen niet overeen. Probeer nogmaals in te loggen.");
        }
    }
    
    function ARRM(obj, func){
        var url = '/application/classes/ajax/AjaxController.php';
        $.ajax({
            type: "POST",
            url: url,
            data: obj,
            dataType: 'json',
            success: function(serverData){
                func(serverData);
            }
        });
    }
    
    function alterPassword(resultLogin){
        if (resultLogin) {
            $('#error').show().html("Het wachtwoord is gewijzigd.");
            $('#oldpass').val("");
            $('#passnew').val("");
            $('#passnew1').val("");
        }
        else {
            $('#error').show().html("Het ingevulde oude wachtwoord komt niet overeen met het wachtwoord dat in de database staat.");
        }
    }
    $('#inloggenForm').submit(function(){
        if ($('#email').val() !== "" && $('#pass').val() !== "") {
            var obj = {};
            obj.email = $('#email').val();
            obj.password = $('#pass').val();
            obj.newType = "User";
            obj.newMethod = "loginUser";
            ARRM(obj, redirect);
        }
        else {
            $('#error').show().html("Wilt u alle velden invullen a.u.b");
        }
    });
    
    
    function subscribeResult(response){
        $('#error').show().html("U bent toegevoegd aan ons nieuwsbrief bestand.");
        $('#emailTxt').val("");
    }
    
    function unsubscribeResult(response){
        $('#errorrAfmeld').show().html("U bent afgemeld voor onze nieuwsbrief.");
        $('#afmeldEmailTxt').val("");
    }
    
    $('#verzendNieuws').submit(function(){
	if($('#accoord:checked').length){
        if ($('#emailTxt').val() !== "" && checkemail($('#emailTxt').val())) {
            var obj = {};
            obj.email = $('#emailTxt').val();
		obj.accoord = $('#accoord:checked').length;
            obj.newType = "Functies";
            obj.newMethod = "addSubscriber";
            ARRM(obj, subscribeResult);
            return false;
        }
        else {
            $('#error').show().html("Vul een geldig e-mailadres in a.u.b.");
        }
	 }else{
		$('#error').show().html("U moet aanvinken dat u zich wilt inschrijven voor de nieuwsbrief.");
	 }
	 
    });
    
    
    $('#afmeldNieuws').submit(function(){
        if ($('#afmeldEmailTxt').val() !== "" && checkemail($('#afmeldEmailTxt').val())) {
            var obj = {};
            obj.email = $('#afmeldEmailTxt').val();
            obj.newType = "Functies";
            obj.newMethod = "removeSubscriber";
            ARRM(obj, unsubscribeResult);
            return false;
        }
        else {
            $('#errorrAfmeld').show().html("Vul een geldig e-mailadres in a.u.b.");
        }
    });
    
    function checkemail(email){
        var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        if (filter.test(email)) {
            return true;
        }
        else {
            return false;
        }
    }
    
    $('#editWachtwoord').submit(function(){
        if ($('#passnew').val() === $('#passnew1').val()) {
        
            if ($('#oldpass').val() === "") {
                $('#error').show().html("Vult u alle velden in a.u.b");
                return false;
            }
            
            if ($('#passnew').val().length < 6) {
                $('#error').show().html("Het opgegeven nieuwe wachtwoord moet minstens 6 karakters zijn.");
                return false;
            }
            var obj = {};
            obj.newType = "User";
            obj.newMethod = "editPassword";
            obj.password = $('#oldpass').val();
            obj.passwordNew = $('#passnew1').val();
            ARRM(obj, alterPassword);
        }
        else {
            $('#error').show().html("De opgegeven nieuwe wachtwoorden komen niet overeen.");
            return false;
        }
    });
    
    $('#linkForgot').click(function(){
        $('#normalLogin').hide(function(){
            $('#forgotten').show(function(){
                $('#tableForgotLogin').hide();
                $('#errorTwo').hide();
                $('#forgot').val("");
                function resetPassword(resultRequest){
                    $('#errorTwo').show().html("Er is een email gestuurd naar het opgegeven e-mailadres, daarin zit uw wachtwoord. Gebruik deze om opnieuw in te loggen");
                    $('#tableForgotLogin').show(function(){
                        $('#forgottenForm').show().click(function(){
                            $('#forgotten').hide(function(){
                                $('#normalLogin').show();
                            });
                        });
                    });
                }
                
                $('#reset').click(function(){
                    if ($('#forgot').val() !== "") {
                        var obj = {};
                        obj.newType = "User";
                        obj.newMethod = "retrievePassword";
                        obj.email = $('#forgot').val();
                        ARRM(obj, resetPassword);
                        return false;
                    }
                    else {
                        $('#errorTwo').show().html("Vul uw e-mailadres in a.u.b.");
                        return false;
                    }
                });
            });
        });
    });
    
    
    function sendFormResponse(resultRequest){
        $('#error').show().html("Bedankt voor het invullen van ons contact formulier. Er zal spoedig contact met u opgenomen worden.");
        $('#voornaamTxt').val("");
        $('#achternaamTxt').val("");
        $('#initialenTxt').val("");
        $('#adresTxt').val("");
        $('#postcodeTxt').val("");
        $('#emailTxt').val("");
        $('#plaatsTxt').val("");
        $('#berichtTxt').val("");
    }
    
    $('#contactForm').submit(function(){
        if ($('#voornaamTxt').val() === "" || $('#achternaamTxt').val() === "" || $('#adresTxt').val() === "" ||
        $('#postcodeTxt').val() === "" ||
        $('#emailTxt').val() === "" ||
        $('#plaatsTxt').val() === "" ||
        $('#berichtTxt').val() === "") {
            $('#error').show().html("Vult u a.u.b alle velden in.");
        }
        else {
            var obj = {};
            obj.aanhef = $('#aanhefTxt').val();
            obj.voornaam = $('#voornaamTxt').val();
            obj.achternaam = $('#achternaamTxt').val();
            obj.initialen = $('#initialenTxt').val();
            obj.adres = $('#adresTxt').val();
            obj.postcode = $('#postcodeTxt').val();
            obj.email = $('#emailTxt').val();
            obj.plaats = $('#plaatsTxt').val();
            obj.bericht = $('#berichtTxt').val();
            obj.newType = "Functies";
            obj.newMethod = "sendContactForm";
            ARRM(obj, sendFormResponse);
            return false;
        }
    });
});

var source = {
    src: '/swf/arialblack.swf',
    ratios: [7, 1.32, 11, 1.31, 13, 1.24, 14, 1.25, 19, 1.23, 27, 1.2, 34, 1.19, 42, 1.18, 47, 1.17, 48, 1.18, 69, 1.17, 74, 1.16, 75, 1.17, 1.16]
};
sIFR.activate(source);
sIFR.replace(source, {
    selector: 'h1',
    wmode: 'transparent',
    css: {
        '.sIFR-root': {
            'color': '#FB7B1B',
            'font-size': '24px',
            'font-weight': 'bold'
        }
    }
});

sIFR.replace(source, {
    selector: '#leftBoxHolder h2',
    wmode: 'transparent',
    css: {
        '.sIFR-root': {
            'color': '#00576D',
            'font-size': '16px',
            'font-weight': 'bold'
        }
    }
});
sIFR.replace(source, {
    selector: 'h2',
    wmode: 'transparent',
    css: {
        '.sIFR-root': {
            'color': '#00576D',
            'font-size': '12px',
            'font-weight': 'bold'
        }
    }
});

