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

var m_eMenuItem;
var m_eSubmenu;

function onGroupExpanded()
{
	setTimeout("fnForceImagePaint()",100)
}

function window.onload()
{
	m_iMsgBehaviorID = idMsgViewer.addBehavior(g_szVirtualRoot + "/CONTROLS/view.htc");

	window.onresize();   

	//note g_szVirtualRoot must be set to call fnForceImageRepaint
	 setTimeout("fnForceImagePaint()",100)
}

function window.onresize()
{
	var nHeight = window.document.body.clientHeight -  idMsgViewer.offsetTop-5;
	if( 0 > nHeight)
	{
		nHeight = 0;
	}
	idMsgViewer.runtimeStyle.height = nHeight;
}

function event_exchangeviewer_onerror()
{
	if (event.command == "BDELETE") 
	{
		alert(L_errCantDelete_ErrorMessage);
	}
}

function idMsgViewer_onbeforedelete()
{
	if(!confirm(L_WarningDeletePermanent_Text))
	{
		event.returnValue = false;
	}
}

function changeView(szXMLViewPath)
{
	idMsgViewer.viewDescriptor =   g_szUserBase + g_szFolder + "/?Cmd=getview&View=" + szXMLViewPath;
	idMsgViewer.update();
}

function changePage()
{
	if (event.keyCode == 13)
	{
		idMsgViewer.gotoPage(idPageControl_PageNumInput.value)
	}

}

function updateContext()
{
		
		idPageControl_PageNumInput.value = idMsgViewer.currentPage;
		idPageControl_PageMaxInput.value = idMsgViewer.pageCount;
		
		if(idMsgViewer.pageCount <= 1)
		{
			tdPageControl.style.display = "none";
			
		}
		else
		{
			
			tdPageControl.style.display = "";
			
		}
		 
		 setTimeout("fnForceImagePaint()",100)
		//TODO: IE5 image repaint workaround
		//1 ms seems to work but .1sec is fine
	
}

function ShowHideFolders()
{
	if(window.parent && window.parent.navbar)
	{
		var obj = window.parent.document.all;
		var objFRAMESET=null;
		var i;
		for(i=0; i < obj.length;i++)
		{
			if(obj[i].tagName.toUpperCase()=="FRAMESET")
			{
				objFRAMESET = obj[i];
			}
		}
		if(objFRAMESET)
		{
			if(objFRAMESET.cols == "0,*")
			{
				objFRAMESET.cols = "150,*";
			}
			else
			{
				objFRAMESET.cols = "0,*";
			}           
		}
	}
}

function MoveMessages()
{
	var szParentURL = g_szUserBase;
	var rgParams = new Array(); 
	var szFolderName = g_szFolder;
	var szDialog = g_szUserBase+"?Cmd=dialog&template=dlg_movecopy"
	var szNewFolderDialog = g_szUserBase +"?Cmd=dialog&template=dlg_newfolder"
	var szDataString = "";
	
	if (idMsgViewer.style.display != "none")
	{
		szDataString =  idMsgViewer.getSelectedXML();
	
	
	
		if(szDataString == "")
		{
			alert(L_NoMessagesSelected_Text);
			return(false);
		} 
		
		rgParams["g_OpenerTreeCtrl"]        =   null;
		rgParams["g_CurrentFolderNode"]     =   null;
		rgParams["g_Location"]              =   g_szUserBase;
		rgParams["g_VirtualRoot"]           =   g_szVirtualRoot;
		rgParams["g_NewFolderDialogPath"]   =   szNewFolderDialog;    
		rgParams["g_MoveCopyMode"]          =   "Move";
		rgParams["g_MessageDataString"]     =   szDataString;
		rgParams["out_DestinationURL"]      =   "";
		rgParams["out_ObjectURL"]           =   "";
		rgParams["out_Verb"]                =   "";
		var bMove = window.showModalDialog(szDialog,    rgParams,"dialogHeight:400px;dialogWidth:350px;status:no;resizable:no;help:no;")       
		
		if (bMove)
		{
			idMsgViewer.refreshPage();
		}
	}
}

function persistSortOrder()
{
	//Following code calls the server with a paramerterized url to persist the view descriptor
		
	var objCol = event.col
	if (objCol != null)
	{
		//Note: toUTF8() is defined in webclientutil.js
		var szURL = idMsgViewer.url + "?Cmd=getview&SortBy=" + toUTF8(objCol.colName) + "&SortOrder=" + event.sortDir;
		
		if(persistSortOrder.m_objPersistView== null)
		{
			persistSortOrder.m_objPersistView = new ActiveXObject("Microsoft.xmlhttp")
		}
		persistSortOrder.m_objPersistView.open("GET",szURL, true);
		if(g_szAcceptLang != "" )
		{
			persistSortOrder.m_objPersistView.setRequestHeader("Accept-Language:",g_szAcceptLang);
		}
		persistSortOrder.m_objPersistView.send()
	}
}
persistSortOrder.m_objPersistView = null;

function onCbClick(szCommand, fState)
{
	if(event && event.button == 2)
	{
		return(false);
	}

	switch(szCommand.toUpperCase())
	{
		case "NEWMESSAGE":
				openNewWindow(g_szUserBase + g_szDraftsURL + "/?Cmd=new","",640, 500);
		break;
		case "NEWCONTACT":
			openNewWindow(g_szUserBase + g_szFolder + "/?Cmd=new","",700, 500);
		break;
		case "NEWAPPOINTMENT":
			openNewWindow(g_szUserBase + g_szCalendarURL + "/?Cmd=new","",700, 500);
		break;
		case "MOVECOPY":
			MoveMessages();
		break;
		case "DELETE":              
			idMsgViewer.deleteSelectedItems();
		break;
		case "SHOWFOLDERS":
			ShowHideFolders();
		break;                  
		case "CHECKMESSAGES":
			idMsgViewer.refreshPage();
		break;
		case "ADDRESSBOOK":
			openGal();
		break;      
		case "HELP":
			LaunchHelp();
		break;  
	}
}