//Method sets parameters to fields of form
function useDeposit(capital, percentage, time_amount, time_type, minimal_capital)
{
	$("[id=minimal_capital]").each(function(i){ $(this).val(minimal_capital);});
	$("[id=percentage]").each(function(i){ $(this).val(parseFloat(percentage));});
	$("[id=capital]").each(function(i){ $(this).val(capital*10);});
	$("[id=time_interval_amount]").each(function(i){ $(this).val(time_amount);});
	$("select option[value=" + time_type + "]").each(function(i){$(this).attr('selected', 'selected');});
}

//Method shows or hides one of examples of use for deposit form.
function presentExample(number)
{
	$('#example' + number + '_content').slideToggle('slow').siblings("[name=example]").slideUp('slow');
}

//Method downloads data of deposit for selected deposit (deposit is selected by passing its id)
function downloadAndUseDepositData(id)
{
	$.ajax({
		   type: "GET",
		   url: "/lokata/informacje/" + id,
		   success: function(msg)
		   {
		   	 items = msg.split("|");
//		     alert( "Data Saved: " + msg );
		   	 useDeposit(items[1], parseFloat(items[2]), items[3], items[4], items[1]);
		   },
		   fail: function(msg)
		   {
				alert(msg);
		   }
		 });
			
}
/*
$(document).ready(function()
{
	$("[name=deposit_option]").change(function(i) 
	{ 
		downloadAndUseDepositData($(this).val());
	});
});
*/
function updateDepositData()
{
	downloadAndUseDepositData($("[name=deposit_option]").val());
}
