﻿ 

 var salesprice=0;
 var percent=0;
 var commisionvalue=0;
 var marketfees=0;
 var otherfess=0;
 var packages=0;
 var totalcommission=0;
 function calculate()
 {
 commisionvalue=(salesprice*percent)/100;
 document.getElementById('txtCommisionValue').value=currency(commisionvalue);
 calculatecommision();
 calculatefinal();
 }

 function calculatecommision()
 {
 totalcommission=parseInt(commisionvalue)+parseInt(marketfees)+parseInt(otherfess);
 //document.getElementById('txtTotalCommision').value=currency(totalcommission);
 calculatefinal();
 }

 function calculatefinal()
 {
 //document.getElementById('txtTotalSaving').value=currency(parseInt(totalcommission) - parseInt(packages));
 }

 //function for returning the currency value
function currency(pNum) {
//-- Returns passed number as string in $xxx,xxx.xx format.
var tRtnValue = "";
if (pNum != "") {
var n = pNum.toString().replace(/\$|\,/g,'');
if (isNaN(n)) {n = "0";}
var tSign = (n == (n = Math.abs(n)));
n = Math.floor(n * 100 + 0.50000000001);
var tCents = n % 100;
if (tCents < 10) {tCents = "0" + tCents;}
n = Math.floor(n / 100).toString();
for (var i = 0; i < Math.floor((n.length - (1 + i)) / 3); i++) {
n = n.substring(0, n.length - (4 * i + 3)) + ',' + n.substring(n.length - (4 * i + 3));
}
tRtnValue = (((tSign)?'':'-') + '$' + n + '.' + tCents);
}else{
tRtnValue = 0;
}
return tRtnValue;
}

function percentage(pNum) {
//-- Returns passed number as string in $xxx,xxx.xx format.
percent=pNum.replace('%','');
return pNum.replace('%','') + '%';
}
//validation of the number
function valid_number(string) {
var sTmp = "";
var sValid = "0123456789.";

for (var i=0; i< string.length; i++) {
if (sValid.indexOf(string.charAt(i)) != -1 )
sTmp += string.charAt(i);
}
return(sTmp)
}
 