//Copyright (c) 2000 Microsoft Corporation.  All rights reserved.
//<script>
var g_szImagePath;
var g_szHTTPServerName;
var m_curTab = -1;
var m_objFreeBusyBehavior;

var g_winDocAll=window.document.all;
var g_winDocBody = window.document.body;;
var g_fIsRecurring=false;
var g_rowStatus;
var g_elemStatusText;
var m_fDirtyDateForFb=true;
var m_fIsAllDayEvent=false;

var m_eDateTimePicker;
var m_eAllDayCheckbox;
var m_rgeTimeCell=new Array();
CONST_SAVE_NO         = 0;
CONST_SAVE_EXPLICIT   = 1;
CONST_SAVE_IMPLICIT   = 2;
var g_nMsgSaved = CONST_SAVE_NO;
//will be set to false for new items untill 'save' or 'send' pressed
//$TODO: use this flag to delete new items not explicitly saved 
//(those saved with checknames etc)
var m_fExplicitSave=true;

function window.onload()
{
	g_rowStatus = g_winDocAll['_trStatus'];
	g_elemStatusText = g_winDocAll['_divStatus'];
	m_eDateTimePicker = g_winDocAll['idDatepicker'];
	m_eAllDayCheckbox = g_winDocAll['_chkAllDay'];
	m_eAllDayCheckbox.onclick = onClickAlldayCheckbox;
	m_eAllDayCheckbox.dirty="0";
	m_rgeTimeCell[0]=g_winDocAll['cellT1'];
	m_rgeTimeCell[1]=g_winDocAll['cellT2'];
	//Initialize the global object for use in recipients.js
	g_objDivTo  = g_winDocAll["divTo"];
	g_objDivCc  = g_winDocAll["divCc"];
	g_objDivBcc = g_winDocAll["divBcc"];

	if (g_iInstanceType.length)
	{
		g_iInstanceType = Number(g_iInstanceType);
	}

	var tblHdr = AccessFld(g_winDocAll.subject);
	g_nFontHeight = tblHdr.offsetHeight;
	g_szHTTPServerName = g_szUserBase.substring(0,g_szUserBase.indexOf("/",8));
	g_szImagePath = g_szVirtualRoot + "/img/";
	objMessage.onchecknames = objMessage_OnCheckNames;
	//search the URL parameters to see if this is a new message or not
	var szURLParams = document.location.search.toLowerCase();
	var szType =null;
	if (szURLParams.indexOf("cmd=new") != -1 )
	{
		gfNewMessage = true;
		m_fExplicitSave=false;
	}
	else
	{
		gfNewMessage = false;
		var szURL = objMessage.url;
		var calUID = "/"+g_szFolder + szURL.substring(szURL.lastIndexOf("/"));
		objMessage.setSchemaProperty("CALENDAR:", "UID",  calUID); 
	}
	if(objMessage.contentclass != null && objMessage.contentclass == "")
	{
		objMessage.contentclass = "urn:content-classes:appointment";
	}
	g_winDocBody.scroll = 'no'

	if (!gfNewMessage)
	{
		var szStatus;
		var szVerb="";
		//is this recurring?
		if ("" != g_iInstanceType && "0" != g_iInstanceType) //this is recurring
		{
			g_fIsRecurring=true;
			//hide the datepicker and
			if ("1"==g_iInstanceType)//master or instance show recurence instead of time:
			{
				g_winDocAll['tblDateTime'].parentElement.style.display=""
				g_winDocAll['tblDateTime'].style.display="none";
				g_winDocAll['spanRecurText'].innerText = L_idsHeaderRecurrence_Text + ": " + g_PrintRecurrencePattern;
				g_winDocAll['spanRecurText'].style.display="";
			}
			else //instance show when on statusbar
			{
				//TODO: need to get the pattern for an instance from the server
				//_divStatus.innerText = g_PrintRecurrencePattern;
				//for now simply say it is recurring
				_divStatus.innerText = L_idsRecurringAppointment_Text;
				g_rowStatus.style.display="";
			}
		}
		//check if this is a meeting request
		if (g_objDivTo.innerText + g_objDivCc.innerText + g_objDivBcc.innerText != "") 
		{
			tbSaveAndClose.style.display = "none";
			tbInvite.style.display = "none";
			//show all three fields (incase user wants to add someone)
			required_RecipientRow.style.display = "";
			optional_RecipientRow.style.display = "";
			resources_RecipientRow.style.display ="";
			InitializeRecipientFields(gfNewMessage)
			if (g_winDocAll['requestResponseRow']!=null) g_winDocAll['requestResponseRow'].style.display ="";   

			if (!g_fUserIsOrganizer)
			{
				tbAccept.style.display          =   "";
				tbTentative.style.display       =   "";
				tbDecline.style.display         =   "";
			}
			else
			{
				tbSendUpdate.style.display      = "";
				tbSaveAndClose.style.display    = "";
			}            
			szStatus = (objMessage.importance>1)?L_MessageSentWithHighImportance_Text+"\n":"";
			var iAttStat = objMessage.getSchemaProperty("urn:schemas:calendar:","attendeestatus");
			if(iAttStat == 1)
			{
				szVerb = L_AcceptedOn_Text
			}
			else if(iAttStat == 2)
			{
				szVerb = L_DeclinedOn_Text
			}
			else if(iAttStat == 3)
			{
				szVerb = L_AcceptedTentativelyOn_Text
			}

			//$$$NOTE:force the status to remain hidden until we get a correct attendeestatus 
				iAttStat = -1;

			var objDate = getLocalDateObjFromGMTTime(objMessage.getSchemaProperty("DAV:","creationdate"));
			szStatus += szVerb + ": "+objDate.toLocaleString();         

			if (szStatus.length > 0 && iAttStat != -1)
			{
				_divStatus.innerText = szStatus;
				g_rowStatus.style.display="";
			}

			try
			{
				g_winDocAll['MsgTo'].focus();
			}
			catch(e)
			{
				g_winDocAll['subject'].focus();
			}    

		}
		else //this is an appointment
		{
			g_winDocAll['subject'].focus();
		}
		//intances can't modify recurrence pattern
		if (g_iInstanceType == 2 || g_iInstanceType == 3)
		{
			g_winDocAll.tbRecurrence.style.filter = "alpha(opacity=35)";
			g_winDocAll.recur.notallowed = true;
		}
		else
		{
			g_winDocAll.tbRecurrence.style.filter = "alpha(opacity=100)";
			g_winDocAll['recur'].notallowed = false;
		}
		m_fIsAllDayEvent = ("1" == objMessage.getSchemaProperty("urn:schemas:calendar:","alldayevent"));
	}
	else //new appointment form
	{
		var objD = new Date();
		var iVal;
		g_winDocAll['subject'].focus();

		//parse the url for date
		//must be in order date-month-year to prevent month overflow (ie: Jan 31.setMonth(1)==Feb 31==Mar 2)
		if (iVal = public_getURLparam("dd",szURLParams)) objD.setDate(iVal);
		if (iVal = public_getURLparam("mm",szURLParams)) objD.setMonth(iVal);
		if (iVal = public_getURLparam("yy",szURLParams)) objD.setFullYear(iVal);
		m_eDateTimePicker.vtLocalCalDate = objD;
		m_eDateTimePicker.vtLocalEndCalDate = objD;
		objMessage.setSchemaProperty("urn:schemas:calendar:","dtstart",m_eDateTimePicker.isoDateUTC);
		objMessage.setSchemaProperty("urn:schemas:calendar:","dtend",m_eDateTimePicker.isoEndDateUTC);
		objMessage.setSchemaProperty("urn:schemas:calendar:","alldayevent", 0);
		m_fIsAllDayEvent = false;

	}
	onStartDateChanged.holdTime=m_eDateTimePicker.vtLocalDate;
	onEndDateChanged.holdTime=m_eDateTimePicker.vtLocalEndDate;
	if (m_fIsAllDayEvent)
	{
		m_eAllDayCheckbox.checked=true;  
		onClickAlldayCheckbox();  
	}	  
	if(objMessage.subject != null)
	{
		g_winDocAll("subject").value = objMessage.subject;
	}
	if(objMessage.getSchemaProperty("urn:schemas:calendar:","busystatus") != null && objMessage.getSchemaProperty("urn:schemas:calendar:","busystatus") != "")
	{
	var szBusyStatus =  objMessage.getSchemaProperty("urn:schemas:calendar:","busystatus"); 
	busystatus.value = szBusyStatus.toUpperCase();
	}
	if(objMessage.getSchemaProperty("urn:schemas:calendar:","location") != null)
	{
		g_winDocAll("location").value = objMessage.getSchemaProperty("urn:schemas:calendar:","location");
	}
	InitializeRecipientFields();

	//Initialize importance
	try
	{
		var iImportance = 1;
		iImportance = objMessage.importance;
		if (iImportance != "")
		{
			if (iImportance == "0")
			{
				IMPLOW.click();
			}
			else if(iImportance == "2")
			{
				IMPHIGH.click();
			}
		}
	}
	catch(e)
	{   
	}

	subject.focus();
}

