// JavaScript Document
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Cyanide_7 |  */
var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
  var keyCode = (isNN) ? e.which : e.keyCode; 
  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
  if(input.value.length >= len && !containsElement(filter,keyCode)) {
    input.value = input.value.slice(0, len);
    input.form[(getIndex(input)+1) % input.form.length].focus();
  }

  function containsElement(arr, ele) {
    var found = false, index = 0;
    while(!found && index < arr.length)
    if(arr[index] == ele)
    found = true;
    else
    index++;
    return found;
  }

  function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
    if (input.form[i] == input)index = i;
    else i++;
    return index;
  }
  return true;
}

//Automated Standard Class Flats Calculator
function saf_calculate() {
five_under3_saf = document.savings_calculator_standard_auto_flats.five_under3_saf.value
three_under3_saf = document.savings_calculator_standard_auto_flats.three_under3_saf.value
adc_under3_saf = document.savings_calculator_standard_auto_flats.adc_under3_saf.value
madc_under3_saf = document.savings_calculator_standard_auto_flats.madc_under3_saf.value

five_over3_saf = document.savings_calculator_standard_auto_flats.five_over3_saf.value
three_over3_saf = document.savings_calculator_standard_auto_flats.three_over3_saf.value
adc_over3_saf = document.savings_calculator_standard_auto_flats.adc_over3_saf.value
madc_over3_saf = document.savings_calculator_standard_auto_flats.madc_over3_saf.value

five_under3_saf = Number(five_under3_saf)
three_under3_saf = Number(three_under3_saf)
adc_under3_saf = Number(adc_under3_saf)
madc_under3_saf = Number(madc_under3_saf)

five_over3_saf = Number(five_over3_saf)
three_over3_saf = Number(three_over3_saf)
adc_over3_saf = Number(adc_over3_saf)
madc_over3_saf = Number(madc_over3_saf)

document.savings_calculator_standard_auto_flats.total_pieces_saf.value = Comma(five_under3_saf + three_under3_saf + adc_under3_saf + madc_under3_saf + five_over3_saf + three_over3_saf + adc_over3_saf + madc_over3_saf)

five_auto_saf = (five_under3_saf * .346) + (five_over3_saf * (.725 + .196))
three_auto_saf = (three_under3_saf * .418) + (three_over3_saf * (.725 + .268))
adc_auto_saf = (adc_under3_saf * .486) + (adc_over3_saf * (.725 + .336))
madc_auto_saf = (madc_under3_saf * .496) + (madc_over3_saf * (.725 + .346))

document.savings_calculator_standard_auto_flats.five_auto_saf.value = formatCurrency(five_auto_saf)
document.savings_calculator_standard_auto_flats.three_auto_saf.value = formatCurrency(three_auto_saf)
document.savings_calculator_standard_auto_flats.adc_auto_saf.value = formatCurrency(adc_auto_saf)
document.savings_calculator_standard_auto_flats.madc_auto_saf.value = formatCurrency(madc_auto_saf)

five_full_saf = (five_under3_saf * .88) + (five_over3_saf * .88)
three_full_saf = (three_under3_saf * .88) + (three_over3_saf * .88)
adc_full_saf = (adc_under3_saf * .88) + (adc_over3_saf * .88)
madc_full_saf = (madc_under3_saf * .88) + (madc_over3_saf * .88)


document.savings_calculator_standard_auto_flats.five_full_saf.value = formatCurrency(five_full_saf)
document.savings_calculator_standard_auto_flats.three_full_saf.value = formatCurrency(three_full_saf)
document.savings_calculator_standard_auto_flats.adc_full_saf.value = formatCurrency(adc_full_saf)
document.savings_calculator_standard_auto_flats.madc_full_saf.value = formatCurrency(madc_full_saf)

five_save_saf = five_full_saf - five_auto_saf
three_save_saf = three_full_saf - three_auto_saf
adc_save_saf = adc_full_saf - adc_auto_saf
madc_save_saf = madc_full_saf - madc_auto_saf

document.savings_calculator_standard_auto_flats.five_save_saf.value = formatCurrency(five_save_saf)
document.savings_calculator_standard_auto_flats.three_save_saf.value = formatCurrency(three_save_saf)
document.savings_calculator_standard_auto_flats.adc_save_saf.value = formatCurrency(adc_save_saf)
document.savings_calculator_standard_auto_flats.madc_save_saf.value = formatCurrency(madc_save_saf)

savings_day_saf = five_save_saf + three_save_saf + adc_save_saf + madc_save_saf
savings_week_saf = savings_day_saf * 5
savings_month_saf = savings_day_saf * 21
savings_year_saf = savings_day_saf * 21 * 12

document.savings_calculator_standard_auto_flats.savings_day_saf.value = formatCurrency(savings_day_saf)
document.savings_calculator_standard_auto_flats.savings_week_saf.value = formatCurrency(savings_week_saf)
document.savings_calculator_standard_auto_flats.savings_month_saf.value = formatCurrency(savings_month_saf)
document.savings_calculator_standard_auto_flats.savings_year_saf.value = formatCurrency(savings_year_saf)
}

