// comment to alter date_time stamp - 6/1/00 17:45
var meVisibleMenu = null;
var meVisibleMenuName = "noMenu";
var mbIsIframeVisible = false;
var isIE = false;
var isNS = false;
var col1 = null;
var styleObj = null;
var delay = 0;
var timeoutId = null;
var delayTime = 25;					// ms for menu open delay

if (top.location == self.location) { window.name = "_mywaywin"; }
detectBrowser();

function detectBrowser() {
	var sAppName = navigator.appName;

	if (sAppName == "Microsoft Internet Explorer") {
		isIE = true;
		col1 = "all.";
		styleObj = ".style";
		window.onload = pageLoad;
		window.onresize = adjustFooter;
	} else if (sAppName == "Netscape") {
		isNS = true;
		document.captureEvents(Event.CLICK);
	}

	isMac = false;
	if (navigator.platform.substring(0,3) == "Mac" && navigator.appVersion.indexOf("MSIE 5") < 0) isMac = true;

	if (document.frames.length == parent.frames.length) {
		document.onclick = clickHandler;
		document.onmouseover = mouseoverMenuHandler;
	}
}

function pageLoad() {
	if (document.all.quotes) document.frames['iframeQuotes'].location = '/elements/stocks/IE_stock_wrap_inc.asp';
	adjustFooter();
}

function adjustFooter() {
	if (document.all.footer) { fixFooter(); }
}

function fixFooter() { }

function helpWindow(sDest) {
	newWin = window.open(sDest, "PopupHelp", "width=620,height=400,scrollbars=1,resizable=1,toolbar=1");
}

function closeMenuMac(evt) {
	if (meVisibleMenuName == "closeNext") {
		closeMenu(evt)
	} else if (meVisibleMenuName != "noMenu") {
		meVisibleMenuName = "closeNext";
	}
}

function closeMenu(evt) {
	delay = -1;
	meVisibleMenuName = "noMenu";
	if (meVisibleMenu != null) {
		meVisibleMenu.visibility = "hidden";
		meVisibleMenu = null;
		showElement("SELECT");
	}
}
	
function clickHandler(evt) {
	eSrc = window.event.srcElement;
	if (eSrc.id.search(".+Arrow$") != -1) { eSrc = eSrc.parentElement; }
	if (eSrc.id.search("^q.+Title$") != -1) { eSrc = eSrc.parentElement; }
	thisMenuName = eSrc.id;

	isSame = false;
	if (meVisibleMenuName == thisMenuName) { isSame = true; }
	closeMenu(evt);

	if (isSame) { return false; }

	if (getClassName(eSrc) == "menuClicker" || getClassName(eSrc) == "intentSelected") {
		doMenu(eSrc, window.event.clientX, window.event.clientY);
		return false;
	}
}
	
function mouseoverMenuHandler(evt) {
	eSrc = window.event.srcElement;
	if (eSrc == null) {
		return false;
	} 
	if (eSrc.id.search(".+Arrow$") != -1) { eSrc = eSrc.parentElement; }
	if (eSrc.id.search("^q.+Title$") != -1) { eSrc = eSrc.parentElement; }
	thisMenuName = eSrc.id;

	isSame = false;
	if (meVisibleMenuName == thisMenuName) { return false; }
	if (getClassName(eSrc) == "menuClicker" || getClassName(eSrc) == "intentSelected") {
		wasOpen = meVisibleMenuName;
		closeMenu(evt);
		clearTimeout(timeoutId);
		if (wasOpen == "noMenu") {
			delay = delayTime;
		} else {
			delay = 1;
		}
		openMenuDelay();
		return false;
	} else if (eSrc.id.search(".+Menu$") == -1 && eSrc.parentElement.id.search(".+Menu$") == -1 && getClassName(eSrc) != "menuItem" && getClassName(eSrc.parentElement) != "menuItem") {
		if (isMac) { closeMenuMac(evt); }
		  else { closeMenu(evt); }
		return false;
	}
}

function openMenuDelay() {
	delay = delay - 1;
	if (delay > 0) {
		timeoutId = setTimeout(openMenuDelay,1);
	} else if (delay == 0) {
		delay = -1;
		doMenu(eSrc);
	}
}

