/*
	taosWin_taosWin.js
	===================================================================================
	TAOS
	TaosWin Core Windows JavaScript 1.4.0

		
	Updated: 20/05/2002 19:41
	Authors: Oliver Emberton (oliveremberton@silktide.com)
	===================================================================================	
*/

	// Browser sniff
	var detect = navigator.userAgent.toLowerCase();
	var browser, browserVersion, browserString;
	
	if (taosBrowserSniff('konqueror')) browser = "Konqueror"
	else if (taosBrowserSniff('safari')) browser = "Safari"
	else if (taosBrowserSniff('opera')) browser = "Opera"
	else if (taosBrowserSniff('msie')) browser = "IE"
	else if (!taosBrowserSniff('compatible'))
	{
		browser = "Netscape"
		browserVersion = detect.charAt(8);
	}
	else browser = "Unknown";
	
	if (!browserVersion) browserVersion = detect.charAt(place + browserString.length);
	
	function taosBrowserSniff(string)
	{
		place = detect.indexOf(string) + 1;
		browserString = string;
		return place;
	}
	
	var isIe = (browser=="IE" ? true : false);

	// XP SP2 - different handling of modal dialogs etc
	browserIsSP2 = (window.navigator.userAgent.indexOf("SV1") != -1);

	if (!browserIsSP2)
	{
		if (top.oPopup)
			top.oPopup="";
	}

// Open a modal dialog
function taosOpenModalDialog(pagename, width, height)
{
	if (!isIe)
		return taosOpenModalDialogNew(pagename, width, height);
		
	//window.open(pagename);
	//return false;
	
	if (!width)
		width=(screen.availwidth-50);
	if (!height)
		height=(screen.availheight-70);

	if (browserIsSP2)
		height+=25; // Add space for status bar

	//window.open(pagename, "window", 'width='+(width-10)+',height='+(height-96)+',left='+((screen.availwidth-width)/2)+',top='+((screen.availheight-height)/2)+',status=no,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,titlebar=no');

	return window.showModalDialog(pagename, "", 'dialogWidth:'+width+'px; dialogHeight:'+height+'px; dialogLeft:'+((screen.availwidth-width)/2)+'px; dialogTop: '+((screen.availheight-height)/2)+'px; center: no; scroll: no; status: no; resizable: no; help: no');
}

// Open a modal dialog (supports IE, FF, Opera)
function taosOpenModalDialogNew(pagename, width, height)
{
	var posX = ((screen.availWidth-width)/2);
	var posY = ((screen.availHeight-height)/2);
	
	// Opera doesn't allow windows opened outside of their parent
	if (browser == "Opera")
	{
		posX = (document.body.clientWidth-width)/2;
		posY = (document.body.clientHeight-height)/2;
	}
	
	windowName="taosPopupDialog";
	return window.open(pagename, windowName, 'width='+(width-10)+',height='+(height-96)+',left='+posX+',top='+posY+',status=no,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,titlebar=no,dependent=yes,modal=yes,dialog=yes');
}

// Open a centered window
function taosOpenWindow(pagename, width, height, windowName)
{
	if (!width)
		width=(screen.availwidth-30); 
	if (!height)
		height=(screen.availheight-50);
	if (!windowName)
		windowName="";

	if (browserIsSP2)
		height+=25; // Add space for status bar

	return window.open(pagename, windowName, 'width='+(width-10)+',height='+(height-96)+',left='+((screen.availwidth-width)/2)+',top='+((screen.availheight-height)/2)+',status=no,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,titlebar=no');
}

// Open a centered preview window, with dimensions no greater than maxWidth, maxHeight
function taosOpenPreviewWindow(pagename, maxWidth, maxHeight)
{
	width=(screen.availwidth-30); 
	height=(screen.availheight-50);
	if (width>maxWidth)
		width=maxWidth;
	if (height>maxHeight)
		height=maxHeight;
		
	windowName="preview";
	if (browserIsSP2)
		height+=25; // Add space for status bar

	return window.open(pagename, windowName, 'width='+(width-10)+',height='+(height-96)+',left='+((screen.availwidth-width)/2)+',top='+((screen.availheight-height)/2)+',status=yes,resizable=yes,scrollbars=yes,toolbar=yes,menubar=yes,location=yes,titlebar=yes');
}

