window.alert = function(m){
    var style = {
        position: 'fixed',
        top: 10,
        padding: 10,
        zIndex: 2000,
        borderRadius: 5,
        fontWeight: 'bold'
    };

    var el = $('<div>');
    el.text(m).css(style).addClass('alert-danger').hide().appendTo('body');
    el.css('left', ($('body').width() - el.width()) / 2);

    el.fadeIn().delay(5000).fadeOut(function(){
        $(this).remove();
    });
};

// URL of the server. Comment for development/production
window.server = 'http://nl.ks07.co.uk:5000/';
window.server = 'localhost:5000/';

$(function(){
    var body = $('body');
    body.append(JST.credits());
    var form = $(JST.login());

    var fields = {
        email: form.find('#email'),
        password: form.find('#password')
    };

    // Bind an event to the submit button in the login form to send the username
    // and password to the server
    form.find('button').on('click', function(e){
        // Grab the email and password from the DOM
        var email = fields.email.val();
        var password = fields.password.val();

        // Send the request
        $.ajax({
            url: server + 'login',
            type: 'POST',
            data: {
                email: email,
                pass: password
            },
            success: function(data){
                // If the login was successful
                if(data.res){
                    // Inform the user
                    alert('Logged in successfully');
                    // Hide the login modal
                    $('#register').modal('hide');

                    // Store the user's credentials for next time
                    // TODO: use cookies or store a token rather than storing
                    // passwords in plaintext
                    localStorage['felina-email'] = email;
                    localStorage['felina-pass'] = password;

                    // TODO: hardcoded gravatar ID. Server needs to be updated
                    // to provide this
                    data.user.icon = '8ff364476b280cd51aba531052a0603c';

                    // Update the header to replace the login button with the
                    // details of the newly logged in user
                    $('header').remove();
                    $('body').prepend(JST.header(data));
                }
                // Login failed
                else {
                    // Inform the user
                    alert('Invalid username or password');
                }
            }
        });
    });

    // Add the login form to the page
    body.append(form);

    // Check the user's status on page load so that their name and icon can be
    // displayed in the header
    // TODO: this doesn't work -- what are endpoints george
    var u = server + 'logincheck' + "?email=" + localStorage['felina-email'] + "&pass=" + localStorage['felina-pass'];
    console.log(u);

    // $.ajax({
    //     url: u,
    //     type: 'GET',
    //     success: function(data){
    //         console.log(data);
    //         body.prepend(JST.header(data));
    //     }
    // });
});

@@ -535,16 +535,19 @@
 5000/';%0A
+// 
 window.s
@@ -555,16 +555,23 @@
 rver = '
+http://
 localhos
@@ -2931,19 +2931,16 @@
 u);%0A%0A   
- //
  $.ajax(
@@ -2940,27 +2940,24 @@
 $.ajax(%7B%0A   
- //
      url: u,
@@ -2956,27 +2956,24 @@
  url: u,%0A   
- //
      type: '
@@ -2977,27 +2977,24 @@
 : 'GET',%0A   
- //
      success
@@ -3010,27 +3010,24 @@
 n(data)%7B%0A   
- //
          con
@@ -3041,27 +3041,24 @@
 g(data);%0A   
- //
          bod
@@ -3089,19 +3089,16 @@
 a));%0A   
- //
      %7D%0A 
@@ -3099,19 +3099,16 @@
    %7D%0A   
- //
  %7D);%0A%7D);

comment out development server url