function doMenu(eSrc, x, y) {
	var eID, eMenu, esMenu, eMenuElement;
	eID = eSrc.id;
	eMenu = document.all(eID + "Menu");
	esMenu = getObj(eID + "Menu");
	if (isMac) {
		if (eID.substr(0,1) == "i") {
			esMenu.left = 6;
			esMenu.top = 19;
		} else if (eID.substr(0,1) == "e") {
			eMenuElement = document.all(eID + "Element");
			esMenu.left = eMenuElement.offsetWidth - 100;
		} else if (eID.substr(0,1) == "q") {
			esMenu.left = -53;
			esMenu.top = 18;
		}
	} else {
		eMenuElement = document.all(eID + "Menu");
		if (eID.substr(0,1) == "i") {
			esMenu.left = getOffset(eSrc, "left") - 5;
			esMenu.top = getOffset(eSrc, "top") + 7;
			x = esMenu.posLeft;
			y = esMenu.posTop;
		} else if (eID.substr(0,1) == "e") {
			eElement = document.all(eID + "Element");
			esMenu.left = eElement.offsetWidth - 100;
			x = getOffset(eMenuElement, "left");
			y = getOffset(eMenuElement, "top");
		} else if (eID.substr(0,1) == "q") {
			esMenu.left = getOffset(eSrc, "left") - 55;
			esMenu.top = getOffset(eSrc, "top") + 4;
			x = esMenu.posLeft;
			y = esMenu.posTop;
		}
		hideElement("SELECT",x,y,eMenuElement.offsetWidth,eMenuElement.offsetHeight);
	}

	meVisibleMenuName = eID;
	esMenu.visibility = "visible";
	meVisibleMenu = esMenu;

}

function getObj(obj) {
	var theObj;
	
	if (typeof obj == "string") {
		theObj = eval("document." + col1 + obj + styleObj);
	} else {
		theObj = obj;
	}
	return theObj;
}

function getClassName(eSrc) {	
	if (eSrc.className != null) {
		return eSrc.className;
	} else {
		return null;
	}
}

function getOffset(eStart,sDirection) {
	var bRecurse = true;
	var eTarget = eStart;

	switch (sDirection) {
	case "left":
		var iOffset = eStart.offsetLeft;
		break;
	case "top":
		var iOffset = eStart.offsetTop;
		break;
	}

	while (bRecurse) {
		eTarget = eTarget.offsetParent;
		switch (eTarget.tagName) {

		case "BODY":
			bRecurse = false;
			break;
		default:
			switch (sDirection) {
			case "left":
				iOffset = iOffset + eTarget.offsetLeft;
				break;
			case "top":
				iOffset = iOffset + eTarget.offsetTop;
				break;
			}
			break;
		}
	}
	return iOffset;
}

function toggleBlock(dialogOn, dialogOff) {
	dialogOff.style.visibility = "hidden";
	switch (dialogOn.style.visibility) {
	case "visible":
		dialogOn.style.visibility = "hidden";
		break;
	default:
		dialogOn.style.visibility = "visible";
		break;
	}
	event.cancelBubble = true;
}

function minimizeElem(sSrc, eCount, cCount, gps_code, returnTo) {
	sBody = eval(sSrc + "Body");
	if (sBody.style.display == "block" || sBody.style.display == "") {
		sBody.style.display = "none";
		if (eCount != -1 && cCount != -1) {
			sMin = eval(sSrc + "Min");
			sMax = eval(sSrc + "Max");
			sMaxText = eval(sSrc + "MaxText");
			sMin.className = "disabled";
			sMax.className = "enabled";
			sMaxText.style.visibility = "visible";
			iframeEdit.location = "/features/edit/default.asp?action=minimize&elementIndex=" + eCount + "&column=" + cCount + "&returnTo=%2Ffeatures%2Fedit%2Fblank%2Ehtm" + "&gps_code=" +gps_code;
		}
	}
	fixFooter();
}