function onClickAlldayCheckbox()
{
	m_fIsAllDayEvent = m_eAllDayCheckbox.checked;
	if (m_fIsAllDayEvent)
	{
		m_rgeTimeCell[0].style.display = "none";
		m_rgeTimeCell[1].style.display = "none";
		busystatus.selectedIndex=1; //free
		busystatus.dirty="1";

	}
	else
	{
		m_rgeTimeCell[0].style.display = "";
		m_rgeTimeCell[1].style.display = "";
		busystatus.selectedIndex=0; //busy
		busystatus.dirty="1";

	}
	m_eAllDayCheckbox.dirty="1"
}

function setStatusText(szStatusText,fAppend,fHide)
{
	g_rowStatus.style.display=(fHide)?"none":"";
	if (fAppend)
	{
		g_elemStatusText.insertAdjacentText("beforeEnd","\r\n" + szStatusText );
	}
	else
	{
		g_elemStatusText.innerText = szStatusText;
	}
}

onClickTabcell.fWhenHidden;
onClickTabcell.fStatusHidden;
onClickTabcell.fHoldAlldayEvent=false;
function onClickTabcell()
{
	var iTab=event.srcElement==g_winDocAll['tabcell'][0]?0:1;
	if (iTab != m_curTab) //user clicked twice quickly
	{
		if (1==iTab)
		{
			mfDisplayTab1("none");
			mfDisplayTab2("");
			g_winDocAll['tabcell'][1].className = "tabselected";
			g_winDocAll['tabcell'][0].className = "tabsunselected";
			g_winDocAll['_btnD1'].popupLocation="topleft";
			g_winDocAll['_btnD2'].popupLocation="topleft";
			g_winDocAll['_btnT1'].popupLocation="topleft";
			g_winDocAll['_btnT2'].popupLocation="topleft";
			g_winDocAll['tdCheckallday'].style.display="none";
			//flag the following to replace state on return
			onClickTabcell.fWhenHidden=("none"==g_winDocAll['trWhen'].style.display);
			onClickTabcell.fStatusHidden=("none"==g_rowStatus.style.display);
			g_winDocAll['trWhen'].style.display = "none";
			g_rowStatus.style.display="none";
			if (g_fIsRecurring) trDatePicker.children[0].style.display="none";//don't display date/time or recurrence pattern row
		}
		else
		{
			mfDisplayTab1("");
			mfDisplayTab2("none");
			g_winDocAll['tabcell'][0].className = "tabselected";
			g_winDocAll['tabcell'][1].className = "tabsunselected";
			g_winDocAll['_btnD1'].popupLocation="bottomleft";
			g_winDocAll['_btnD2'].popupLocation="bottomleft";
			g_winDocAll['_btnT1'].popupLocation="bottomleft";
			g_winDocAll['_btnT2'].popupLocation="bottomleft";
			g_winDocAll['tdCheckallday'].style.display="";
			if (!onClickTabcell.fWhenHidden) g_winDocAll['trWhen'].style.display = "";
			if (!onClickTabcell.fStatusHidden) g_rowStatus.style.display = "";
			if (g_fIsRecurring) trDatePicker.children[0].style.display="";
		}
		if (m_curTab==-1) //this is the first time (load freebusy)
		{ 
			window.document.createStyleSheet(g_szVirtualRoot+"/controls/freebusy.css");
			//once the freebusy behavior is loaded it will fire to FreeBusy_onReady;			
			m_objFreeBusyBehavior = divFreebusy.addBehavior(g_szVirtualRoot+"/controls/freebusy.htc");
		}
		else if ((iTab==1) && (m_FreeBusyIsLoaded==true))
		{            
			if (m_fDirtyDateForFb==true)
			{
				divFreebusy.clearAttendees();
			}    
			FreeBusy_onReady();
		}    
		else  //going to first page
		{
			m_fDirtyDateForFb=false;
		}
		m_curTab = iTab;
	}
}

