/*
 * 
 old tarif view variant
 
window.addEvent('domready', function() {
	$$('.rollingRow').each(function(el) {
		el.addEvent('mouseenter', function() {
			var index = el.cellIndex;
			$$('.rollingRow').each(function(el2) {
				if(el2.cellIndex == index) {
					el2.addClass('rowHilight');
				}
			});
		});

		el.addEvent('mouseleave', function() {
			$$('.rollingRow').each(function(el2) {
				el2.removeClass('rowHilight');
			});
		});
	});
});


*/

function updatePrices(link, curr) {
	if (typeof tarifsData == 'undefined') { return; }
	// update prices
	for (var i in tarifsData) {
		if (typeof tarifsData[i] == 'function ') { continue; }
		var div = document.getElementById('tarif_' + tarifsData[i].id +  '_price');
		if (div) { // empty for 'free' tarif
			var price = _getMonthlyPrice(curr, tarifsData[i].prices);
			div.innerHTML = Math.round(parseFloat(price), 0);
			document.getElementById('tarif_' + tarifsData[i].id + '_currency').innerHTML = curr;
		}
	}
	
	// update links
	var cont = document.getElementById('currency_links');
	for (var i in cont.childNodes) {
		var node = cont.childNodes[i];
		if (node.nodeType == 1 && (node.tagName == 'A' || node.tagName == 'a')) {
			node.className = 'currency_link';
		}
	}
	link.className = 'selected_currency_link';
}

// this is hack function. if prices format will not be changed, add here convertation rates, and cases for 'week' and 'year'
function _getMonthlyPrice(currency, prices) {
	var mp = null;
	var cps = [];
	// get monthly price in proper currency
	for (var i = 0; i < prices.length; i++) {
		if (prices[i].currency == currency) {
			if (parseInt(prices[i].period_length) == 30 && prices[i].period_type == 'day' || 
				parseInt(prices[i].period_length) == 1 && prices[i].period_type == 'month') {
				mp = prices[i].price;
			}
			cps.push(prices[i]);
		}		
	}
	if (mp != null) { return mp; }

	// recalculate price per month by using price per some other period
	if (cps.length > 0) {
		if (cps[0].period_type == 'day') { 
			var coef = 30 / parseInt(cps[0].period_length);
		} else if (cps[0].period_type == 'month') {
			var coef = 1 / parseInt(cps[0].period_length);
		} else {
			return 0;
		}
		return cps[0].price * coef;
	} else {
		// actually need for currency rate
		return 0;
	}
}
