// JavaScript Document
var RefundCalUI = {
	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['frmRefund'].reset();
			$U.focus('txtManagedBalance');
		  });
	},
	doCal: function()
	{
		var vld = new FormValidator();
		vld.checkNumber({'txtManagedBalance' : 'Managed fund balance amount is invalid. Please enter a valid numeric amount.',
						'txtPensionBalance' : 'Superannuation / Pension fund balance amount is invalid. Please enter a valid numeric amount.',
						'txtAgribusiness' : 'Agribusiness investment amount is invalid. Please enter a valid numeric amount.',
						'txtGrowth' : 'Average annual growth amount is invalid. Please enter a valid numeric amount.',
						'txtContributions' : 'Annual contributions amount is invalid. Please enter a valid numeric amount.',
						'txtEntryFees' : 'Entry fees amount is invalid. Please enter a valid numeric amount.',
						'txtTrailing' : 'Trailing commissions amount is invalid. Please enter a valid numeric amount.',
						'txtHomeLoan' : 'Home loan amount is invalid. Please enter a valid numeric amount.',
						'txtMortgageLoan': 'Reverse mortgage loan is invalid. Please enter a valid numeric amount.',
						'txtInsuranceNew' : 'New personal insurances is invalid. Please enter a valid numeric amount.',
						'txtInsuranceExisting' : 'Existing personal insurances is invalid. Please enter a valid numeric amount.',
						'txtInsuranceGeneral' : 'General insurance is invalid. Please enter a valid numeric amount.',
						'txtInsuranceGeneral' : 'General insurance is invalid. Please enter a valid numeric amount.',
						'txtRealEstateSales' : 'Real estate sales commission is invalid. Please enter a valid numeric amount.',
						'txtRealEstateProperty': 'Property management fees is invalid. Please enter a valid numeric amount.',
						'txtFinanceBusiness' : 'Business / commercial finance is invalid. Please enter a valid numeric amount.',
						'txtFinanceLeasing': 'Leasing finance 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(RefundCalUI.submitUrl, $('#frmRefund').fastSerialize(), 
					function(html)
					{
						$('div.loading').hide();
						
						$('div.resultsheet').html(html).slideDown('fast', 
																  function()
																  {
																		$.scrollTo($('div.resultsheet'), 500);
																  });
					});
			  });
		}
		
		return false;
	},
	init: function()
	{
		$('#frmRefund').bind('submit', RefundCalUI.doCal);
		$('#btnReset').bind('click', RefundCalUI.resetForm);
		$U.focus('txtManagedBalance');
	}
}
