TaxTool.YourInformation = function()
{
	var form;
	var table;
	var DEFAULT_VALUE = '$0';
	var showme_button

	function onFocus(field)
	{
		this.dom.value = this.dom.getAttribute("hiddenvalue");
	}

	var onBlur = function(field)
	{
		if (this.dom.value == DEFAULT_VALUE) { return; }
		this.dom.setAttribute('hiddenvalue', this.dom.value);
		if (this.dom.value == '.') { return; }
		this.dom.value = Ext.util.Format.usMoney(this.dom.value);
	}

	var keyPress = function(e)
	{
		var k = e.getKey();
		var c = e.getCharCode();
		var t = String.fromCharCode(c);

		if (t == '.' && this.dom.value.indexOf('.') > -1) { e.stopEvent(); }
		if (!Ext.isIE && (e.isSpecialKey()  || k == e.BACKSPACE || k == e.DELETE)) { return; }
	}

	function createTooltip(id, message)
	{
		return new Ext.ToolTip({
			target: id,
			showDelay: 0,
			width: 230,
			mouseOffset: [-240, 18],
			html: message
		});
	}

	return {
		getNumValue: function(elementId)
		{
			var val = Ext.get(elementId).dom.value;
			return Number(val.replace(/\$/,'').replace(/,/g, ''));
		},

		showMeWhereMyMoneyWentClicked: function()
		{
			TaxTool.TaxTree.mediacre = this.getNumValue('amt_medicare') * 2.0;
			TaxTool.TaxTree.social = this.getNumValue('amt_social_security') * 2.0;
			TaxTool.TaxTree.federalAndPropery = this.getNumValue('amt_federal_taxes') + this.getNumValue('amt_propery_taxes');

			TaxTool.TaxTree.calcAverage();
			location.href = '#treeplace';
		},

		init: function()
		{
			showme_button = new Ext.Button({
				text: 'Show me where my money went'
			});

			showme_button.on('click', function() { TaxTool.YourInformation.showMeWhereMyMoneyWentClicked(); });

			var propTaxDefValue = DEFAULT_VALUE;
			var refreshGrid = false;

			var query = String(window.location.search || '').replace(/^\s\s*/, '').replace(/\s\s*$/, '').replace(/^\?/, '');
			var spl = query.split(/&/g);

			for (var i = 0; i < spl.length; i++)
			{
				var str = spl[i].replace(/^\s\s*/, '').replace(/\s\s*$/, '');
				var kv = str.split(/=/);

				if (kv.length == 2)
				{
					var key = kv[0].replace(/^\s\s*/, '').replace(/\s\s*$/, '');
					var value = kv[1].replace(/^\s\s*/, '').replace(/\s\s*$/, '');

					if (key.toLowerCase() == 'amount')
					{
						value = Number(value);

						if (value != NaN)
						{
							propTaxDefValue = '$' + value;
							refreshGrid = true;
							break;
						}
					}
				}
			}

			table = new Ext.Panel({
				layout:'table',
				layoutConfig: {
					columns: 3
				},
				items: [{
					html: 'Federal income tax',
					bodyStyle: 'padding-right: 10px; font-size: 11px;'
				},{
					items: [new Ext.form.NumberField({
						fieldLabel: 'Amount Propery Taxes',
						id: 'amt_propery_taxes',
						emptyText: propTaxDefValue,
						validateOnBlur: false,
						// anchor: '100%',
						width: 80,
						validationDelay: 0
					})],
					bodyStyle: 'padding-bottom: 1px;'
				},{
					html: '<a href="#"><img src="images/info.png" id="incometax_help"></a>',
					bodyStyle: 'padding-left: 3px;'
				},{
					html: 'Social security',
					bodyStyle: 'padding-right: 10px;font-size: 11px;'
				},{
					items: [new Ext.form.NumberField({
						fieldLabel: 'Amount Social Security',
						id: 'amt_social_security',
						emptyText: DEFAULT_VALUE,
						baseChars: '$0123456789',
						validateOnBlur: false,
						// anchor: '100%',
						width: 80,
						validationDelay: 0
					})],
					bodyStyle: 'padding-bottom: 1px;'
				},{
					html: '<a href="#"><img src="images/info.png" id="socsecurity_help"></a>',
					bodyStyle: 'padding-left: 3px;'
				},{
					html: 'Medicare',
					bodyStyle: 'padding-right: 10px;font-size: 11px;'
				},{
					items: [new Ext.form.NumberField({
						fieldLabel: 'Amount Medicare',
						id: 'amt_medicare',
						emptyText: DEFAULT_VALUE,
						baseChars: '$0123456789',
						validateOnBlur: false,
						// anchor: '100%',
						width: 80,
						validationDelay: 0})
					],
					bodyStyle: 'padding-bottom: 1px;'
				},{
					html: '<a href="#"><img src="images/info.png" id="medicare_help"></a>',
					bodyStyle: 'padding-left: 3px;'
				},{
					html: 'Other federal taxes',
					bodyStyle: 'padding-right: 10px; font-size: 11px;'
				},
					new Ext.form.NumberField({
						fieldLabel: 'Other federal taxes',
						id: 'amt_federal_taxes',
						emptyText: DEFAULT_VALUE,
						validateOnBlur: false,
						baseChars: '$0123456789',
						// anchor: '100%',
						width: 80,
						validationDelay: 0
				}),{
					html: '<a href="#"><img src="images/info.png" id="othertaxse_help"></a>',
					bodyStyle: 'padding-left: 3px;'
				}]
			});

			form = new Ext.FormPanel({
				collapsible: false,
				animCollapse: false,
				frame: true,
				title: 'Enter your information',
				width: 222,
				labelWidth: 150,
				url: 'test.php',
				bodyStyle: 'text-align: right;',

				items: [{
					html:'<b>Customize this data!</b> (Enter 0 for any unknown or non-applicable values)',
					bodyStyle: 'font-size: 10px; padding: 2px 0px 2px 0px; text-align: right;'
				},
				table,
				{
					items: [showme_button],
					bodyStyle: 'margin: 3px 0px 3px 17px;'
				},{
					bodyStyle: 'font-size: 10px;text-align:justify;',
					html: '<b>Privacy Notice:</b> We will not store any of the values you enter in the above fields. No one besides you will see this information.'
				}]
			});

			form.render(Ext.get('your_information_holder'));

			var field = Ext.get('amt_federal_taxes');
			field.on('focus', onFocus);
			field.on('blur', onBlur);
			field.dom.setAttribute("hiddenvalue", '');
			field.on("keypress", keyPress);

			field = Ext.get('amt_social_security');
			field.on('focus', onFocus);
			field.on('blur', onBlur);
			field.dom.setAttribute('hiddenvalue', '');
			field.on("keypress", keyPress);

			field = Ext.get('amt_medicare');
			field.on('focus', onFocus);
			field.on('blur', onBlur);
			field.dom.setAttribute('hiddenvalue', '');
			field.on("keypress", keyPress);

			field = Ext.get('amt_propery_taxes');
			field.on('focus', onFocus);
			field.on('blur', onBlur);
			field.dom.setAttribute('hiddenvalue', '');
			field.on("keypress", keyPress);

			createTooltip('incometax_help', 'To find this value, look on line 63 of your Form 1040. If you have not yet filled out this form this year, estimate from previous years, or from adding the fields in Box 2 of your W-2 form(s).');
			createTooltip('socsecurity_help', 'To find this value, look in Box 4 of your W-2 form. If you have multiple W-2 forms, add together all the values in Box 4 of each form.');
			createTooltip('medicare_help', 'To find this value, look in Box 6 of your W-2 form. If you have multiple W-2 forms, add together all the values in Box 6 of each form.');
			createTooltip('othertaxse_help', 'This value can be comprised of other tax items such as cigarette taxes or gasoline taxes. For reference, someone who smokes two packs a week would pay a yearly federal cigarette tax of about $40, and someone who drives 15000 miles in a car that gets 25mpg would pay about $110 in yearly gasoline taxes.');

			if (refreshGrid)
			{
				var refreshGridInterval = setInterval(function()
				{
					if (TaxTool.TaxTree.gridLoaded)
					{
						clearInterval(refreshGridInterval);
						TaxTool.YourInformation.showMeWhereMyMoneyWentClicked();
					}
				}, 100);
			}
		}
	}
}();
