











































































//Copyright (c) 2000-2003 Microsoft Corporation. All rights reserved.

var g_nFontHeight = 13;
var g_fIsMimeInstalled = false;
var g_sLogonPageGuid = "{57A118C6-2DA9-419d-BE9A-F92B0F9A418B}";


// Declarations for hotkey implementation.
var m_rgHotkeys = new Array();		// Array to hold the collection of Hotkey objects.
var C_HK_NONE = 0;			// Always generate a click event
var C_HK_CB = 1;	// Set this bit to cancel bubbling of the keystroke event.


function AccessFld(o)
{
	return (null != o.length) ? o[0] : o;
}

function openGal(szFieldNameTo, szFieldNameCc, szFieldNameBcc, oMsg)
{
	var rgParams = new Array();
	if (szFieldNameTo != null)
	{
		rgParams["ToName"]   = szFieldNameTo;
		rgParams["CcName"]   = szFieldNameCc;
		rgParams["BccName"]  = szFieldNameBcc;
		rgParams["objMessage"] = oMsg;
	}
	else
	{
		rgParams["fnAddRecip"] = sendToNewMessage;
	}
	rgParams["search"] = g_iDefaultAddrSearch;

	//g_sContactsFolder will not be defined when contacts are segmented out
	if(typeof(g_sContactsFolder) == "string")
		rgParams["contacts"] = g_sContactsFolder;

	rgParams["fCertCheck"] = g_fIsMimeInstalled;
	rgParams["fontHeight"] = g_nFontHeight;
	var nFontHeight = g_nFontHeight - 2;
	var nWidth = 110 + 30 * nFontHeight;
	var nHeight = 210 + 25 * nFontHeight;
	var vRetval = showDlg(MODELESS, g_sBase + "?Cmd=dialog&template=dlg_gal&ver=6.5.7651.60" + "&theme="+g_thid, rgParams, nWidth, nHeight);
}

function sendToNewMessage(sEm)
{
	if (g_fIsIE6Tpl)
		_mimeOpenNewWindow(g_sDrafts + "/?Cmd=new&mailtoaddr="+sEm, true);
	else
		openNewWindow(g_sBase + "/" + g_sDrafts + "/?Cmd=new&mailtoaddr="+sEm,"",700, 500, true);
}

//returns a window object
function openNewWindow(sFileName, sWindowName, nWidth, nHeight, fUsrSize)
{
	if ("newMessageWindow" == sWindowName || "" == sWindowName)
	{
		//generate random window ID
		 sWindowName = new String(Math.round(Math.random() * 100000));
	}

	if (fUsrSize != null && fUsrSize)
	{
		var newHeight = 0;
		var newWidth = 0;
		try
		{
			newHeight = parent.g_iNewWindowHeight;
			newWidth = parent.g_iNewWindowWidth;
			if (newHeight != null)
				nHeight = newHeight;
			if (newWidth != null)
				nWidth = newWidth;
		} catch (e) {}
	}

	return (window.open(sFileName, sWindowName,
		"toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=" +
		nWidth + ",height=" + nHeight));
}


function setAttachOnClick(oAttachments)
{
	var rgAnchors = oAttachments.getElementsByTagName("A");
	if (null != rgAnchors && rgAnchors.length)
	{
		for (i =0; i < rgAnchors.length; i++)
		{
			if (-1 != rgAnchors[i].href.indexOf("translate=0"))
				rgAnchors[i].onclick = OnClick_EmbeddedAttach;
		}
	}
}

function OnClick_EmbeddedAttach()
{
	var szURL = this._href;

	openNewWindow(szURL,"",700, 500);

	window.event.returnValue = false;
	window.event.cancelBubble = true;
}


function getMimeControlVersion()
{
	var oMimeVersion;
	var sMimeControlVersion;

	oMimeVersion = null;
	// ExchangeLegacy 260658 - The version string must be "," separated.  If it isn't, make it so.
	sMimeControlVersion = "0,0,0,0";
	try {
		oMimeVersion = new ActiveXObject( "MimeBhvr.MimeCtlVer" );
		sMimeControlVersion = oMimeVersion.VersionString;
	} catch (e) { }

	sMimeControlVersion = sMimeControlVersion.replace(/\./g,",");
	return sMimeControlVersion;
}