// Open a plain (no menus etc) centered window
function taosOpenPlainWindow(pagename, width, height, maxWidth, maxHeight)
{
	if (!width)
		width=(screen.availwidth-30); 
	if (!height)
		height=(screen.availheight-50);
	if (maxWidth && width>maxWidth)
		width=maxWidth;
	if (maxHeight && height>maxHeight)
		height=maxHeight;
	
	if (browserIsSP2)
		height+=25; // Add space for status bar

	return window.open(pagename, '', 'width='+(width-10)+',height='+(height-96)+',left='+((screen.availwidth-width)/2)+',top='+((screen.availheight-height)/2)+',status=no,resizable=yes,scrollbars=no,toolbar=no,menubar=no,location=no,titlebar=no');
}

// Open a centered fullscreen window
function taosOpenFullscreenWindow(pagename)
{
	width=screen.availwidth; 
	height=screen.availheight;

	if (browserIsSP2)
		height+=25; // Add space for status bar

	return window.open(pagename, '', 'width='+(width-10)+',height='+(height-96)+',left='+((screen.availwidth-width)/2)+',top='+((screen.availheight-height)/2)+',status=no,resizable=no,scrollbars=yes,toolbar=no,menubar=no,location=no,titlebar=no');
}

// Open a hidden (offscreen) window
function taosOpenHiddenWindow(pagename)
{
	return window.open(pagename, '', 'width=40,height=100,left='+((screen.availwidth-40)/2)+',top=2000,status=no,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,titlebar=no');
}

// Open a fullscreen window
function taosOpenFullscreen(pagename, windowName)
{
	// Modal code
	/*width=(screen.availwidth);
	height=(screen.availheight);

	return window.showModalDialog(pagename, "", 'dialogWidth:'+width+'px; dialogHeight:'+height+'px; center: no; dialogTop: 0px; dialogLeft: 0px; scroll: no; status: no; resizable: no; help: no;');
	*/
	width=(screen.availwidth-10); 
	height=(screen.availheight-36);

	//if (browserIsSP2)
	//	height+=25; // Add space for status bar

	return window.open(pagename, windowName, 'width='+width+',height='+height+',left=0,top=0,status=no,resizable=yes,scrollbars=no,toolbar=no,menubar=no,location=no,titlebar=no');
}

// Popup message window
function taosOpenMessage(pagename)
{
	height=150;
	if (browserIsSP2)
		height+=25; // Add space for status bar

	showModalDialog(pagename, "", 'dialogWidth: 450px; dialogHeight: "+height+"px; center: yes; scroll: no; status: no; resizable: yes; help: no');
	return false;
}

// Popup message window
function taosOpenOldMessage(title, message, backColor, foreColor, borderColor, taosPublicHtmlRoot)
{
	width=440;
	height=150;
	
	top.oPopup = window.createPopup();
	var oPopBody = top.oPopup.document.body;
	oPopBody.id="popupMessage";
	oPopBody.style.backgroundColor = backColor;
	oPopBody.style.color = foreColor;
	oPopBody.style.border = "solid 2px "+borderColor;
	
	temphtml='<table width="100%" height="21" border="0" cellspacing="0" cellpadding="0" background="/'+taosPublicHtmlRoot+'/gfx/taoswin/smallwintitlebar.gif" UNSELECTABLE="on">'
		+'<tr><td style="font-family: verdana, arial; color: #FFFFFF; font-size: 11px; position: relative; left: 6px; font-weight: bold;" UNSELECTABLE="on">'
		+title
		+'</td></tr></table>'
		+"<table width='100%' cellpadding='0' cellspacing='8' border='0'><tr><td align='center' style='font-family: verdana, arial; font-size: 13px;'>"
		+message
		+"<br><br>"
		+"<input type='button' value='  Ok  ' style='width: 100px; font-family: verdana, arial; font-size: 13px;' onclick='top.oPopup.hide();'><br>"
		+"</td></tr></table>";

	oPopBody.innerHTML = temphtml;
	top.oPopup.show((screen.availWidth-width)/2, (screen.availHeight-height)/2, width, height); //, document.body);
	
	//oPopBody.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=50)";
}

// Close message window
function taosCloseMessage()
{
	if (top.oPopup)
		top.oPopup.hide();
}