$(document).ready(function() {
    
    $("#submission :input").not(":button").focus(function() {
    
        $(this).css({background:"#abacb0"});
    
    });
    
    $("#submission :input").not(":button").blur(function() {
    
        $(this).css({background:"#fff"});
    
    });
    
     $("#member a.reminder").click(function () {
                
        var epos = $("#epos").val();
        $(this).text("Please wait");
        
        if (epos == '') {
            $.prompt("Please enter your email address.",{
            
                callback: function (v,m,f) {
                    $("#epos").focus();
                    $("#member a.reminder").text("Forgot your password?");
                }
            
            });
            
        } else {
            $("#submission .alert").load("library/remind.php",{
                
                    username:epos
                
                }, function() {
                    $("#member a.reminder").text("Forgot your password?");                        
                });
            }
    });

    
    $("#loginActivate.boxbutton").click(function() {
        
        var btn = $(this).val();
        $(this).val("Please wait");
        
        var epos = $("#epos").val();
        var wagwoord = $("#wagwoord").val();
        var kaartnommer = $("#kaartnommer").val();
                   
    
        if (epos == '' || wagwoord == '' || kaartnommer == '') {
            $.prompt("Please enter all fields. We thank you kindly.", {
                
                callback: function(v,m,f) { $("#member :input").each(function() {
                
                    if ($(this).val() == '' || $(this).val() == 'Please select') {
                        $("#loginActivate.boxbutton").val(btn);
                        $(this).focus();
                        return false;
                    } 
                
                }) }
                
            });
        
        } else {

            $("#submission .alert").load("library/register_giftcard.php",{
            
                epos:epos,
                wagwoord:wagwoord,
                kaartnommer:kaartnommer
            
            }, function() {
                //clear all fields after submit
                $("#member :input").not(":last").not(":button").each(function() {
                    
                   //$(this).val('');
                    $("#loginActivate.boxbutton").val(btn);
                    
                });
            
            });
        }
    
        
    
    });
    
    $("#activateRegister.boxbutton").click(function() {
        
        var btn = $(this).val();
        $(this).val("Please wait");
        
        var firstname = $("#firstName").val();
        var lastname = $("#lastName").val();
        var country = $("#country").val();
        var orgName = $("#orgName").val();
        var orgType = $("#orgType").val();
        var ecoSec = $("#ecoSec").val();
        var jobTitle = $("#jobTitle").val();
        var interests = $("#interests").val();
        var find = $("#find").val();
        var giftcard = $("#giftcard").val();
        var tel = Number($("#tel").val());
        var mobile = Number($("#mobile").val());
        var email = $("#email").val();
        var pw = $("#pw").val();
        var pwc = $("#pwc").val();
        var com = $("#com").val();                        

        if (firstname == '' || lastname == '' || country == '' || orgType == 'Please select' || jobTitle == 'Please select' || interests == 'Please select'  || find == 'Please select' || email == '' || pw == '' || pwc == '') {
            $.prompt("Please enter all fields. We thank you kindly.", {
                
                callback: function(v,m,f) { $("#notMember :input").each(function() {
                
                    if ($(this).val() == '' || $(this).val() == 'Please select') {
                        $(this).focus();
                        $("#activateRegister.boxbutton").val(btn);
                        return false;
                    } 
                
                }) }
                
            });
        } else if (email != '') {
            apos=email.indexOf("@");
            dotpos=email.lastIndexOf(".");
            if (apos<1||dotpos-apos<2) {
                $.prompt("Please check your email address",{
                    callback: function(v,m,f) { $("#email").focus();$("#activateRegister.boxbutton").val(btn);  }
                });
                
            } else if (pw != pwc) {
                $.prompt("Your passwords don't match.",{
                    callback: function(v,m,f) { $("#pwc").val('');$("#pw").val('').focus();$("#activateRegister.boxbutton").val(btn);  }
                });
            } else if (com == 'phone' && tel == '') {
                $.prompt("Please enter your phone number.",{
                    callback: function(v,m,f) { $("#tel").focus();$("#activateRegister.boxbutton").val(btn);  }
                });
            } else if (com == 'mobile' && mobile == '') {
                $.prompt("Please enter your mobile number.",{
                    callback: function(v,m,f) { $("#mobile").focus();$("#activateRegister.boxbutton").val(btn);  }
                });
            } else {

                $("#submission .alert").load("library/register.php",{
                
                    firstname:firstname,
                    lastname:lastname,
                    country:country,
                    orgName:orgName,
                    orgType:orgType,
                    ecoSec:ecoSec,
                    jobTitle:jobTitle, 
                    interests:interests,
                    find:find,
                    giftcard:giftcard,
                    tel:tel, 
                    mobile:mobile,
                    email:email, 
                    pw:pw, 
                    pwc:pwc, 
                    com:com
                
                }, function() {
                    //clear all fields after submit
                    $("#notMember :input").not(":button").each(function() {
                    
                        $(this).val('');
                        $("#activateRegister.boxbutton").val(btn);
                    
                    });
                
                });
            }

        }
    
    });  
    
 });   