//collection of all 'TAB1' elements
mfDisplayTab1.rge;
function mfDisplayTab1(szDisplay)
{
	if (null == mfDisplayTab1.rge)
	{
		if (null == g_winDocAll['TAB1'].length)
		{
			mfDisplayTab1.rge=new Array();
			mfDisplayTab1.rge[0]=g_winDocAll['TAB1'];
		}
		else
		{
			mfDisplayTab1.rge=g_winDocAll['TAB1'];
		}
		
	}
	for (var x=0;x<mfDisplayTab1.rge.length;x++)
	{
		mfDisplayTab1.rge[x].style.display=szDisplay;
	}

}

//collection of all 'TAB2' elements
mfDisplayTab2.rge;
function mfDisplayTab2(szDisplay)
{
	if (null == mfDisplayTab2.rge)
	{
		if (null == g_winDocAll['TAB2'].length)
		{
			mfDisplayTab2.rge=new Array();
			mfDisplayTab2.rge[0]=g_winDocAll['TAB2'];
		}
		else
		{
			mfDisplayTab2.rge=g_winDocAll['TAB2'];
		}
	}
	for (var x=0;x<mfDisplayTab2.rge.length;x++)
	{
		mfDisplayTab2.rge[x].style.display=szDisplay;
	}


}

