var ECLIPSE_FRAME_NAME = "ContentViewFrame";

function findObject(objId) {
	if (document.getElementById)
		return document.getElementById(objId);

	if (document.all)
		return document.all[objId];
}

function isEclipse() {
	return (window.name == ECLIPSE_FRAME_NAME) || (parent.name == ECLIPSE_FRAME_NAME) || (parent.parent.name == ECLIPSE_FRAME_NAME);
}

function configPage() {
	if (isEclipse()) {
		findObject("titleTable").style.display = "";
		for (i = 1; i < 11; i++) {
			cell = findObject("noFramesLink" + i);
			if (cell == null)
				break;
				
			if (cell != null) {
				if (window.name == ECLIPSE_FRAME_NAME)
					cell.style.display = "none";
				else
					cell.style.display = "";
			}
			
			cell = findObject("framesLink" + i);
			if (cell != null) {
				if (window.name == ECLIPSE_FRAME_NAME)
					cell.style.display = "";
				else
					cell.style.display = "none";
			}
		}
	}
	else if (window == top) { // no frames
		findObject("titleTable").style.display = "";
	}
	else { // frames
		findObject("titleTable").style.display = "none";
	}
	showTitle(asdocTitle);
}

function loadFrames(classFrameURL, classListFrameURL) {
	var classListFrame = findObject("classListFrame");
	if(classListFrame != null && classListFrameContent!='')
		classListFrame.document.location.href=classListFrameContent;
 
	if (isEclipse()) {
		var contentViewFrame = findObject(ECLIPSE_FRAME_NAME);
		if (contentViewFrame != null && classFrameURL != '')
			contentViewFrame.document.location.href=classFrameURL;
	}
	else {
		var classFrame = findObject("classFrame");
		if(classFrame != null && classFrameContent!='')
			classFrame.document.location.href=classFrameContent;
	}
}

function showTitle(title) {
	if (!isEclipse())
		top.document.title = title;
}

function loadClassListFrame(classListFrameURL) {
	if (parent.frames["classListFrame"] != null) {
		parent.frames["classListFrame"].location = classListFrameURL;
	}
	else if (parent.frames["packageFrame"] != null) {
		if (parent.frames["packageFrame"].frames["classListFrame"] != null) {
			parent.frames["packageFrame"].frames["classListFrame"].location = classListFrameURL;
		}
	}
}

function gotoLiveDocs(primaryURL, secondaryURL) {
	var urlBase = "http://livedocs.macromedia.com/labs/1/flex20beta3/langref/";
	var url = urlBase + "index.html?" + primaryURL;
	if (secondaryURL != null && secondaryURL != "")
		url += ("&" + secondaryURL);
	window.open(url, "mm_livedocs", "menubar=1,toolbar=1,status=1,scrollbars=1");
}

function findTitleTableObject(id)
{
	if (top.titlebar)
		return top.titlebar.document.getElementById(id);
	else
		return document.getElementById(id);
}

function titleBar_setSubTitle(title)
{
	findTitleTableObject("subTitle").childNodes.item(0).data = title;
}