function maximizeElem(sSrc, eCount, cCount, gps_code, returnTo) {
	sBody = eval(sSrc + "Body");
	if (sBody.style.display == "none" || sBody.style.display == "") {
		sBody.style.display = "block";
		if (eCount != -1 && cCount != -1) {
			sMin = eval(sSrc + "Min");
			sMax = eval(sSrc + "Max");
			sMaxText = eval(sSrc + "MaxText");
			sMin.className = "enabled";
			sMax.className = "disabled";
			sMaxText.style.visibility = "hidden";
			iframeEdit.location = "/features/edit/default.asp?action=maximize&elementIndex=" + eCount + "&column=" + cCount + "&returnTo=%2Ffeatures%2Fedit%2Fblank%2Ehtm" + "&gps_code=" +gps_code;
		}
	}
	fixFooter();
}

function maxMinElement(sSrc, eCount, cCount, gps_code) {
	sBody = eval(sSrc + "Body");
	if (sBody.style.display == "none" || sBody.style.display == "") {
		if (sBody.id == "addContentItemsBody") {
			chooseColorsBody.style.display = "none";
		} else if(sBody.id == "chooseColorsBody") {
			addContentItemsBody.style.display = "none";
		}
		sBody.style.display = "block";
	} else if (sBody.style.display == "block") {
		sBody.style.display = "none";
	}
	fixFooter();
}

function hideElement(elmID,x,y,w,h)
{
	for (i = 0; i < document.all.tags(elmID).length; i++)
	{
		obj = document.all.tags(elmID)[i];
		if (! obj || ! obj.offsetParent)
			continue;

		// Find the element's offsetTop and offsetLeft relative to the BODY tag.
		objLeft   = obj.offsetLeft;
		objTop    = obj.offsetTop;
		objParent = obj.offsetParent;
		while (objParent.tagName.toUpperCase() != "BODY")
		{
			objLeft  += objParent.offsetLeft;
			objTop   += objParent.offsetTop;
			objParent = objParent.offsetParent;
		}
		// Adjust the element's offsetTop relative to the dropdown menu
		objTop = objTop - y;

		if (x > (objLeft + obj.offsetWidth) || objLeft > (x + w))
			;
		else if (objTop > h)
			;
		else if ((y + h) <= 80)
			;
		else {
			obj.style.visibility = "hidden";
			}
	}
}

function showElement(elmID)
{
	for (i = 0; i < document.all.tags(elmID).length; i++)
	{
		obj = document.all.tags(elmID)[i];
		if (! obj || ! obj.offsetParent)
			continue;
		obj.style.visibility = "";
	}
}

function openChat(room){
	window.open('/features/chat/gochat.asp?room='+room,'Chat','menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,height=480,width=620')
}

function openWin(Url){
	window.open(Url,'Chat','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,height=480,width=620')
}

function openPlayer(url, topic, focusid, videoid, rate, format) {
	if (rate == "28" || rate == "56") {
		width = 500; height = 500;
	} else {
		width = 600; height = 625;
	}
	window.open("/features/topics/multimedia_popup.asp?topic=" + topic + "&rate=" + rate + "&url=" + url + "&format=" + format + "&videoid=" + videoid + "&focusid=" + focusid, "Video" + rate, "width=" + width + ",height=" + height + ",scrollbars=no,resizeable=no,toolbar=no,location=no,directories=no,status=no");
}

function menuPopup(which, focusid, topic) {
	var format = "", rate = "", videoid = "";
	imc_format = which.imc_format.options[which.imc_format.selectedIndex].value;
	if (imc_format != "") {
		arrformat = imc_format.split("|")
		rate = arrformat[0];
		format = arrformat[1];
	}
	videoid = which.imc_video.options[which.imc_video.selectedIndex].value;

	if (format == "" || rate == "" || videoid == "") {
		alert("Please choose a valid video format and video to watch.");
	} else {
		if (rate == "28" || rate == "56") {
			width = 500; height = 500;
		} else {
			width = 600; height = 625;
		}
		window.open("/features/topics/multimedia_popup.asp?from=menu&topic=" + topic + "&rate=" + rate + "&format=" + format + "&videoid=" + videoid + "&focusid=" + focusid, "Video" + rate, "width=" + width + ",height=" + height + ",scrollbars=no,resizeable=no,toolbar=no,location=no,directories=no,status=no");
	}
}
