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

var	m_dlgArgs =	window.dialogArguments;
var	m_winDocAll	= window.document.all;
var	m_objStartTime;
var	m_objEndTime;
var	m_objStartOnDate;
var	m_objEndByDate;
var	m_rgReturnCommands = m_dlgArgs["rgReturnCommands"]
var	m_rgReturnValues = m_dlgArgs["rgReturnValues"]
var g_cExceptions = m_dlgArgs["cExceptions"]
var	m_msDateDiffStartEnd;

function window.onload()
{
	//+1ms seems to prevent random drops of a second (a JS rounding thing)
	m_objStartTime=new Date(m_dlgArgs["vtStartDate"]+1);//input from the current datepicker settings
	m_objEndTime=new Date(m_dlgArgs["vtEndDate"]+1);
	m_objStartOnDate=new Date(m_dlgArgs["vtStartDate"]+1);
	m_objEndByDate=new Date(m_dlgArgs["vtEndDate"]+1);
	m_objEndByDate.setMonth(m_objEndByDate.getMonth()+3);

	//now init all the fields to the given dates
	//this sets both the dates and times
	idDatepickers.vtLocalDate = m_objStartTime;
	idDatepickers.vtLocalEndDate = m_objEndByDate;
	m_iMsDuration =	m_objEndTime.getTime() - m_objStartTime.getTime();
	var	iDateNumber	= m_objStartTime.getDate();
	var	iWeekdayNumber = m_objStartTime.getDay();
	var	iMonthNumber = m_objStartTime.getMonth();

	chkDOW[iWeekdayNumber].checked = true;
	txtMonthlyDays.value = iDateNumber;
	listMonthlyDay.selectedIndex = iWeekdayNumber + 3;
	listYearlyMonth.selectedIndex =	iMonthNumber;
	txtYearlyDay.value = iDateNumber;
	//calc is this the first/second/third/fourth/last weekday of the month
	var	iR = parseInt(iDateNumber/7);
	listYearlyEach.selectedIndex = iR;
	listYearlyDay.selectedIndex	= iWeekdayNumber + 3;
	listYearlyMonth2.selectedIndex = iMonthNumber;
	
	m_msDateDiffStartEnd = m_objEndTime	- m_objStartTime;
	var	objMsgDataXml =	m_dlgArgs["objMsgDataXml"];
	var	nodeRecurType =	objMsgDataXml.selectSingleNode("messagedata/recurtype");
	if ( -1	< (	(null!=nodeRecurType)?parseInt(nodeRecurType.text):-1) ) //sync	to existing	recur pattern
	{
		switch(Number(nodeRecurType.text))
		{	 
			case 1://daily
				m_winDocAll['optMainPattern'][0].checked=true;
				showMainPattern(0);
				
				var	iWeekPatternBitMask	=	Number(objMsgDataXml.selectSingleNode("messagedata/dow_mask").text);
				if (iWeekPatternBitMask	!= 0)
				{
					m_winDocAll['optDaily'][1].checked=true;
					m_winDocAll['optDaily'][0].checked=false;
				}
				else //default to "days" 
				{
					m_winDocAll['optDaily'][0].checked=true;
					m_winDocAll['optDaily'][1].checked=false;
					m_winDocAll['txtDailyEvery'].value = objMsgDataXml.selectSingleNode("messagedata/interval").text;
				}
				break;
			case 2:	//weekly
				var	iWeekPatternBitMask		=	Number(objMsgDataXml.selectSingleNode("messagedata/dow_mask").text);
				m_winDocAll['txtWeeklyEvery'].value	= objMsgDataXml.selectSingleNode("messagedata/interval").text;
				m_winDocAll["chkDOW1"].checked	= (iWeekPatternBitMask&1)?true:false;
				m_winDocAll["chkDOW2"].checked	= (iWeekPatternBitMask&2)?true:false;
				m_winDocAll["chkDOW3"].checked	= (iWeekPatternBitMask&4)?true:false;
				m_winDocAll["chkDOW4"].checked	= (iWeekPatternBitMask&8)?true:false;
				m_winDocAll["chkDOW5"].checked	= (iWeekPatternBitMask&16)?true:false;
				m_winDocAll["chkDOW6"].checked	= (iWeekPatternBitMask&32)?true:false;
				m_winDocAll["chkDOW7"].checked	= (iWeekPatternBitMask&64)?true:false;
				break;
			case 3://monthly
				m_winDocAll['optMainPattern'][2].checked=true;
				showMainPattern(2);
				
				var iInterval				=	Number(objMsgDataXml.selectSingleNode("messagedata/interval").text);
				var	iWeeklyPatternBitMask	=	Number(objMsgDataXml.selectSingleNode("messagedata/dow_mask").text);
				var iDayOfMonth				=	Number(objMsgDataXml.selectSingleNode("messagedata/dayofmonth").text);

				m_winDocAll['txtMonthlyMonth'].value=iInterval;
				m_winDocAll['txtMonthlyMonths'].value=iInterval;

				if (iDayOfMonth != 0)
				{
					m_winDocAll['idOM1'].checked=true;
					m_winDocAll['idOM2'].checked=false;
					m_winDocAll['txtMonthlyDays'].value=iDayOfMonth;
				}
				else
				{
					var iByPosition		=	Number(objMsgDataXml.selectSingleNode("messagedata/position").text);

					m_winDocAll['idOM1'].checked=false;
					m_winDocAll['idOM2'].checked=true;
					m_winDocAll['txtMonthlyDays'].value=iDateNumber;

					if (iWeeklyPatternBitMask != 0)
					{
						if (iWeeklyPatternBitMask == 0x7f)
						{
							m_winDocAll['listMonthlyDay'].selectedIndex = 0;
						}
						else if (iWeeklyPatternBitMask == 0x3e)
						{
							m_winDocAll['listMonthlyDay'].selectedIndex = 1;
						}
						else if (iWeeklyPatternBitMask == 0x41)
						{
							m_winDocAll['listMonthlyDay'].selectedIndex = 2;
						}
						if (iByPosition == -1)
						{
							m_winDocAll['listMonthlyEach'].selectedIndex = 4;
						}
						else 
						{
							m_winDocAll['listMonthlyEach'].selectedIndex = iByPosition - 1;
						}
					}
					else
					{
						var	WeekDaysBlob	=	Number(objMsgDataXml.selectSingleNode("messagedata/weekdays").text);
						var Interval		=	WeekDaysBlob & 0xFFFF;
						var WeekDays		=	(WeekDaysBlob > 0xFFFF)?((WeekDaysBlob & 0xFFFF0000) >> 16):0;

						m_winDocAll['listMonthlyDay'].selectedIndex = 3 + WeekDays;

						if (Interval == 0xFFFF)
						{
							m_winDocAll['listMonthlyEach'].selectedIndex = 4;
						}
						else 
						{
							m_winDocAll['listMonthlyEach'].selectedIndex = Interval - 1;
						}
					}
				}
				
				break;
			case 4://yearly
				m_winDocAll['optMainPattern'][3].checked=true;
				showMainPattern(3);
				
				var	iMonthPatterBitMask	= Number(objMsgDataXml.selectSingleNode("messagedata/moy_mask").text);
				var listMonthIndex		= (iMonthPatterBitMask.toString(2).length-1) - 1;
				var iDayOfMonth			= Number(objMsgDataXml.selectSingleNode("messagedata/dayofmonth").text);

				if (iDayOfMonth != 0)
				{
					m_winDocAll['optY1'].checked=true;
					m_winDocAll['txtYearlyDay'].value =	iDayOfMonth;
					m_winDocAll['listYearlyMonth'].selectedIndex = listMonthIndex;
				}
				else
				{
					var iByPosition		=	Number(objMsgDataXml.selectSingleNode("messagedata/position").text);
					var	iWeeklyPatternBitMask	=	Number(objMsgDataXml.selectSingleNode("messagedata/dow_mask").text);

					m_winDocAll['optY2'].checked=true;
					m_winDocAll['listYearlyMonth2'].selectedIndex = listMonthIndex;

					if (iWeeklyPatternBitMask != 0)
					{
						if (iWeeklyPatternBitMask == 0x7f)
						{
							m_winDocAll['listYearlyDay'].selectedIndex = 0;
						}
						else if (iWeeklyPatternBitMask == 0x3e)
						{
							m_winDocAll['listYearlyDay'].selectedIndex = 1;
						}
						else if (iWeeklyPatternBitMask == 0x41)
						{
							m_winDocAll['listYearlyDay'].selectedIndex = 2;
						}

						if (iByPosition == -1)
						{
							m_winDocAll['listYearlyEach'].selectedIndex = 4;
						}
						else 
						{
							m_winDocAll['listYearlyEach'].selectedIndex = iByPosition - 1;
						}
					}
					else
					{
						var	WeekDaysBlob	=	Number(objMsgDataXml.selectSingleNode("messagedata/weekdays").text);
						var Interval		=	WeekDaysBlob & 0xFFFF;
						var WeekDays		=	(WeekDaysBlob > 0xFFFF)?((WeekDaysBlob & 0xFFFF0000) >> 16):0;

						m_winDocAll['listYearlyDay'].selectedIndex = 3 + WeekDays;

						if (Interval == 0xFFFF)
						{
							m_winDocAll['listYearlyEach'].selectedIndex = 4;
						}
						else 
						{
							m_winDocAll['listYearlyEach'].selectedIndex = Interval - 1;
						}
					}
				}
				break;
		}
		
		// ********** Range	of recurrence **********************
		// Start Date
		var	szTzDate;
		var	objD;
		if (objMsgDataXml.selectSingleNode("messagedata/patternstart") !=	null &&
			objMsgDataXml.selectSingleNode("messagedata/patternstart").text != "")
		{
			szTzDate = objMsgDataXml.selectSingleNode("messagedata/patternstart").text
			objD = getLocalDateObjFromGMTTime(szTzDate);
			idDatepickers.vtLocalCalDate = objD;
		}
		else
		{
			 idDatepickers.vtLocalCalDate = new Date(m_dlgArgs["vtStartDate"]);
		}

		// Pattern End
		if (objMsgDataXml.selectSingleNode("messagedata/end_type").text == "0")
		{
			// No end date
			objD =	new	Date(m_dlgArgs["vtStartDate"]);
			objD.setMonth(objD.getMonth()+3);
			
			idDatepickers.vtLocalEndCalDate = objD;
		}
		else if (objMsgDataXml.selectSingleNode("messagedata/end_type").text == "1")
		{
			// End after N occurences
			m_winDocAll["optRangeEnd"][1].checked=true;
			m_winDocAll['txtRangeOccurances'].value	= objMsgDataXml.selectSingleNode("messagedata/occurences").text;
			objD =	new	Date(m_dlgArgs["vtStartDate"]);
			objD.setMonth(objD.getMonth()+3);
			idDatepickers.vtLocalEndCalDate = objD;
		}
		else
		{
			// End by date...
			szTzDate = objMsgDataXml.selectSingleNode("messagedata/patternend").text;
			objD = getLocalDateObjFromGMTTime(szTzDate);
			idDatepickers.vtLocalEndCalDate =	objD;
			m_winDocAll["optRangeEnd"][2].checked=true;
		}
	}
	if (null != m_dlgArgs["iWeekdayStartsOn"])
	{
		idDatepickers.firstDayOfWeek = m_dlgArgs["iWeekdayStartsOn"];
	}
}