function titleBar_setSubNav(showConstants,showProperties,showStyles,showEffects,showEvents,showConstructor,showMethods,showExamples,
				showPackageConstants,showPackageProperties,showPackageFunctions,showInterfaces,showClasses,showPackageUse)
{
	findTitleTableObject("constantsLink").style.display = showConstants ? "inline" : "none";
	findTitleTableObject("constantsBar").style.display = (showConstants && (showPackageConstants || showProperties || showPackageProperties || showStyles || showEffects || showEvents || showConstructor || showMethods || showPackageFunctions || showInterfaces || showClasses || showPackageUse || showExamples)) ? "inline" : "none";

	findTitleTableObject("packageConstantsLink").style.display = showPackageConstants ? "inline" : "none";
	findTitleTableObject("packageConstantsBar").style.display = (showPackageConstants && (showProperties || showPackageProperties || showStyles || showEffects || showEvents || showConstructor || showMethods || showPackageFunctions || showInterfaces || showClasses || showPackageUse || showExamples)) ? "inline" : "none";

	findTitleTableObject("propertiesLink").style.display = showProperties ? "inline" : "none";
	findTitleTableObject("propertiesBar").style.display = (showProperties && (showPackageProperties || showStyles || showEffects || showEvents || showConstructor || showMethods || showPackageFunctions || showInterfaces || showClasses || showPackageUse || showExamples)) ? "inline" : "none";

	findTitleTableObject("packagePropertiesLink").style.display = showPackageProperties ? "inline" : "none";
	findTitleTableObject("packagePropertiesBar").style.display = (showPackageProperties && (showStyles || showEffects || showEvents || showConstructor || showMethods || showPackageFunctions || showInterfaces || showClasses || showPackageUse || showExamples)) ? "inline" : "none";

	findTitleTableObject("stylesLink").style.display = showStyles ? "inline" : "none";
	findTitleTableObject("stylesBar").style.display = (showStyles && (showEffects || showEvents || showConstructor || showMethods || showPackageFunctions || showInterfaces || showClasses || showPackageUse || showExamples)) ? "inline" : "none";

	findTitleTableObject("effectsLink").style.display = showEffects ? "inline" : "none";
	findTitleTableObject("effectsBar").style.display = (showEffects && (showEvents || showConstructor || showMethods || showPackageFunctions || showInterfaces || showClasses || showPackageUse || showExamples)) ? "inline" : "none";

	findTitleTableObject("eventsLink").style.display = showEvents ? "inline" : "none";
	findTitleTableObject("eventsBar").style.display = (showEvents && (showConstructor || showMethods || showPackageFunctions || showInterfaces || showClasses || showPackageUse || showExamples)) ? "inline" : "none";

	findTitleTableObject("constructorLink").style.display = showConstructor ? "inline" : "none";
	findTitleTableObject("constructorBar").style.display = (showConstructor && (showMethods || showPackageFunctions || showInterfaces || showClasses || showPackageUse || showExamples)) ? "inline" : "none";

	findTitleTableObject("methodsLink").style.display = showMethods ? "inline" : "none";
	findTitleTableObject("methodsBar").style.display = (showMethods && (showPackageFunctions || showInterfaces || showClasses || showPackageUse || showExamples)) ? "inline" : "none";

	findTitleTableObject("packageFunctionsLink").style.display = showPackageFunctions ? "inline" : "none";
	findTitleTableObject("packageFunctionsBar").style.display = (showPackageFunctions && (showInterfaces || showClasses || showPackageUse || showExamples)) ? "inline" : "none";

	findTitleTableObject("interfacesLink").style.display = showInterfaces ? "inline" : "none";
	findTitleTableObject("interfacesBar").style.display = (showInterfaces && (showClasses || showPackageUse || showExamples)) ? "inline" : "none";

	findTitleTableObject("classesLink").style.display = showClasses ? "inline" : "none";
	findTitleTableObject("classesBar").style.display = (showClasses && (showPackageUse || showExamples)) ? "inline" : "none";

	findTitleTableObject("packageUseLink").style.display = showPackageUse ? "inline" : "none";
	findTitleTableObject("packageUseBar").style.display = (showPackageUse && showExamples) ? "inline" : "none";

	findTitleTableObject("examplesLink").style.display = showExamples ? "inline" : "none";
}

function titleBar_gotoClassFrameAnchor(anchor)
{
	top.classFrame.location = top.classFrame.location.toString().split('#')[0] + "#" + anchor;
}

function setMXMLOnly() 
{
	if (getCookie("showMXML") == "false")
	{
		toggleMXMLOnly();
	}	
}
function toggleMXMLOnly() 
{
	var mxmlDiv = findObject("mxmlSyntax");
	var mxmlShowLink = findObject("showMxmlLink");
	var mxmlHideLink = findObject("hideMxmlLink");
	if (mxmlDiv && mxmlShowLink && mxmlHideLink)
	{
		if (mxmlDiv.style.display == "none")
		{
			mxmlDiv.style.display = "block";
			mxmlShowLink.style.display = "none";
			mxmlHideLink.style.display = "inline";
			setCookie("showMXML","true", new Date(3000,1,1,1,1), "/", document.location.domain);
		}
		else
		{
			mxmlDiv.style.display = "none";
			mxmlShowLink.style.display = "inline";
			mxmlHideLink.style.display = "none";
			setCookie("showMXML","false", new Date(3000,1,1,1,1), "/", document.location.domain);
		}
	}

}

function showHideInherited()
{	
	setInheritedVisible(getCookie("showInheritedConstant") == "true", "Constant");
	setInheritedVisible(getCookie("showInheritedProtectedConstant") == "true", "ProtectedConstant");
	setInheritedVisible(getCookie("showInheritedProperty") == "true", "Property");
	setInheritedVisible(getCookie("showInheritedProtectedProperty") == "true", "ProtectedProperty");
	setInheritedVisible(getCookie("showInheritedMethod") == "true", "Method");
	setInheritedVisible(getCookie("showInheritedProtectedMethod") == "true", "ProtectedMethod");
	setInheritedVisible(getCookie("showInheritedEvent") == "true", "Event");
	setInheritedVisible(getCookie("showInheritedStyle") == "true", "Style");
	setInheritedVisible(getCookie("showInheritedEffect") == "true", "Effect");
}
function setInheritedVisible(show, selectorText)
{
	var rules = (document.styleSheets[0].cssRules != undefined) ? document.styleSheets[0].cssRules : document.styleSheets[0].rules;
	for (var i = 0; i < rules.length; i++)
	{
		if (rules[i].selectorText == ".hideInherited" + selectorText)
			rules[i].style.display = show ? "" : "none";
			
		if (rules[i].selectorText == ".showInherited" + selectorText)
			rules[i].style.display = show ? "none" : "";
	}
	
	setCookie("showInherited" + selectorText, show ? "true" : "false", new Date(3000,1,1,1,1), "/", document.location.domain);
}
