// orderform.js

  var shipBook = new Array();
  var shipBookp = new Array();
  shipBook[1]="1.55";
  shipBookp[1]="4.05";
  shipBook[2]="2.00";
  shipBookp[2]="4.05";
  shipBook[3]="2.00";
  shipBookp[3]="5.15";
  shipBook[4]="2.55";
  shipBookp[4]="6.15";
  shipBook[5]="2.55";
  shipBookp[5]="6.55";
  shipBook[6]="2.55";
  shipBookp[6]="7.20";
  shipBook[7]="3.05";
  shipBookp[7]="7.30";
  shipBook[8]="3.05";
  shipBookp[8]="7.30";
  shipBook[9]="3.55";
  shipBookp[9]="8.25";
  shipBook[10]="3.55";
  shipBookp[10]="12.95";
  shipBook[11]="4.00";
  shipBookp[11]="10.15";
  shipBook[12]="4.50";
  shipBookp[12]="11.25";
  shipBook[13]="4.50";
  shipBookp[13]="11.25";
  shipBook[14]="4.50";
  shipBookp[14]="11.25";
  shipBook[15]="4.50";
  shipBookp[15]="11.25";
  shipBook[16]="5.50";
  shipBookp[16]="13.95";

  
  
  
  var prodlist = new Array();
  var prodprice1 = new Array();  var prodprice2 = new Array();
    prodprice1[1]="9.95"; // The Bench
  prodprice1[2]="2.00"; // Racing toward God
  prodprice1[3]="9.95"; // World Class Truth
  prodprice1[4]="7.95"; // Little Drop of Water
  prodprice1[5]="8.95"; // Heroes of the Valley
  prodprice1[6]="9.95"; // Clouds without Rain
  prodprice1[7]="35.00"; // Set of ALL 5
  

 
 function clearform(){
 document.orderform.Book_1.selectedIndex=0;
 document.orderform.Book_2.selectedIndex=0;
 document.orderform.Book_3.selectedIndex=0;
 document.orderform.Book_4.selectedIndex=0;
 document.orderform.Book_5.selectedIndex=0;
 document.orderform.Quantity_1.selectedIndex=0;
 document.orderform.Quantity_2.selectedIndex=0;
 document.orderform.Quantity_3.selectedIndex=0;
 document.orderform.Quantity_4.selectedIndex=0;
 document.orderform.Quantity_5.selectedIndex=0;
 document.orderform.Quantity_1.disabled=true;
 document.orderform.Quantity_2.disabled=true;
 document.orderform.Quantity_3.disabled=true;
 document.orderform.Quantity_4.disabled=true;
 document.orderform.Quantity_5.disabled=true;
 document.orderform.Cost_1.value=""
 document.orderform.Cost_1.value=""
 document.orderform.Cost_2.value=""
 document.orderform.Cost_3.value=""
 document.orderform.Cost_4.value=""   
 document.orderform.Cost_5.value="" 
 document.orderform.Subtotal_1.value=""
 document.orderform.Subtotal_1.value=""
 document.orderform.Subtotal_2.value=""
 document.orderform.Subtotal_3.value=""
 document.orderform.Subtotal_4.value=""   
 document.orderform.Subtotal_5.value="" 
 document.orderform.shipOption.value="0"
 document.orderform.TotalBooks.value="";
 document.orderform.Subtotal.value="";
 document.orderform.Shipping.value="";
 document.orderform.TOTAL.value="";
 

}

function do_shipping(){
 document.orderform.FinalProduct.value="$ "+totalproduct;
 document.orderform.FinalCost.value="$ "+totalcostval+".00";
}