function SaveMessage()
{
	DisableButtons();
	UpdateMessageData();
	objMessage.save();
}

function window.document.onkeydown()
{    
	var fClearKey=false;
	if (event.ctrlKey) 
	{
		if(event.keyCode==75) //ctrl-K = Resolve
		{
			onCbClick("CHKNAMES");
			fClearkey=true;
		}
		else if(event.keyCode==83) //ctrl-S = Save
		{
			onCbClick("SAVE");
			fClearkey=true;
		}
	}
	if (fClearKey)
	{
		event.cancelBubble=true;
		event.returnValue=false;
	}
}

var g_fCloseAfterSave   =   false;
var g_fSendAfterSave    =   false;
var g_fSaveAfterSend    =   false;
var g_fOpenAttach       =   false;
var g_fButtonsDisabled  =   false;
function onCbClick(szCommand, varValue )
{
	if(event && event.button == 2)
	{
		return(false);
	}
	if( g_fButtonsDisabled )
	{
		return(false);
	}
	var szURL = objMessage.url;
	switch(szCommand.toUpperCase())
	{
		case "PRINT":
			window.print();
			break;
		case "ACCEPT":
		case "TENTATIVE":
		case "DECLINE":
			if (false == g_fUserIsOrganizer)
			{
				var oDate = new Date();

				DisableButtons();
				szURL  += "?Cmd=" + szCommand.toLowerCase() + "&tzoffset=" + oDate.getTimezoneOffset(); 
				this.location = szURL;
			}
			else //organizer doesn't need to respond
			{
				alert(L_idsAppointmentOrganizer);  
			}
			break;
		case "SEND":
			if (g_fButtonsDisabled || !mfValidDates()) break;
			if (g_winDocAll['chkResponseRequested'] != null)
			{
				if (g_winDocAll['chkResponseRequested'].checked)
				{
					objMessage.setSchemaProperty('urn:schemas:calendar:','responserequested',1);
				}
				else
				{
					objMessage.setSchemaProperty('urn:schemas:calendar:','responserequested',0);
				}
			}
			else //default to responserequest=1
			{
				objMessage.setSchemaProperty('urn:schemas:calendar:','responserequested',1);
			}
			DisableButtons();
			UpdateMessageData();
			objMessage.send();
			m_fExplicitSave=true;
			break;
		case "SAVE": 
			if (!mfValidDates()) break;
			DisableButtons();
			UpdateMessageData();
			objMessage.save();
			m_fExplicitSave=true;
			break;
		case "SAVEANDCLOSE":
			if (!mfValidDates()) break;
			DisableButtons();
			UpdateMessageData();
			g_fCloseAfterSave = true;
			objMessage.save();
			m_fExplicitSave=true;
			break;
		case "ATTACH":
			if( CONST_SAVE_NO == g_nMsgSaved )
			{
				g_nMsgSaved = CONST_SAVE_IMPLICIT;
				g_fOpenAttach=true;
				SaveMessage();
			}
			else
			{
				openAttach();
			}
			break;        
		case "CHKNAMES": 
			DisableButtons();       
			mf_setRecipients();
			//change the update recipient handler to dislay anr dialog
			objMessage.onupdaterecipients = resolveAllRecipients;
			objMessage.checkNames();
			break;
		case "CANCELINVITE":
			InviteAttendees(false);
			break;
		case "INVITE":
			InviteAttendees(true);
			break;
		case "FLAG":
			alert(L_FeatureNYI_Text);
			break;
		case "RECUR":
			if (!mfValidDates()) break;
			if (g_winDocAll['recur'].notallowed)
			{
				alert(L_idsMustModifySeries_Text);
			}
			else
			{
				openRecurrence();
			}
			break;
		case "DELETE":
			if( szURL.length && szURL != g_szUserBase )
			{
				DisableButtons();
				DeleteMessage(objMessage.url, g_szUserBase)
			}
			else
			{
				self.close();
			}
			break;
		case "HELP":
			LaunchHelp();
			break;
		case "IMPHIGH":
			objMessage.importance = (varValue) ? 2 : 1;
			break;
		case "IMPLOW":
			objMessage.importance = (varValue) ? 0 : 1;
			break;
	}
	return (true);
}

