//Hides the unneeded inputs, attaches event listeners to the radio buttons
function body_Load()
{
	var salaryContainer=document.getElementById('SalaryContainer');
	var alternateDateContainer=document.getElementById('AlternateDateContainer');
	var salaryTextBox=document.getElementById(IDPREFIX+'SalaryTextBox');
	var radioList=0;
	var i;
	attachEventListener('focus',salaryTextBox,textBox_Focus);
	attachEventListener('blur',salaryTextBox,textBox_Blur);
	salaryContainer.style.visibility='hidden';
	alternateDateContainer.style.visibility='hidden';

	radioList=document.forms[0][NAMEPREFIX+'ResultTypeRadioButtonList'];
	for(i=0;i<radioList.length;i++)
	{
		attachEventListener('click',radioList[i],changeSalaryVisibility);
	}
	simulateClick(getCheckedRadio(radioList));
	radioList=document.forms[0][NAMEPREFIX+'SingleMonthOrTwoMonthsComparisonRadioButtonList'];
	for(i=0;i<radioList.length;i++)
	{
		attachEventListener('click',radioList[i],changeAlternateDateVisibility);
	}
	simulateClick(getCheckedRadio(radioList));
}
//When non-default values are selected in a radio button group and the page is
//loaded from the cache / history some elements might have the wrong style applied to them. This method simulates
//clicks on the radios thus forcing the browser to reapply the styles
function simulateClick(element)
{
	if((document.createEvent) && (dispatchEvent))//DOM Level 2
	{
		var evt=document.createEvent('MouseEvents');
		if(!evt.initMouseEvent) {return;}
		evt.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
		element.dispatchEvent(evt);
	}
	else if(element.click)//MSIE
	{
		element.click();
	}
}
//Change event handler for ResultTypeRadioButtonList
function changeSalaryVisibility(e)
{
	var evt=new CommonEvent(e);
	if(!evt.sender.value){return;}//Gecko needs this as we might get here with an non-input element (i.e an html document)
	var salaryContainer=document.getElementById('SalaryContainer');
	if(-1!=getCheckedRadio(document.forms[0][evt.sender.name]).value.indexOf('Calculation'))//Calculation requested means we show the salary inputs
	{
		salaryContainer.style.visibility='visible';
	}
	else
	{//We are hiding the inputs, if an invalid value is stored in the salary TextBox it is removed along with the notification about it
		if(!Page_ClientValidate())
		{
			document.getElementById(IDPREFIX+'SalaryTextBox').value='';
			Page_ClientValidate();
		}
		salaryContainer.style.visibility='hidden';
	}
}
//Change event handler for SingleMonthOrTwoMonthsComparisonRadioButtonList
function changeAlternateDateVisibility(e)
{
	var evt=new CommonEvent(e);
	var alternateDateContainer=document.getElementById('AlternateDateContainer');
	if(-1!=getCheckedRadio(document.forms[0][evt.sender.name]).value.indexOf('Two'))//Two months mean we show the alternate inputs
	{
		alternateDateContainer.style.visibility='visible';
	}
	else
	{
		alternateDateContainer.style.visibility='hidden';
	}
}
//Checks that salary is in the form of is a positive integer/float
function validateSalary(validator,args)
{
	var radioList=document.forms[0][NAMEPREFIX+'ResultTypeRadioButtonList'];
	if(-1==getCheckedRadio(radioList).value.indexOf('Calculation'))
	{
		args.IsValid=args.IsValid&&true;
	}
	else
	{
		var rx=/^[1-9]{1}[0-9]{1,8}(()|(\.[0-9]{1,2}))$/;
		var salaryTextBox=document.getElementById(IDPREFIX+'SalaryTextBox');
		var salary=salaryTextBox.value;
		while(-1!=salary.indexOf(' '))
		{
			salary=salary.replace(' ','');
		}
		while(0==salary.indexOf('0'))
		{
			salary=salary.substr(1);
		}
		salaryTextBox.value=salary;
		args.IsValid=args.IsValid&&rx.test(salaryTextBox.value);
	}
}