
/***** sprawdzanie kosztu wiadomosci ******/
if (sLanguage == "uk")
{
	var CHECK_PRICE_LINK = '<a href="#" id="kosztWiadomosciLink" class="linkSprawdzKoszt">[check price]</a>';
	var CREDIT_BALANCE_ZERO = '<stron>Out of credits!</strong><br /><a href="topUp.php">[top up your account]</a>';
}
else
{
	var CHECK_PRICE_LINK = '<a href="#" id="kosztWiadomosciLink" class="linkSprawdzKoszt">[sprawdź koszt]</a>';
	var CREDIT_BALANCE_ZERO = '<stron>Brak punktów</strong><br /><a href="topUp.php">doładuj...</a>';
}
var bRestoreLocked = false;
function restoreLink(oEvent) {
	if(bRestoreLocked) {
		return;	
	}
	bRestoreLocked = true;
	var oPriceDiv = document.getElementById('kosztWiadomosci');
	oPriceDiv.innerHTML = CHECK_PRICE_LINK;
	var oCheckLink = document.getElementById('kosztWiadomosciLink');
	addEventHandler(oCheckLink, "click", getPrice);
	setTimeout(unlockRestoreLink, 100);	
}

function unlockRestoreLink() {
	bRestoreLocked = false;
}

function getPrice(oEvent)
{
	var oPriceDiv = document.getElementById('kosztWiadomosci');
	if (sLanguage == "uk")
		oPriceDiv.innerHTML = "<strong>Please wait...</strong>";
	else
		oPriceDiv.innerHTML = "<strong>Proszę czekać...</strong>";
	
	var oRecipient = document.getElementById('odbiorca');
	var oContent = document.getElementById('trescWiadomosci');
	var oPrefix = document.getElementById('prefixKraju');
	
	var iType = getSmsType();

	var sRequest = "number=" + encodeURIComponent(oPrefix.value + oRecipient.value) + "&" +
					"type=" + encodeURIComponent(iType);
	if(oContent)
		sRequest += "&content=" + encodeURIComponent(oContent.value);

	if(oEvent)
		preventDefaultEvent(oEvent);
		
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
//		enableButton(false, oSendButton, sendLogoStep2);
//		showProgress(true, "blokWyslijLogoPostep", "blokWyslijLogoTresc");
		xmlHttp.open("POST", "engine/getPrice.php", true);  
		xmlHttp.onreadystatechange = getPriceResults;
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.send(sRequest);
	}
	else
	    setTimeout('getPrice()', 1000);
}


function getPriceResults() 
{
	var oPriceDiv = document.getElementById('kosztWiadomosci');
	// kontynuuje jedynie jesli transakcja zostala zakonczona
	if (xmlHttp.readyState == 4) 
	{
  		// status 200 oznacza pomyslne ukonczenie transakcji
		if (xmlHttp.status == 200) 
		{	
			// wyodrebnia wiadomosc wyslana z serwera
			sResponse = xmlHttp.responseText;
			oPriceDiv.innerHTML = sResponse;
			//showProgress(false, "blokWyslijLogoPostep", "blokWyslijLogoTresc");
		} 
		// dla statusu protokolu HTTP innego niz 200 zglasza blad
		else 
		{
			alert("Wystapil blad podczas uzyskiwania dostepu do serwera: " + xmlHttp.statusText);
		}
	}
}

function selectCountryPrefix(oEvent) {
	var oCountrySelect = getEventSrc(oEvent);
	var oCountryField = document.getElementById("prefixKraju");
	oCountryField.value = oCountrySelect.options[oCountrySelect.selectedIndex].value;
}

var xmlHttp2 = createXmlHttpRequestObject(); 

function updateCreditBalance()
{
	if (xmlHttp2.readyState == 4 || xmlHttp2.readyState == 0)
	{
		xmlHttp2.open("POST", "engine/getBalance.php", true);  
		xmlHttp2.onreadystatechange = getUpdateBalanceResult;
		xmlHttp2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp2.send("");
	}
	else
	    setTimeout('updateCreditBalance()', 1000);
}


function getUpdateBalanceResult() 
{
	if (xmlHttp2.readyState == 4) 
	{
		if (xmlHttp2.status == 200) 
		{	
			var oBalanceDiv = document.getElementById("stanKonta");
			oBalanceDiv.innerHTML = xmlHttp2.responseText;
/*			if(iCredit == 0)
				oBalanceDiv.innerHTML = CREDIT_BALANCE_ZERO;
			else {
				oBalanceDiv.innerHTML = '<strong>' + iCredit + '</strong>';
				if(iCredit == 1)
					oBalanceDiv.innerHTML += ' punkt';
				else if(iCredit % 10 == 2 || iCredit % 10 == 3 || iCredit % 10 == 4)
					oBalanceDiv.innerHTML += ' punkty';
				else
					oBalanceDiv.innerHTML += ' punktów';
			}
*/
		} 
		// dla statusu protokolu HTTP innego niz 200 zglasza blad
		else 
		{
			alert("Wystąpił błąd podczas uzyskiwania dostępu do serwera: " + xmlHttp2.statusText);
		}
	}
}