//fired from freebusy.htc when adding a single recip
//event.szRecipientName on the stack
//event.iType = 0:from 1:To(required) 2:Cc(optional) 3:Bcc(resource)
function FreeBusy_onAddRecipient()
{
	objMessage.addRecipients(event.iRecipientType, event.szRecipientName);
	if (g_winDocAll['tbInvite'].style.display != "none")
	{
		InviteAttendees(true);
		eBtnInvite = g_winDocAll['tbInvite'];
		if(eBtnInvite.swapitems != null)
		{
			eBtnInvite.style.display = "none";
			var x;
			var rg_szItems = eBtnInvite.swapitems.split(";");
			for (x=0;x<rg_szItems.length;x++)
			{
				g_winDocAll[rg_szItems[x]].style.display = (g_winDocAll[rg_szItems[x]].style.display == "none")?"":"none";
			}
		}
	}
	onCbClick("CHKNAMES")
}

function openAttach()
{
	var msgURL = objMessage.url;
	var rgParams = new Array();
	rgParams["MessageURL"] = msgURL;
	rgParams["WindowOpener"] = window;
	rgParams["InsertAttachWellAfterElement"] = g_winDocAll("txtMsgBody");
	var szPath  =   g_szUserBase+"?Cmd=dialog&template=dlg_attach";
	var hWin = window.showModelessDialog(szPath, rgParams,"dialogHeight:400px;status:no;resizable:yes;help:no;center:yes;")
}

