











































































//Copyright (c) 2000-2003 Microsoft Corporation. All rights reserved.
//<script>

var aOffsets = new Array(0, 300, 600, 900, 1800, 3600, 7200, 14400, 28800, 43200, 86400, 172800);
var m_oOptionsForm = null;
var m_bSignatureIsDirty = false;

// enablereminder is a bitmap:
// Playsound				== 0x1
// Calendar reminders	== 0x4
// Task reminders			== 0x8
//
// Note: 0x2 bit is NOT set to correct from prev non-bitmapped values
// of 0,1, or 2 for calendar reminders
//
var CONST_B_SOUND = 0x1;
var CONST_B_CALENDAR = 0x4;
var CONST_B_TASKS = 0x8;

//used by options and composenoteprolog.
//
function CalculateIndex(szOffset)
{
	var i, lo=0, hi;
	for (i=0;i<aOffsets.length-1;i++)
	{
		hi = aOffsets[i] + (aOffsets[i+1]-aOffsets[i])/2;
		if (szOffset >= lo && szOffset < hi) return i;
		lo = hi;
	}
	if (szOffset >= lo) return i;
	return -1;
}

function OptionsOnLoad()
{
	var iResult = 0;
	m_oOptionsForm = document.OptionsPageForm;

	// if element m_oOptionsForm["http://schemas.microsoft.com/exchange/enablereminders"]
	// is null, no reminder options are enabled
	//
	if (null != m_oOptionsForm["http://schemas.microsoft.com/exchange/enablereminders"])
	{
		if (null != m_oOptionsForm.enablereminders)
		{
			m_oOptionsForm.enablereminders.checked = (CONST_B_CALENDAR == (g_bmpEnableReminders & CONST_B_CALENDAR))? true : false;
			m_oOptionsForm["http://schemas.microsoft.com/exchange/enablereminders"].value = (g_bmpEnableReminders & CONST_B_CALENDAR);

			var iRemCal = parseInt(m_oOptionsForm["http://schemas.microsoft.com/exchange/enablereminders"].value, 10);
			if (isNaN(iRemCal) || (iRemCal != 4))
				iRemCal = 0;

			iResult = iRemCal;
		}

		if (null != m_oOptionsForm["taskreminders"])
		{
			m_oOptionsForm.enabletaskreminders.checked = (CONST_B_TASKS == (g_bmpEnableReminders & CONST_B_TASKS))?  true : false;
			m_oOptionsForm["taskreminders"].value = (g_bmpEnableReminders & CONST_B_TASKS);

			var iRemTask = parseInt(m_oOptionsForm["taskreminders"].value, 10);
			if (isNaN(iRemTask) || iRemTask != 8)
				iRemTask = 0;

			iResult += iRemTask;
		}

		if ((iResult != 0) || (null !=  m_oOptionsForm.enablereminders) || (null != m_oOptionsForm["taskreminders"]) )
			m_oOptionsForm.remindersound.checked = (CONST_B_SOUND == (g_bmpEnableReminders & CONST_B_SOUND)) ? true: false;
		else
			m_oOptionsForm.remindersound.checked = false;

		if (null != m_oOptionsForm["http://schemas.microsoft.com/exchange/reminderinterval"])
			m_oOptionsForm["http://schemas.microsoft.com/exchange/reminderinterval"].selectedIndex=CalculateIndex(g_szDefaultReminder);

	}

	if (g_bSignatureUI == true)
	{
		if (m_oOptionsForm["http://schemas.microsoft.com/exchange/signaturetext"].value == "")
		{
			m_oOptionsForm["http://schemas.microsoft.com/exchange/signaturetext"].value = g_szSignatureDefault;
			m_bSignatureIsDirty = false;
		}
	}


}