function event_btnRemoveRecurrence_onclick()
{
	putReturnData("dtStart",m_objEndTime);
	putReturnData("dtEnd",m_objEndTime);
	putReturnData("recur_type","0");
	this.returnValue = 0; //indicates remove 
	window.close();
}

function event_btnCancel_onclick()
{
	this.returnValue = -1; //indicates cancel 
	window.close();
}

//keeps	two	arrays in ssync
//needs	to be called after field validation	and	just before	closing
function putReturnData(szCommand,vData)
{
		var	iX = m_rgReturnCommands.length;
		m_rgReturnCommands[iX] = szCommand;
		m_rgReturnValues[iX] = vData;
}

function event_btnOk_onclick()
{
	var	szError="";
	var	iRangeOccurences;

	if (g_cExceptions > 0)
		if (confirm (L_idsConfirmRemoveExceptions_Text) == false)
			return;

	//first	validate Range entry is	a valid	number if they are selecting it
	if (m_winDocAll['optRangeEnd'][1].checked)
	{
		iRangeOccurences = validateNumber(m_winDocAll['txtRangeOccurances'].value);
		if (isNaN(iRangeOccurences))
		{
			m_winDocAll['txtRangeOccurances'].focus();
			szError	= L_idsRecurrencePatterNotValid_Text;
		}
	}
	if (szError	== "")
	{	
		var	objMsgDataXml =	m_dlgArgs["objMsgDataXml"];
		var	idx=0;
		var	rgCommands = new Array();
		var	iNumber;
		//reset	the	return arrays if not empty
		if (m_rgReturnCommands.length >	0)
		{
			m_rgReturnCommands.length =	0;
			m_rgReturnValues.length	  =	0;
		}
		//Appointment time
		//TODO:	need to	do this	if the user	changes	this here (or make it so he	can't do that?);
		//right	now	just i don't know  send	back the times and let the call	decide
		putReturnData("dtStart",m_objEndTime);
		putReturnData("dtEnd",m_objEndTime);
	
		//Recurrence pattern
		var	iMainPattern = getMainPattern();
		var	eParent	= window.document.all['divRecurPatterns'][iMainPattern];
		objMsgDataXml.selectSingleNode("messagedata/recurtype").text = iMainPattern +	1;
		switch (iMainPattern)
		{
		case 0:
			putReturnData("recur_type","1");
			var	eAllOptDaily = eParent.all['optDaily'];
			for	(var x=0;x<eAllOptDaily.length;x++)
			{
				if (eAllOptDaily[x].checked) break;
			}
			if (x==0)
			{
				putReturnData("daily_type","days");
				iNumber	= validateNumber(eParent.all['txtDailyEvery'].value)
				if (isNaN(iNumber))
				{
					eParent.all['txtDailyEvery'].focus();
					szError	= L_idsRecurrencePatterNotValid_Text;
					break;
				}
				else
				{
					putReturnData("days",iNumber); //every x days 
					objMsgDataXml.selectSingleNode("messagedata/interval").text =	iNumber;
					objMsgDataXml.selectSingleNode("messagedata/dow_mask").text =	0;
				}
			}
			else
			{
			   putReturnData("daily_type","weekdays");
			   var bitMask = 0;
					bitMask	|= 1;
					bitMask	|= 2;
					bitMask	|= 4;
					bitMask	|= 8;
					bitMask	|= 16;
					bitMask	|= 32;
					bitMask	|= 64;
				objMsgDataXml.selectSingleNode("messagedata/dow_mask").text =bitMask;
			}
			break;

		case 1:	//weeks; weekly
			putReturnData("recur_type","2");
			
			var	szDOW="";
			var	eAllChkDOW = eParent.all['chkDOW'];
			iNumber	= validateNumber(eParent.all['txtWeeklyEvery'].value)
			if (isNaN(iNumber))
			{
				eParent.all['txtWeeklyEvery'].focus();
				szError	= L_idsRecurrencePatterNotValid_Text;
				break;
			}
			else
			{
				putReturnData("weeks",iNumber);
				var	iBitMask	=	0;
				objMsgDataXml.selectSingleNode("messagedata/interval").text = iNumber;
				iBitMask = (eParent.all["chkDOW1"].checked)?iBitMask|1:iBitMask;
				iBitMask = (eParent.all["chkDOW2"].checked)?iBitMask|2:iBitMask;
				iBitMask = (eParent.all["chkDOW3"].checked)?iBitMask|4:iBitMask;
				iBitMask = (eParent.all["chkDOW4"].checked)?iBitMask|8:iBitMask;
				iBitMask = (eParent.all["chkDOW5"].checked)?iBitMask|16:iBitMask;
				iBitMask = (eParent.all["chkDOW6"].checked)?iBitMask|32:iBitMask;
				iBitMask = (eParent.all["chkDOW7"].checked)?iBitMask|64:iBitMask;
				if (iBitMask ==	0) //gotta have	at least one day checked
				{
					eParent.all['chkDOW1'].focus();
					szError	= L_idsRecurrencePatterNotValid_Text;
					break;
				}
				else
				{
					objMsgDataXml.selectSingleNode("messagedata/dow_mask").text =	iBitMask;
					putReturnData("dow_mask",iBitMask);
				}
			}
			break;

		case 2:	//monthly_type("day"); month_day; month_number;	("pattern")month_recur1;month_recur2
			putReturnData("recur_type","3");
		  
			if (eParent.all['optMonthly'][0].checked)//day X of	every X	months
			{
				var	iDays =	validateNumber(eParent.all['txtMonthlyDays'].value);
				var	iMonth = validateNumber(eParent.all['txtMonthlyMonth'].value);
				if (isNaN(iDays) ||	iDays >	31)
				{
					eParent.all['txtMonthlyDays'].focus();
					szError	= L_idsRecurrencePatterNotValid_Text;
					break;
				}
				else if	(isNaN(iMonth))
				{
					eParent.all['txtMonthlyMonth'].focus();
					szError	= L_idsRecurrencePatterNotValid_Text;
					break;
				}
				else
				{
					objMsgDataXml.selectSingleNode("messagedata/dayofmonth").text	= iDays;
					objMsgDataXml.selectSingleNode("messagedata/interval").text	= iMonth;
					objMsgDataXml.selectSingleNode("messagedata/dow_mask").text =	0;
					putReturnData("monthly_type","day");
					putReturnData("month_day",iDays);
					putReturnData("month_number",iMonth);
				}
			}
			else
			{
				iNumber	= validateNumber(eParent.all['txtMonthlyMonths'].value);
				if (isNaN(iNumber))
				{
					eParent.all['txtMonthlyMonths'].focus();
					szError	= L_idsRecurrencePatterNotValid_Text;
					break;
				}
				else
				{
					var iDOWMask = 0;
					var iMoDayVal = eParent.all['listMonthlyDay' ].selectedIndex;
					switch(iMoDayVal)
					{
						case 0:
							iDOWMask = 0x7f;
						break;
						case 1:
							iDOWMask = 0x3e;
						break;
						case 2:
							iDOWMask = 0x41;
						break;
					}
					if(0 != iDOWMask)
					{
						objMsgDataXml.selectSingleNode("messagedata/dow_mask").text = iDOWMask;
						objMsgDataXml.selectSingleNode("messagedata/weekdays").text = 0;								
					}
					else//construct the blob
					{
						var WeekDaysBlob = (iMoDayVal-3|0xFFFF0000)<<16;
						var Interval = eParent.all['listMonthlyEach'].value;                                         
						if(-1 == Interval)
						{
							Interval = 0xFFFF;
						}
						objMsgDataXml.selectSingleNode("messagedata/dow_mask").text = 0;
						objMsgDataXml.selectSingleNode("messagedata/weekdays").text = WeekDaysBlob | Interval;                                   				
					}
					objMsgDataXml.selectSingleNode("messagedata/interval").text	= iNumber;										
					objMsgDataXml.selectSingleNode("messagedata/position").text = eParent.all['listMonthlyEach' ].value;		
					putReturnData("monthly_type", "pattern");
					putReturnData("month_recur1", eParent.all['listMonthlyEach'].value	);
					putReturnData("month_recur2", eParent.all['listMonthlyDay'].value);
					putReturnData("month_number2",iNumber);
				}	   
			}
	
			break;

		case 3: //Yearly
			putReturnData("recur_type","4");
			var	iMonthBitMask	=	0;	  //every MMMM DDDD	(every dec 3rd)
			if (eParent.all['optYearly'][0].checked)
			{
				iNumber	= validateNumber(m_winDocAll['txtYearlyDay'].value);
				if (isNaN(iNumber) || iNumber >	31)
				{
					eParent.all['txtYearlyDay'].focus();
					szError	= L_idsRecurrencePatterNotValid_Text;
					break;
				}
				else
				{
					//validate not greater than	the	last day of	selected month
					var	objD = new Date();
					objD.setDate(1);
					objD.setMonth(eParent.all['listYearlyMonth'].selectedIndex + 1)
					objD.setDate(0);
					if (iNumber	> objD.getDate())
					{
						eParent.all['txtYearlyDay'].focus();
						szError	= L_idsRecurrencePatterNotValid_Text;
						break;
					}
					else
					{
						var res,i;
						for(res	= 2, i=0; i	< m_winDocAll['listYearlyMonth'].selectedIndex;i++,res*=2);
						objMsgDataXml.selectSingleNode("messagedata/moy_mask").text =	res;
						objMsgDataXml.selectSingleNode("messagedata/dayofmonth").text	= iNumber;
						objMsgDataXml.selectSingleNode("messagedata/dow_mask").text =	0;
						putReturnData("yearly_type","every");
						putReturnData("year_recur1", eParent.all['listYearlyMonth'].selectedIndex +	1);
						putReturnData("month_day_number", iNumber);
					}
				}
			}
			else
			{
					var iDOWMask = 0;
					var iMoDayVal = eParent.all['listYearlyDay' ].selectedIndex;
					var iMonthIndex = eParent.all['listYearlyMonth2'].selectedIndex;
					switch(iMoDayVal)
					{
						case 0:
							iDOWMask = 0x7f;
						break;
						case 1:
							iDOWMask = 0x3e;
						break;
						case 2:
							iDOWMask = 0x41;
						break;
					}
					if(0 != iDOWMask)
					{
						objMsgDataXml.selectSingleNode("messagedata/dow_mask").text = iDOWMask;
						objMsgDataXml.selectSingleNode("messagedata/weekdays").text = 0;								
					}
					else//construct the blob
					{
						var WeekDaysBlob = (iMoDayVal-3|0xFFFF0000)<<16;
						var Interval = eParent.all['listYearlyEach'].value;                                         
						if(-1 == Interval)
						{
							Interval = 0xFFFF;
						}
						objMsgDataXml.selectSingleNode("messagedata/dow_mask").text = 0;
						objMsgDataXml.selectSingleNode("messagedata/weekdays").text = WeekDaysBlob | Interval;                                   				
					}									
					objMsgDataXml.selectSingleNode("messagedata/position").text = eParent.all['listYearlyEach' ].value;		
					objMsgDataXml.selectSingleNode("messagedata/monthofyear").text = iMonthIndex+1;
					objMsgDataXml.selectSingleNode("messagedata/moy_mask").text = Math.pow(2,iMonthIndex+1);
					putReturnData("yearly_type", "pattern");
					putReturnData("year_recur2", eParent.all['listYearlyEach'  ].value);
					putReturnData("year_recur3", eParent.all['listYearlyDay'   ].value);
					putReturnData("year_recur4", iMonthIndex + 1);
			}
			break;
		}

		if (szError	== "")
		{
			// ********** Range	of recurrence **********************
			eParent	= window.document.all['grpRangeRecurrence'];
			//combine the dates with the times
			
			//m_objStartTime.setFullYear(m_objStartOnDate.getFullYear(),m_objStartOnDate.getMonth(),m_objStartOnDate.getDate());
			//m_objEndTime.setFullYear(m_objStartOnDate.getFullYear(),m_objStartOnDate.getMonth(),m_objStartOnDate.getDate());
			//update the vtstart (first	item in	array always) vtend	(second	in array)
			m_rgReturnValues[0]	= m_objStartTime.getVarDate();
			m_rgReturnValues[1]	= m_objEndTime.getVarDate();
			//zero out the times for startson/endsby date
			idDatepickers.startHours=0;
			idDatepickers.startMinutes=0;
			idDatepickers.endHours=0;
			idDatepickers.endMinutes=0;
			putReturnData("recur_start_month",(	idDatepickers.startMonth ) + 1);
			putReturnData("recur_start_day",idDatepickers.startDate );
			putReturnData("recur_start_year",idDatepickers.startFullYear );
			objMsgDataXml.selectSingleNode("messagedata/patternstart").text = idDatepickers.isoDateUTC;
			if (eParent.all['optRangeEnd'][0].checked) //no end date
			{
				putReturnData("recur_end","none");
				objMsgDataXml.selectSingleNode("messagedata/end_type").text = "0";
				objMsgDataXml.selectSingleNode("messagedata/occurences").text = "0";
			}
			else if	(eParent.all['optRangeEnd'][1].checked) //end after x occurences
			{
				putReturnData("recur_end","occurrences");
				putReturnData("recur_end_occurrences", iRangeOccurences); 
				objMsgDataXml.selectSingleNode("messagedata/occurences").text =	iRangeOccurences;
				objMsgDataXml.selectSingleNode("messagedata/end_type").text = "1";
			}
			else //end by date
			{
				putReturnData("recur_end","date");
				putReturnData("recur_end_month",idDatepickers.endMonth + 1);
				putReturnData("recur_end_day",idDatepickers.endDate);
				putReturnData("recur_end_year",idDatepickers.endFullYear);
				objMsgDataXml.selectSingleNode("messagedata/patternend").text	= idDatepickers.isoEndDateUTC;
				objMsgDataXml.selectSingleNode("messagedata/end_type").text = "2";
				objMsgDataXml.selectSingleNode("messagedata/occurences").text = "0";
			}
			this.returnValue = 1; //indicates setting recurrence  
			window.close();
		}
	}
	if (szError	!= "")
	{
		alert(szError);
	}
}

