// Voting
function vote()
{
    var v, i, f, radioObj;
    
    f = fetch_object('voting_form');
    radioObj = f.elements['voting_number'];

	if(!radioObj){
		return;
    }
    
	var radioLength = radioObj.length;
    
	if(radioLength == undefined){
		if(radioObj.checked){
		    v = radioObj.value;
        } else{
		    return;
        }
    }
    
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			v = radioObj[i].value;
		}
	}
    
    ajax__progress_indicator('voting_h');
    
    u = 'voting.php5?v=' + v;
    ajax_do(u);
}

// Currency converter
function currency__convert()
{
    var sum = parseInt(fetch_object('cur1').value);
    if (sum <= 0 || isNaN(sum)){
        return;
    } else {
        var from_rate   = parseFloat(fetch_object('cur1id').value);
        var to_rate     = parseFloat(fetch_object('cur2id').value);
        var result      = sum * from_rate / to_rate;
        result = Math.ceil(result * 100) / 100;
        
        fetch_object('cur2').value = result;
    }
}

// Credit calculation
function credit__count()
{
    var sum = parseInt(fetch_object('cred_sum').value);
    if (sum <= 0 || isNaN(sum)){
        return;
    } else {
        //var first   = parseFloat(fetch_object('cred_start').value) * sum / 100;
        var percent = parseFloat(fetch_object('cred_percent').value) / 1200;
        var period  = parseInt(fetch_object('cred_months').value);
        //var pl = (sum - first) * percent / (1 - 1 / Math.pow(1 + percent, period));
        var pl = sum * percent / (1 - 1 / Math.pow(1 + percent, period));
        result = Math.ceil(pl * 100) / 100;
        
        fetch_object('cred_monthly').value = result;
    }
}

// Clock
var clockID = 0;

function UpdateClock() {
    if(clockID) {
        clearTimeout(clockID);
        clockID  = 0;
    }

    var today = new Date();
    var m = checkTime(today.getMinutes());
    var s = checkTime(today.getSeconds());
    var h = checkTime(today.getHours());
    var d = checkTime(today.getDate());
    var month = checkTime(today.getMonth() + 1);
    var y = today.getYear();
    if (!is_ie){
        y += 1900;
    }

    var holder = fetch_object('time');
    holder.innerHTML = d + "." + month + "." + y + " - " + h + ":" + m + ":" + s;

    clockID = setTimeout("UpdateClock()", 1000);
}
function StartClock() {
   clockID = setTimeout("UpdateClock()", 500);
}

function KillClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
}

function checkTime(i)
{
    if (i<10){
        i="0" + i;
    }
    
    return i;
}

