var theCurrentLiterature = null;
var inAnimationDown = false;
var inAnimationUp = false;

function CallBackOnFinishDown(inObject)
{
	inAnimationDown = false;
}

function CallBackOnFinishUp(inObject)
{
	inAnimationUp = false;
}

function ShowLiterature(inActive, inTotal)
{
	// if we are currently animating, do nothing
	if (inAnimationDown || inAnimationUp) return;

	// get the id of the clicked element
	var theId = document.getElementById('literature-' + inActive);

	// if the user has clicked on the currently open section, close it
	if (theId == theCurrentLiterature)
	{
		inAnimationUp = true;
		Effect.BlindUp(theCurrentLiterature, {afterFinish: CallBackOnFinishUp});

		theCurrentLiterature = null;
		return;
	}

	// if there is a section open, close it
	if (theCurrentLiterature)
	{
		inAnimationUp = true;
		Effect.BlindUp(theCurrentLiterature, {afterFinish: CallBackOnFinishUp});
	}

	// open the clicked section	
	inAnimationDown = true;
	Effect.BlindDown(theId, {afterFinish: CallBackOnFinishDown});

	// store the currently open section
	theCurrentLiterature = theId;
}

function ValidatePolicyNumber(inForm)
{
	inForm.policyNumber.value = inForm.policyNumber.value.toUpperCase();
	
	var theErrorInvalid = document.getElementById('error-policy-number-invalid');
	var theErrorEmpty = document.getElementById('error-policy-number-empty');

	if (inForm.policyNumber.value == '')
	{
		theErrorEmpty.style.display = 'block';	
		theErrorInvalid.style.display = 'none';	
		return false;
	}
	else
	{
		theErrorEmpty.style.display = 'none';	

		if (inForm.policyNumber.value.match(/^D[0-9]{10}$/))
		{
			theErrorInvalid.style.display = 'none';	
			return true;
		}
		else
		{
			theErrorInvalid.style.display = 'block';	
			return false;
		}
	}		
}

function ShowFundTable()
{
	var theFundManager = escape(document.getElementById('select_fund_manager').value);
	
	agent.call('', 'fund_table', 'fund_table_div', theFundManager, 0);
}

function RedirectForm(inForm, inName, inParameters)
{
	var theWindow = window.open('about:blank', inName, inParameters);
	inForm.target = inName;
	return true;
}