var	m_iSavedNumber;
function saveNumber(elem)
{
	m_iSavedNumber = event.srcElement.value;
}
//Validates	number by returning	the	valid number or	NaN	(unicode is	converted to ansi number)
function validateNumber(inNum)
{
	var	iEntry = Number(inNum);
	if(isNaN(iEntry))
	{
		//eval each	character looking for unicode and converting...
		var	iCh,chCode,szNewNumber=""; 
		for	(var x=0; x<inNum.length; x++)
		{
			//ASCII	  8	= 0000000000111000
			//UNICODE 8	= 1111111100011000
			//Need to mask off all but the last	5 bits (& 1F)

			iCh	= inNum.charCodeAt(x);
			chCode = Number(iCh.toString(10));
			if (chCode > 0xFF) //unicode
			{
				chCode = (iCh &	0x001f)	| 0x20;
			}
			szNewNumber	+= String.fromCharCode(chCode);
		}
		iEntry = Number(szNewNumber);
	}
	return (iEntry)
}

//returns: 0=daily 1=weekly	2=monthly 3=yearly
//no error checking
function getMainPattern()
{
	ePattern = window.document.all['optMainPattern'];
	for	(var x=0;x<4;x++)
	{
		if (ePattern[x].checked) break;
	}
	return(x);
}