function FreeBusy_onTimeChange()
{
	//the logic below picks up for 'both'
	if (event.szWhichTimeChanged != 'end')
	{
		m_eDateTimePicker.vtLocalDate = event.objDateStart;
		onStartDateChanged();
	}
	if (event.szWhichTimeChanged != 'start')
	{
		m_eDateTimePicker.vtLocalEndDate = event.objDateEnd;
		onEndDateChanged();

	}
}

var m_FreeBusyIsLoaded  = false;
var m_fGoingToFb=false;
function FreeBusy_onReady()
{
	divFreebusy.allDayEvent = m_fIsAllDayEvent;
	divFreebusy.viewDate = m_eDateTimePicker.vtLocalDate;
	divFreebusy.startDate = m_eDateTimePicker.vtLocalDate;
	divFreebusy.endDate = m_eDateTimePicker.vtLocalEndDate;
	if (required_RecipientRow.style.display == "") //is meeting request
	{
		//is there any unchecked stuff in the input fields?
		m_fGoingToFb = true;
		mf_setRecipients()
		objMessage.checkNames(false);
	}
	else
	{
	
		divFreebusy.addAttendees(null); //places current user
	}
	m_FreeBusyIsLoaded = true;
}

function RecipientField_OnDeleteRecipients()
{
	m_fDirtyDateForFb=true; //forces recip refresh when tabbing to fb page
}

void function UpdateMessageData()
{
	mf_setRecipients();
	if (onStartDateChanged.fDirty || onEndDateChanged.fDirty || m_fIsAllDayEvent)
	{
		if (m_fIsAllDayEvent)
		{
			m_eDateTimePicker.startHours=0;
			m_eDateTimePicker.startMinutes=0;
			m_eDateTimePicker.endHours=24;
			m_eDateTimePicker.endMinutes=0;
		}
		objMessage.setSchemaProperty("urn:schemas:calendar:","dtstart",m_eDateTimePicker.isoDateUTC);
		onStartDateChanged.fDirty=false;
		objMessage.setSchemaProperty("urn:schemas:calendar:","dtend",m_eDateTimePicker.isoEndDateUTC);
		onStartDateChanged.fDirty=false;
	}
	if (g_winDocAll("subject").dirty == "1")
	{
		objMessage.subject = g_winDocAll("subject").value;
		g_winDocAll("subject").dirty="0";
	}    
	if (g_winDocAll("busystatus").dirty == "1")
	{
		objMessage.setSchemaProperty("urn:schemas:calendar:","busystatus",g_winDocAll("busystatus").value);
		g_winDocAll("busystatus").dirty="0";
	}    
	if (g_winDocAll("location").dirty == "1")
	{
		objMessage.setSchemaProperty("urn:schemas:calendar:","location",g_winDocAll("location").value);
		g_winDocAll("location").dirty="0";
	}    
	if (g_winDocAll("txtMsgBody").dirty == "1")
	{
		objMessage.setSchemaProperty("urn:schemas:httpmail:","textdescription",g_winDocAll("txtMsgBody").value);
		g_winDocAll("location").dirty="0";
	}	
	if("0" != m_eAllDayCheckbox.dirty)
	{
		objMessage.setSchemaProperty("urn:schemas:calendar:","alldayevent",(m_eAllDayCheckbox.checked)?"1":"0");
		m_eAllDayCheckbox.dirty="0";
	}

	var szHr	=	String(m_eDateTimePicker.startHours);
	var szMin	=	String(m_eDateTimePicker.startMinutes);
	szHr	= (2 >  szHr.length)?"0" + szHr:szHr;
	szMin	= (2 >  szMin.length)?"0" + szMin:szMin;
	objMessage.addPostData("dtstart_Time", szHr + ":" + szMin);

	szHr	=	String(m_eDateTimePicker.endHours);
	szMin	=	String(m_eDateTimePicker.endMinutes);
	szHr	= (2 >  szHr.length)?"0" + szHr:szHr;
	szMin	= (2 >  szMin.length)?"0" + szMin:szMin;
	objMessage.addPostData("dtend_Time", szHr + ":" + szMin);
}
//RETURNS: true if valid
function mfValidDates()
{
	if (m_eDateTimePicker.vtLocalDate > m_eDateTimePicker.vtLocalEndDate)
	{
		alert(L_EndDateBeforeStartDate_Text);
		return(false);
	}
	return(true);
}

