﻿function addition( table_id, lang ) {
    if (table_id == 'additions') {
		var table = document.getElementById("additions");
	} else {
		var table = document.getElementById("withdrawals");
	}
		
	//максимальное количество пополнений - 80
    if (table.rows.length > 80) {
		return false;    
	}
	var newrow = table.insertRow(-1);
	now = new Date();
	var day_list =  '<option value=01' + ((now.getDate() ==1) ? (' selected="" ') : (' ')) +'>1</option>'+
					'<option value=02' + ((now.getDate() ==2) ? (' selected="" ') : (' ')) +'>2</option>'+
					'<option value=03' + ((now.getDate() ==3) ? (' selected="" ') : (' ')) +'>3</option>'+
					'<option value=04' + ((now.getDate() ==4) ? (' selected="" ') : (' ')) +'>4</option>'+
					'<option value=05' + ((now.getDate() ==5) ? (' selected="" ') : (' ')) +'>5</option>'+
					'<option value=06' + ((now.getDate() ==6) ? (' selected="" ') : (' ')) +'>6</option>'+
					'<option value=07' + ((now.getDate() ==7) ? (' selected="" ') : (' ')) +'>7</option>'+
					'<option value=08' + ((now.getDate() ==8) ? (' selected="" ') : (' ')) +'>8</option>'+
					'<option value=09' + ((now.getDate() ==9) ? (' selected="" ') : (' ')) +'>9</option>'+
					'<option value=10' + ((now.getDate() ==10) ? (' selected="" ') : (' ')) +'>10</option>'+
					'<option value=11' + ((now.getDate() ==11) ? (' selected="" ') : (' ')) +'>11</option>'+
					'<option value=12' + ((now.getDate() ==12) ? (' selected="" ') : (' ')) +'>12</option>'+
					'<option value=13' + ((now.getDate() ==13) ? (' selected="" ') : (' ')) +'>13</option>'+
					'<option value=14' + ((now.getDate() ==14) ? (' selected="" ') : (' ')) +'>14</option>'+
					'<option value=15' + ((now.getDate() ==15) ? (' selected="" ') : (' ')) +'>15</option>'+
					'<option value=16' + ((now.getDate() ==16) ? (' selected="" ') : (' ')) +'>16</option>'+
					'<option value=17' + ((now.getDate() ==17) ? (' selected="" ') : (' ')) +'>17</option>'+
					'<option value=18' + ((now.getDate() ==18) ? (' selected="" ') : (' ')) +'>18</option>'+
					'<option value=19' + ((now.getDate() ==19) ? (' selected="" ') : (' ')) +'>19</option>'+
					'<option value=20' + ((now.getDate() ==20) ? (' selected="" ') : (' ')) +'>20</option>'+
					'<option value=21' + ((now.getDate() ==21) ? (' selected="" ') : (' ')) +'>21</option>'+
					'<option value=22' + ((now.getDate() ==22) ? (' selected="" ') : (' ')) +'>22</option>'+
					'<option value=23' + ((now.getDate() ==23) ? (' selected="" ') : (' ')) +'>23</option>'+
					'<option value=24' + ((now.getDate() ==24) ? (' selected="" ') : (' ')) +'>24</option>'+
					'<option value=25' + ((now.getDate() ==25) ? (' selected="" ') : (' ')) +'>25</option>'+
					'<option value=26' + ((now.getDate() ==26) ? (' selected="" ') : (' ')) +'>26</option>'+
					'<option value=27' + ((now.getDate() ==27) ? (' selected="" ') : (' ')) +'>27</option>'+
					'<option value=28' + ((now.getDate() ==28) ? (' selected="" ') : (' ')) +'>28</option>'+
					'<option value=29' + ((now.getDate() ==29) ? (' selected="" ') : (' ')) +'>29</option>'+
					'<option value=30' + ((now.getDate() ==30) ? (' selected="" ') : (' ')) +'>30</option>'+
					'<option value=31' + ((now.getDate() ==31) ? (' selected="" ') : (' ')) +'>31</option>';
	
if (lang == 'ru') {	var month_list = '<option value=01' + ((now.getMonth() ==0) ? (' selected="" ') : (' ')) +'>января</option>'+
					'<option value=02' + ((now.getMonth() ==1) ? (' selected="" ') : (' ')) +'>февраля</option>'+
					'<option value=03' + ((now.getMonth() ==2) ? (' selected="" ') : (' ')) +'>марта</option>'+
					'<option value=04' + ((now.getMonth() ==3) ? (' selected="" ') : (' ')) +'>апреля</option>'+
					'<option value=05' + ((now.getMonth() ==4) ? (' selected="" ') : (' ')) +'>мая</option>'+
					'<option value=06' + ((now.getMonth() ==5) ? (' selected="" ') : (' ')) +'>июня</option>'+
					'<option value=07' + ((now.getMonth() ==6) ? (' selected="" ') : (' ')) +'>июля</option>'+
					'<option value=08' + ((now.getMonth() ==7) ? (' selected="" ') : (' ')) +'>августа</option>'+
					'<option value=09' + ((now.getMonth() ==8) ? (' selected="" ') : (' ')) +'>сентября</option>'+
					'<option value=10' + ((now.getMonth() ==9) ? (' selected="" ') : (' ')) +'>октября</option>'+
					'<option value=11' + ((now.getMonth() ==10) ? (' selected="" ') : (' ')) +'>ноября</option>'+
					'<option value=12' + ((now.getMonth() ==11) ? (' selected="" ') : (' ')) +'>декабря</option>';
} else {			var month_list = '<option value=01' + ((now.getMonth() ==0) ? (' selected="" ') : (' ')) +'>January</option>'+
					'<option value=02' + ((now.getMonth() ==1) ? (' selected="" ') : (' ')) +'>February</option>'+
					'<option value=03' + ((now.getMonth() ==2) ? (' selected="" ') : (' ')) +'>March</option>'+
					'<option value=04' + ((now.getMonth() ==3) ? (' selected="" ') : (' ')) +'>April</option>'+
					'<option value=05' + ((now.getMonth() ==4) ? (' selected="" ') : (' ')) +'>May</option>'+
					'<option value=06' + ((now.getMonth() ==5) ? (' selected="" ') : (' ')) +'>June</option>'+
					'<option value=07' + ((now.getMonth() ==6) ? (' selected="" ') : (' ')) +'>July</option>'+
					'<option value=08' + ((now.getMonth() ==7) ? (' selected="" ') : (' ')) +'>August</option>'+
					'<option value=09' + ((now.getMonth() ==8) ? (' selected="" ') : (' ')) +'>September</option>'+
					'<option value=10' + ((now.getMonth() ==9) ? (' selected="" ') : (' ')) +'>October</option>'+
					'<option value=11' + ((now.getMonth() ==10) ? (' selected="" ') : (' ')) +'>November</option>'+
					'<option value=12' + ((now.getMonth() ==11) ? (' selected="" ') : (' ')) +'>December</option>';		
}	
	var year_list = '<option value=2005' + ((now.getFullYear() == 2005) ? (' selected="" ') : (' ')) +'>2005</option>'+
					'<option value=2006' + ((now.getFullYear() == 2006) ? (' selected="" ') : (' ')) +'>2006</option>'+
					'<option value=2007' + ((now.getFullYear() == 2007) ? (' selected="" ') : (' ')) +'>2007</option>'+
					'<option value=2008' + ((now.getFullYear() == 2008) ? (' selected="" ') : (' ')) +'>2008</option>'+
					'<option value=2009' + ((now.getFullYear() == 2009) ? (' selected="" ') : (' ')) +'>2009</option>'+
					'<option value=2010' + ((now.getFullYear() == 2010) ? (' selected="" ') : (' ')) +'>2010</option>'+
					'<option value=2011' + ((now.getFullYear() == 2011) ? (' selected="" ') : (' ')) +'>2011</option>'+
					'<option value=2012' + ((now.getFullYear() == 2012) ? (' selected="" ') : (' ')) +'>2012</option>'+
					'<option value=2013' + ((now.getFullYear() == 2013) ? (' selected="" ') : (' ')) +'>2013</option>'+
					'<option value=2014' + ((now.getFullYear() == 2014) ? (' selected="" ') : (' ')) +'>2014</option>'+
					'<option value=2015' + ((now.getFullYear() == 2015) ? (' selected="" ') : (' ')) +'>2015</option>'+
					'<option value=2016' + ((now.getFullYear() == 2016) ? (' selected="" ') : (' ')) +'>2016</option>';
			
	if (table_id == 'additions') {
		var date_block = '<select name="addition_day'+newrow.sectionRowIndex+'" id="addition_day'+newrow.sectionRowIndex+'">'+day_list+'</select><select name="addition_month'+newrow.sectionRowIndex+'" id="addition_month'+newrow.sectionRowIndex+'">'+month_list+'</select><select name="addition_year'+newrow.sectionRowIndex+'" id="addition_year'+newrow.sectionRowIndex+'">'+year_list+'</select>';
	} else {
		var date_block = '<select name="withdrawal_day'+newrow.sectionRowIndex+'" id="withdrawal_day'+newrow.sectionRowIndex+'">'+day_list+'</select><select name="withdrawal_month'+newrow.sectionRowIndex+'" id="withdrawal_month'+newrow.sectionRowIndex+'">'+month_list+'</select><select name="withdrawal_year'+newrow.sectionRowIndex+'" id="withdrawal_year'+newrow.sectionRowIndex+'">'+year_list+'</select>';
	}
	
	if (lang == 'ru') {
		date_block = date_block +  ' года';
	}
	
	newrow.insertCell(-1).innerHTML =  newrow.rowIndex;
	newrow.insertCell(-1).innerHTML = date_block;
	if (table_id == 'additions') {
    	newrow.insertCell(-1).innerHTML =  '<input type="text" name="addition_amount'+newrow.sectionRowIndex+'" size="8" >';
	} else {
    	newrow.insertCell(-1).innerHTML =  '<input type="text" name="withdrawal_amount'+newrow.sectionRowIndex+'" size="8" >';
	}
} //addition

