
var bContentAppleted = false;

function URLEncoder( s )
{
	if(document.AppletContentLoader) return document.AppletContentLoader.Encode(s);
	else return "";
}

var SetContentDownloaderSourceId = null;

function CContentDownloader( sVariableName, sURL, sSourceId, nPeriod, sJavaClassesPath, sPostParameters )
{
	this.sVariableName = sVariableName;
	this.sURL = sURL;
	this.sSourceId = sSourceId;
	if(nPeriod) this.nPeriod = nPeriod; else this.nPeriod = 0;
	if(sJavaClassesPath) this.sJavaClassesPath = sJavaClassesPath; else this.sJavaClassesPath = '/JavaClassesResolusherNoCookies/';
	this.sPostParameters = sPostParameters;

	this.sContent = "";

	if(!bContentAppleted)
	{
		document.write("<APPLET codebase='"+this.sJavaClassesPath+"' CODE='FileLoader.class' NAME='AppletContentLoader' width=0 height=0 MAYSCRIPT></APPLET>");
		bContentAppleted = true;
	}

	this.Init = CContentDownloader.Init;
	this.SetContent = CContentDownloader.SetContent;
	this.Set = CContentDownloader.Set;
}

CContentDownloader.Init = function()
{
	this.SetContent();
}

CContentDownloader.SetContent = function()
{
	if( document.AppletContentLoader )
		if(this.sPostParameters)
			document.AppletContentLoader.PostReadTextFile(this.sURL, 'CContentDownloader.Set', this.sVariableName+",", this.sPostParameters);
		else
			document.AppletContentLoader.ReadTextFile(this.sURL, 'CContentDownloader.Set', this.sVariableName+",");
	if(this.nPeriod>0)
		setTimeout( this.sVariableName+'.SetContent()', this.nPeriod*1000);
}

CContentDownloader.Set = function( obj, sContent )
{
	obj.sContent = sContent;
	obj.bScript = false;
	if(obj)
	{
		if( sContent.indexOf('<script>')>-1 )
		{
			sContent = sContent.substr(sContent.indexOf("<script"));
			sContent = sContent.substr(sContent.indexOf(">")+1);
			sContent = sContent.substr(0, sContent.lastIndexOf("</script"));
			sContent = sContent.replace(/<script.*?>/gi, "");
			sContent = sContent.replace(/<\/script>/gi, "");
			sContent = sContent.replace(/\xA0/g, "");
			sContent = sContent.replace(/\u0412/g, "");		
			eval(sContent);
			obj.bScript = true;
		}
		else
			if(document.getElementById(obj.sSourceId))
				document.getElementById(obj.sSourceId).innerHTML = sContent;

		if(typeof(SetContentDownloaderHTML) != 'undefined') SetContentDownloaderHTML( obj );
		if(SetContentDownloaderSourceId) SetContentDownloaderSourceId( obj );
	}
}