function isMimeControlInstalled()
{
	var oMimeVersion;

	oMimeVersion = null;
	try { oMimeVersion = new ActiveXObject( "MimeBhvr.MimeCtlVer" ); } catch (e) { }
	if (oMimeVersion != null)
		return true;
	else
		return false;
}

// This function can only be called if the browser is IE6
//
function _mimeCheckMimeInstalled ()
{
	if (( typeof g_fIsMimeEnabled != "undefined") && g_fIsMimeEnabled &&
			(getOS(window.navigator.userAgent) >= 5) && isMimeControlInstalled())
	{
		g_fIsMimeInstalled = 1;
		return true;
	}
	else
	{
		return false;
	}
}

function _mimeOpenNewWindow(szFolderURL, fUsrSize)
{
	openNewWindow(g_sBase + (g_sBase.lastIndexOf("/") != (g_sBase.length - 1) ? "/" : "")  + szFolderURL  + ((g_fIsMimeEnabled && g_fIsMimeInstalled)?"&mime=1":""),"",700, 500, fUsrSize);
}

function openEditRuleDialog(rgParams)
{
	var iFontHeight = g_nFontHeight - 2;

	// These values were carefully chosen from line equations (y = mx + b).
	// We do this so the dialog will scale properly as iFontHeight goes from
	// 8 to 16.  If you change them, change them in dlg_rules.js
	//
	var iWidth = (25 * iFontHeight) + 345;
	var iHeight = (13 * iFontHeight) + 385;

	// This function is called to open the edit rule dialog from the viewer
	// or message form.  We must pass in the URL of the message before opening
	// the edit rule dialog.
	//
	showDlg(MODAL, rgParams["URL"] + "/?cmd=editrule", rgParams, iWidth, iHeight);
}

function fnForceImagePaint()
{
	if (window.document.all.dirtyImage == null)
		window.document.body.insertAdjacentHTML("beforeEnd", "<DIV id=\"dirtyImage\" style=\"display:none;\"></DIV>");

	window.document.all.dirtyImage.innerHTML = "<IMG style=\"\" src=\"" + g_szVirtualRoot + "/img/icon-msg-unread.gif\">";
}

// bug 213331 enlarge help window width
//
function LaunchHelp(o)
{
	if (o)
		openNewWindow(AccessFld(o).innerText, "OutlookWebAccessHelp", 640, 540).focus();
	else if (idHelpLinkText != null)
		openNewWindow(AccessFld(idHelpLinkText).innerText, "OutlookWebAccessHelp", 640, 540).focus();
}

function parseURLfor(szWhat)
{
	var re = new RegExp("[?|&]" + szWhat + "=([^&]*)","gi");
	var arr = re.exec(window.document.location.search);
	return ((arr==null) ? null : arr[1]);
}

//returns all characters utf8 encoded
function toUTF8(szInput)
{
	var wch, x, uch = "", szRet = "";

	for (x = 0; x < szInput.length; x++)
	{
		wch = szInput.charCodeAt(x);
		if (!(wch & 0xFF80))
		{
			szRet += "%" + wch.toString(16);
		}
		else if (!(wch & 0xF800))
		{
			uch = "%" + (wch>>6 | 0xC0).toString(16) +
				  "%" + (wch & 0x3F | 0x80).toString(16);
			szRet += uch;
		}
		else
		{
			uch = "%" + (wch >> 12 | 0xE0).toString(16) +
				  "%" + (((wch >> 6) & 0x3F) | 0x80).toString(16) +
				  "%" + (wch & 0x3F | 0x80).toString(16);
			szRet += uch;
		}
	}
	return(szRet);
}

function openNewFolderDialog(szBaseURL, szDisplayName, szVirtualRoot)
{
	var szNewFolderDialog           =   szBaseURL + "?Cmd=dialog&template=dlg_newfolder&ver=6.5.7651.60" + "&theme="+g_thid;
	var rgParams                    =   new Array();
	rgParams["g_Location"]          =   szBaseURL;
	rgParams["g_DisplayName"]		=	szDisplayName;
	rgParams["g_VirtualRoot"]       =   szVirtualRoot;

	var nFontHeight = g_nFontHeight - 2;
	var nWidth = 50 + 20 * nFontHeight;
	var nHeight = 220 + 12 * nFontHeight;
	var hWin = showDlg(MODAL, szNewFolderDialog, rgParams, nWidth, nHeight);
}

