var dirname = function(path)
{
	var _pattern = /^(.*\/)?(.*)/;
	var rc = path.match(_pattern);
	return rc[1];
}

function GetXmlHttpObject()
	{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
	    {
	    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	  catch (e)
	    {
	    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
	  }
	return xmlHttp;
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	//document.getElementById("printer_row").innerHTML=xmlHttp.responseText;
	eval(xmlHttp.responseText);
	}
}

function doSubmit(id2)
{
	id1 = document.getElementById("mans").value;
	if (id2>0) location.href = 'index.php?cPath=' + id1 + '_' + id2;
}
function doPrinters(id)
{
	document.printer_form.printers.options.length = 0;
	document.printer_form.printers.options.length = 0;
	if (id.length==0)
	  { 
	  return;
	  }
	  document.printer_form.printers.options[0] = new Option('Loading...', 0);
	  
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url=dirname(document.location.href) + "ajax_printer.php?id=" + id;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}


function stateChanged2() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	document.getElementById("printer_row2").innerHTML=xmlHttp.responseText;
	}
}


function doPrinters2(id)
{
	if (id.length==0)
	  { 
	  document.getElementById("printers2").innerHTML="";
	  return;
	  }
	  //document.getElementById("printers").innerHTML="<option>Loading...";
	  document.getElementById("printer_row2").style.visibility = "visible";
	  //document.getElementById("submit_row").style.visibility = "hidden";
	  
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url=dirname(document.location.href) + "/ajax_printer_dropdown.php?id=" + id;
	xmlHttp.onreadystatechange=stateChanged2;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

