function updateImpressions() {
document.getElementById('clicks').value = parseInt(parseFloat(document.getElementById('impressions').value) * (parseFloat(document.getElementById('ctr').value) / 100));
document.getElementById('earnings').value = roundCurrency(parseFloat(document.getElementById('clicks').value) * parseFloat(document.getElementById('epc').value));
showEarnings();
}

function updateClicks() {
document.getElementById('ctr').value = roundCurrency(parseFloat(document.getElementById('clicks').value) / parseFloat(document.getElementById('impressions').value) * 100);
document.getElementById('earnings').value = roundCurrency(parseFloat(document.getElementById('clicks').value) * parseFloat(document.getElementById('epc').value));
showEarnings();
}

function updateCTR() {
document.getElementById('clicks').value = parseInt(parseFloat(document.getElementById('impressions').value) * (parseFloat(document.getElementById('ctr').value) / 100));
document.getElementById('earnings').value = roundCurrency(parseFloat(document.getElementById('clicks').value) * parseFloat(document.getElementById('epc').value));
showEarnings();
}

function updateCPM() {
document.getElementById('earnings').value = roundCurrency(parseFloat(document.getElementById('impressions').value) * parseFloat(document.getElementById('cpm').value) / 1000);
document.getElementById('epc').value = roundCurrency(parseFloat(document.getElementById('earnings').value) / parseFloat(document.getElementById('clicks').value));
showEarnings();
}

function updateEPC() {
document.getElementById('earnings').value = roundCurrency(parseFloat(document.getElementById('clicks').value) * parseFloat(document.getElementById('epc').value));
document.getElementById('cpm').value = roundCurrency(parseFloat(document.getElementById('earnings').value) / (parseFloat(document.getElementById('impressions').value) / 1000));
showEarnings();
}

function updateEarnings() {
document.getElementById('impressions').value = parseInt(parseFloat(document.getElementById('earnings').value) / parseFloat(document.getElementById('cpm').value) * 1000)
document.getElementById('clicks').value = parseInt(parseFloat(document.getElementById('impressions').value) * (parseFloat(document.getElementById('ctr').value) / 100));
document.getElementById('earnings').value = roundCurrency(parseFloat(document.getElementById('clicks').value) * parseFloat(document.getElementById('epc').value));
showEarnings();
}

function showEarnings()  {
document.getElementById('info').innerHTML = '<span class="daily">Günde ' + document.getElementById('earnings').value + ' dolar</span>';
document.getElementById('info').innerHTML = document.getElementById('info').innerHTML + '<span class="weekly"> = haftada ' + roundCurrency(document.getElementById('earnings').value * 7) + ' dolar</span>';
document.getElementById('info').innerHTML = document.getElementById('info').innerHTML + '<span class="monthly"> = ayda ' + roundCurrency(document.getElementById('earnings').value * 30) + ' dolar =</span>';
document.getElementById('info').innerHTML = document.getElementById('info').innerHTML + '<span class="yearly"> yılda ' + roundCurrency(document.getElementById('earnings').value * 365) + ' dolar</span>';
}

function roundCurrency(c) {
c = c * 100;
c = Math.round(c).toString();
if (c.length == 2) {c = '0' + c;}
if (c.length == 1) {c = '00' + c;}
c = c.substring(0,c.length - 2) + '.' + c.substring(c.length - 2);
return c;
}