//First Class Flats New Calculator
function new_fcf_calculate() {

fcf_total = document.savings_calculator_fcf.fcf_total.value
fcf_total = Number(fcf_total)

fcf_method = document.savings_calculator_fcf.fcf_method.value
fcf_method = Number(fcf_method)

switch (fcf_method)
{
	case 1:
	five_total_fcf = fcf_total * .425;
	three_total_fcf = fcf_total * .375;
	adc_total_fcf = fcf_total * .15;
	madc_total_fcf = fcf_total * .05;
	break;

	case 2:
	five_total_fcf = fcf_total * .20;
	three_total_fcf = fcf_total * .35;
	adc_total_fcf = fcf_total * .30;
	madc_total_fcf = fcf_total * .15;
	break;

	case 3:
	five_total_fcf = fcf_total * .075;
	three_total_fcf = fcf_total * .225;
	adc_total_fcf = fcf_total * .425;
	madc_total_fcf = fcf_total * .275;
	break;
}

document.savings_calculator_fcf.five_fcf.value = Math.round(five_total_fcf)
document.savings_calculator_fcf.three_fcf.value = Math.round(three_total_fcf)
document.savings_calculator_fcf.adc_fcf.value = Math.round(adc_total_fcf)
document.savings_calculator_fcf.madc_fcf.value = Math.round(madc_total_fcf)

five_auto_fcf = five_total_fcf * .380
three_auto_fcf = three_total_fcf * .542
adc_auto_fcf = adc_total_fcf * .603
madc_auto_fcf = madc_total_fcf * .725

document.savings_calculator_fcf.five_auto_fcf.value = formatCurrency(five_auto_fcf)
document.savings_calculator_fcf.three_auto_fcf.value = formatCurrency(three_auto_fcf)
document.savings_calculator_fcf.adc_auto_fcf.value = formatCurrency(adc_auto_fcf)
document.savings_calculator_fcf.madc_auto_fcf.value = formatCurrency(madc_auto_fcf)

five_full_fcf = five_total_fcf * .88
three_full_fcf = three_total_fcf * .88
adc_full_fcf = adc_total_fcf * .88
madc_full_fcf = madc_total_fcf * .88


document.savings_calculator_fcf.five_full_fcf.value = formatCurrency(five_full_fcf)
document.savings_calculator_fcf.three_full_fcf.value = formatCurrency(three_full_fcf)
document.savings_calculator_fcf.adc_full_fcf.value = formatCurrency(adc_full_fcf)
document.savings_calculator_fcf.madc_full_fcf.value = formatCurrency(madc_full_fcf)

five_save_fcf = five_full_fcf - five_auto_fcf
three_save_fcf = three_full_fcf - three_auto_fcf
adc_save_fcf = adc_full_fcf - adc_auto_fcf
madc_save_fcf = madc_full_fcf - madc_auto_fcf

document.savings_calculator_fcf.five_save_fcf.value = formatCurrency(five_save_fcf)
document.savings_calculator_fcf.three_save_fcf.value = formatCurrency(three_save_fcf)
document.savings_calculator_fcf.adc_save_fcf.value = formatCurrency(adc_save_fcf)
document.savings_calculator_fcf.madc_save_fcf.value = formatCurrency(madc_save_fcf)

savings_day_fcf = five_save_fcf + three_save_fcf + adc_save_fcf + madc_save_fcf
savings_week_fcf = savings_day_fcf * 5
savings_month_fcf = savings_day_fcf * 21
savings_year_fcf = savings_day_fcf * 21 * 12

document.savings_calculator_fcf.savings_day_fcf.value = formatCurrency(savings_day_fcf)
document.savings_calculator_fcf.savings_week_fcf.value = formatCurrency(savings_week_fcf)
document.savings_calculator_fcf.savings_month_fcf.value = formatCurrency(savings_month_fcf)
document.savings_calculator_fcf.savings_year_fcf.value = formatCurrency(savings_year_fcf)
}

