function setTitle()
{
	if (!parent || !parent.header.document)
	{
		window.setTimeout("setTitle()", 100);
	}
	else
	{
		nameElem = parent.header.document.getElementById("modelname")
    if (!nameElem)
    {
      window.setTimeout("setTitle()", 100);;    
    }
    else
    {
    	var maxStrLength = Math.floor(self.document.body.offsetWidth / 9);
  		if (document.title.length > maxStrLength)
  		{
  			var modelname = document.title.substring(0, maxStrLength - 4) + "...";
  		}
  		else
  		{
  			var modelname = document.title;
  		}
      nameElem.innerHTML = "<nobr>" + maskTags(modelname) + "</nobr>";
      nameElem.title = document.title;      
    }
	}
}

function setModelInfo()
{
	var modelInfoElem = parent.header.document.getElementById("info-m");
	var erg = ""
	if (modelInfoElem)
	{
		for (var entry in modInfo)
		{
			erg = (erg + "<tr><td class='info-head'>" + entry + ":</td><td>" + modInfo[entry] + "</td></tr>");
		}
		
		if (erg != "")
		{
			erg = ("<table>" + erg + "</table>");
			modelInfoElem.innerHTML = erg;
			showButton("modelinfo", true);			
		}
	}
}

function setMail(show)
{
	if (!parent || !parent.header.document)
	{
		window.setTimeout("setMail(" + show + ");", 100);  
	}
	else
	{
		var strAction = "";
		var mailElem = parent.header.document.getElementById('mail');
		if ((currMailAddress != "") && show)
		{
			mailElem.title = currMailAddress;
			mailElem.href = "mailto:" + currMailAddress;
			showButton("mail", true);
		}
	}
}

function showButton(elem, show)
{
	if (!parent || !parent.header)
	{
		window.setTimeout("showButton(" + elem + ", " + show + ");", 100);
	}
	else
	{
		var buttonElem = parent.header.document.getElementById(elem);
		buttonElem.style.display = (show) ? "block" : "none";
	}
}

function checkPrint()
{
	if (!parent || !parent.header)
	{
		window.setTimeout("checkPrint();", 100);
	}
	else
	{
		var printType = parent.header.printFormat;
		
		if (bPrintOne)
		{
			with (parent.header)
			{
				var currElement = document.getElementById("print1");
				currElement.style.backgroundImage = "url(../misc/images/header/" + printOne['low'] + ")";
				currElement.onmouseover	= function(){quickTip(printOne['name']); this.style.backgroundImage = "url(../misc/images/header/" + printOne['high'] + ")";};
				currElement.onmouseout 	= function(){quickTip(''); this.style.backgroundImage = "url(../misc/images/header/" + printOne['low'] + ")";};
				currElement.onclick = function(){currWindow = window.open("../print/print1/" + currModelId + "." + printType); currWindow.focus()};
			}
			showButton("print1", true);
		}
		
		if (bPrintTwo)
		{
			with (parent.header)
			{
				var currElement = document.getElementById("print2");
				currElement.style.backgroundImage = "url(../misc/images/header/" + printTwo['low'] + ")";
				currElement.onmouseover	= function(){quickTip(printTwo['name']); this.style.backgroundImage = "url(../misc/images/header/" + printTwo['high'] + ")";};
				currElement.onmouseout 	= function(){quickTip(''); this.style.backgroundImage = "url(../misc/images/header/" + printTwo['low'] + ")";};
				currElement.onclick = function(){currWindow = window.open("../print/print2/" + currModelId + "." + printType); currWindow.focus()};
			}		
			showButton("print2", true);
		}		
	}
}

function openWindow(modId, instId)
{
	try
	{
		killCM()
	}
	catch(e){}
	
	if (instId != "")
	{
		instLink = "../" + modId + "/" + instId + ".html";
		instWindow = window.open(instLink, "InstanceWindow", "scrollbars=yes, resizable=yes, width=400, height=600, dependent=yes, left=0, top=300");
  	instWindow.focus();
  }
  else
  {
  	modLink = "../" + modId + "/" + modId + ".html";
  	top.model.location.href = modLink;
  }
}

function actualizeTreeView()
{
	if (parent.menu)
	{
		if (!parent.menu.boolMenuLoaded)
		{
			window.setTimeout("actualizeTreeView()", 100);
		}
		else
		{
			var boolFound = parent.menu.showElemInTree(currModelId);
			
			if (!boolFound)
			{
				if (parent.header.defaultView)
				{
					parent.header.changeView(parent.header.defaultView);
					window.setTimeout("actualizeTreeView()", 100);					
				}
			}
		}
	}
}

function maskTags(source)
{
  source = source.replace(/\</g, "&lt;");
  source = source.replace(/\>/g, "&gt;");  
  return source;
}

function unMaskTags(source)
{
  source = source.replace(/\&lt;/g, "<");
  source = source.replace(/\&gt;/g, ">");  
  return source;
}

function unMaskQuotes(source)
{
  source = source.replace(/\\"/g, "\"");
  source = source.replace(/\\'/g, "\'");
  source = source.replace(/\\\\/g, "\\");
  return source;
}