function InviteAttendees(fInvite)
{
	m_eDateTimePicker.unpopall();
	switch(fInvite)
	{
		case true:
			required_RecipientRow.style.display     =   "";
			optional_RecipientRow.style.display     =   "";
			resources_RecipientRow.style.display    =   "";
			if (g_winDocAll['requestResponseRow']!=null) g_winDocAll['requestResponseRow'].style.display ="";   
		break;
		case false:
			required_RecipientRow.style.display     =   "none";
			optional_RecipientRow.style.display     =   "none";
			resources_RecipientRow.style.display    =   "none";
			if (g_winDocAll['requestResponseRow']!=null) g_winDocAll['requestResponseRow'].style.display ="none";
		break;
	} 

	try	
	{
		g_winDocAll['MsgTo'].focus();
	} catch(e){}
}

function DateTimeTable_OnChangeMessageProperty()
{
	var szNameSpace     =   event.nameSpace;
	var szSchema        =   event.schemaProperty;
	var szVal           =   event.value;
	if(szSchema == "alldayevent" && szVal == 1)
	{
		busystatus.selectedIndex = 1;
	}
	objMessage.setSchemaProperty(szNameSpace,szSchema,szVal)
}

function openRecurrence()
{
	var rgParams=new Array();
	var rgReturnCommands=new Array();
	var rgReturnValues=new Array();
	rgParams["objMsgDataXml"]       = objMessage.messageXML;
	rgParams["vtStartDate"]         = m_eDateTimePicker.vtLocalDate;
	rgParams["vtEndDate"]           = m_eDateTimePicker.vtLocalEndDate;
	rgParams["rgReturnCommands"]    = rgReturnCommands;
	rgParams["rgReturnValues"]      = rgReturnValues;
	rgParams["cExceptions"]         = g_cExceptions;
	rgParams["iWeekdayStartsOn"]     = m_eDateTimePicker.firstDayOfWeek;

	var vRetval = window.showModalDialog(g_szUserBase+"?Cmd=dialog&template=dlg_recurrence", rgParams,"dialogHeight:24em;dialogWidth:35em;status:no;resizable:no;help:no;");

	if (vRetval != null && vRetval != -1) //-1 if user canceled the dialog
	{
		if(vRetval==1)  //setting existing recurring pattern
		{
			//the first two items are the start/end times (may have changed)
			if (m_eDateTimePicker.vtLocalDate != rgReturnValues[0])
			{
				m_eDateTimePicker.vtLocalDate = rgReturnValues[0];
				onStartDateChanged.fDirty=true;
			}
			if (m_eDateTimePicker.vtLocalEndDate != rgReturnValues[1])
			{
				m_eDateTimePicker.vtLocalEndDate = rgReturnValues[1];
				onEndDateChanged.fDirty=true;
			}
			for (var x=2;x<rgReturnCommands.length;x++)
			{
				objMessage.addPostData(rgReturnCommands[x], rgReturnValues[x]);
			}
			//now hide/unhide the date/time pickers accordingly
			g_winDocAll['tblDateTime'].parentElement.style.display=""
			g_winDocAll['tblDateTime'].style.display="none";
			g_winDocAll['spanRecurText'].innerText = L_idsHeaderRecurrence_Text + ": " + L_idsRecurringAppointment_Text;
			g_winDocAll['spanRecurText'].style.display="";
			g_fIsRecurring=true;
			if (m_curTab==1) trDatePicker.children[0].style.display="none";//don't display date/time or recurrence pattern row
		}
		else //assume removing pattern(0)
		{
			objMessage.addPostData("recur_type","0");
			g_winDocAll['tblDateTime'].parentElement.style.display=""
			g_winDocAll['spanRecurText'].style.display="none";
			g_winDocAll['tblDateTime'].style.display="";
			g_fIsRecurring=false;
			if (m_curTab==1) trDatePicker.children[0].style.display="";
		}
	}
}

