// JScript source code
////////////////////////////////////
//
// 组件加载启动函数
//
////////////////////////////////////
function compXLoaded()
{
	var objSrc = event.srcElement;
	if(document == null || objSrc == null)
	{
		return;
	}
	if(document.SDNetWebCompXsEntry == null)
	{
		document.SDNetWebCompXsEntry = new SDNetWebCompXsEntry();
	}
	document.SDNetWebCompXsEntry.AddComponent(objSrc);
}

////////////////////////////////////
//
// 组件解析对象模型入口类
//
////////////////////////////////////
function SDNetWebCompXsEntry()
{
	document.UseLocalHost = false;
	document.LocalHost = "http://localhost:8080/";
	this.CompXScopeName = "sdnet";
	this.tagCompXs = Array();
	this.objCompXs = Array();
	this.Count = 0;
	this.IsScriptLoaded = false;
	this.CompXsScriptLoaded = false;
	//
	// 附加脚本加载完成事件处理函数
	//
	this.CompXScriptReady = function()
	{
		if(event.srcElement.Loaded)
			return;
		if(event.srcElement.CompXsEntry != document.SDNetWebCompXsEntry)
			return;
		event.srcElement.Loaded = true;
	}
	this.StartInit = function()
	{
		var entry = document.SDNetWebCompXsEntry;
		entry.CompXsScriptLoaded = true;
		var i;
		for(i = 0; i < entry.tagCompXs.length; i++)
		{
			entry.InitCompX(entry.tagCompXs[i]);
		}
	}
	
	this.AddComponent = function(objCompX)
	{
		var objParent = objCompX;
		var vv = "";
		while(objParent != document.body)
		{
			if(objParent.scopeName.toLowerCase() == this.CompXScopeName)
			{
				break;
			}
			objParent = objParent.parentElement;
		}
		if(objParent == document.body)
		{
			return;
		}

		if(objParent.Loaded)
		{
			return;
		}
		objParent.Loaded = true;
		this.tagCompXs[this.tagCompXs.length] = objParent
		if(this.tagCompXs.length == 1)
		{
			var script = document.createElement("SCRIPT");
			script.CompXsEntry = this;
			script.Loaded = false;
			script.src="WebCompX.js";
			script.onreadystatechange = this.CompXScriptReady;
			document.body.previousSibling.appendChild(script);
		}
		if(this.CompXsScriptLoaded)
		{
			this.InitCompX(objParent);
		}
	}
	this.InitCompX = function(tmpCompX)
	{
		if(tmpCompX.Inited)
		{
			return;
		}
		tmpCompX.Inited = true;
		var objTmp = new SDNetWebCompX(tmpCompX);
		objTmp.Init();
		this.objCompXs[this.objCompXs.length] = objTmp;
	}
}
