var bHoldSelection = true;	// Retain selected items when reloading message list

<!-- Credits: The following two functions are courtesy of Mozilla.org -->
function getOffsetTop(obj)
{
	var mOffsetTop = obj.offsetTop;
	var mOffsetParent = obj.offsetParent;
	
	while( mOffsetParent )
	{
		mOffsetTop += mOffsetParent.offsetTop;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	
	return mOffsetTop;
}

function getOffsetLeft(obj)
{
	var mOffsetLeft = obj.offsetLeft;
	var mOffsetParent = obj.offsetParent;
	
	while( mOffsetParent )
	{
		mOffsetLeft += mOffsetParent.offsetLeft;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	
	return mOffsetLeft;
}

function menuItemHover(event,hoverFlag)
{
	var eventSrc = ( window.event != null) ? window.event.srcElement : event.currentTarget;
	
	if( eventSrc.id == "idNew" )
	{
		return;
	}

	/*				
		FIXME/TODO: We cannot hover over the gifs because their background is getting 
		messed up for IE and SAFARI. Serenity now!!! 
	*/
	if( inc_browserName == "MSIE" || inc_browserName == "SAFARI" || inc_browserFlavor == "SAFARI" )
	{
		if( eventSrc.tagName == "IMG" || eventSrc.className == "icon" )
		{
			return;
		}
	}

	if (eventSrc.style != null)
	{
		if( hoverFlag )
		{
			if( inc_browserName == "SAFARI" || inc_browserFlavor == "SAFARI" )
			{
				eventSrc.style.color = "black";
				eventSrc.style.backgroundColor = "#B5D5FF";
			}
			else
			{
				eventSrc.style.color = "HighlightText";
				eventSrc.style.backgroundColor = "Highlight";
			}
		}
		else
		{
			eventSrc.style.color = "black";
			eventSrc.style.backgroundColor = "white";
		}
	}
}

var popupDrn = 0;	
function showGwMenu(event,showFlag,drn)
{
	return showGwMenuEx(event, "idPopupMenu", showFlag, drn );
}

function showGwMenuEx(event,id,showFlag,drn)
{
	var divPopupMenu = document.getElementById( id );
	popupDrn = drn;
	
	if( divPopupMenu == null )
	{
		return true;
	}
	
	if( showFlag )
	{
		divPopupMenu.style.display = "block";
		
		if( inc_browserName == "MSIE" )
		{
			var realX = (document.documentElement.scrollLeft + event.clientX);
			var realY = (document.documentElement.scrollTop + event.clientY);
		}
		else if( inc_browserName  == "SAFARI" )
		{
			var realX = event.clientX;
			var realY = event.clientY;
		}
		else
		{
			var realX = (self.pageXOffset + event.clientX);
			var realY = (self.pageYOffset + event.clientY);
		}
		
		var bodyHeight;
		if( inc_browserName == "SAFARI" || inc_browserFlavor == "SAFARI" )
		{
			bodyHeight = document.body.scrollHeight;
		}
		else
		{
			bodyHeight = document.documentElement.clientHeight;
		}
		
		if( bodyHeight  < ( realY + divPopupMenu.offsetHeight ) )
		{
			divPopupMenu.style.top = realY - divPopupMenu.offsetHeight + "px";
		}
		else
		{
			divPopupMenu.style.top = realY + "px";
		}
		
		var left;
		if( document.dir.toLowerCase() == "rtl" )
		{
			if( realX < divPopupMenu.offsetWidth )
			{
				left = realX;
			}
			else
			{
				left = realX - divPopupMenu.offsetWidth;
			}
		}
		else
		{
			if( document.documentElement.clientWidth < ( event.clientX + divPopupMenu.offsetWidth ) )
			{
				left = realX - divPopupMenu.offsetWidth;
			}
			else
			{
				left = realX;
			}
		}
		
		divPopupMenu.style.left = left + "px";
		divPopupMenu.className = "popup popupShow";
		
		return false;
	}
	else
	{
		divPopupMenu.className = "popup popupHide";

		return true;
	}
}

/***************************************************************
* This method is the event handler for 'onclick'
***************************************************************/
function handleNewDropDown(e)
{
	var divNewPopupMenu = document.getElementById( "idNewPopupMenu" );
	
	if( divNewPopupMenu == null )
	{
		return;
	}
	
	//TODO: We probably should get rid of this first check here. Its just a 'fix'
	if( divNewPopupMenu.style.visibility == "" || divNewPopupMenu.style.visibility == "hidden" )
	{
		showNewPopupMenu(1);
	}
	else
	{
		showNewPopupMenu(0);
	}

	if( window.event )
	{
		window.event.cancelBubble = true;
	}
	else
	{
		e.stopPropagation();			
	}
}

/***************************************************************
* This is a bi-di friendly routine. It will set the "left" or "right" position
* based on the "dir" attribute of the document.
***************************************************************/
function setXPosition(obj, value)
{
		if( document.dir.toLowerCase() == "rtl" )
		{
			obj.style.right = value + "px";
		}
		else
		{
			obj.style.left = value + "px";
		}
}

/***************************************************************
* This method does actual work of hiding or showing the popup menu
***************************************************************/
function showNewPopupMenu(flag)
{
	var divNewPopupMenu = document.getElementById( "idNewPopupMenu" );
	var objToolbarChangeItemType = document.getElementById( 'idNew' );
	
	if( divNewPopupMenu == null )
	{
		return;
	}
	
	if( flag )
	{
		var posX = getOffsetLeft(objToolbarChangeItemType) + 5;
		setXPosition( divNewPopupMenu, posX );

		divNewPopupMenu.style.top = ( getOffsetTop(objToolbarChangeItemType) + objToolbarChangeItemType.offsetHeight ) + "px";
		divNewPopupMenu.style.visibility = "visible";
		divNewPopupMenu.style.display = "block";
	}
	else
	{
		divNewPopupMenu.style.visibility = "hidden";
		divNewPopupMenu.style.display = "none";
	}
}

/***************************************************************
* This method performs the action depending on what menu item has
* been 'selected'
***************************************************************/
function handleNewRequest(e, type)
{
	var sUrl = homeURL + "?User.context=" + userContext + "&action=Compose.Action&merge=xsend";
	
	handleNewRequestEx(e, type, sUrl );
}

/***************************************************************
* This method performs the action depending on what menu item has
* been 'selected'
***************************************************************/
function handleNewRequestEx(e, type, sUrl)
{
	var thisEvent = ( e != null ) ? e : window.event;
	//var sUrl = "{VAR Home.url}?User.context={VAR User.context}&action=Compose.Action&merge=xsend";
	
	if( type >= 6 && type <= 10 )
	{
		sUrl = sUrl + "&Item.Compose.method=POST&Item.Folder.id=" + inc_folderId;
	}
	
	if( type == 1 || type == 6 )
	{
		sUrl = sUrl + "&Item.type=Mail";
	}
	else if( type == 2 || type == 7 )
	{
		sUrl = sUrl + "&Item.type=Appointment";
	}
	else if( type == 3 || type == 8 )
	{
		sUrl = sUrl + "&Item.type=Task";
	}
	else if( type == 4 || type == 9 )
	{
		sUrl = sUrl + "&Item.type=Note";
	}
	else if( type == 5 || type == 10 )
	{
		sUrl = sUrl + "&Item.type=Phone";
	}
	
	popoutComposeEx( sUrl, "_blank" );
	showNewPopupMenu(0);
	
	//Take the "hover" effect off, otherwise the next time they open the menu,
	//the last selected item will have the "hover" background/font colors.
	menuItemHover(thisEvent,0);
}


// This needs to be fixed if the current page plans to use the "bUseSame" option
// for more than one window. ViewWin is obviously not sufficient for tracking multiple windows
var uniqueUrl = 1;
var ViewWin = null;
function popout(url, targetWin, h, w, bTouchUrl, bUseSame )
{
	if( bUseSame && ViewWin != null && !ViewWin.closed && ViewWin.name == targetWin )
	{
		ViewWin.focus();
	}
	else
	{
		if (bTouchUrl)
		{
			if (bTouchUrl == 1)
			{
				url += "&z=" + uniqueUrl;
				uniqueUrl++;
			}
		}

		if (h && h > 0)
		{
			height=h;
		}
		else
		{
			height = 600;
		}

		if (w && w > 0)
		{
			width=w;
		}
		else
		{
			width = 800;
		}

		if (screen.width > 0) 
		{
			var w = 480, h = 340;
			if (document.layers) 
			{
				w = window.innerWidth;
				h = window.innerHeight;
			} 
			else 
			{
				w = document.documentElement.clientWidth;
				h = document.documentElement.clientHeight;
			}
			
			winLeft = (screen.width-width)/2;
			winTop = (screen.height-height)/2;
			
			//if( navigator.userAgent.indexOf( "Microsoft Internet Explorer" ) != -1 )
			if( inc_browserName == "MSIE" )
			{
				posLeft = "left";
				posTop = "top";
			}
			else
			{
				posLeft = "screenX";
				posTop = "screenY";
			}
			
			//var winLeft = Math.abs((w-width)/2)+window.screenX, winTop = (Math.abs((h-height)/2)+window.screenY)/1.5;
			//document.write(winLeft+' :: '+winTop);
			//document.write(w+' :: '+h);
		}

		if( bUseSame  )            
			ViewWin=window.open(url, targetWin, 'width='+width+',height='+height+',resizable=yes,menubar=yes,scrollbars=yes,status=yes,' + posLeft + '='+winLeft+',' + posTop + '='+winTop );
		else
			ViewWin = window.open(url, targetWin, 'width='+width+',height='+height+',resizable=yes,menubar=yes,scrollbars=yes,status=yes,' + posLeft + '='+winLeft+',' + posTop + '='+winTop );

		/*--------------------------------------------------------------------------- 
		Have the focus() call happen in the window being loaded because if we do
		it here, and they click on another message before the first gets loaded,
		we wind up having javascript errors.
		-----------------------------------------------------------------------------*/
		if (window.focus)
		{
			ViewWin.focus();
		}
	}
}

//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
function getEventSrc(e)
{
	//IE does NOT pass the event object into the event handler method. We need
	//to retrieve that object from the 'window' object. 
	//KONQUEROR has partial support for window.event and is thus unreliable. We must
	//check for e.currentTarget FIRST and return that if its valid
	return ( e != null && e.currentTarget != null ) ? e.currentTarget : window.event.srcElement;
}

/***********************************************************************
*
**********************************************************************/
function isFreqContactsCached()
{
	var captionWindow = null;
	var retCached = false;
	
	//We need to catch this exception to avoid any JavaScript errors because of ExteNd portlets
	try
	{
		captionWindow = findCaptionWindowEx();
	}
	catch(error)
	{
		captionWindow = null;
	}
	
	if( captionWindow != null )
	{
		retCached = ( captionWindow.cachedFrequentContacts != null ) ? true : false;
	}

	return retCached;
}

/***********************************************************************
* Find the caption window. There are many ways the compose window can
* be launched from...
**********************************************************************/
function popoutComposeEx(url, targetWin, h, w, bTouchUrl, bUseSame )
{
	if( inc_nameCompletionEnabled == true )
	{
		if( inc_gwapVersion >= 6.7 )
		{
			if( inc_lowBandwidth == false )
			{
				if( isFreqContactsCached() == false )
				{
					//download only frequent contacts
					url = url + "&Compose.downloadAddrBook=";
				}
			}
		}
	}

	popout(url,targetWin,h,w,bTouchUrl,bUseSame);
}

//------------------------------------------------------------------------------
// Find the caption window so we can see if the 
// frequent contacts have been cached or not. 
// If not, then we will need to modify the URL, 
// so we get the FCs
//------------------------------------------------------------------------------
function findCaptionWindowEx()
{
	var captionWindow = null;
	var mainWindow = getMainWindow();
	
	if( mainWindow != null )
	{
		captionWindow = mainWindow.frames[ "caption" ];
	}
	
	return captionWindow;
}

/***********************************************************************
*
**********************************************************************/
function getMainWindow()
{
	var win = window;
	var loopCount = 0;

	while( win != null && win.name != userContext && loopCount < 1000 )
	{
		loopCount++;

		if( win.parent != null && win.parent != win )
		{
			win = win.parent;
			continue;
		}
		
		if( win.opener != null )
		{
			win = win.opener;
			continue;
		}
		
	}

	return win;
}

/***********************************************************************
*
**********************************************************************/
function xhandleMsglistPopupMenu(menuItem)
{
	var hiddenAction = document.MessageList.elements[ "Toolbar.button" ];
	var itemDrn = document.MessageList.elements[ "Undefined" ];
	itemDrn.value = popupDrn;
	
	var baseURL = homeURL + "?User.context=" + userContext + inc_providerString + inc_urlFolderType + inc_urlFolderRightsPost + inc_urlFolderRightsDelete;
					
	if( menuItem == 1 ) //reply
	{
		var strUrl = baseURL + "&action=Item.Action&merge=xsend&Url.Item.Reply=1&Item.Read=&Item.Reply=sender&Item.drn=" + popupDrn;

		popout(strUrl, "_blank" );
	}
	else if( menuItem == 2 ) //forward
	{
		var strUrl = baseURL + "&action=Compose.Action&merge=xsend&Item.Enclosure.id=" + popupDrn + "&Url.Enclosure.type=forward&Item.drn=" + popupDrn;

		popout(strUrl, "_blank" );
	}
	else if( menuItem == 3 ) //accept 
	{
		hiddenAction.name = "Item.Accept";
		bHoldSelection = false;
		
		if( isItemSelected() == false )
		{
			itemDrn.name = "Item.drn";
		}
		
		document.MessageList.submit();
	}
	else if( menuItem == 4 ) //decline
	{
		hiddenAction.name = "Item.Decline";
		bHoldSelection = false;
		
		if( isItemSelected() == false )
		{
			itemDrn.name = "Item.drn";
		}
		
		document.MessageList.submit();
	}
	else if( menuItem == 5 ) //complete
	{
		hiddenAction.name = "Item.Complete";
		bHoldSelection = false;
		
		if( isItemSelected() == false )
		{
			itemDrn.name = "Item.drn";
		}
		
		document.MessageList.submit();
	}
	else if( menuItem == 6 ) //delete
	{
		hiddenAction.name = "Item.Delete";
		bHoldSelection = false;
		
		if( isItemSelected() == false )
		{
			itemDrn.name = "Item.drn";
		}
		
		document.MessageList.submit();
	}
	else if( menuItem == 7 ) //readlater
	{
		hiddenAction.name = "Item.ReadLater";
		bHoldSelection = false;
		
		if( isItemSelected() == false )
		{
			itemDrn.name = "Item.drn";
		}
		
		document.MessageList.submit();
	}
	else if( menuItem == 10 ) //markread
	{
		hiddenAction.name = "Item.MarkRead";
		bHoldSelection = false;
		
		if( isItemSelected() == false )
		{
			itemDrn.name = "Item.drn";
		}
		
		document.MessageList.submit();
	}
	else if( menuItem == 11 ) //move
	{
		hiddenAction.name = "Folder.List";
		bHoldSelection = false;
		
		if( isItemSelected() == false )
		{
			itemDrn.name = "Item.drn";
		}
		
		document.MessageList.submit();
	}
	else if( menuItem == 8 ) //properties
	{
		var sUrl = baseURL + "&action=Item.Action&Item.Properties=&Item.Read=&Url.Folder.type=&tab=1&Folder.name=&Folder.id=&merge=msgitem&Item.drn=" + popupDrn + "&Item.Enclosure.id=" + popupDrn;
		popout( sUrl, "ItemView" );
	}
	else if( menuItem == 9 ) //open
	{
		doPopout(popupDrn, "&Url.Folder.type=" + inc_folderType + inc_findUpdateList + inc_rightsDeleteAndPost + inc_sentValue, 0);
	}
	else
	{
		alert( "Unhandled menu item: " + menuItem );
	}
}

var context = "mailbox";
/***********************************************************************
*
**********************************************************************/
function selectTab(contextName)
{
	document.getElementById("gw-tb-" + context).className = "unselected";

	document.getElementById("gw-tb-" + contextName).className = "selected";
	context = contextName;
}

/***********************************************************************
*
**********************************************************************/
function mouseOverTab(name) 
{
	var gwId = document.getElementById("gw-tb-" + name);
	
	if(gwId.className == "unselected") 
	{
		gwId.className = "hover";
	}
}

/***********************************************************************
*
**********************************************************************/
function mouseOutTab(name) 
{
	var gwId = document.getElementById("gw-tb-" + name);
	if(gwId.className == "hover") 
	{
		gwId.className = "unselected";
	}
}
/***************************************************************
* This method will change the number of days displayed in the
* <select> control depending on what month/year are selected
* Used by: Calendar, Compose...
***************************************************************/
listHas = 31;
EndlistHas = 31;
function changeMonth(thisForm, bDueDate)
{
	// This is the current control
	var ctrlCurrentControl; 
	var curList = 0;

	if( inc_browserName == "MSIE" )
	{
		if (bDueDate == 1)
		{
			year = parseInt(thisForm.elements['Calendar.queryEndYear'].value);
			month = parseInt(thisForm.elements['Calendar.queryEndMonth'].value);
			day = parseInt(thisForm.elements['Calendar.queryEndDay'].value);
			ctrlCurrentControl = thisForm.qendday;
		} // if
		else
		{
			year = parseInt(thisForm.elements['Calendar.queryYear'].value);
			month = parseInt(thisForm.elements['Calendar.queryMonth'].value);
			day = parseInt(thisForm.elements['Calendar.queryDay'].value);
			ctrlCurrentControl = thisForm.qday;
		} // else
	}
	else if( inc_browserName == "MOZILLA" || inc_browserName == "FIREFOX" )
	{
		if (bDueDate == 1)
		{
			iSelDay = thisForm.elements['Calendar.queryEndDay'].options.selectedIndex;
			day = parseInt(thisForm.elements['Calendar.queryEndDay'].options[iSelDay].value);
			ctrlCurrentControl = thisForm.elements['Calendar.queryEndDay'];

			iSelMonth = thisForm.elements['Calendar.queryEndMonth'].options.selectedIndex;
			month = parseInt(thisForm.elements['Calendar.queryEndMonth'].options[iSelMonth].value);

			iSelYear = thisForm.elements['Calendar.queryEndYear'].options.selectedIndex;
			year = parseInt(thisForm.elements['Calendar.queryEndYear'].options[iSelYear].value);
		} // if
		else
		{
			iSelDay = thisForm.elements['Calendar.queryDay'].options.selectedIndex;
			day = parseInt(thisForm.elements['Calendar.queryDay'].options[iSelDay].value);
			ctrlCurrentControl = thisForm.elements['Calendar.queryDay'];

			iSelMonth = thisForm.elements['Calendar.queryMonth'].options.selectedIndex;
			month = parseInt(thisForm.elements['Calendar.queryMonth'].options[iSelMonth].value);

			iSelYear = thisForm.elements['Calendar.queryYear'].options.selectedIndex;
			year = parseInt(thisForm.elements['Calendar.queryYear'].options[iSelYear].value);
		} // else
	}
	else
	{
		alert( inc_browserName );
	}

	curMonthDays = 31;
	if (month == 4 || month == 6 || month == 9 || month == 11)
	{
		curMonthDays = 30;
	}
	else if (month == 2)
	{
		isLeap = 0;
		if (year % 4 == 0)
		{
			isLeap = 1;
			if (year % 100 == 0 && year % 400 != 0)
			{
				isLeap = 0;
			}
		}
		
		if (isLeap == 1)
		{
			curMonthDays = 29;
		}
		else
		{
			curMonthDays = 28;
		}
	}

	if (bDueDate)
	{
		curList = EndlistHas;
	} // if
	else
	{
		curList = listHas;
	} // else

	if (curList > curMonthDays)
	{
		// Remove extra days
		iCurSelected = day;
		if( inc_browserName == "MSIE" && ctrlCurrentControl)
		{
			iCurSelected = ctrlCurrentControl.selectedIndex;
		}
		else if( inc_browserName == "MOZILLA" || inc_browserName == "FIREFOX" )
		{
			iCurSelected = ctrlCurrentControl.options.selectedIndex;
		}
	
		for (i = curList; i > curMonthDays; i--)
		{
			if( inc_browserName == "MSIE" && ctrlCurrentControl)
			{
				if (iCurSelected == i-1)
				{
					ctrlCurrentControl.options[iCurSelected].selected = false;
					ctrlCurrentControl.options[i-2].selected = true;
					iCurSelected = i-2;
				}
				
				ctrlCurrentControl.options.remove(i-1);
			}
			else if( inc_browserName == "MOZILLA" || inc_browserName == "FIREFOX" )
			{
				if (iCurSelected == i-1)
				{
					ctrlCurrentControl.options[iCurSelected].selected = false;
					ctrlCurrentControl.options[i-2].selected = true;
					iCurSelected = i-2;
				}
				ctrlCurrentControl.options[i-1] = null;
			}
		}
	}
	else if (curList < curMonthDays)
	{
		// add additional days
		for (i = curList+1; i <= curMonthDays; i++)
		{
			if( inc_browserName == "MSIE" && ctrlCurrentControl)
			{
				var newElem = document.createElement("OPTION");
				newElem.text = i;
				newElem.value = i;
				ctrlCurrentControl.options.add(newElem);
			}
			else if( inc_browserName == "MOZILLA" || inc_browserName == "FIREFOX" )
			{
				iCurSelected = ctrlCurrentControl.options.selectedIndex;
				len = ctrlCurrentControl.options.length;
				ctrlCurrentControl.options[len] = new Option(i, i, false, false);
				ctrlCurrentControl.options[iCurSelected].selected = true;
			}
		}
	}

	if (bDueDate)
	{
		EndlistHas = curMonthDays;
	} // if
	else
	{
		listHas = curMonthDays;
	} // else
}

/********************************************
* Set the focus in username field on the login
* page...
********************************************/
function setFocus()
{
	document.getElementById('username').focus();
	document.getElementById('username').select();
}



/********************************************
* 
********************************************/
function showOptions(event)
{

	var button = document.getElementById( "SettingsButton" );
	var obj = document.getElementById( "Options" );
	
	if( obj.className == "optionsVisible" )
	{
		obj.className = "optionsHidden";
		button.value = inc_SettingsStr_closed;
	}
	else
	{
		obj.className = "optionsVisible";
		button.value = inc_SettingsStr_open;
	}

}


/********************************************
* 
********************************************/
function readLoginSettings()
{	
	// See if a cookie is set for the login settings. Set the form if
	// the user wanted to remember the settings or if the bTempSave 
	// parameter is true.
	var userSettingsCookie = readCookie( "Cookie.User.settings" );
	var aSettings = {};

	// Parse the values out of the cookie string
	if( userSettingsCookie && userSettingsCookie.length > 0 )
	{
		var pairs= userSettingsCookie.split("&");
		var keyval;
		var i= 0;
		for ( ; i < pairs.length; i++)
		{
			keyval= pairs[i].split( "=" );
			aSettings[keyval[0]] = unescape(keyval[1]);
		}
	}

	// We only need to set things if the bTempSave parameter or
	// SaveSettingsCheckbox parameter is present
	if( aSettings['bTempSave'] == "1" ||
		aSettings['SaveSettingsCheckbox'] == "1" )
	{
		// Set the language
		if( document.getElementById("LangSelect") &&
			document.getElementById("LangSelect").value != aSettings['UserLanguage'] )
		{
			document.getElementById("LangSelect").value = aSettings['UserLanguage'];
			handleLangChange();
		}

		// If present, set to low bandwidth
		if( aSettings['LowBandwidthRadio'] == "1" )
			document.getElementById("User.settings.speed.low").checked = true;

		// If present, set to simple interface
		if( aSettings['SimpleCheckbox'] == "1" )
			document.getElementById("User.settings.simple").checked = true;

		// If present, set to "remember my settings" checkbox
		if( aSettings['SaveSettingsCheckbox'] == "1" )
			document.getElementById("User.settings.save").checked = true;
		else
			document.getElementById("User.settings.save").checked = false;

		// If present, set options hidden
		if( aSettings['OptionsHidden'] == "1" &&  
			document.getElementById("Options").className == "optionsVisible")
			showOptions(null);

	}
	else if( aSettings['SaveSettingsCheckbox'] == "0" )
		document.getElementById("User.settings.save").checked = false;


}	// readLoginSettings


/********************************************
* Save login settings to a cookie, "Cookie.User.settings"
* The bTempSave is parameter is set to true if this is to be saved temporarily
* (as in updating the login screen due to a language change) and not "permanently"
* as if the "remember my settings" checkbox was checked.
********************************************/
function saveLoginSettings( bTempSave )
{
	var UserLanguage = document.getElementById("LangSelect");
	var SimpleCheckbox = document.getElementById("User.settings.simple");
	var LowBandwidthRadio = document.getElementById("User.settings.speed.low");
	var SaveSettingsCheckbox = document.getElementById("User.settings.save");
	var OptionsHidden = document.getElementById("Options");

	var sCookie = "";

	if( SaveSettingsCheckbox.checked == true )
		sCookie = "&SaveSettingsCheckbox=1";
	else
		sCookie = "&SaveSettingsCheckbox=0";

	if( UserLanguage && UserLanguage.value && UserLanguage.value != "" )
		sCookie += "&UserLanguage=" + UserLanguage.value;

	if( bTempSave )
		sCookie += "&bTempSave=1";

	if( OptionsHidden.className == "optionsHidden" )
		sCookie += "&OptionsHidden=1";
	
	if( SimpleCheckbox.checked == true )
		sCookie += "&SimpleCheckbox=1";

	if( LowBandwidthRadio.checked == true )
		sCookie += "&LowBandwidthRadio=1";

	document.cookie = "Cookie.User.settings=" + sCookie + ";expires="+(new Date(new Date().getTime()+31104000000)).toGMTString()+";path=/;";;

}	// saveLoginSettings


/********************************************
* Fix up the parameters passed to the server when attempting to login
********************************************/
function fixSettings()
{
	var SimpleCheckbox = document.getElementById("User.settings.simple");
	var LowBandwidthRadio = document.getElementById("User.settings.speed.low");
	var SaveSettingsCheckbox = document.getElementById("User.settings.save");

	if( SimpleCheckbox.checked == true )
		document.getElementById("UserInterface").value = "simple"; 

	if( LowBandwidthRadio.checked == true )
		document.getElementById("LowBandwidth").value = "1"; 

	// Save the user settings
	saveLoginSettings( false );

}	// fixSettings




/********************************************
* To update the message list, call this function
********************************************/
function updateMessageList( sFolderID, bFindUpdateList, bForceUpdateList )
{

	if( bForceUpdateList == 1 || inc_lowBandwidth == false )
	{
// Defect 143591: We need to update the main window even if doing a find because:
//		1) The find may actually be in the main window (using the quick find at the top 
//		   of the message list
//					or
//		2) The message list beneath the find window is the same one containing a posted
//		   or draft item that is edited/sent from the find window and we don't want
//		   to leave an invalid message item in the list.
//		if( bFindUpdateList == false )
//		{
			var dorefresh = true;
			var mainWindow = getMainWindow();
			
			if( mainWindow != null )
			{
				if ( mainWindow.document.getElementById('nomsgitemrefresh') != null )
				{
					dorefresh = false;
				}
				
				if (dorefresh == true && top != null)
				{
					var workspace = mainWindow.frames[ "workspace" ];

					if ( workspace.document.getElementById('msglistRefreshButton') != null ) 
					{
						//also do a refresh if you are in a reply
						workspace.document.getElementById('msglistRefreshButton').onclick();
					} 
					else if( workspace.document.getElementById('calRefreshButton') != null )
					{
						workspace.document.getElementById('calRefreshButton').onclick();
					}
				}    
			}
//		}
// Only do this update if the find window is the opener for the message item
		if( bFindUpdateList == true && window.opener != null && window.opener.name == "wsright" )
//		else
		{
			window.open( homeURL + "?action=Find.Action&User.context=" + userContext + "&Find.UpdateList=1&Find.NewUpdate=1&merge=msglist",  "wsright" );
		}

		if( window.inc_ItemResend && window.inc_ItemResend == true && window.opener != null && window.opener.name == "ItemView" )
			window.opener.close();

	}
}	// updateMessageList

/***************************************************************
* 
***************************************************************/
function doPopout(drn, moreUrl, bIsDraft, bIsEditPost)
{
	if( bIsDraft )
	{
		strUrl = homeURL + "?action=Item.Compose&User.context=" + userContext + "&Item.drn=" + drn + "&merge=xsend" + moreUrl;
//		sTarget = "_blank";
		sTarget = drn;
	}
	else if( bIsEditPost )
	{
		strUrl = homeURL + "?action=Item.EditPost&User.context=" + userContext + "&Item.drn=" + drn + "&Item.Compose.method=POST&Item.Folder.id=" + inc_folderId + "&merge=xsend" + moreUrl;
//		sTarget = "_blank";
		sTarget = drn;
	}
	else
	{
		strUrl = homeURL + "?action=Item.Read&User.context=" + userContext + "&Item.drn=" + drn + "&merge=msgitem" + moreUrl;
		sTarget = "ItemView";
	}

	popout(strUrl, sTarget);
	return false;
} 

/***********************************************************************
 * A helper function for trimming a given string
 **********************************************************************/
function trim(s)
{
	return s.replace( /^\s*|\s*$/g, "" );
}