function resizeButtons(winDocAll, rgszButtons)
{
	var nWidth = 0;
	for (var i = 0; i < rgszButtons.length; i++)
	{
		var o = winDocAll[rgszButtons[i]];
		if (o != null)
		{
			var n = 0;
			if (o.scrollWidth > o.clientWidth)
				n = o.scrollWidth-o.clientWidth + o.offsetWidth + 8;
			else
				n = o.offsetWidth + 8;

			if (n > nWidth)
				nWidth = n;
		}
	}
	if (nWidth < 50)
		nWidth = 50;

	if (0 < nWidth)
	{
		for (var i = 0; i < rgszButtons.length; i++)
		{
			var o = winDocAll[rgszButtons[i]];
			if (o != null)
				o.style.width = "" + nWidth + "px";
		}
	}
}

function updateNewWindowSize()
{
	try
	{
		var iWidth = window.document.body.clientWidth;
		var iHeight = window.document.body.clientHeight;
		var dMaxPerc = 0.9; //maximum percentage of screen size for a new window dimension
		if (iWidth > (screen.availWidth * dMaxPerc))
		{
			if ((screen.availWidth * dMaxPerc) > 500)
				iWidth = Math.round(screen.availWidth * dMaxPerc);
			else
				iWidth = 500;
		}
		if (iHeight > (screen.availHeight * dMaxPerc))
		{
			if ((screen.availHeight * dMaxPerc) > 550)
				iHeight = Math.round(screen.availHeight * dMaxPerc);
			else
				iHeight = 550;
		}
		opener.parent.g_iNewWindowWidth = iWidth;
		opener.parent.g_iNewWindowHeight = iHeight;
	}
	catch (e) {}
}

function resizeWindow()
{
	var oBody = window.document.body;
	var iHeight = 0;
	var iWidth = 0;
	var bResizeTo = false;
	if ((oBody.clientWidth < oBody.scrollWidth) || (oBody.clientHeight < oBody.scrollHeight)
		|| (iWidth > screen.width) || (iHeight > screen.height))
	{
		iWidth = oBody.scrollWidth + (2 * (parseInt(oBody.currentStyle.marginLeft, 10) + parseInt(oBody.currentStyle.marginRight, 10)));
		if (iWidth > screen.width)
		{
			iWidth = screen.width;
			bResizeTo = true;
		}

		iHeight = oBody.scrollHeight + (2 * (parseInt(oBody.currentStyle.marginTop, 10) + parseInt(oBody.currentStyle.marginBottom, 10)));
		if (iHeight > screen.height)
		{
			iHeight = screen.height;
			bResizeTo = true;
		}
		if (bResizeTo)
			window.resizeTo(iWidth ,iHeight);
		else
			window.resizeBy(iWidth - oBody.clientWidth, iHeight - oBody.clientHeight);
	}
}

function resizeDialog()
{
	var oBody = window.document.body;
	
	// X228193
	// The body attributes have not been scaled to the display yet
	// so we need to call scaleX and scaleY on them so that they are 
	// on the same scale as window.dialogHeight/Width when doing our calculations
	// for sizing the dialog
	//	
	var iCH = scaleY(oBody.clientHeight);
	var iSH = scaleY(oBody.scrollHeight);
	var iCW = scaleX(oBody.clientWidth);
	var iSW = scaleX(oBody.scrollWidth);

	if (iCH != iSH)
	{
		var iHeight = iSH + (parseInt(window.dialogHeight, 10) - iCH) + 20;
		if (iHeight > scaleY(screen.height))
			iHeight = screen.height;
			
		window.dialogHeight = iHeight + "px";
		window.dialogTop = Math.round((screen.availHeight - iHeight) / 2);
	}
	
	if (iCW != iSW)
	{
		var iWidth = iSW + (parseInt(window.dialogWidth, 10) - iCW ) + 20;		

		if (iWidth > scaleX(screen.width))
			iWidth = screen.width;
		window.dialogWidth = iWidth + "px";
		window.dialogLeft = Math.round((screen.availWidth - iWidth) / 2);
	}
}

