/* Code by Saied Dardour Developed for Mark Lappin August 2012 */ google.load("visualization", "1", {packages:["corechart"]}); google.setOnLoadCallback(marklappincalc_initChart); var chart; var chart_data; var chart_options; function marklappincalc_initChart() { chart = new google.visualization.PieChart(document.getElementById('pie-chart')); chart_data = new google.visualization.DataTable(); chart_data.addColumn('string', 'Portion'); chart_data.addColumn('number', 'Value'); chart_data.addRows(2); var i = 0; chart_data.setValue(0, 0, 'Commission Paid'); chart_data.setValue(1, 0, 'Remaining Equity'); chart_data.setValue(0, 1, 24000); chart_data.setValue(1, 1, 36000); chart_options = { is3D: true, colors: ['#ff3f3f', '#4fd5d6'], theme: 'maximized' }; chart.draw(chart_data, chart_options); }; var flag = 0.0; var tmp; var tmp_v1; var tmp_v2; var tmp_v3; var v1 = 0.0; var v2 = 0.0; var v3 = 0.0; var v4 = 0.0; var v5 = 0.0; var v6 = 0.0; var v7 = 0.0; jQuery(function($) { $('#v1').keydown(function(event) { if (event.which == 13) { marklappincalc_reformat(); } }); $('#v1').focusout(function() { marklappincalc_reformat(); }); $('#v2').keydown(function(event) { if (event.which == 13) { marklappincalc_reformat(); } }); $('#v2').focusout(function() { marklappincalc_reformat(); }); $('#v3').keydown(function(event) { if (event.which == 13) { marklappincalc_reformat(); } }); $('#v3').focusout(function() { marklappincalc_reformat(); }); $('input').hover( function () { $(this).parent().parent().parent().find('.tooltip').removeClass('hideme'); }, function () { $(this).parent().parent().parent().find('.tooltip').addClass('hideme'); } ); $('.refresh').click(function () { flag = 0.0; }); var refreshId = setInterval(function(){ marklappincalc_calc(); }, 250); function marklappincalc_calc() { var cont = 0.0; tmp_v1 = $('#v1').val(); tmp_v1 = marklappincalc_process(tmp_v1); tmp_v2 = $('#v2').val(); tmp_v2 = marklappincalc_process(tmp_v2); tmp_v3 = $('#v3').val(); tmp_v3 = marklappincalc_process(tmp_v3); if ( v1 != 1.0 * tmp_v1 ) { cont = 1.0; } if ( v2 != 1.0 * tmp_v2 ) { cont = 1.0; } if ( v3 != 1.0 * tmp_v3 ) { cont = 1.0; } if ( flag == 0.0 ) { cont = 1.0; flag = 1.0; } if ( cont == 1.0 ) { tmp_v1 = $('#v1').val(); tmp_v1 = marklappincalc_process(tmp_v1); tmp_v2 = $('#v2').val(); tmp_v2 = marklappincalc_process(tmp_v2); tmp_v3 = $('#v3').val(); tmp_v3 = marklappincalc_process(tmp_v3); v1 = 1.0 * tmp_v1; v2 = 1.0 * tmp_v2; v3 = 1.0 * tmp_v3; v4 = v2 - v3; v5 = v2 * v1 / 100; v6 = v4 - v5; v7 = 100 * (v5 / v4); $('#v4').val('$' + marklappincalc_addCommas(Math.round(v4 * 10.0) / 10.0)); $('#v5').val('$' + marklappincalc_addCommas(Math.round(v5 * 10.0) / 10.0)); $('#v6').val('$' + marklappincalc_addCommas(Math.round(v6 * 10.0) / 10.0)); $('#v7').val(Math.round(v7 * 10.0) / 10.0 + '%'); $('#commission-paid-dollar').text(marklappincalc_addCommas(Math.round(v5 * 10.0) / 10.0)); $('#commission-paid-percent').text(Math.round(v7 * 10.0) / 10.0); $('#remaining-equity').text(marklappincalc_addCommas(Math.round(v6 * 10.0) / 10.0)); $('#commission-paid').text(marklappincalc_addCommas(Math.round(v5 * 10.0) / 10.0)); try { chart_data.setValue(0, 1, Math.round(v5 * 10.0) / 10.0); chart_data.setValue(1, 1, Math.round(v6 * 10.0) / 10.0); chart.draw(chart_data, chart_options); } catch ( e ) {}; } }; function marklappincalc_addCommas(nStr) { nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; }; function marklappincalc_process(str) { tmp = str; tmp = tmp.replace('$', ''); tmp = tmp.replace('%', ''); tmp = tmp.replace(',', ''); tmp = tmp.replace(',', ''); tmp = tmp.replace(',', ''); return tmp; }; function marklappincalc_reformat() { tmp = $('#v1').val(); tmp = tmp.replace('%', ''); $('#v1').val(marklappincalc_addCommas(marklappincalc_process(tmp)) + '%'); tmp = $('#v2').val(); tmp = tmp.replace('$', ''); $('#v2').val('$' + marklappincalc_addCommas(marklappincalc_process(tmp))); tmp = $('#v3').val(); tmp = tmp.replace('$', ''); $('#v3').val('$' + marklappincalc_addCommas(marklappincalc_process(tmp))); }; });