// JavaScript Document
var InsuranceCalUI = {
	submitUrl: '',
	_intVal: function(ctl)
	{
		var data = parseInt($('#' + ctl).val());
		if(isNaN(data))
		{
			return 0;
		}
		
		return data;
	},
	resetForm: function()
	{
		$('div.resultsheet').slideUp('fast', function()
		  {
			$.scrollTo({ top:0, left:0}, 500 );
			document.forms['frmInsuranceCal'].reset();
			$U.focus('txtMortgages');
		  });
	},
	doCal: function()
	{
		var vld = new FormValidator();
		vld.checkNumber({'txtMortgages' : 'Value of mortgages debts is invalid. Please enter a valid numeric amount.',
						'txtDebts' : 'Other debts amount is invalid. Please enter a valid numeric amount.',
						'txtFuneralExpenses' : 'Funeral expenses amount is invalid. Please enter a valid numeric amount.',
						'txtMedicalExpenses' : 'Medical expenses amount is invalid. Please enter a valid numeric amount.',
						'txtGiftExpenses' : 'Bequests and gifts amount is invalid. Please enter a valid numeric amount.',
						'txtTotalIncome' : 'Total income per annum is invalid. Please enter a valid numeric amount.',
						'txtTotalIncome2' : 'Partner\'s Total income per annum is invalid. Please enter a valid numeric amount.',
						'txtTotalPartnerNeed' : 'Required surviving partner\'s amount is invalid. Please enter a valid numeric amount.',
						'txtTotalPartnerNeed2' : 'Partner\'s Required surviving partner\'s amount is invalid. Please enter a valid numeric amount.',
						'txtLifeInsurance' : 'Current life insurance policies amount is invalid. Please enter a valid numeric amount.',
						'txtLifeInsurance2' : 'Partner\'s current life insurance policies is invalid. Please enter a valid numeric amount.',
						'txtSupperannuation' : 'Value of superannuation amount is invalid. Please enter a valid numeric amount.',
						'txtSupperannuation2' : 'Partner\'s value of superannuation amount is invalid. Please enter a valid numeric amount.',
						'txtInvestments' : 'Value of investments amount is invalid. Please enter a valid numeric amount.',
						'txtInvestments2' : 'Partner\'s value of investments amount is invalid. Please enter a valid numeric amount.'});
		
		if(!vld.isValid())
		{
			$('#result').html(vld.html()).attr('class','error').slideDown('fast', function()
		   {
			   $.scrollTo($('#result'), 500);
		   });
			vld.focus();
			return false;
		}
		else
		{
			$('div.loading').show();
			
			$('#result').slideUp('fast', function()
			  {
				  $.post(InsuranceCalUI.submitUrl, $('#frmInsuranceCal').fastSerialize(), 
					function(response)
					{
						$('div.loading').hide();
						$('#spnTPD').html(response.tpd);
						$('#spnTPD2').html(response.tpd2);
						$('#spnTrauma').html(response.trauma);
						$('#spnTrauma2').html(response.trauma2);
						$('#spnIncome').html(response.income);
						$('#spnIncome2').html(response.income2);
						$('div.resultsheet').slideDown('fast');
						$.scrollTo($('div.resultsheet'), 500);
					},'json');
			  });
		}
		
		return false;
	},
	init: function()
	{
		$('#frmInsuranceCal').bind('submit', InsuranceCalUI.doCal);
		$('#btnReset').bind('click', InsuranceCalUI.resetForm);
		$U.focus('txtMortgages');
	}
}