function getOS(sUserAgent)
{
	var OSVer = 0;
	try
	{
		var iOSVer = sUserAgent.indexOf("Windows NT");
		if (iOSVer >= 0)
			OSVer =  parseInt(sUserAgent.substring (iOSVer+11, sUserAgent.indexOf (".", iOSVer)), 10);
		if (isNaN(OSVer)) OSVer = 0;
	}
	catch(e) {}
	return OSVer;
}

// Constructor for a new Hotkey object. The properties for this object are
// the keycode, the states of the Ctrl, Shift and Alt keys and the Id of the
// element on the page to click when the hotkey is detected.
//
function Hotkey(sKeyStroke, sCmd, iFlags, oElement)
{
	// Initialize the properties of the object.
	//
	this.key = 0;
	this.ctrl = false;
	this.shift = false;
	this.alt = false;
	this.cmd = sCmd;
	this.flags = iFlags;
	this.element = oElement;

	var rgKey = sKeyStroke.split("+");
	for (var i=0; i<rgKey.length; i++)
	{
		if ( "ctrl" === rgKey[i].toLowerCase() )
			this.ctrl = true;
		else if ( "shift" === rgKey[i].toLowerCase() )
			this.shift = true;
		else if ("alt" === rgKey[i].toLowerCase() )
			this.alt = true;
		else if (0 == this.key)
		{
			if (isNaN(parseInt(rgKey[i], 10)))
			{
				var s = rgKey[i].toUpperCase();
				this.key = (isNaN(s.charCodeAt(0)) ? 0: s.charCodeAt(0));
			}
			else
				this.key = parseInt(rgKey[i], 10);
		}
	}
}

function AddHotkey(sKeystroke, sCmd, iFlags)
{
	var oHk = new Hotkey(sKeystroke, sCmd, iFlags);
	var iHash = GenHash(oHk.ctrl, oHk.alt, oHk.shift, oHk.key);
	if (null == m_rgHotkeys[iHash])
		m_rgHotkeys[iHash] = oHk;
}

function ClearHotkeys()
{
	//called from frm_MimeNote.js
	m_rgHotkeys = new Array();
}

// function to take either a Hotkey or an event object and return an 6-digit integer value based on the
// values of the ctrl, alt, shift and keycode properties.
function GenHash(fCtrl, fAlt, fShift, iKey)
{
	var sHash = new String(iKey);
	sHash += (fCtrl ? "1" : "0");
	sHash += (fAlt ? "1" : "0");
	sHash += (fShift ? "1" : "0");
	return(parseInt(sHash, 10));
}

// Function that looks for all Buttons on a page, finds the accelerator key and
// and assigns a Alt+<letter> hotkey assignment for it. This replaces the SetAccessKeys()
// functionality that existed before.
//
function InitButtonHotkeys()
{
	var reAccel = /<U>(.)<\/U>/;
	var o;
	var sKeyStroke;

	var rgBtns = document.body.getElementsByTagName("BUTTON");
	for (var i = 0; i < rgBtns.length; i++)
	{
		o = rgBtns[i];
		var rgRet = reAccel.exec(o.innerHTML);
		if (null != rgRet)
		{
			// Create a new hotkey assignment that will fire if the button is enabled and visible.
			//
			sKeyStroke = "Alt+" + rgRet[1].toUpperCase();
			var oHk = new Hotkey(sKeyStroke, "", C_HK_CB, o);
			var iHash = GenHash(oHk.ctrl, oHk.alt, oHk.shift, oHk.key);
			if (null == m_rgHotkeys[iHash])
				m_rgHotkeys[iHash] = oHk;
		}
	}
}


// Function that takes a keystroke event as argument,
// checks the keycode and the state of the Ctrl, Shift and Alt keys
// and generates a click() if a match is found.
// Parameters:
// 	e - (required) The event object
function CheckHotkeys(e)
{
	if (null == e)
		return;
	var iHash = GenHash(e.ctrlKey, e.altKey, e.shiftKey, e.keyCode);
	if (null == m_rgHotkeys[iHash])
		return;
	var oKey = m_rgHotkeys[iHash];
	if (oKey.flags & C_HK_CB)
	{
		e.cancelBubble = true;
		e.returnValue = false;
	}
	if (null != oKey.element)
	{
		var oElement = oKey.element;
		try
		{
			if(!oElement.disabled)
				oElement.click();
		}
		catch(e) {}
	}
	else
	{
		onCbClick(oKey.cmd, null, true);
	}
}