function deletion(table_id) {
    if (table_id == 'additions') {
    	var table = document.getElementById("additions");
	} else {
    	var table = document.getElementById("withdrawals");		
	}
   
    if (table.rows.length > 1) {
		table.deleteRow(-1);
	}
	return false;
} //deletion

// Функция изменяет свойство видимости элемента "Каждые N дней" в зависимости от выбранного режима начисления процентов
function interest_accrual_changed(list_value) 
{
	if (list_value == 'EVERY_N_DAYS'){
		document.getElementById('accrual_gap_block').className = "shown";
	} else {
		document.getElementById('accrual_gap_block').className = "hidden";
	}
}

// Функция визуализирует один из трех блоков с типом ставки, а остальные скрывает
function rate_type_selected(rate_type) 
{
	switch (rate_type){
		case 'FIXED':
			document.getElementById('foa_rate_block').className = "hidden";
			document.getElementById('fot_rate_block').className = "hidden";
			break;
		case 'FLOAT_ON_AMOUNT':
			document.getElementById('foa_rate_block').className = "shown_block";
			document.getElementById('float_on_amount').checked = true;
			document.getElementById('fot_rate_block').className = "hidden";
			document.getElementById('float_on_term').checked = false;
			break;
		case 'FLOAT_ON_TERM':
			document.getElementById('foa_rate_block').className = "hidden";
			document.getElementById('float_on_amount').checked = false;
			document.getElementById('fot_rate_block').className = "shown_block";
			document.getElementById('float_on_term').checked = true;
			break;
	}
	return false;
}

