var rates = new Array(3);
var characters = new Array();
var rate = 1;

function hideIt(id){
	if(	document.getElementById(id).style.display=="none"){
		document.getElementById(id).style.display="block";
	}else{
		document.getElementById(id).style.display="none";
	}
}

function flr (value){
	value=value*100;
	return Math.round(value) /100;
}

function changeBilling(){
	rate = 1;
	var from = document.getElementById('billingList').value;

	if (from != '' && document.getElementById(from)) {
		document.getElementById('desc').innerHTML =	document.getElementById(from).innerHTML;
	} else {
		document.getElementById('desc').innerHTML = '';
	}
	
	document.getElementById('tr_unit').style.display = (from == "webmoney") ? '' : 'none';
	document.getElementById('tr_amount').style.display = (from == "webmoney") ? '' : 'none';
	document.getElementById('tr_price').style.display = (from == "webmoney") ? '' : 'none';
	document.getElementById('tr_desc').style.display = (from == "webmoney") ? '' : 'none';
	document.getElementById('tr_next').style.display = (from == "webmoney" || from == "sms") ? '' : 'none';
	document.getElementById('tr_1').style.display = (from != "") ? '' : 'none';
	document.getElementById('tr_2').style.display = (from != "") ? '' : 'none';
	
	wmr = document.getElementById('wmr');
	wme = document.getElementById('wme');
	wmu = document.getElementById('wmu');
	
	if (wmr != null && wmr.checked) rate = rates['wmr'];
	if (wme != null && wme.checked) rate = rates['wme'];
	if (wmu != null && wmu.checked) rate = rates['wmu']; 

	changeBillingAmount(true);
}
function changeBillingAmount(fixAmount){
	var amount	= document.getElementById('local_amount').value;
	var summa	= document.getElementById('local_price').value;

	if (fixAmount){
		amount 	= flr(amount);
		if (amount > 1000)
			amount = 1000;
		summa = flr(amount*rate);
	} else {
		summa = flr(summa);
		if (summa/rate > 1000)
			summa = 1000*rate;
		amount 	= flr(summa/rate);
	}
	
	document.getElementById('local_price').value = summa;
	document.getElementById('local_amount').value = amount;
}

function changeCharacter() {
	var char = document.getElementById('charList').value;
	if (char == "") {
		document.getElementById('id').value = 0;
	} else {
		document.getElementById('id').value = characters[char]['id'];
	}
}