function isLogonPage(sText)
{
	return (-1 < sText.indexOf(g_sLogonPageGuid));
}

// Open a new window containing the logon page and a message that the session has expired.
// IMPORTANT: This function is to be called only when we are sure that the cookie has expired!!!
//
function showLogonPage(sVRoot, sRedirectUrl, fOpenNew)
{

	if (fOpenNew)
	{
		if (-1 < sRedirectUrl.indexOf("?"))
			sRedirectUrl = sRedirectUrl.substring(0, sRedirectUrl.indexOf("?"));	//strip off any querystring as we will be adding our own.

		if ((0 < sRedirectUrl.length) && (sRedirectUrl.lastIndexOf("/") != (sRedirectUrl.length -1)))
			sRedirectUrl += "/";	// add a trailing slash if missing.

		openNewWindow(sVRoot + "/bin/auth/owalogon.asp?url=" + escape(sRedirectUrl) + "%3Fcmd=close&reason=3", "", 700, 500);
	}
	else
	{
		location.href = sVRoot + "/bin/auth/owalogon.asp?url=" + escape(sRedirectUrl) + "&reason=3";
	}
}

getBrowserVer.ver = null;
function getBrowserVer()
{
	if (getBrowserVer.ver != null)
		return getBrowserVer.ver;

	var iBV = 0;
	var verRegExp=/MSIE \d+.\d+/;
	var oVer = navigator.appVersion.match(verRegExp);

	// no match returns null
	if (oVer != null)
	{
		// we should now have something like "MSIE 6.0"
		var verIExp=/ \d+.\d+/;
		oVer = oVer[0].match(verIExp);

		// no match returns null
		if (oVer != null)
		{
			// we should now have something like "6.0"
			iBV = parseFloat(oVer[0]);

			if (isNaN(iBV))
				iBV = 0;
		}
	}
	getBrowserVer.ver = iBV;
	return iBV;
}

function logOff()
{
	if (event)
	{
		event.cancelBubble = true;
		event.returnValue = false;
	}
	try
	{
		top.g_fWarnOnLogOff=false;
	}
	catch(e){}

	if (null != parent) 
		parent.location = g_sBase + "?Cmd=logoff" + (g_fIsPublic?"&Public=1":"");
}

//******** Request Object Implementation ****************
//Request Object is created by calling new requestFactory
//fnCallBack is called with the request object on the call stack
//Once the callback is called the request object is destroyed automatically
var E_FAIL = (1^ 0x80004005) + 1;
var m_rgRequestFactory = new Array();


function requestFactory(szURL, szCommand, objContext, fnCallBack)
{
	var objXMLHTTP;
	var i=0;
	var iErrCode = 0;

	try
	{
		this.xmlhttp = new ActiveXObject("MSXML2.xmlhttp");
		this.xmlVersion = 2;
	}
	catch(e)
	{
		this.xmlhttp = new ActiveXObject("Microsoft.xmlhttp");
		this.xmlVersion = 1;
	}
	objXMLHTTP = this.xmlhttp;

	if(2 == this.xmlVersion)
	{
		iErrCode = mf_XMLHTTPOpen(objXMLHTTP,szCommand,szURL,true, 3);
	}

	if(E_FAIL == iErrCode) //Fall back to msxml version 1
	{
		this.xmlhttp = new ActiveXObject("Microsoft.xmlhttp");
		this.xmlVersion = 1;
		objXMLHTTP = this.xmlhttp;
	}

	if(1 == this.xmlVersion)
	{
		var iErrCode = mf_XMLHTTPOpen(objXMLHTTP,szCommand,szURL,true, 1);
	}

	if( 0 != iErrCode)
	{
		this.xmlhttp = null;
		throw iErrCode;
		return;
	}

	this.url = szURL;
	this.context = objContext;
	this.index = requestFactory.index;
	this.expand = false;
	this.lockRequest = false;
	if(null != fnCallBack)
	{
		this.callBack = fnCallBack;
		this.xmlhttp.onreadystatechange = new Function("requestDispatch(" + (this.index) + ")");
	}
	m_rgRequestFactory[this.index] = this;
	requestFactory.index += 1;
}
requestFactory.index = 0;


