//
// fscommand handlers
var isIE = navigator.appName.indexOf("Microsoft") != -1;
function xmlhttp_DoFSCommand(command, args) {
	var xmlhttpObj = isIE ? document.all.xmlhttp : document.xmlhttp;
	if (command == "FlashRequestResponse") {
		var res=args.split("|||", 2);
		var obj=__flashRequest[Number(res[0])];
		var ifr=self["__FlashIframe"+res[0]];
		/*ifr.document.open();
		ifr.document.write("");
		ifr.document.close();*/
		try{
			var domXml=new ActiveXObject("Microsoft.XMLDOM");
			domXml.loadXML(res[1]);
		}catch(e){
			var domXml=(new DOMParser()).parseFromString(res[1], "application/xml");
		}
		obj.onData(domXml, res[1]);
	}
}
// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub xmlhttp_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call xmlhttp_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</scr\ipt\>\n');
}
//
// Cria os parâmetros e objetos iniciais para o objeto FlashRequest
__flashUID=new Date().getTime();	//impede que duas janelas ou mais compartilhem a mesma conexão
__flashRequest=[];					//array que guardará todos os objetos FlashRequest
//
// Cria o objeto de requisições por flash
function FlashRequest(){
	this.pos=__flashRequest.length;
	__flashRequest.push(this);
	this.onData=function(x, t){};
}
FlashRequest.prototype.send=function(url){
	var nd=document.createElement("iframe");
	nd.name="__FlashIframe"+this.pos;
	nd.id="__FlashIframe"+this.pos;
	nd.style.position="absolute";
	nd.style.top="-200px";
	nd.style.left="-200px";
	nd.style.width="100px";
	nd.style.height="100px";
	document.getElementsByTagName("body")[0].appendChild(nd);
	if(document.frames){
		var win=document.frames[document.frames.length-1];
	}else{
		var win=window["__FlashIframe"+this.pos];
	}
	var ndFlash=FlashRequest.generateFlashTag("flashproxy/xmlgateway.swf", "flash", "xmlUrl="+escape(url)+"?p="+Math.round(Math.random()*1000000)+"|||"+this.pos+"|||"+__flashUID);
	win.document.open();
	win.document.write(ndFlash);
	win.document.close();
}
//
// gera as tags HTML para carregar novos .swf
FlashRequest.generateFlashTag=function(url, id, vars){
	var t="<html><body>";
	t+="<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" id=\""+id+"\" width=\"100\" height=\"100\" align=\"middle\">";
	t+="<param name=\"allowScriptAccess\" value=\"sameDomain\" />";
	t+="<param name=\"movie\" value=\""+url+"\" />";
	t+="<param name=\"quality\" value=\"high\" />";
	t+="<param name=\"FlashVars\" value=\""+vars+"\" />";
	t+="<param name=\"bgcolor\" value=\"#ffffff\" />";
	t+="<embed src=\""+url+"?"+vars+"\" quality=\"high\" bgcolor=\"#ffffff\" width=\"100\" height=\"100\" swLiveConnect=\"true\" id=\""+id+"\" name=\""+id+"\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />";
	t+="</object>";
	t+="</body></html>";
	return t;
}
//
// carrega o arquivo xmlhttp.swf
document.write("<div style=\"position: absolute; left: -200px; width: 1px; height: 1px; overflow: hidden;\">"+FlashRequest.generateFlashTag("flashproxy/xmlhttp.swf", "xmlhttp", "uniqueId="+__flashUID)+"</div>");