var montly_clicks; var cpc; var conversion_rate; var profit; $(document).ready(function() { $("#monthly_clicks").keyup( function() { var val = $("#monthly_clicks").val(); if (val == "") { if (!$("#monthly_click_err").is(":hidden")) $("#monthly_click_err").hide("fast"); return; } var no = parseInt(val, 10); if (!isNaN(no)) { if (!$("#monthly_click_err").is(":hidden")) $("#monthly_click_err").hide("fast"); montly_clicks = no; calculate(); } else { $("#monthly_click_err").text("Eroare la procesarea numarului"); if ($("#monthly_click_err").is(":hidden")) $("#monthly_click_err").show("fast"); clear(); } }); $("#cpc").keyup( function () { var val = $("#cpc").val(); if (val == "") { if (!$("#cpc_err").is(":hidden")) $("#cpc_err").hide("fast"); return; } var no = parseFloat(val); if (!isNaN(no)) { if (!$("#cpc_err").is(":hidden")) $("#cpc_err").hide("fast"); cpc = no; calculate(); } else { $("#cpc_err").text("Eroare la procesarea numarului"); if ($("#cpc_err").is(":hidden")) $("#cpc_err").show("fast"); clear(); } }); $("#conversion_rate").keyup( function() { var val = $("#conversion_rate").val(); if (val == "") { if (!$("#conversion_rate_err").is(":hidden")) $("#conversion_rate_err").hide("fast"); return; } var no = parseFloat(val); if (!isNaN(no) && (no <= 100)) { if (!$("#conversion_rate_err").is(":hidden")) $("#conversion_rate_err").hide("fast"); conversion_rate = no; calculate(); } else { $("#conversion_rate_err").text("Eroare la procesarea numarului"); if ($("#conversion_rate_err").is(":hidden")) $("#conversion_rate_err").show("fast"); clear(); } }); $("#profit").keyup( function() { var val = $("#profit").val(); if (val == "") { if (!$("#profit_err").is(":hidden")) $("#profit_err").hide("fast"); return; } var no = parseFloat(val); if (!isNaN(no)) { if (!$("#profit_err").is(":hidden")) $("#profit_err").hide("fast"); profit = no; calculate(); } else { $("#profit_err").text("Eroare la procesarea numarului"); if ($("#profit_err").is(":hidden")) $("#profit_err").show("fast"); clear(); } }); $("#go").click( function() { var val = $("#monthly_clicks").val(); var no = parseInt(val, 10); if (!isNaN(no)) montly_clicks = no; val = $("#cpc").val(); no = parseFloat(val); if (!isNaN(no)) cpc = no; val = $("#conversion_rate").val(); no = parseFloat(val); if (!isNaN(no)) conversion_rate = no; val = $("#profit").val(); no = parseFloat(val); if (!isNaN(no)) profit = no; calculate(); }) }); function calculate() { if (!montly_clicks || !cpc || !conversion_rate || !profit) return; if ((isNaN( eval(montly_clicks * cpc) )==true)) var monthlycost=0; else var monthlycost = eval(montly_clicks * cpc) if ((isNaN( eval(montly_clicks * (conversion_rate / 100)) )==true)) var numberofconversions=0; else var numberofconversions = eval(montly_clicks * (conversion_rate / 100)) if ((isNaN( eval((numberofconversions * profit) - monthlycost) )==true)) var projectedprofit=0; else var projectedprofit = eval((numberofconversions * profit) - monthlycost) if ((monthlycost==0)) roi=0; else var roi = eval((projectedprofit / monthlycost)*100); var result1 = Math.round(monthlycost*100)/100; var result2 = Math.round(numberofconversions*100)/100; var result3 = Math.round(projectedprofit*100)/100; var result4 = Math.round(roi*100)/100; var html = '

Rezultate

'; html+='

Cost per luna = '+ result1 +' €

'; html+='

Numărul de conversii = ' + result2 +'

'; html+='

Profitul estimat = ' + result3 +' €

'; html+='

ROI (returnarea investiei) = '+ result4 + "%

"; $("#results").html(html); } function clear() { var html = '

Rezultate

'; $("#results").html(html); }