//Barcoded Bound Printer Matter Flats Calculator
function bbpm_calculate() {

bbpm_total = document.savings_calculator_bbpm.bbpm_total.value
bbpm_total = Number(bbpm_total)

bbpm_method = document.savings_calculator_bbpm.bbpm_method.value
bbpm_method = Number(bbpm_method)

switch (bbpm_method)
{
	case 1:
	onetwo_bbpm = bbpm_total * .20;
	three_bbpm = bbpm_total * .10;
	four_bbpm = bbpm_total * .10;
	five_bbpm = bbpm_total * .10;
	six_bbpm = bbpm_total * .10;
	seven_bbpm = bbpm_total * .10;
	eight_bbpm = bbpm_total * .10;
	break;

	case 2:
	onetwo_bbpm = bbpm_total * .10;
	three_bbpm = bbpm_total * .10;
	four_bbpm = bbpm_total * .15;
	five_bbpm = bbpm_total * .15;
	six_bbpm = bbpm_total * .10;
	seven_bbpm = bbpm_total * .10;
	eight_bbpm = bbpm_total * .10;
	break;

	case 3:
	onetwo_bbpm = bbpm_total * .10;
	three_bbpm = bbpm_total * .10;
	four_bbpm = bbpm_total * .10;
	five_bbpm = bbpm_total * .10;
	six_bbpm = bbpm_total * .10;
	seven_bbpm = bbpm_total * .15;
	eight_bbpm = bbpm_total * .15;
	break;
}

document.savings_calculator_bbpm.onetwo_bbpm.value = Math.round(onetwo_bbpm)
document.savings_calculator_bbpm.three_bbpm.value = Math.round(three_bbpm)
document.savings_calculator_bbpm.four_bbpm.value = Math.round(four_bbpm)
document.savings_calculator_bbpm.five_bbpm.value = Math.round(five_bbpm)
document.savings_calculator_bbpm.six_bbpm.value = Math.round(six_bbpm)
document.savings_calculator_bbpm.seven_bbpm.value = Math.round(seven_bbpm)
document.savings_calculator_bbpm.eight_bbpm.value = Math.round(eight_bbpm)

onetwo_bbpm_full = onetwo_bbpm * 1.89
three_bbpm_full = three_bbpm * 1.93
four_bbpm_full = four_bbpm * 1.99
five_bbpm_full = five_bbpm * 2.08
six_bbpm_full = six_bbpm * 2.19
seven_bbpm_full = seven_bbpm * 2.25
eight_bbpm_full = eight_bbpm * 2.44

document.savings_calculator_bbpm.onetwo_bbpm_full.value = formatCurrency(onetwo_bbpm_full)
document.savings_calculator_bbpm.three_bbpm_full.value = formatCurrency(three_bbpm_full)
document.savings_calculator_bbpm.four_bbpm_full.value = formatCurrency(four_bbpm_full)
document.savings_calculator_bbpm.five_bbpm_full.value = formatCurrency(five_bbpm_full)
document.savings_calculator_bbpm.six_bbpm_full.value = formatCurrency(six_bbpm_full)
document.savings_calculator_bbpm.seven_bbpm_full.value = formatCurrency(seven_bbpm_full)
document.savings_calculator_bbpm.eight_bbpm_full.value = formatCurrency(eight_bbpm_full)

onetwo_bbpm_auto = onetwo_bbpm * (1.2160 + .1380)
three_bbpm_auto = three_bbpm * (1.2160 + .1580)
four_bbpm_auto = four_bbpm * (1.2160 + .2000)
five_bbpm_auto = five_bbpm * (1.2160 + .2530)
six_bbpm_auto = six_bbpm * (1.2160 + .3210)
seven_bbpm_auto = seven_bbpm * (1.2160 + .3620)
eight_bbpm_auto = eight_bbpm * (1.2160 + .4820)

document.savings_calculator_bbpm.onetwo_bbpm_auto.value = formatCurrency(onetwo_bbpm_auto)
document.savings_calculator_bbpm.three_bbpm_auto.value = formatCurrency(three_bbpm_auto)
document.savings_calculator_bbpm.four_bbpm_auto.value = formatCurrency(four_bbpm_auto)
document.savings_calculator_bbpm.five_bbpm_auto.value = formatCurrency(five_bbpm_auto)
document.savings_calculator_bbpm.six_bbpm_auto.value = formatCurrency(six_bbpm_auto)
document.savings_calculator_bbpm.seven_bbpm_auto.value = formatCurrency(seven_bbpm_auto)
document.savings_calculator_bbpm.eight_bbpm_auto.value = formatCurrency(eight_bbpm_auto)

onetwo_bbpm_save = onetwo_bbpm_full - onetwo_bbpm_auto
three_bbpm_save = three_bbpm_full - three_bbpm_auto
four_bbpm_save = four_bbpm_full - four_bbpm_auto
five_bbpm_save = five_bbpm_full - five_bbpm_auto
six_bbpm_save = six_bbpm_full - six_bbpm_auto
seven_bbpm_save = seven_bbpm_full - seven_bbpm_auto
eight_bbpm_save = eight_bbpm_full - eight_bbpm_auto

document.savings_calculator_bbpm.onetwo_bbpm_savings.value = formatCurrency(onetwo_bbpm_save)
document.savings_calculator_bbpm.three_bbpm_savings.value = formatCurrency(three_bbpm_save)
document.savings_calculator_bbpm.four_bbpm_savings.value = formatCurrency(four_bbpm_save)
document.savings_calculator_bbpm.five_bbpm_savings.value = formatCurrency(five_bbpm_save)
document.savings_calculator_bbpm.six_bbpm_savings.value = formatCurrency(six_bbpm_save)
document.savings_calculator_bbpm.seven_bbpm_savings.value = formatCurrency(seven_bbpm_save)
document.savings_calculator_bbpm.eight_bbpm_savings.value = formatCurrency(eight_bbpm_save)

savings_day_bbpm = onetwo_bbpm_save + three_bbpm_save + four_bbpm_save + five_bbpm_save + six_bbpm_save + seven_bbpm_save + eight_bbpm_save
savings_week_bbpm = savings_day_bbpm * 5
savings_month_bbpm = savings_day_bbpm * 21
savings_year_bbpm = savings_day_bbpm * 21 * 12

document.savings_calculator_bbpm.savings_day_bbpm.value = formatCurrency(savings_day_bbpm)
document.savings_calculator_bbpm.savings_week_bbpm.value = formatCurrency(savings_week_bbpm)
document.savings_calculator_bbpm.savings_month_bbpm.value = formatCurrency(savings_month_bbpm)
document.savings_calculator_bbpm.savings_year_bbpm.value = formatCurrency(savings_year_bbpm)
}

function Comma(number) {
number = '' + number;
if (number.length > 3) {
var mod = number.length % 3;
var output = (mod > 0 ? (number.substring(0,mod)) : '');
for (i=0 ; i < Math.floor(number.length / 3); i++) {
if ((mod == 0) && (i == 0))
output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
else
output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
}
return (output);
}
else return number;
}

function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}