// Функция добавляет строку в таблицу для задания плавающей ставки
function float_rate_add_row(table_name)
{
	switch (table_name) {
		case 'FLOAT_ON_AMOUNT':
			var table = document.getElementById("float_on_amount_table");
			break;
		case 'FLOAT_ON_TERM':
			var table = document.getElementById("float_on_term_table");
			break;
		default:
			return false;
	}
	
	//максимальное количество пополнений - 60
    if (table.rows.length > 60) {
		return false;    
	}
	
	var newrow = table.insertRow(-1);
	
	switch (table_name) {
		case 'FLOAT_ON_AMOUNT':
			newrow.insertCell(-1).innerHTML = '<input type="text" name="foa_principal'+newrow.sectionRowIndex+'" size="10" >';
			newrow.insertCell(-1).innerHTML = '<input type="text" name="foa_rate'+newrow.sectionRowIndex+'" size="3" >';
			break;
		case 'FLOAT_ON_TERM':	
			newrow.insertCell(-1).innerHTML = '<input type="text" name="fot_day_no'+newrow.sectionRowIndex+'" size="10" >';
			newrow.insertCell(-1).innerHTML = '<input type="text" name="fot_rate'+newrow.sectionRowIndex+'" size="3" >';
			break;
	}
} // foa_add_row()

// Функция удаляет последнюю строку в таблицах для задания плавающей ставки
function float_rate_delete_row(table_name) {
	
	switch (table_name) {
		case 'FLOAT_ON_AMOUNT':
			var table = document.getElementById("float_on_amount_table");
			break;
		case 'FLOAT_ON_TERM':
			var table = document.getElementById("float_on_term_table");
			break;
		default:
			return false;
	}
	
    
	if (table.rows.length > 2) {
		table.deleteRow(-1);
	}
	return false;
} // foa_delete_row()


//Функция в зависимости от режима капитализации процентов по вкладу (есть или нет), делает доступными или скрытыми 
//поля, где задается счет, с которого осуществляется частичное снятие
function interest_capitalization_changed() {
			document.getElementById('partial_withdrawal_account_main').disabled = document.getElementById('interest_capitalization').checked;
			document.getElementById('partial_withdrawal_account_aux').disabled =  document.getElementById('interest_capitalization').checked;
}
