var rslt1doc;
var rslt2doc;
var status = 0;
function transformXml(xml, xsl)
{
	return xml.transformNode(xsl.documentElement);
}
var busy = 0;
function doConv(実行契機)
{
	if(busy>0) return;
	{
		switch(status) {
		case 0:
			for(var i=0;i<xmlInput.length;++i) {
				var s = xmlInput[i].readyState;
				if(s!="complete" && s!=4) return;
			}
			if(busy>0) return;
			busy++;
			rslt1doc  = xmlLoadStr(xmlHeader+"<再編集版/>");
			var root = rslt1doc.documentElement;
			for(var i=0;i<xmlInput.length;++i) {
				var node = xmlInput[i].documentElement;
				if(node!=null) {
					root.appendChild(node.cloneNode(true));
				}
			}
			try { saverslt1(); } catch(e) { }
			status = 1;
			busy--;
		case 1:
			var s = xslCnv2.readyState;
			if(s!="complete" && s!=4) return;
			if(busy>0) return;
			busy++;
			rslt2doc = transformXml(rslt1doc, xslCnv2);
			rslt2doc = cvUniCodeChars(rslt2doc);

			status = 2;
			if(window.location.search.indexOf("Debug")<0) {
				exec();
			}
			status = 2;
			busy--;
		}
	}
}
function redoConv()
{
	status = 0;
	busy=0;
	doConv("XSLT再適用");
}
function getReadyStates()
{
	var str = "status = " + status;
	str = str + "\nbusy = " + busy;
	var i = 0;
	for(i=0; i<xmlInput.length; ++i) {
		str = str + "\n入力XML"+(i+1)+"のreadyState = "+xmlInput[i].readyState;
	}
	str = str + "\nXSLTのreadyState = "+xslCnv2.readyState;
	return str;
}
function registDoConv()
{
	for(i=0;i<xmlInput.length;++i) {
		xmlInput[i].onreadystatechange=doConv;
	}
	xslCnv2.onreadystatechange=doConv;
}
if(window.location.search.indexOf("Debug")>=0) {
	var strDebuger = ""
		 + '<DIV id=debug><CENTER>'
		 + '<input type="button" value="XSLT適用" onclick="redoConv()">&nbsp;&nbsp;<input type="button" value="  実行  " onclick="exec()">'
		 + '<BR><BR>'
		 + '<input type="button" value="HTML表示" onclick="viewHtml.innerHTML = cvMetaChars(rslt2doc)">'
		 + '<input type="button" value="連結XML表示" onclick="viewHtml.innerHTML = cvMetaChars(rslt1doc.xml)">'
		 + '<input type="button" value="XSLT表示" onclick="viewHtml.innerHTML = cvMetaChars(xslCnv2.xml)">'
		 + '<input type="button" value="readyState" onclick="viewHtml.innerHTML = cvMetaChars(getReadyStates())">'
		 + '<input type="button" value="クリア" onclick="viewHtml.innerHTML = \'\'">'
		 + '<input type="button" value="デバッガ起動" onclick="stop">'
		 + '<BR>'
		 + '</CENTER>'
		 + '<BR><BR>'
		 + '<DIV id="viewHtml"></DIV>'
		 + '</DIV>'
		 ;
	document.write(strDebuger);
}