function DisableButtons()
{
	g_fButtonsDisabled = true;

	with( g_winDocAll.idToolbar )
	{
		with( runtimeStyle )
		{
			filter = "alpha(opacity=35)";
			cursor = "wait";
		}
	}
}

//PUBLIC: called from recipients.js
function EnableButtons()
{
	g_fButtonsDisabled = false;

	with( g_winDocAll.idToolbar )
	{
		with( runtimeStyle )
		{
			filter = "alpha(opacity=100)";
			cursor = "hand";
		}
	}
}

void function mf_setRecipients()
{
	if(g_winDocAll["MsgTo"].value != "")
	{
		objMessage.addRecipients(1,g_winDocAll["MsgTo"].value) 
	}
	if(g_winDocAll["MsgCc"].value != "")
	{
		objMessage.addRecipients(2,g_winDocAll["MsgCc"].value) 
	}
	//must always submit resources
	if(g_winDocAll["MsgBcc"].value != "")
	{
		objMessage.addRecipients(3,g_winDocAll["MsgBcc"].value) 
	}
}

//Following four onDateChange events are fired from the datepicker (m_eDateTimePicker)
//functions do not rely on event stack thus callable from anywhere
onStartDateChanged.fDirty=false;
onStartDateChanged.holdTime;
function onStartDateChanged()
{
	onStartDateChanged.fDirty=true;
	onStartDateChanged.holdTime=m_eDateTimePicker.vtLocalDate;
	if (m_curTab==1)
	{
		divFreebusy.viewDate = m_eDateTimePicker.vtLocalDate;
		divFreebusy.startDate = m_eDateTimePicker.vtLocalDate;
		m_fDirtyDateForFb=false;
	}
	else
	{
		m_fDirtyDateForFb=true;
	}
}

onEndDateChanged.fDirty=false;
onEndDateChanged.holdTime;
function onEndDateChanged()
{
	onEndDateChanged.fDirty=true;
	onEndDateChanged.holdTime = m_eDateTimePicker.vtLocalEndDate;
	if (m_curTab==1)
	{
		divFreebusy.endDate = m_eDateTimePicker.vtLocalEndDate;
		m_fDirtyDateForFb=false;
	}
	else
	{
		m_fDirtyDateForFb=true;
	}
}
function onStartTimeChanged()
{
	//maintain duration
	var iDur = (null==onStartDateChanged.holdTime) ? 0 : (onEndDateChanged.holdTime - onStartDateChanged.holdTime);
	m_eDateTimePicker.vtLocalEndDate = m_eDateTimePicker.vtLocalDate + iDur;
	onEndDateChanged();
	onStartDateChanged();
}
function onEndTimeChanged()
{
	onEndDateChanged();
}

