

function base_price(){

//variable costs

var screen = "20"; // getting the art processed, making the screen, setting the press up.
var load_charge = ".30"; // getting the garment on the press for that location
var impression = ".17"; // ink costs + labor of pulling squeegee

//define form fields

var front = document.gatherer.front.value;
var back = document.gatherer.back.value;
var left_slv = document.gatherer.left_slv.value;
var right_slv = document.gatherer.right_slv.value;

var line1_quan = document.gatherer.line1_quan.value;
var line2_quan = document.gatherer.line2_quan.value;
var line3_quan = document.gatherer.line3_quan.value;
var line4_quan = document.gatherer.line4_quan.value;

//start applying formula

var colors = (front*1)+(back*1)+(left_slv*1)+(right_slv*1); //same as screens - sum of colors for all locations

var c=0;
while (c==0){ 

var screen_total = (screen)*(colors); // screens x screen charge
c++;
}

var quantity = (line1_quan*1) + (line2_quan*1) + (line3_quan*1) + (line4_quan*1); // add the line quantities together for a total number of imprinted pieces


var impression_total = (impression)*(colors)*(quantity); // impression charge x colors x quantity

//Figure out how many times we have to load the press, then charge for it:

var load_quan = new Array(front, back, left_slv, right_slv);
var count=0;
var load=0;

while (count<=6) {

 if (load_quan[count] > 0){
     load++};
 count++;}

var load_total = (load_charge)*(load)*(quantity); // charge x number of loads x number of pieces

//Add all of the charges together:

var sum= new Array(screen_total, load_total, impression_total);

var base_total = 0;
var i=0;
while (i<=2) {
  base_total = base_total + sum[i]; 
  i++;
}

var base = (base_total) / (quantity) // Total non-garment charges divided by total quantity

return base;
}

function dollarValue(n)
{
  var Bstr = "";
  var b = n * 100;
  var c = Math.round(b);
  var Astr = c.toString();
  var Alength = Astr.length;
  if (Alength <= 2) Bstr = Bstr + ".";
  var dot = Alength - 3;
  var counter = 0;
    while (counter < Alength )
    {
      Bstr = Bstr + Astr.charAt(counter);
      if (counter == dot) Bstr = Bstr + ".";
      counter = counter + 1;
    }
  var d = Bstr;
  return d;
  }

function populateFields(){



var markup = "1.40";
var markedup = base_price() * markup;
var garment_markup = markup;
var shipping = document.gatherer.shipping.value;

var line1_quan = document.gatherer.line1_quan.value;
var line2_quan = document.gatherer.line2_quan.value;
var line3_quan = document.gatherer.line3_quan.value;
var line4_quan = document.gatherer.line4_quan.value;
var quantity = (line1_quan*1) + (line2_quan*1) + (line3_quan*1) + (line4_quan*1); // add the line quantities together for a total number of imprinted pieces

var front = document.gatherer.front.value;
var back = document.gatherer.back.value;
var left_slv = document.gatherer.left_slv.value;
var right_slv = document.gatherer.right_slv.value;


//Out of Range Error

if (quantity*1 < 20) {
  alert("Minimum Order is 20 pieces per design. \n You've only entered "  + quantity + " pieces.")
  }
  
else if (front*1 > 9 || back*1 > 9 || left_slv*1 > 6 || right_slv*1 > 6){

  alert("There\'s a maximum of 9 colors per standard location, 6 colors per sleeve.")
  }

else {

//var base = dollarValue(markedup);

if (line1_quan != ""){

document.gatherer.base1.value=markedup;
var line1each=(document.gatherer.base1.value*1) + (document.gatherer.line1_type.value*garment_markup);
document.gatherer.line1_each.value=dollarValue(line1each);
var line1total=(document.gatherer.line1_each.value) * (document.gatherer.line1_quan.value);
document.gatherer.line1_total.value=dollarValue(line1total);

};

document.gatherer.base2.value=markedup;
var line2each=(document.gatherer.base2.value*1) + (document.gatherer.line2_type.value*garment_markup);
document.gatherer.line2_each.value=dollarValue(line2each);
var line2total=(document.gatherer.line2_each.value) * (document.gatherer.line2_quan.value);
document.gatherer.line2_total.value=dollarValue(line2total);

if (line2_quan != ""){

document.gatherer.base3.value=markedup;
var line3each=(document.gatherer.base3.value*1) + (document.gatherer.line3_type.value*garment_markup);
document.gatherer.line3_each.value=dollarValue(line3each);
var line3total=(document.gatherer.line3_each.value) * (document.gatherer.line3_quan.value);
document.gatherer.line3_total.value=dollarValue(line3total);

};

document.gatherer.base4.value=markedup;
var line4each=(document.gatherer.base4.value*1) + (document.gatherer.line4_type.value*garment_markup);
document.gatherer.line4_each.value=dollarValue(line4each);
var line4total=(document.gatherer.line4_each.value) * (document.gatherer.line4_quan.value);
document.gatherer.line4_total.value=dollarValue(line4total);

var sub_total=(document.gatherer.line1_total.value*1) + (document.gatherer.line2_total.value*1) + (document.gatherer.line3_total.value*1) + (document.gatherer.line4_total.value*1);
document.gatherer.sub_total.value=dollarValue(sub_total);

var grand_total=(document.gatherer.line1_total.value*1) + (document.gatherer.line2_total.value*1) + (document.gatherer.line3_total.value*1) + (document.gatherer.line4_total.value*1) + (shipping*1);
document.gatherer.grand_total.value=dollarValue(grand_total);
   }
  }