function requestDispatch(iIndex)
{
	//handle readystate here
	var obj = m_rgRequestFactory[iIndex];
	if(null != obj && !obj.lockRequest && 4 == obj.xmlhttp.readystate)
	{
		obj.lockRequest = true;
		if(obj.callBack != null)
			obj.callBack(obj);
		delete m_rgRequestFactory[iIndex];
	}
}
function mf_XMLHTTPOpen(objXMLHTTP,szCommand,szURL,fisAsync, iOpenAttempts)
{
	var i;
	for(i= 0; i < iOpenAttempts; i++)
	{
		try
		{
			objXMLHTTP.open(szCommand, szURL, fisAsync);
			break;
		}
		catch(e)
		{
			if(E_FAIL != e.number || i == iOpenAttempts - 1)
				return(e.number);
		}
	}
	return(0);
}

// sSMTP is the SMTP address or domain to add to the list.
//
// iList is the junk e-mail list
// 0 = Trusted Senders List
// 1 = Trusted Recipients List
// 2 = Junk Senders List
//
// fGalLookup is a flag indicating whether the server should attempt
// to determine if the address is in the GAL or not.
//
// sURL is the URL to the messsage.
//
function addToJunkList(sSMTP, iList, fGalLookup, sURL)
{
	var sCmd = "";
	switch (iList)
	{
		case 0:
			sCmd = "addsender=ts\n";
			break;
		case 1:
			if ((sSMTP == null) || (sSMTP == ""))
				return;
			sCmd = "addrecip=" + sSMTP + "\n" + (fGalLookup ? "gallookup=1\n" : "");
			break;
		case 2:
			sCmd = "addsender=js\n";
			break;
		default:
			return;
	}
	var oReq = new requestFactory(sURL, "POST", new Array(sURL, iList), addToJunkListEnd);
	var oHTTP = oReq.xmlhttp;
	var sBody = "cmd=savejunkemailrule\n" + sCmd;

	oHTTP.setRequestHeader("Accept-Language", g_szAcceptLang);
	oHTTP.setRequestHeader("Content-type", "application/x-www-UTF8-encoded");
	oHTTP.send(sBody);
}

function addToJunkListEnd(oReq)
{
	if (oReq.xmlhttp.status == 200)
	{
		var oXML = oReq.xmlhttp.responseXML;
		if ((oXML != null) && (oXML.xml != ""))
		{
			var oErrNode = oXML.selectSingleNode("a:response/a:rule/a:errorstring");
			if (oErrNode)
			{
				// Some error occurred
				//
				alert(oErrNode.text);
				return;
			}
		}

		var sURL = oReq.context[0];
		var iList = oReq.context[1];
		if ((iList == 2) && (sURL != null) && (sURL != "") && (sURL.indexOf(g_sDelItems) == -1) && (sURL.indexOf(g_sJunkItems) == -1))
			moveToJnkFldr(sURL);
	}
	else
	{
		if (!handleErr(oReq.xmlhttp.status))
			alert(L_ErrJunkSave);
	}
}

function moveToJnkFldr(sURL)
{
	var rgURL = sURL.split("?");
	var rgItems = rgURL[0].split("/");

	// We have to check to see if there is a trailing slash because sometimes it's there, sometimes it's not.
	//
	var sBase = g_sBase;
	if (sBase.charAt(sBase.length -1) == "/")
		sBase = sBase.substring(0, sBase.length - 1);
		
	var sDestURL = sBase + "/" + g_sJunkItems + "/" + rgItems[rgItems.length-1];

	var oReq = new requestFactory(sURL, "MOVE", sURL, moveToJnkFldrEnd);
	var xmlhttp = oReq.xmlhttp;

	if (null == xmlhttp)
		return;

	xmlhttp.setRequestHeader("Destination", sDestURL);
	xmlhttp.setRequestHeader("Content-type", "text/xml");
	xmlhttp.setRequestHeader("Overwrite", "F");
	xmlhttp.setRequestHeader("Translate", "F");
	xmlhttp.setRequestHeader("Allow-rename", "t");
	xmlhttp.send("");
}

