// <![CDATA[

var operatorList = [
		[ [ "38067", "38096", "38097", "38098" ], [ "kyivstar.gif" ] ],
		[ [ "38050", "38066", "38095", "38099" ], [ "mts.gif" ] ],
		[ [ "38063", "38093" ], [ "life.gif" ] ],
		[ [ "38068" ], [ "beeline.gif" ] ],
		[ [ "38094" ], [ "intertelecom.gif" ] ],
		[ [ "38092" ], [ "peoplenet.gif" ] ], [ [ "38091" ], [ "utel.gif" ] ] ];

function phone_onkeyup() {

	var phoneElement = document.getElementById("phone");

	if (null == phoneElement)
		return;

	var phone = phoneElement.value;

	phone = phone.replace(/[^\d]+/g, "");
	phone = phone;

	var logo = "phone.gif";

	for ( var operatorIndex in operatorList) {
		var prefixList = operatorList[operatorIndex][0];
		for ( var prefixIndex in prefixList) {
			if (0 == phone.indexOf(prefixList[prefixIndex])) {
				logo = [ operatorList[operatorIndex][1] ];
				break;
			}
		}
	}

	phoneElement.style.backgroundImage = "url(/pictures/" + logo + ")";
}

function amount_onkeyup() {

	var amountElement = document.getElementById("amount");
	var currencyElement = document.getElementById("currency");
	var totalElement = document.getElementById("total");

	if (null == amountElement || null == currencyElement
			|| null == totalElement)
		return;

	var currency = currencyElement[currencyElement.selectedIndex].value;
	var rate = rateList[currency];

	var temp = amountElement.value.replace(",", ".");
	var amount = parseFloat(temp);

	if (!isNaN(amount)) {

		if (rate > 0) {

			amount *= rate;

			amount *= 100;
			amount = Math.round(amount);

			if (amount == 0)
				amount = 1;

			if (amount < 100)
				amount += 1;

			amount /= 100;

		} else {
			amount = 0;
		}

		totalElement.innerHTML = amount;
	} else {
		totalElement.innerHTML = "?";
	}
}

function initialization() {
	phone_onkeyup();
	amount_onkeyup();
}

function sendMail() {
	var array = [ 'm', 'a', 'i', 'l', 't', 'o', ':', '@', 'c', 'a', 's', 'h',
			'e', 'l', 'e', 'c', '.', 'r', 'u' ];

	var location = "";

	for ( var i = 0; i < 7; i++) {
		location += array[i];
	}

	for ( var i = 0; i < 4; i++) {
		location += array[i];
	}

	for ( var i = 7; i < 19; i++) {
		location += array[i];
	}

	window.location = location;
}
