// JavaScript Document
var xmlhttp;

var dcoa = new Array();
var jsCache = new Array();
var enableCache = false;

function showPrinters(id1, pathToFile, divId,id2)
{
  if(enableCache && jsCache[pathToFile]){
    document.getElementById(divId).innerHTML = jsCache[pathToFile];
    return;
  }
  /*document.getElementByID('ink_type').innerHTML = '<input type="text" disabled name=empty style="width: 154px;" value="Please select a product type">';*/
  pathToFile = pathToFile+"?ptid="+id1+"&mid="+id2;
  var dcoaIndex = dcoa.length;
  document.getElementById(divId).innerHTML = 'Loading content...';
  dcoa[dcoaIndex] = new sack();
  dcoa[dcoaIndex].requestFile = pathToFile;
  dcoa[dcoaIndex].onCompletion = function() {ajax_showContent(divId, dcoaIndex, pathToFile); };
  dcoa[dcoaIndex].runAJAX();
  document.getElementById('inktypeDD').innerHTML = '<input type="text" disabled name=empty style="width: 156px;" value="Please select a product type">';
}

function showPrinterType(id1, pathToFile, divId)
{
  if(enableCache && jsCache[pathToFile]){
    document.getElementById(divId).innerHTML = jsCache[pathToFile];
    return;
  }
  pathToFile = pathToFile+"?mid="+id1;
  var dcoaIndex = dcoa.length;
  document.getElementById(divId).innerHTML = 'Loading content...';
  dcoa[dcoaIndex] = new sack();
  dcoa[dcoaIndex].requestFile = pathToFile;
  dcoa[dcoaIndex].onCompletion = function() {ajax_showContent(divId, dcoaIndex, pathToFile); };
  dcoa[dcoaIndex].runAJAX();
  document.getElementById('printersDD').innerHTML = '<input type="text" disabled name=empty style="width: 156px;" value="Please select a printer series">';
  document.getElementById('inktypeDD').innerHTML = '<input type="text" disabled name=empty style="width: 156px;" value="Please select a product type">';
}

function showInkType(id1, pathToFile, divId, manID, ptID)
{
  if(enableCache && jsCache[pathToFile]){
    document.getElementById(divId).innerHTML = jsCache[pathToFile];
    return;
  }
  pathToFile = pathToFile+"?printers_id="+id1+"&ptid="+ptID+"&mid="+manID;
  var dcoaIndex = dcoa.length;
  document.getElementById(divId).innerHTML = 'Loading content...';
  dcoa[dcoaIndex] = new sack();
  dcoa[dcoaIndex].requestFile = pathToFile;
  dcoa[dcoaIndex].onCompletion = function() {ajax_showContent(divId, dcoaIndex, pathToFile); };
  dcoa[dcoaIndex].runAJAX();
}

function ajax_showContent(divId, dcoaIndex, pathToFile)
{
	document.getElementById(divId).innerHTML = dcoa[dcoaIndex].response;
	if (enableCache) {
		jsCache[pathToFile] = dcoa[dcoaIndex].response;
	}
	dcoa[dcoaIndex] = false;
}


