var httpRequest;
onload = function () {
  loaded = true;
  if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    httpRequest = new XMLHttpRequest();
    if (httpRequest.overrideMimeType) {
      httpRequest.overrideMimeType('text/xml');
    // See note below about this line
    }
  } else if (window.ActiveXObject) { // IE
    try {
      httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
    }
  }
  if (!httpRequest) {
    alert('Giving up :( Cannot create an XMLHTTP instance');
    return false;
  }
  resize2();
}
function resize2() {
  var save = document.getElementById('save');
  var width = null;
  try {
    width = window.innerWidth;
  } catch (e) {
    width = document.body.offsetWidth;  //-= Silly IE
  }
  var height = save.offsetTop + 128;
  window.resizeTo(width, height);
}
function dump(obj) {
  for (prop in obj) {
    document.writeln(prop +' : '+ obj[prop] +'<br/>\n');
  }
}
function fieldCallback(field) {
  input = document.getElementById(field);
  bg = input.style.background.value;
  try {
    input.style.background = '#ffff00';
    input.style.opacity = 0.6;
    setTimeout("httpRequest.input.style.background = '#ffffff'", 400);
    setTimeout("httpRequest.input.style.background = bg", 400);
    setTimeout("httpRequest.input.style.opacity = 0.7 ", 500);
  } catch (e) {
  }
}
function makeRequest(url) {
  if (httpRequest.readyState != 4) {
    //-= Don't bother till the last request is done..
    //return;
  }
  window.status = 'Please wait updating "'+ input.name +'" ....';
  httpRequest.onreadystatechange = function() { updateCallback(httpRequest); };
  httpRequest.open('GET', url, true);
  httpRequest.send(null);
}

function updateCallback(httpRequest) {
  if (httpRequest.readyState == 4) {
    if (httpRequest.status == 200) {
      input = httpRequest.field;
      window.status = '';
      try {
        input.style.background = '#ffff00';
        input.style.opacity = 0.4;
        setTimeout("input.style.background = '#ffffff'", 400);
        setTimeout("input.style.opacity = 0.7 ", 500);
      } catch (e) {
      }
    } else {
      alert('There was a problem with the request.');
    }
  }
}
function deleteObj(input) {
  if (confirm('Would you like to delete this '+ input.name +'?') && input.id > 0) {
    self.location = '/user/delete/'+ input.name +'/'+ input.id;
  }
}