function do_book(x){
if (x==1 && document.orderform.Book_1.value==0) return;
if (x==2 && document.orderform.Book_1.value==0) return;
if (x==3 && document.orderform.Book_1.value==0) return;
if (x==4 && document.orderform.Book_1.value==0) return;
if (x==5 && document.orderform.Book_1.value==0) return;

 if(x==1){document.orderform.Quantity_1.selectedIndex=1;document.orderform.Quantity_1.disabled=false;}
 if(x==2){document.orderform.Quantity_2.selectedIndex=1;document.orderform.Quantity_2.disabled=false;}
 if(x==3){document.orderform.Quantity_3.selectedIndex=1;document.orderform.Quantity_3.disabled=false;}
 if(x==4){document.orderform.Quantity_4.selectedIndex=1;document.orderform.Quantity_4.disabled=false;}
 if(x==5){document.orderform.Quantity_5.selectedIndex=1;document.orderform.Quantity_5.disabled=false;}  
 if(x==1) document.orderform.Cost_1.value="$ "+prodprice1[document.orderform.Book_1.selectedIndex];
 if(x==2) document.orderform.Cost_2.value="$ "+prodprice1[document.orderform.Book_2.selectedIndex];
 if(x==3) document.orderform.Cost_3.value="$ "+prodprice1[document.orderform.Book_3.selectedIndex];
 if(x==4) document.orderform.Cost_4.value="$ "+prodprice1[document.orderform.Book_4.selectedIndex];
 if(x==5) document.orderform.Cost_5.value="$ "+prodprice1[document.orderform.Book_5.selectedIndex]; 
 do_subtotal(x);

}
function do_subtotal(x){
var y=0.0
 if(x==1) y=document.orderform.Book_1.selectedIndex;
 if(x==2) y=document.orderform.Book_2.selectedIndex;
 if(x==3) y=document.orderform.Book_3.selectedIndex;
 if(x==4) y=document.orderform.Book_4.selectedIndex;
 if(x==5) y=document.orderform.Book_5.selectedIndex;
var bookCost=prodprice1[y]
if(x==1)bookQty=document.orderform.Quantity_1.value;
if(x==2)bookQty=document.orderform.Quantity_2.value;
if(x==3)bookQty=document.orderform.Quantity_3.value;
if(x==4)bookQty=document.orderform.Quantity_4.value;
if(x==5)bookQty=document.orderform.Quantity_5.value;

var subCost=(bookCost*bookQty)
if(x==1){document.orderform.Subtotal_1.value="$ "+subCost.toFixed(2);document.orderform.Book_1[0].enabled=false;}
if(x==2){document.orderform.Subtotal_2.value="$ "+subCost.toFixed(2);document.orderform.Book_1[0].disabled=true;}
if(x==3){document.orderform.Subtotal_3.value="$ "+subCost.toFixed(2);document.orderform.Book_1[0].disabled=true;}
if(x==4){document.orderform.Subtotal_4.value="$ "+subCost.toFixed(2);document.orderform.Book_1[0].disabled=true;}
if(x==5){document.orderform.Subtotal_5.value="$ "+subCost.toFixed(2);document.orderform.Book_1[0].disabled=true;}

do_Totals(x);
}

