function handleHttpResponseSubCategory() {
  if (http.readyState == 4) {
    // Split the comma delimited response into an array
    pairs = http.responseText.split("|");
    count = pairs.length;
	if(document.getElementById("supercategory").options[0].value == "-") {
		document.getElementById("supercategory").options[0] = null;
	}
	document.getElementById("subcategory").options.length = 0; //empty the select
	for(i = 0; i < count; i+=1) {
		results = pairs[i].split(",");
		document.getElementById("subcategory").options[i] = new Option(results[0],results[1]);
	}
  }
}

function handleHttpResponseGetArticles() {
  if (http.readyState == 4) {
	document.getElementById("theshop").innerHTML = http.responseText;
	if(document.getElementById("subcategory").options[0].value == "-") {
		document.getElementById("subcategory").options[0] = null;
	}
  }
}

function updatesubcategory() {
  var myselect = document.getElementById("supercategory");
  var supercategory = myselect.options[myselect.selectedIndex].value;
  http.open("GET", "/components/get_subcategories.php?supercategory=" + escape(supercategory), true);
  http.onreadystatechange = handleHttpResponseSubCategory;
  http.send(null);
}

function getarticles() {
  document.getElementById("theshop").innerHTML = "loading...";
  var myselect = document.getElementById("subcategory");
  var subcategory = myselect.options[myselect.selectedIndex].value;
  http.open("GET", "/components/get_articles.php?subcategory=" + escape(subcategory), true);
  http.onreadystatechange = handleHttpResponseGetArticles;
  http.send(null);
}

function getarticles_forregistry() {
  document.getElementById("theshop").innerHTML = "loading...";
  var myselect = document.getElementById("subcategory");
  var subcategory = myselect.options[myselect.selectedIndex].value;
  http.open("GET", "/components/get_articles_for_registry.php?subcategory=" + escape(subcategory), true);
  http.onreadystatechange = handleHttpResponseGetArticles;
  http.send(null);
}

function getarticles_forregistry_admin(registrant) {
  document.getElementById("theshop").innerHTML = "loading...";
  var myselect = document.getElementById("subcategory");
  var subcategory = myselect.options[myselect.selectedIndex].value;
  http.open("GET", "/components/get_articles_for_registry.php?mode=admin&subcategory=" + escape(subcategory) + "&registrant=" + registrant, true);
  http.onreadystatechange = handleHttpResponseGetArticles;
  http.send(null);
}

function safe_quantity(id) {
  document.getElementById("safeprocess_" + id).innerHTML = "saving quantity...";
  var quantity = document.getElementById("qty_" + id).value;
  http.open("GET", "/components/save_quantity_for_registry.php?id=" + escape(id) + "&quantity=" + escape(quantity), true);
  http.onreadystatechange = function() { savingsuccessfull(id); };
  http.send(null);
}

function safe_quantity_to_mysql(registrant,id) {
  document.getElementById("safeprocess_" + id).innerHTML = "saving quantity...";
  var quantity = document.getElementById("qty_" + registrant + "_" + id).value;
  http.open("GET", "/components/save_quantity_for_registry.php?registrant=" + registrant + "&id=" + escape(id) + "&quantity=" + escape(quantity) + "&mysql=1", true);
  http.onreadystatechange = function() { savingsuccessfull(id); };
  http.send(null);
}

function savingsuccessfull(id) {
  if (http.readyState == 4) {
 	document.getElementById("safeprocess_" + id).innerHTML = "";
	document.getElementById("qty_" + id).value = http.responseText;
  }
}

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object