function moveToJnkFldrEnd(oReq)
{
	var sURL = oReq.context;
	
	if (oReq.xmlhttp.status == 201)
	{
		if (window.opener == null)
		{
			// in the viewer
			//
			RefreshMessageList(g_szFolder, new Array(sURL));
		}
		else
		{
			// in a form
			//
			try
			{
				window.opener.RefreshMessageList(g_szFolder, new Array(sURL));
			}
			catch (e){}
			self.close();
		}
	}
	else
	{
		if (!handleErr(oReq.xmlhttp.status))
			alert(L_JunkMoveErr);
	}
}

function handleErr(iErr)
{
	switch (iErr)
	{
		case 440:
			showLogonPage(g_szVirtualRoot, g_sBase, true);
			break;
		case 503:
			alert(L_ErrSvcNotAvail);
			break;
		case 12007:
		case 12029:
			alert(L_NetFail);
			break;
		default:
			return false;
	}
	return true;
}

function fmtstr(szFmt, rgArg)
{
	var i;
	var sz = szFmt;
	for (i = 0; i < rgArg.length; i++)
	{
		sz = sz.replace("%" + (i + 1), (rgArg[i] != null) ? rgArg[i] : "");
	}
	return sz;
}

function resizeWells(oTbl)
{
	var i;
	for ( i = 0; i < oTbl.rows.length; i++ )
	{
		var oRow = oTbl.rows[i];
		if (oRow)
		{
			// get the label TD text and we'll check the height of that
			var oTD = oRow.children[0].children[0];
			if (oTD)
			{
				var nLine = oTD .offsetHeight;
				// now get the DIV which is the well we need to size
				var oWell = oRow.children[1].children[0];
				if (oWell)
				{
					oWell.style.overflow = "auto";
					// the +3 is only so that the attachment well doesn't scroll when there is only 1 row of stuff in there, the image
					// in there is taller than the normal text, and so we think there is more than 1 line when there may not be
					oWell.runtimeStyle.height = (oWell .scrollHeight > (nLine+3)) ? 2 * nLine :  (nLine+3);
				}
				else
					oTD.runtimeStyle.height = nLine+3;
			}
		}
	}
}

function scaleX(nVal)
{
	if (getBrowserVer() >= 6)
	{
		nVal *= (screen.deviceXDPI / screen.logicalXDPI);
	}
	return nVal;
}
function scaleY(nVal)
{
	if (getBrowserVer() >= 6)
	{
		nVal *= (screen.deviceYDPI / screen.logicalYDPI);
	}
	return nVal;
}

function showPU(oPU, x, y, w, h, b)
{
	oPU.show(scaleX(x), scaleY(y),scaleX(w), scaleY(h), b);
}

function exists(o)
{
	return (typeof(o) != "undefined" && o != null);
}

var MODAL = 0;
var MODELESS = 1;
var RESIZE = 0x0001;
var STATUS = 0x0002;
var CENTER = 0x0004;
var SCROLL = 0x0008;

function showDlg(iType, sUrl, rgParams, w, h, dwFlgs)
{	
	var sF = "help:no;"

	if (exists(w) && exists(h))
	{
		w = scaleX(w);
		h = scaleY(h);
		sF += "dialogWidth:" + w + "px;dialogHeight:" + h + "px;";
	}

	if (!exists(dwFlgs))
		dwFlgs = RESIZE | CENTER;
	
	sF += "resizable:" + ((dwFlgs & RESIZE)?"yes;":"no;");
	sF += "status:" + ((dwFlgs & STATUS)?"yes;":"no;");
	sF += "scroll:" + ((dwFlgs & SCROLL)?"yes;":"no;");
	sF += "center:" + ((dwFlgs & CENTER)?"yes;":"no;");

	if (iType == MODAL)
		return window.showModalDialog(sUrl, rgParams, sF);
	else
		return window.showModelessDialog(sUrl, rgParams, sF);
}

function trim(sWhat)
{
	return(sWhat.replace(/^\s*|\s*$/g, ""));
}
