// JavaScript Document
// webcam

var xmlhttp = null;

function executeAjaxCall(type, file, objectId, postVar) {
  if (xmlhttp != null && xmlhttp.readyState != 0 && xmlhttp.readyState != 4) {
   xmlhttp.abort();
  }
  
  try {
    // IE does not support XMLHttpRequest, to avoid browser sniffing, this is a proper solution
    xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
  } 
  catch (e) {
    // use of antique browser, do what you want 
  }
  
  // when the status changes of the xmlhttp object. A function will be triggered. 
  // to pass the variables you could use the below mentioned construct. If no variables
  // should be passed you do xmlhttp.onreadystatechange = action;
  xmlhttp.onreadystatechange =function() { action(objectId);};
  
  // depending on the type a different protocal is used
  // for post action it is required to use a specific request header
  // the send() function should always contain a value, since IE can not handle an empty send()
  if(type == "POST"){
    xmlhttp.open("POST", file, true);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.send(postVar);
  }
  else{
    xmlhttp.open("GET", file, true);
    xmlhttp.send(null);
  }
}
  
  
// function used when the onready state changed
function action(objectId) {
  // if the ready state is finished (4) and the http status is OK (200
  // a responseText should be available
  // in this case we use the responseText to enter into the innerHTML of the object provided via the var
  if ((xmlhttp.status == 200) && (xmlhttp.readyState == 4)) {
    // xmlhttp.responseText object contains the response.  
    document.getElementById(objectId).innerHTML = xmlhttp.responseText;
  }
}


