/*
'=======================================================================
' /resources/scripts/explorer.js
'
' Copyright © 2003 prismausa.com
'
' author		date		comments
' ------		----		--------
' Santosh Pathak	09/17/02	removed pageLoad function
' Santosh Pathak	04/15/03	removing the call
'=======================================================================
*/

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

var objCurrDrawer = null;
var drawerTimeout = null;

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;
	}
}

var intervalId = 0;
function toggleCheck(autoCheck) {
	OnOff = autoCheck.value;
	if (OnOff == 1) {
		iframeEdit.location = "/features/edit/fol.asp?value=on&returnTo=%2Ffeatures%2Fedit%2Fblank%2Ehtm";
		alert("Turning ON Friends OnLine Check");
		intervalId = setInterval(getFriends,10000);
	} else {
		clearInterval(intervalId);
		iframeEdit.location = "/features/edit/fol.asp?value=off&returnTo=%2Ffeatures%2Fedit%2Fblank%2Ehtm";
		alert("Turning OFF Friends OnLine Check");
	}
}

function getFriends() {
	if (document.frames["iframeFriends"]) document.frames["iframeFriends"].location = "/elements/friends/iframe_wrap.asp";
}

function pageLoad() {
	if (document.all.quotes) document.frames["iframeQuotes"].location = "/elements/stocks/IE_stock_wrap_inc.asp";
	getDropZones();
}
 
function adjustFooter() {
	if (document.all.footer) { fixFooter(); }
}

function fixFooter() { }
function getDropZones() { }

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" || getClassName(eSrc) == "customButton") {
		doMenu(eSrc, window.event.clientX, window.event.clientY);
		return false;
	}
}
	
function mouseoverMenuHandler(evt) {
	eSrc = window.event.srcElement;

	if (objCurrDrawer != null) {

		while (eSrc.tagName != "DIV" && eSrc.tagName != "BODY") { eSrc = eSrc.parentElement; }
		if (eSrc.id.search(".+Drawer$") == -1 && eSrc.id.search(".+Handle$") == -1) { closeDrawers(); }

	} else {

		if (eSrc.id.search(".+Arrow$") != -1) { eSrc = eSrc.parentElement; }
		if (eSrc.id.search("^q.+Title$") != -1) { eSrc = eSrc.parentElement; }

		thisMenuName = eSrc.id;
		if (meVisibleMenuName == thisMenuName) { return false; }

		isSame = false;
		if (getClassName(eSrc) == "menuClicker" || getClassName(eSrc) == "customButton" || getClassName(eSrc).substr(0,6) == "intent") {
			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); }

			if (drawerTimeout != null) {
				while (eSrc.tagName != "DIV" && eSrc.tagName != "BODY") { eSrc = eSrc.parentElement; }
				if (eSrc.id.search(".+Drawer$") == -1 && eSrc.id.search(".+Handle$") == -1) { drawerTimeout = eraseTimeout(drawerTimeout); }
			}

			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", "width=620,height=480,scrollbars,resizable");
}

function openWin(url){
	window.open(url, "Chat", "width=620,height=480,scrollbars,resizable");
}

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);
}

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);
	}
}

/* popup the small window for a single element */
function popElem(elm, col, rfs, atr) {
	if (col == 0) {
		width = 200;
	} else if (col == 1) {
		width = 450;
	} else {
		width = 350;
	}
	window.open("/features/popup/default.asp?elem=" + elm + "&refresh=" + rfs + "&attrib=" + escape(atr), "PopUp", "width=" + width + ",height=325,scrollbars,resizable");
}

function slideOut(strIntent) {
	drawerTimeout = eraseTimeout(drawerTimeout);
	if (objCurrDrawer != null) {
		slideOutTimed(strIntent);
	} else {
		drawerTimeout = setTimeout("slideOutTimed('" + strIntent + "')", 300);
	}
}

function slideOutTimed(strIntent) {
	closeDrawers();

	objDrawer = document.all(strIntent + "Drawer").style;
	objDrawer.zIndex = 100;
	objDrawer.visibility = "visible";

	objCurrDrawer = objDrawer;
}

function closeDrawers() {
	if (objCurrDrawer != null) {
		objCurrDrawer.visibility = "hidden";
		objCurrDrawer = null;
	}
}

function eraseTimeout(tId) {
	clearTimeout(tId);
	return null;
}