function onClickEnableRemindersCheckbox()
{

	if (null != m_oOptionsForm["http://schemas.microsoft.com/exchange/enablereminders"])
	{
		if (null != m_oOptionsForm.enablereminders)
			m_oOptionsForm["http://schemas.microsoft.com/exchange/enablereminders"].value = (m_oOptionsForm["enablereminders"].checked==true)? 4 : 0;
		if (null != m_oOptionsForm["http://schemas.microsoft.com/exchange/reminderinterval"])
			m_oOptionsForm["http://schemas.microsoft.com/exchange/reminderinterval"].selectedIndex=CalculateIndex(g_szDefaultReminder);
	}

	if (null != m_oOptionsForm["taskreminders"])
		m_oOptionsForm["taskreminders"].value = (m_oOptionsForm.enabletaskreminders.checked)? 8 : 0;
}

function calcRemVal()
{
	var iResult = 0;

	// Since prop 'http://schemas.microsoft.com/exchange/enablereminders' is the value
	// that must be set to enable reminder(s); if this hidden input for the prop is null, it
	// means that no reminders are enabled
	//
	if (null != m_oOptionsForm["http://schemas.microsoft.com/exchange/enablereminders"])
	{
		var iRemCal = parseInt(m_oOptionsForm["http://schemas.microsoft.com/exchange/enablereminders"].value, 10);
		if (isNaN(iRemCal) || (iRemCal != 4))
			iRemCal = 0;

		iResult = iRemCal;

		if (null != m_oOptionsForm["taskreminders"])
		{
			var iRemTask = parseInt(m_oOptionsForm["taskreminders"].value, 10);
			if (isNaN(iRemTask) || (iRemTask != 8))
				iRemTask = 0;


			iResult += iRemTask;
		}
		if (null != m_oOptionsForm["remindersound"])
		{
			var iRemSnd = (m_oOptionsForm["remindersound"].checked) ? 1 : 0;
			iResult += iRemSnd;
		}
		// can't have value of sound only
		//
		if (iResult == 1)
			iResult = 0;

		m_oOptionsForm["http://schemas.microsoft.com/exchange/enablereminders"].value = iResult.toString();
	}

}
function SaveOptions()
{
	if (fValidate())
	{
		calcRemVal();
		m_oOptionsForm.submit();
	}
}

function openChangePassword()
{
	var szURL = "https://" + window.location.host + "/iisadmpwd/" + g_szChangePasswordPage + "/?Cmd=close";
	var szOpts = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=355,height=350";
	window.open(szURL,0,szOpts);
}

function _chkAutoAddSignature_onclick()
{
	m_oOptionsForm["http://schemas.microsoft.com/exchange/autoaddsignature"].value = (m_oOptionsForm["enableautosignature"].checked==true ? "1" : "0");
}

function onBlockExternalContent()
{
	m_oOptionsForm["http://schemas.microsoft.com/exchange/blockexternalcontent"].value = (m_oOptionsForm["chkBlockExtern"].checked==true ? "1" : "0");
}

function txtSignature_onchange()
{
	m_bSignatureIsDirty = true;
}

function fValidate()
{
	//Insert hooks to future validation routines here.

	var fResult = true;

	if (g_bSignatureUI == true)
		fResult = fResult && fValidateAndSaveSignature();

	return fResult;
}

function fValidateAndSaveSignature()
{
	var szSignature = m_oOptionsForm["http://schemas.microsoft.com/exchange/signaturetext"].value;
	if (m_bSignatureIsDirty == false)
	{
		//signature has not been modified. Don't save the default signature.
		if (szSignature == g_szSignatureDefault)
		{
			szSignature = "";
		}
		return true;
	}
	if (szSignature.length > g_iSignatureMaxLength)
	{
		alert(L_SigTooLarge);
		return false;
	}
	else
	{
		m_oOptionsForm["http://schemas.microsoft.com/exchange/signaturetext"].value = szSignature;
		m_oOptionsForm["dlsignaturemodified"].value = "1";	// Downlevel save wipes out the html signature.
		return true;
	}
}

function enableJunkOptions()
{
	var oJunkEmailState = m_oOptionsForm["junkemailstate"];
	var fChecked = m_oOptionsForm["_chkEnableJunkFiltering"].checked;

	if (oJunkEmailState != null)
	{
		oJunkEmailState.value = (fChecked ? "1" : "0");
	}
}


