// IE Check bool
var xmlhttp = false;

// Check for IE
try {
  // Javascript > 5
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
  // Older version of IE
  try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch(e) {
  // Not using IE
  xmlhttp = false;
  }
}

// Instantiate xmlhttp object if not IE
if(!xmlhttp && typeof(XMLHttpRequest != 'undefined')) {
  xmlhttp = new XMLHttpRequest();
}

function getData(phpFile, objID) {
  var obj = document.getElementById(objID);
  xmlhttp.open("GET", phpFile);
  xmlhttp.onreadystatechange = function() {
    if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      obj.innerHTML = '';
      obj.innerHTML = "&pound;" + xmlhttp.responseText;
    }
  }
  xmlhttp.send(null);
}

// Submit AJAX request to specified script, return data retrieved to a callback function
function ajax_request(phpFile, phpParams, callback) {
  var params = "";
  if(phpParams) {
    params = "?" + phpParams;
  }

  xmlhttp.open("GET", "logicajax/" + phpFile + ".php" + params);
  xmlhttp.onreadystatechange = function() {
    if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      callback.call(xmlhttp.responseText);
    }
  }
  xmlhttp.send(null);
}
// Update the value of an element property (e.g. 'innerHTML') with data retrieved via AJAX
function ajax_update_value(phpFile, phpParams, element, property) {
  var callback = function() {
    if(document.getElementById(element)) {
      document.getElementById(element)[property] = this;
    }
  };
  ajax_request(phpFile, phpParams, callback);
}
