function TaxationParams()
{
	this.currency = 0;
	this.taxRate = 0;
	this.refinancingRate = 0;
	this.minNotaxRateRub = 0;
	this.minNotaxRateExchange = 0.09;

	this.fill = function(depositParams)
	{
	   this.currency = depositParams.currencyType;
	   this.taxRate = depositParams.resident == '1' ? 0.35 : 0.30;
	   this.refinancingRate = (typeof refinancingRate == "undefined") ? 0 : refinancingRate;
	   this.minNotaxRateRub = (refinancingRate + 0.05).toFixed(4);
	}	
}

function DepositParams()
{
	this.region = '';
	this.amountOnDeposit = 0;
	this.currencyType = '';
	this.depositPeriod = 0;
	this.capOfPct = 0;
	this.paymentOfPct = 0;
	this.resupply = 0;
	this.writeDown = 0;
	this.resident = 0;
	this.openDate = null;

	this.fill = function(controlWrapper)
	{
	   this.region = controlWrapper.getElement('d_region').value;
       this.amountOnDeposit = parseInt(controlWrapper.getElement('d_amount_on_deposit').value);
       this.currencyType = controlWrapper.getElement('d_currency_type').value;
       this.depositPeriod = parseInt(controlWrapper.getElement('d_deposit_period').value);
       this.capOfPct = parseInt(controlWrapper.getElement('d_cap_of_pct').value);
       this.paymentOfPct = controlWrapper.getElement('d_payment_of_pct').value;
       this.resupply = controlWrapper.getElement('d_resupply').value;
       this.writeDown = controlWrapper.getElement('d_write_down').value;
       this.resident = controlWrapper.getElement('d_resident').value;
       
       var in_date = controlWrapper.getElement('d_open_date').value;
       var day = in_date.replace(/(\d+)\.(\d+)\.(\d+)/,"$1");
       day = parseInt(day,10)+1;

       var openDate = strToDate(controlWrapper.getElement('d_open_date').value);
       if(day>0 && openDate)openDate.setDate(day);
       this.openDate = openDate  == false ? new Date() : openDate;
	}
}

function DataOfPeriod()
{
	periodBeginDate: null;
	periodEndDate: null;
	this.calc = {
		pctByPeriod: 0,
		taxBase: 0,
		payTax: 0,
		payPctByPeriod: 0,
		amtRemains: 0
	};
	this.periods = [];
	this.addPeriod = function(period)
	{
		this.calc.pctByPeriod += period.calc.pctByPeriod;
		this.calc.taxBase += period.calc.taxBase;
		this.calc.payTax += period.calc.payTax;
		this.calc.payPctByPeriod += period.calc.payPctByPeriod;
		//this.calc.amtRemains += period.calc.amtRemains;		
		
		this.periods.push(period);
	}
};

function dateToStr(date)
{
    var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
    var month = date.getMonth() < 9 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
    var year = new String(date.getFullYear())
    year = year.substring(2, 4); 

    return day + '.' + month + '.' + year; 
}

function strToDate(dateStr)
{
	var oStr = new String(dateStr);
	if (oStr.match(/^[0-9]{2}\.[0-9]{2}\.[0-9]{2}$/g) == null) {
		return false;
	}
	var aPeace = oStr.match(/[0-9]{2}/g);
	
	var day = parseInt(aPeace[0],10);
	var month = parseInt(aPeace[1],10) - 1;
	var year = parseInt('20' + aPeace[2]);
	var oDepositDate = new Date(year, month, day);
    //if(day>0)oDepositDate.setDate(day+1);
	if (oDepositDate.getFullYear() != year || oDepositDate.getMonth() != month || oDepositDate.getDate() != day) {
		return false;
	}
	return oDepositDate;
}