DocumentLoader = function ()
{
	this.documentNode = null;
	this.originNode = null;
	this.targetNode = null;
	this.scriptsToRun = new Array();
}

DocumentLoader.prototype.getDocumentNode = function ()
{
	return this.documentNode;
}

DocumentLoader.prototype.setDocumentNode = function (newNode)
{
	this.documentNode = newNode;
}

DocumentLoader.prototype.getOriginNode = function ()
{
	return this.originNode;
}

DocumentLoader.prototype.setOriginNode = function (newNode)
{
	this.originNode = newNode;
}

DocumentLoader.prototype.getTargetNode = function ()
{
	return this.getTargetNode;
}

DocumentLoader.prototype.setTargetNode = function (newNode)
{
	this.targetNode = newNode;
}

DocumentLoader.prototype.load = function (runScripts)
{
	if (runScripts == true)
	{
		this.parseScripts();
	}

	this.importDocument();

	if (runScripts == true)
	{
		this.runScripts();
	}
}

DocumentLoader.prototype.parseScripts = function ()
{
	var documentScripts = this.documentNode.getElementsByTagName("SCRIPT");
	if (documentScripts == null || documentScripts.length == 0)
	{
		return;
	}

	for (var i = 0; i < documentScripts.length; i++)
	{
		var cScript = documentScripts.item(i);
		
		// Remove html comments
		var scriptCode = trim(cScript.innerHTML);
		if (scriptCode.indexOf('<!--') == 0 && scriptCode.indexOf('-->') == scriptCode.length - 3) {
			scriptCode = scriptCode.substring(4, scriptCode.length - 3);
		}
		scriptCode = trim(scriptCode);
		if (scriptCode.indexOf('//') == scriptCode.length - 2) {
			scriptCode = scriptCode.substring(0, scriptCode.length - 2);
		}

		//this.scriptsToRun.push(cScript.innerHTML);
		this.scriptsToRun.push(scriptCode);
	}
}

DocumentLoader.prototype.importDocument = function ()
{
	this.targetNode.innerHTML = this.originNode.innerHTML;
}

DocumentLoader.prototype.runScripts = function ()
{
	for (var i = 0; i < this.scriptsToRun.length; i++)
	{
		try
		{
			eval(this.scriptsToRun[i]);
		}
		catch (ex) {}
	}
}
