/**
 * jQuery configuration
 * Configuratie bestand voor initialisatie van de jQuery componenten
 * @name jquery.configuration.js
 * @author P.F. Esser - http://www.esser-emmerik.nl
 * @version 0.1
 * @date November 13, 2008
 * @copyright (c) 2008 esser-emmerik
 */

function loadContent(mod, vars) {

    var url = mod; //+ ".php";

	$.ajax({
    	method: "get",url: url,data: vars,
    	beforeSend: function(){ $("#contentLoading").show("");  }, // show loading just when link is clicked
    	complete: function(){ $("#contentLoading").hide("");  }, // stop showing loading when the process is complete
    	success: function(html){ // so, if data is retrieved, store it in html
            $("#contentArea").show(""); // animation
            $("#contentArea").html(html);
           // $('a.lightbox').lightBox();

           $('#divvoorwaarden').hide('fast');

           if (vars != "hold") { $('li a').css('color','#3f4446'); }
                $("a").click(function() {

                     href = "loadContent('" + $(this).attr('href') + "','');return false;";

                     if( $(this).attr('onclick') == undefined) {
                            //     $(this).attr('onclick', href);

                            loadContent($(this).attr('href') + "&ajax=true",'');
                            return false;
                     }

           })
              // Reset Font Size
              var originalFontSize = $('html').css('font-size');
              $(".resetFont").click(function(){
              $('html').css('font-size', originalFontSize);
              });
              // Increase Font Size
              $(".increaseFont").click(function(){
              	var currentFontSize = $('html').css('font-size');
             	var currentFontSizeNum = parseFloat(currentFontSize, 10);
                var newFontSize = currentFontSizeNum*1.2;
            	$('html').css('font-size', newFontSize);

                return false;
              });
              // Decrease Font Size
              $(".decreaseFont").click(function(){
              	var currentFontSize = $('html').css('font-size');
             	var currentFontSizeNum = parseFloat(currentFontSize, 10);
                var newFontSize = currentFontSizeNum*0.8;
            	$('html').css('font-size', newFontSize);

            	return false;
              });


            // stel validatie in voor contact formulier
            $.validator.setDefaults({
            	submitHandler: function() {

                        $('#frmAanmelden').ajaxSubmit({
            	            target: "#contentArea",
                            beforeSubmit: function() {

                                    $("#butSubmit").attr("disabled","true").attr("value", "BEZIG MET VERSTUREN...");
                             },
                            success: function() {

                                       $('#frmAanmelden').clearForm();
                                }
                    	});

                 }
            });

              $.extend($.validator.messages, {
                required: "Dit veld is verplicht"

              });

             $.validator.addMethod(
                "nlTelefoon",
                function(value, element) {
                    // put your own logic here, this is just a (crappy) example

                        return value.match(/^[0-9]{10}$/);

                },
                "Een geldig telefoonnr. is vereist en mag alleen uit 10 cijfers bestaan (zonder - of spaties)"
            );




             $.validator.addMethod(
                "nlTelefoonAlt",
                function(value, element) {
                    // put your own logic here, this is just a (crappy) example
                    if ($('#sMobiel').val() == "") {
                        if (value.match(/^[0-9]{10}$/)) {
                             return true;
                        } else {
                             return false;
                        }
                    } else {
                        if ( $('#sContact_methode option:selected').val() == 'thuis') {
                            return false;
                        } else {
                             return true;
                        }
                    }
                },
                "U dient een telefoon thuis en/of mobielnummer op te geven. Deze mag alleen uit 10 cijfers bestaan (zonder - of spaties)"
            );

             $.validator.addMethod(
                "nlMobiel",
                function(value, element) {
                    // put your own logic here, this is just a (crappy) example
                    if ($('#sTelefoon').val() == "") {
                        if (value.match(/^[0-9]{10}$/)) {
                             return true;
                        } else {
                             return false;
                        }
                    } else {
                           if ( $('#sContact_methode option:selected').val() == 'mobiel') {
                                 return false;
                            } else {
                                 return true;
                            }
                    }
                },
                "U dient een telefoon thuis en/of mobielnummer op te geven. Deze mag alleen uit 10 cijfers bestaan (zonder - of spaties)"
            );

            $.validator.addMethod(
                "GeboorteDatum",
                function(value, element) {
                    // put your own logic here, this is just a (crappy) example

                    if ( $('#sGeboortedatumDag option:selected').val() == '0') {
                                 return false;
                    } else {
                        if ( $('#sGeboortedatumMaand option:selected').val() == '0') {
                            return false;
                        } else {
                            if ( $('#sGeboortedatumJaar option:selected').val() == '0') {
                               return false;
                            } else {  return true; }

                      }
                    }

                },
                "U dient uw volledige geboortedatum op te geven"
            );

            $("#frmAanmelden").validate( {
                    rules: {
                        sEmail: {
                            required: true,
                            email: true
                        },

                        sVoornaam: { required: true },
                        sAchternaam: { required: true },
                        sVoorletters: { required: true },
                        sAkkoordGebruik: { required: true },
                        sAkkoordCoCo: { required: true },
                        sPostcode: { required: true },
                        sAdres: { required: true },
                        sGeboortedatumJaar: { GeboorteDatum: true},

                      sTelefoon: { nlTelefoon: true }


                    },
                    messages: {
                        sEmail: "Een geldig e-mailadres is vereist",
                        sAanvrager: "",
                        sFoto: "Alleen een foto als jpg formaat is toegestaan",
                        sBank_Giro: "Je moet een bank of giro nummer opgeven",
                        sGift: "Je moet een bedrag opgeven als gift",
                        sPostcode: "Geef een geldige postcode op",
                        sAkkoordGebruik: "U dient akkoord te gaan met de gebruikersvoorwaarden",
                        sAkkoordCoCo: "U dient akkoord te gaan met de privacyverklaring van myCoachConnect"
                    }
            });
        }

    });

}

