/** (C) Copyright Prijsvragen TOP 100 2009 - 2020 -
 *
 * Permission to use, copy, modify, and distribute this software and or portions of it 
 * without prior explicit written approval is strictly prohibited. 
 * 
 *
 * Author: Yoni Nijs
 * Last edited: 25/12/2009 21:25
 **/
$(document).ready(function(){ 
    $('a[rel*=modal]').facebox();
    $("#land").msDropDown({visibleRows:2, rowHeight:29});
    
    $("#land_msdd").css('width', '48px');
    $("#land_child").hide();
    $("#land_child").css('width', '48px');
	                var rowCount = $('#items tr').length;
                if(rowCount == 0){
                    $("#headerTabel").html("Geen acties gevonden!");
                }else if(rowCount == 1){
                    $("#headerTabel").html("1 actie gevonden!");
                }else{
                    $("#headerTabel").html(rowCount + " acties gevonden!");
                }					 

});
function dologin(){
    
    param = {user: $('#facebox input[type=text]:first').val(),
             pass: $('#facebox input[type=password]:first').val()};
    $.post("_ajax/login.php", param,
            function(data){
                if(data.success == 'OK'){
                    $.facebox.close();
                    $("#inlog").hide();
                    $("#register").hide();
                    $("#uitlog").show();
                    $("#inlog_onder").hide();
                    $("#rechts_blok").css('margin-top', '-24px');
                    $("#login_panel").show();
                    $("#login_panel_title").html('Welkom ' + data.user);
                }else{
                    $('#facebox #login_error').html(data.error);
                }
            }, 'json')
}
function doRegister(){
    
    param = {txtUser: $('#facebox input[type=text]:first').val(),
             txtPass: $('#facebox input[type=password]:first').val(),
             txtMail: $('#facebox #txtMail').val()};
    $.post("_ajax/register.php", param,
            function(data){
                if(data.success){
                    $('#facebox #reg').html(data.success);
                    $('#facebox #register_error').html(data.err);
                }else{
                    var error = "Fouten: ";
                    if(data.mail){
                        error = error + "<br />" + data.mail;
                    }
                    if(data.pass){
                        error = error + "<br />" + data.pass;
                    }
                    if(data.user){
                        error = error + "<br />" + data.user;
                    }
                    $('#facebox #register_error').html(error);
                    
                }
            }, 'json')
}
function addmailing(){
    $("#aj_nieuwsbrief_error").html('');
    	param = {mail: $("#nieuwsbrief_email").val(),
                 country: $("#land").val()};

    	$.post("_ajax/addmail.php", param, 
    		 	function(data){
     				if(data == 'OK'){
     					$("#frmNieuwsbrief").hide('slow');
     					$("#aj_nieuwsbrief_succes").show('slow');
     				}else{
     					$("#aj_nieuwsbrief_error").html('<i>'+data+'</i>');
     				}
     		});

} 
function sendContact(){
    $("#contact_error").html('');
    	param = {naam: $("#facebox input[name=naam]").val(),
                 email: $("#facebox input[name=email]").val(),
                 onderwerp: $("#facebox #onderwerp option[selected='selected']").val(),
                 bericht: $("#facebox #bericht").val()};

    	$.post("_ajax/contact.php", param, 
    		 	function(data){
     				if(data == 'OK'){
     					$("#facebox #contact").html("Email succesvol verzonden. U krijgt zo spoedig mogelijk antwoord.");
     				}else{
     					$("#facebox #contact_error").html('<i>'+data+'</i>');
     				}
     		});

}
function filter(type, value){
    if(type == 0){
        param = {type: 'select', val: ''};
    }else{
        param = {type: type, val: value};
    }
    $("#items").hide();
    $("#lader").show();
    
    $.post("_ajax/filter.php", param,
            function(data){
                $("#lader").hide();
                $("#items").html(data);
                $("#items").show();
                var rowCount = $('#items tr').length;
                if(rowCount == 0){
                    $("#headerTabel").html("Geen acties gevonden!");
                }else if(rowCount == 1){
                    $("#headerTabel").html("1 actie gevonden!");
                }else{
                    $("#headerTabel").html(rowCount + " acties gevonden!");
                }
            }
    );
   
}

function filterSelect(value){
    param = {type: 'select', val: value};
    $("#items").hide();
    $("#lader").show();
    
    $.post("_ajax/filter.php", param,
            function(data){
                $("#lader").hide();
                $("#items").html(data);
                $("#items").show();
                var rowCount = $('#items tr').length;
                if(rowCount == 0){
                    $("#headerTabel").html("Geen acties gevonden!");
                }else if(rowCount == 1){
                    $("#headerTabel").html("1 actie gevonden!");
                }else{
                    $("#headerTabel").html(rowCount + " acties gevonden!");
                }
            }
    );
}