var count = 10;
//Add the 2 days of weekend in numer of days .
var d = new Date();
count = count + (parseInt(count/5))*2;
d.setDate(d.getDate() -count);
//suppose its ending on weekend day then increment them manually.
if(d.getDay() == 6 ) d.setDate(d.getDate() -1);
if(d.getDay() == 0){ d.setDate(d.getDate() - 2);};
alert(d);
it will substract all weekend day from whatever you want to substract day dynamically