function do_Totals(x){
if (document.orderform.Book_1.selectedIndex==0) {count1=0;total1=0} else{
count1=parseInt(document.orderform.Quantity_1.value);
total1=count1* prodprice1[document.orderform.Book_1.selectedIndex];
}
if (document.orderform.Book_2.selectedIndex==0) {count2=0;total2=0} else{
count2=parseInt(document.orderform.Quantity_2.value);
total2=count2* prodprice1[document.orderform.Book_2.selectedIndex];
}
if (document.orderform.Book_3.selectedIndex==0) {count3=0;total3=0} else{
count3=parseInt(document.orderform.Quantity_3.value);
total3=count3* prodprice1[document.orderform.Book_3.selectedIndex];
}
if (document.orderform.Book_4.selectedIndex==0) {count4=0;total4=0} else{
count4=parseInt(document.orderform.Quantity_4.value);
total4=count4* prodprice1[document.orderform.Book_4.selectedIndex];
}
if (document.orderform.Book_5.selectedIndex==0) {count5=0;total5=0} else{
count5=parseInt(document.orderform.Quantity_5.value);
total5=count5* prodprice1[document.orderform.Book_5.selectedIndex];
}

var totalCount=count1+count2+count3+count4+count5
var discountflag=0
var discountamount=0.0
var subTotal=total1+total2+total3+total4+total5
if (totalCount>4) {discountamount=0.15*subTotal;discountflag=15}
if (totalCount>15) {discountamount=0.20*subTotal;discountflag=20}
document.orderform.discount15.checked=false;
document.orderform.discount20.checked=false;
if (discountflag==15)document.orderform.discount15.checked=true;
if (discountflag==20)document.orderform.discount20.checked=true;
document.orderform.Discount.value="$ "+discountamount.toFixed(2)
var totalCost=total1+total2+total3+total4+total5-discountamount
var shipCost=0.0;
if (totalCount==0)
{
document.orderform.TotalBooks.value="";
document.orderform.Subtotal.value=""
document.orderform.Shipping.value="";
document.orderform.TOTAL.value="";
return;
}
if (totalCount==1 && document.orderform.shipOption[0].checked==true)shipCost=shipBook[1];
if (totalCount==1 && document.orderform.shipOption[1].checked==true)shipCost=shipBookp[1];
if (totalCount==2 && document.orderform.shipOption[0].checked==true)shipCost=shipBook[2];
if (totalCount==2 && document.orderform.shipOption[1].checked==true)shipCost=shipBookp[2];
if (totalCount==3 && document.orderform.shipOption[0].checked==true)shipCost=shipBook[3];
if (totalCount==3 && document.orderform.shipOption[1].checked==true)shipCost=shipBookp[3];
if (totalCount==4 && document.orderform.shipOption[0].checked==true)shipCost=shipBook[4];
if (totalCount==4 && document.orderform.shipOption[1].checked==true)shipCost=shipBookp[4];
if (totalCount==5 && document.orderform.shipOption[0].checked==true)shipCost=shipBook[5];
if (totalCount==5 && document.orderform.shipOption[1].checked==true)shipCost=shipBookp[5];
if (totalCount==6 && document.orderform.shipOption[0].checked==true)shipCost=shipBook[6];
if (totalCount==6 && document.orderform.shipOption[1].checked==true)shipCost=shipBookp[6];
if (totalCount==7 && document.orderform.shipOption[0].checked==true)shipCost=shipBook[7];
if (totalCount==7 && document.orderform.shipOption[1].checked==true)shipCost=shipBookp[7];
if (totalCount==8 && document.orderform.shipOption[0].checked==true)shipCost=shipBook[8];
if (totalCount==8 && document.orderform.shipOption[1].checked==true)shipCost=shipBookp[8];
if (totalCount==9 && document.orderform.shipOption[0].checked==true)shipCost=shipBook[9];
if (totalCount==9 && document.orderform.shipOption[1].checked==true)shipCost=shipBookp[9];
if (totalCount==10 && document.orderform.shipOption[0].checked==true)shipCost=shipBook[10];
if (totalCount==10 && document.orderform.shipOption[1].checked==true)shipCost=shipBookp[10];
if (totalCount==11 && document.orderform.shipOption[0].checked==true)shipCost=shipBook[11];
if (totalCount==11 && document.orderform.shipOption[1].checked==true)shipCost=shipBookp[11];
if (totalCount==12 && document.orderform.shipOption[0].checked==true)shipCost=shipBook[12];
if (totalCount==12 && document.orderform.shipOption[1].checked==true)shipCost=shipBookp[12];
if (totalCount==13 && document.orderform.shipOption[0].checked==true)shipCost=shipBook[13];
if (totalCount==13 && document.orderform.shipOption[1].checked==true)shipCost=shipBookp[13];
if (totalCount==14 && document.orderform.shipOption[0].checked==true)shipCost=shipBook[14];
if (totalCount==14 && document.orderform.shipOption[1].checked==true)shipCost=shipBookp[14];
if (totalCount==15 && document.orderform.shipOption[0].checked==true)shipCost=shipBook[15];
if (totalCount==15 && document.orderform.shipOption[1].checked==true)shipCost=shipBookp[15];
if (totalCount>15 && document.orderform.shipOption[0].checked==true)shipCost=shipBook[16];
if (totalCount>15 && document.orderform.shipOption[1].checked==true)shipCost=shipBookp[16];



var finalCost=parseFloat(totalCost)+parseFloat(shipCost)
document.orderform.TotalBooks.value=totalCount;
document.orderform.Subtotal.value="$ "+totalCost.toFixed(2)

document.orderform.Shipping.value="$ "+shipCost

document.orderform.TOTAL.value="$ "+finalCost.toFixed(2)

if(x==1)document.orderform.Book_1[0].disabled=true;
if(x==2)document.orderform.Book_2[0].disabled=true;
if(x==3)document.orderform.Book_3[0].disabled=true;
if(x==4)document.orderform.Book_4[0].disabled=true;
if(x==5)document.orderform.Book_5[0].disabled=true;

}

function clearROW(x){
 if (x==1){document.orderform.Subtotal_1.value="";
           document.orderform.Cost_1.value="";
		   document.orderform.Book_1[0].selected=true;
		   document.orderform.Quantity_1[0].selected==true;
		   document.orderform.Quantity_1.disabled=true;
		   }
 if (x==2){document.orderform.Subtotal_2.value="";
           document.orderform.Cost_2.value="";
		   document.orderform.Book_2[0].selected=true;
		   document.orderform.Quantity_2[0].selected==true;
		   document.orderform.Quantity_2.disabled=true;
		   }
 if (x==3){document.orderform.Subtotal_3.value="";
           document.orderform.Cost_3.value="";
		   document.orderform.Book_3[0].selected=true;
		   document.orderform.Quantity_3[0].selected==true;
		   document.orderform.Quantity_3.disabled=true;
		   }
 if (x==4){document.orderform.Subtotal_4.value="";
           document.orderform.Cost_4.value="";
		   document.orderform.Book_4[0].selected=true;
		   document.orderform.Quantity_4[0].selected==true;
		   document.orderform.Quantity_4.disabled=true;
		   }
 if (x==5){document.orderform.Subtotal_5.value="";
           document.orderform.Cost_5.value="";
		   document.orderform.Book_5[0].selected=true;
		   document.orderform.Quantity_5[0].selected==true;
		   document.orderform.Quantity_5.disabled=true;
		   }		   		   		   		
 do_Totals(1);		   
 }		     
