//Copyright (c) 2000 Microsoft Corporation.  All rights reserved.
//<script>

var g_iCurFlag = -1;
var g_iCurStatus = -1;
var m_gobjXMLHTTP;
var g_szImagePath;
var m_otblHeader = null;
var g_winDocAll;
var m_otxtBody = null;

function private_getXMLHTTPObj()
{
	if (typeof(m_gobjXMLHTTP) != "OBJECT")
	{
		try
		{
			m_gobjXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
		}  
		catch(e)
		{
			return(false);
		}
	}
	return(true);    
}

function InitBodyHeight( nHeight )
{
	if( null != m_otxtBody )
	{
		var i;
		var objs = m_otxtBody.children;
		for( i = 0; i < objs.length; i++ )
		{
			if( "TABLE" == objs[i].tagName )
			{
				objs[i].border = 0;
				with( objs[i].style )
				{
					overflow = "auto";
					height = "100%";
					backgroundColor = "window";
					borderRight = "threedshadow 2px solid";
					borderTop = "threedshadow 2px inset";
					borderLeft = "threedshadow 2px inset";
					borderBottom = "threedshadow 2px solid"
				}
				break;
			}
		}
	}
}

function window.onload() 
{
	var x=0,iImp=0,iFlag=0;

	g_winDocAll = window.document.all;
	g_szImagePath = g_szVirtualRoot + "/img/";

	window.document.attachEvent("onkeydown",event_onkeydown);

	m_otblHeader = AccessFld(g_winDocAll.tblHeader);
	m_otxtBody = AccessFld(g_winDocAll.txtMsgBody);
	InitBodyHeight();

	var szText = "";
	var iImp = parseInt(g_szImportance);
	if( !isNaN(iImp) )
	{
		if (iImp == 2)
		{
			szText = L_MessageSentWithHighImportance_Text;
		}
		else if (iImp == 0)
		{
			szText = L_MessageSentWithLowImportance_Text;
		}
	}

	var iFlag = parseInt(g_szFlag);
	if( !isNaN(iFlag) )
	{
		//array set in webclientutil.js
		if( 0 < L_rgszFlags[iFlag].length )
		{
			if( szText.length )
			{
				szText += '\r\n' + L_rgszFlags[iFlag];
			}
			else
			{
				szText = L_rgszFlags[iFlag];
			}
		}
	}
	if( 0 < szText.length )
	{
		var obj = AccessFld( g_winDocAll.trStatus );
		obj.style.display = "";

		obj = AccessFld( g_winDocAll.idStatusText );
		obj.style.display = "";
		obj.innerText = szText;
	}
	CheckHeaderFieldsHeight();   
}

function window.onbeforeprint()
{
	if( null != m_otxtBody )
	{
		m_otxtBody._szTitle = document.title;
		document.title = "";

		var objs = m_otxtBody.children;
		for( i = 0; i < objs.length; i++ )
		{
			if( "TABLE" == objs[i].tagName )
			{
				with( objs[i].style )
				{
					overflow = "visible";
					height = "auto";
					borderRight = "";
					borderTop = "";
					borderLeft = "";
					borderBottom = ""
				}
				break;
			}
		}
	}
}

function window.onafterprint()
{
	document.title = m_otxtBody._szTitle;

	InitBodyHeight( m_otxtBody._nHeight );
}

function tbPick(szCommand) 
{
	if(event.button == 2)
	{
	    return(false);
	}
	var szURL  = window.document.location.protocol + "//" + window.document.location.hostname  + window.document.location.pathname + "?Cmd=" + szCommand; 
	var fOpen = true;

	switch(szCommand.toUpperCase()) 
	{
		case "PRINT":
			window.print();
			fOpen=false;
			break;
		
		case "MOVE":
			//Move message function is defined in webclientutil.js
			var szMsgURL = window.document.location.protocol + "//" + window.document.location.hostname  + window.document.location.pathname;
			var szContentClass = "urn:content-classes:news";
			if (MoveMessage(g_szUserBase, szMsgURL, g_szVirtualRoot, szContentClass))
			{
				if (window.opener != null) 
				{
					window.opener.RefreshMessageList();
				}
				self.close();
			}
			fOpen=false;
			break;
		case "DELETE":
			DeleteMessage(szURL, g_szUserBase)
			fOpen=false;
			break;
		case "HELP":
			LaunchHelp();	
			fOpen=false;
			break;            
	}
	if(fOpen)
	{
		var oDate = new Date();
		szURL += "&tzoffset=" + oDate.getTimezoneOffset();
		openNewWindow(szURL, "", 640, 480);
		self.close();     
	}   
	
	return(true);   
}

function event_onkeydown() 
{
	switch(event.keyCode) 
	{   
		case 27:
			window.close();
		break;            
	}
	return(true);
}

function CheckHeaderFieldsHeight()
{
	var fields = m_otblHeader.children[4].children;
	var i;
	var nBegin = 2;
	var nLine = fields[nBegin].children[0].children[0].offsetHeight;
	for( i = nBegin; i < fields.length - 1; i++ )
	{
		var objItem = fields[i].children[1];
		if( objItem )
		{
			objItem = objItem.children[0];
			if( objItem )
			{
				objItem.style.overflow = "visible";
				objItem.runtimeStyle.overflow = "auto";
				objItem.runtimeStyle.height = (objItem.scrollHeight > nLine) ? 2 * nLine : nLine;
			}
		}
	}
}