/*
  TODO:
  - Convert all Delegate.create calls to binds
  - Take a look at converting form.js to util.addEvent/removeEvent
*/

function sendEmail(id) {
  // TODO: Deprecate this function. It's only used by the reservation system.
  document.location = 'mailto:' + id + '@cs.virginia.edu';
}

/*
  These days I prefer using .bind(), but a lot of code still uses this function
  and it works fine. So I'll put off cleaning it till I run out of other things
  to do. -Mike
*/
function Delegate() {}
Delegate.create = function (o, f) {
  var a = new Array();
  var l = arguments.length;
  for(var i = 2 ; i < l ; i++) a[i - 2] = arguments[i];
  return function() {
    var aP = [].concat(arguments, a);
    f.apply(o, aP);
  }
}

/*
  ------------------------------------------------------------------------------
  Lots of handy functions specific to the CS website.
  ------------------------------------------------------------------------------
*/
var csUtil = {};

/*
  Performs an asynchronous LDAP lookup on the specified userId (via PHP) and
  passes the user's name and UID to the specified callback function as an array.
*/
csUtil.ldapLookup = function(userId, callback) {
  var success = function(xmlHttp) {
    try {
      var result = eval(xmlHttp.responseText);
    } catch(e) {
      var result = false;
    }
    callback(result);
  };
  var failure = function() {
    callback(false);
  }
  util.httpRequest('/includes/get_ldap.php?id=' + userId, success, failure);
};
