$(document).ready( function() {

    $('#gameReports img').qtip({
        content: 'STAT Game Reports are unmatched in the Sports Information industry. More details are a click away.',
        show: 'mouseover',
        hide: 'mouseout',
        position: {
            corner: {
                target: 'topLeft',
                tooltip: 'bottomLeft'
            }
        },
        style: {
            width: 240,
            tip: 'bottomLeft',
            name: 'cream',
            border: {
                radius: 4,
                width: 1
            }
        }
    });

    $('input[placeholder],textarea[placeholder]').placeholder();

    // Change Password Form
    $('ul#admin li a').click(function() {      
        $('span.message').empty().hide();
        $('form#change ul').slideToggle('slow');   
    });

    $("form#change").submit(function(e){
        e.preventDefault();
        $('span.error').empty();
        var password1 = $('#password1').val();
        var password2 = $('#password2').val();
        var token = $('#token').val();

        if(password1 != password2) {
            $('span.error').text('Passwords do not match.');
            return false;
        }

        if(password1.length == 0 || password2.length == 0) {
            $('span.error').text('Enter the password in BOTH fields.');
            return false;
        }

        if(password1.length < 6 || password2.length < 6) {
            $('span.error').text('Password is too short.');
            return false;
        }
    
        $.post("../includes/password.php", {
            "password1" : password1,
            "password2" : password2,
            "token" : token
        },
        function(data){
            if (data == "changed")
            {
                $('span.message').fadeIn(300).text('Congratulations, you successfully changed your password!');
                $('form#change ul').delay(3000).slideToggle(500);
            } 
            if (data == "failed")
            {
                $('span.message').fadeIn(300).text('Your password could not be changed at this time. Please try again later.');
                $('form#change ul').delay(3000).slideToggle(500);
            }
        });
        return false;
    });
});
