var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
var IsIE4 = (navigator.userAgent.indexOf('MSIE 4')>0);
var Netscape = (! InternetExplorer);

function getWindowFeatures(AWidth,AHeight,AScrollbars,AMenubar,AWindowName)
{
	var lWindowParams;
	var lLeft; 
	var lTop;
	var lScreenWidth;
	var lScreenHeight;
	var lResizable;
	var lIsMainWindow;
	var lIsFlashPopup;
	
	lScreenWidth = GetScreenWidth();
	lScreenHeight = GetScreenHeight();
	
	if (lScreenWidth <= 800)
	{
		lLeft = 0;
		lTop = 0;
/*		
		lLeft = parseInt(((lScreenWidth - AWidth) / 2));
		lTop = parseInt(((lScreenHeight - AHeight) / 2));
		if (window.screen && screen.availTop)
		{
			if (lTop < screen.availTop)
				lTop = screen.availTop;
		}
		else
		{
			if (lTop > 28)
				lTop = lTop - 14;
		}
*/
	}
	else 
	{
		lLeft = parseInt(((lScreenWidth - AWidth) / 2));
		lTop = parseInt(((lScreenHeight - AHeight) / 2));
	}
	
	lResizable = "1";
	if (Netscape)
		lResizable = "0";
		
	lWindowParams = "resizable=" + lResizable + ",";
	lWindowParams += "toolbar=0,location=0,directories=0,status=0,menubar=0,left=";
	lWindowParams += lLeft + ",top=" + lTop;
	lWindowParams += ",width=" + AWidth + ",height=" + AHeight;
	lWindowParams += ",menubar=" + AMenubar;
	lWindowParams += ",scrollbars=" + AScrollbars;
	return lWindowParams;
}

function ShowWindow(WindowName, FileToOpen, AWidth, AHeight, AWindowFeatures)
{
	var lResult;
	var lWindowFeatures;
	
	if (IsMissing(AWindowFeatures))
	{
		lWindowFeatures = getWindowFeatures(AWidth,AHeight,0,0,WindowName);
	}
	else
	{
		lWindowFeatures = AWindowFeatures;
	}
		
	lResult = window.open(FileToOpen,WindowName, lWindowFeatures);
	if (lResult && (!lResult.opener))
		lResult.opener = self;
	return lResult;
}

function GetScreenWidth(){
	var lResult;

	if (window.screen) 
		lResult = screen.availWidth
	else
		lResult = 800;

	return lResult;	   
}

function GetScreenHeight(){
	var lResult;

	if (window.screen)
		lResult = screen.availHeight
	else
		lResult = 600;

	return lResult;	   
}

function IsMissing(aTarget)
{
	if (aTarget == "")
		return true;
	if (aTarget+"" == "undefined")
		return true;
	return false;
}

function openScrollablePopup(sWindowName, sUrl)
{
	// (AWidth,AHeight,AScrollbars,AMenubar,AWindowName)
	var sFeatures = getWindowFeatures(360, 400,1,0,sWindowName);
	openWin(sWindowName, sUrl, 360, 400, sFeatures);
}

function openWin(sWindowName, sUrl, nWidth, nHeight, sFeatures)
{
	ShowWindow(sWindowName, sUrl, nWidth, nHeight, sFeatures);
}

function sGetDir()
{
	return window.prompt("Dir:", "73");
}

function openPopup(sWindow,sUrl)
{
	openWin(sWindow, sUrl, 360, 400);
}

function bShouldUse800x600()
{
		return (top.GetScreenWidth() <= 800);
}

function NowInMilliseconds()
{
	var lNow;
	lNow = new Date();
	return lNow.getTime();
};


function showTutorial()
{
		openWin("Tutorial", "http://www.chattoons.com/chat/main/actors/detectflash.php?url=http://www.chattoons.com/chat/main/tutorial.html", 510, 510);
}

function openChat()
{
  window.alert("ChatToons is temporarily offline.\n\nPlease read the notice on the home page.");
  return;
//	openChatEx('main');
}

function openHiddenChat(){
	openChatEx('main');
}

function openChatEx(sDir)
{
	var sQuery = window.location.search;
	if (sQuery == '')
		sQuery = '?'
  else
		sQuery = sQuery + "&";
	
	var sUrl;
	var sUnique = sQuery + "uid=" + NowInMilliseconds();
	var sQueryString = sUnique + "&url=http://www.chattoons.com/chat/" + sDir + "/actors/gochat.php";
	var sDomain = "http://www.chattoons.com";
	
//	if (bShouldUse800x600())
	if (true)
	{
		sUrl = sDomain + "/chat/" + sDir + "/actors/detectflash.php" + sQueryString;
		openWin("ChatToonsChat", sUrl, 800, 540);
	}
	else
	{
		sUrl = sDomain + "/chat/" + sDir + "/actors/mainframes.php" + sQueryString;
		openWin("ChatToonsChat", sUrl, 800, 620);
	}
}