function showMainPattern(idx)
{
	eAllPatterns = window.document.all['divRecurPatterns'];
	for(var	x=0;x<eAllPatterns.length;x++)
	{
		eAllPatterns[x].style.display="none";
	}
	window.document.all['divRecurPatterns'][idx].style.display="";
}

function IsLeapYear(yr)
{
	return (((yr % 4 == 0) && (yr % 100 != 0)) || (yr % 400 == 0))?1:0;
}

function daysInMonth(iMonth, iYear)
{
	return( (2 == iMonth) ? (28+issLeapYear(iYear)):(30+((iMonth+(iMonth>7))%2)));
}
function checkYear(YF)
{
	var	year = parseInt(YF)

	if (!isNaN(year))
	{
		if ((1970 <= year) && (year	<= 2038))
		{		
			return year;
		}
		else if	((70 <=	year) && (year <= 99))
		{		
			return year	+ 1900;
		}
		else if	((0	<= year) &&	(year <= 38))
		{
			return year	+ 2000;	
		}
		else
		{
			return 0;
		}
	}
	else
	{
		return 0;
	}
}
function onDateChanged(iWhich)
{
	if (0==iWhich)
	{
		var iMs1 = m_objStartOnDate.getTime();
		m_objStartOnDate.setFullYear( idDatepickers.startFullYear,idDatepickers.startMonth,idDatepickers.startDate );
		var msDiff = m_objStartOnDate.getTime()-iMs1;
		m_objStartTime.setTime(m_objStartTime.getTime()+msDiff);
		m_objEndTime.setTime(m_objEndTime.getTime()+msDiff);
	}
	else
	{
		m_objEndByDate.setFullYear( idDatepickers.endFullYear,idDatepickers.endMonth,idDatepickers.endDate );
	}
}

var	m_iMsDuration;
function onTimeChanged(iWhich) {

	switch (iWhich)
	{
		case 0:	//start
			//adjust endtime to	maintain duration
			m_objStartTime.setHours(idDatepickers.startHours,idDatepickers.startMinutes,0,0);
			idDatepickers.vtLocalEndTime = idDatepickers.vtLocalDate + m_iMsDuration;
			m_objEndTime.setHours(idDatepickers.endHours,idDatepickers.endMinutes,0,0);
			break;

		case 1:	//end
			//if end before	begin adjust begin to maintain duration
			m_objEndTime.setHours(idDatepickers.endHours,idDatepickers.endMinutes,0,0);
			if (m_objStartTime >= m_objEndTime)
			{
				idDatepickers.vtLocalTime = m_objEndTime.getTime() - m_iMsDuration;
			}
			else
			{
				m_iMsDuration =	m_objEndTime.getTime() - m_objStartTime.getTime();
			}
			break;

		case 2:	//duration (NYI)
			break;
	}
}
