var boolModelNamesLoaded = false;
var boolModelNamesLoadStarted = false;
var boolObjectNamesLoaded = false;
var boolObjectNamesLoadStarted = false;

window.onload = function()
{
	loadStartModel();
}

function loadStartModel()
{
	var pattern = decodeURI(top.frames.document.location.search);
	
	if (pattern != "")
	{
		var sortedParams = new Array()
		sortedParams.push(new Array(pattern.indexOf('?model='), "model", "strModelName"));
		sortedParams.push(new Array(pattern.indexOf('?object='), "object", "strObjectName"));
		sortedParams.push(new Array(pattern.indexOf('?type='), "type", "strTypeName"));
		sortedParams.push(new Array(pattern.indexOf('?class='), "class", "strClassName"));
		sortedParams.push(new Array(pattern.indexOf('?id='), "id", "strModelId"));
		sortedParams.sort();

		for (var i = 0; i < sortedParams.length; i++)
		{
			if (sortedParams[i][0] > -1)
			{
				intStartPos = (Number(sortedParams[i][0]) + sortedParams[i][1].length + 2);
				intEndPos = (i+1 >= sortedParams.length) ? Number(pattern.length) : Number(sortedParams[i+1][0]);
				eval("var " + sortedParams[i][2] + "= unescape(pattern.substring(" + intStartPos + ", " + intEndPos + "));");
			}
			else
			{
				eval("var " + sortedParams[i][2] + "= '';");
			}
		}
		
		if (strModelId != '')
		{
			parent.frames['model'].document.location = "../" + strModelId + "/" + strModelId + ".html";
		}
		else if (strObjectName != '' && strClassName != '' && strModelName != '' && strTypeName != '')
		{
			if (!boolObjectNamesLoaded)
			{
				if (!boolObjectNamesLoadStarted)
				{
					boolObjectNamesLoadStarted = true;
					heads 							= document.getElementsByTagName("head");
					scriptElem					= document.createElement("script");
					scriptElem.charset	= "ISO-8859-1";
					scriptElem.type 		= "text/javascript";
					scriptElem.src 			= "../js/objectnames.js";
					heads[0].appendChild(scriptElem);
				}		
				window.setTimeout("loadStartModel()", 100); 		
			}
			else
			{
				objToken = objectId[strObjectName + "¦" + strClassName + "¦" + strModelName + "¦" + strTypeName];
				if (typeof(objToken) == "undefined")
				{
					parent.frames['model'].document.location = "../ID" + startModelId + "/ID" + startModelId + ".html";
				}
				else
				{
					var objTokenArray = objToken.split(".");
					parent.frames['model'].document.location = "../ID" + objTokenArray[1] + "/ID" + objTokenArray[1] + ".html";
					instLink = "../ID" + objTokenArray[1] + "/ID" + objTokenArray[0] + ".html";
					instWindow = window.open(instLink, "InstanceWindow", "scrollbars=yes, resizable=yes, width=400, height=600, dependent=yes, left=0, top=300");
					instWindow.focus();				
				}
				return
			}			
		}
		else if (strModelName != '' && strTypeName != '')
		{
			if (!boolModelNamesLoaded)
			{
				if (!boolModelNamesLoadStarted)
				{
					boolModelNamesLoadStarted = true;
					heads 							= document.getElementsByTagName("head");
					scriptElem					= document.createElement("script");
					scriptElem.charset	= "ISO-8859-1";
					scriptElem.type 		= "text/javascript";
					scriptElem.src 			= "../js/modelnames.js";
					heads[0].appendChild(scriptElem);
				}		
				window.setTimeout("loadStartModel()", 100); 		
			}
			else
			{
				modid = modelId[strModelName + "¦" + strTypeName];
				if (typeof(modid) == "undefined")
				{
					parent.frames['model'].document.location = "../ID" + startModelId + "/ID" + startModelId + ".html";
				}
				else
				{
					parent.frames['model'].document.location = "../ID" + modid + "/ID" + modid + ".html";
				}
				return
			}			
		}
		else
		{
			parent.frames['model'].document.location = "../ID" + startModelId + "/ID" + startModelId + ".html";
		}
	}
	else
	{
		parent.frames['model'].document.location = "../ID" + startModelId + "/ID" + startModelId + ".html";
	}
}