var Conditions={ /* as colorsFront price is everywhere equal to colorBack price we can use only one array for both. Enter quantity as '1-12':[1 color,2color, 3color, etc] */
'12-23' :[8.00, 9,10,11,12,13], '24-35' :[2.50,3.13,3.75,3.75,3.75,3.75], '36-71' :[2.00,2.50,3.00,3.50,4.00,5.00], '72-99' :[1.80,2.25,2.70,3.15,3.60,4.05], '100-199':[1.60,2.00,2.40,2.80,3.20,3.60], '200-499':[1.30,1.63,1.95,2.28,2.61,2.94], '500-999':[1.10,1.38,1.63,1.93,2.26,2.56], '1000+' :[0.90,1.13,1.35,1.58,1.80,2.02] }
function _(id){return document.getElementById(id);}
function calc(){ var numberOfShirts = Number(_('numberOfShirts').value), numberOfColorsFront = Number(_('numberOfColorsFront').value), numberOfColorsBack = Number(_('numberOfColorsBack').value), productStyle = Number(_('ProductStyle').value), productColor = Number(_('ShirtColor').value), feeFront = (numberOfColorsFront == 0) ? 0 : (25 + 20*(numberOfColorsFront - 1)), feeBack = (numberOfColorsBack == 0) ? 0 : (25 + 20*(numberOfColorsBack - 1)), fee = feeFront + feeBack, priceForColors = pricePerColorFront = pricePerColorBack = total = 0, arr;
switch(true){
case numberOfShirts >= 24 && numberOfShirts <= 35 : arr = Conditions['24-35']; break; case numberOfShirts >= 36 && numberOfShirts <= 71 : arr = Conditions['36-71']; break; case numberOfShirts >= 72 && numberOfShirts <= 99 : arr = Conditions['72-99']; break; case numberOfShirts >= 100 && numberOfShirts <= 199 : arr = Conditions['100-199']; break; case numberOfShirts >= 200 && numberOfShirts <= 499 : arr = Conditions['200-499']; break; case numberOfShirts >= 500 && numberOfShirts <= 999 : arr = Conditions['500-999']; break; case numberOfShirts >= 1000 : arr = Conditions['1000+']; break; default: alert('Number of Shirts can not be empty!');_('numberOfShirts').focus(); }
pricePerColorFront = arr[numberOfColorsFront-1] || 0; pricePerColorBack = arr[numberOfColorsBack-1] || 0; priceForColors = pricePerColorFront+pricePerColorBack;
total = ((numberOfShirts * priceForColors) + fee) + (numberOfShirts *(productStyle + productColor)); total_w_tax = total * 1.0825; total_per_shirt = total / numberOfShirts; /* these are just for testing purpose
_('res').innerHTML='numberOfShirts = '+numberOfShirts+'
';
_('res').innerHTML+='numberOfColorsFront = '+numberOfColorsFront+'
';
_('res').innerHTML+='numberOfColorsBack = '+numberOfColorsBack+'
';
_('res').innerHTML+='productStyle = '+productStyle+'
';
_('res').innerHTML+='productColor = '+productColor+'
';
_('res').innerHTML+='feeFront = '+feeFront+'
';
_('res').innerHTML+='feeBack = '+feeBack+'
';
_('res').innerHTML+='fee = '+fee+'
';
_('res').innerHTML+='priceForColors = '+priceForColors+'
';
_('res').innerHTML+='pricePerColorFront = '+pricePerColorFront+'
';
_('res').innerHTML+='pricePerColorBack = '+pricePerColorBack+'
';
*/
_('res').innerHTML='Total = $'+total.toFixed(2)+' | Price per Shirt = $'+total_per_shirt.toFixed(2)+
'
| YOUR TOTAL w/tax = $'+total_w_tax.toFixed(2) ;
}
onload=function(){
_('clr').onclick=function(){
_('res').innerHTML='';
_('numberOfShirts').focus();
}
_('numberOfShirts').onchange=function(){
if(this.value <24){this.value = 24;}
if(this.value > 5000){this.value = 5000;}
}
}