/**
 * SiteClick CMS login
 */
var Login = new function LoginBox() {
  
  var _this = this;
  this.root = location.href.split('index.php')[0];

  this.submit = function() {
    var pword = hex_md5($('#password').attr('value'));
    var user  = $('#username').attr('value');

    $.post(_this.root+'index.php/home/dologin', 'user=' + user + '&pword=' + pword, _this.submit_cb);
    return false;
  }
  
  this.submit_cb = function(data) {
    if(data == 'ok')
      $('#loginBox').fadeOut('slow', _this.fadeOut_cb);
    else
      alert('Please check your login details');
  }
  
  this.fadeOut_cb = function() {
    location.href = _this.root + 'index.php/home/selectworkspace';
  }
}

$(document).ready(function() {
  $('#username').focus();
  $('#username').select();

  
  $('#loginForm').submit(Login.submit);
})
