// CALCULATE ORDER TOTAL

function calc_total() {

total = 0


addmain();
addgenoa();
addjib();
addspi();
addoptionals();
addacc();
calcroyalties();
calcshipping();

// Apply discount  -----------------


discount = document.f1.discount.value;

discount = parseInt(discount);


if (discount > "0" ) { 
	percentage = 100 - discount;	
	percentage = percentage / 100;
	total = total * percentage;
	total = 5 * Math.round(total/5);
}


// REMOVE AFTER - FALL DEAL - FREE SHIPPING ALL ORDERS - excludes m32, 505, j105

if ((document.f1.boat.value == "505") || (document.f1.boat.value == "melges32") || (document.f1.boat.value == "Tornado") || (document.f1.boat.value == "J105") || (document.f1.boat.value == "Atlantic") || (document.f1.boat.value == "Sonar") || (document.f1.boat.value == "Regatta Folder") || (document.f1.boat.value == "Book") || (document.f1.boat.value == "CD")) {

	shipping = shipping;
}
else
{

	shipping = 0;
}

//-------------------------------

document.f1.sailstotal.value = total;
document.f1.royaltiestotal.value = royalties;
document.f1.shippingtotal.value = shipping;


	
	

if (shipping == "call") {
document.f1.ordertotal.value = total + royalties;
}
else
{
	document.f1.ordertotal.value = total + shipping + royalties;
}

}



function addmain(){
	qty_main = 0
	if (document.f1.main1)
	{ 
	total = total + document.f1.main1.value * (document.f1.main1Price.value);
	qty_main = qty_main + eval(document.f1.main1.value);
	
	}
	
	if (document.f1.main2)
	{ 
	total = total + document.f1.main2.value * (document.f1.main2Price.value);
	qty_main = qty_main + eval(document.f1.main2.value);
	
	}
	
	if (document.f1.main3)
	{ 
	total = total + document.f1.main3.value * (document.f1.main3Price.value);
	qty_main = qty_main + eval(document.f1.main3.value);
	}
	
	if (document.f1.main4)
	{ 
	total = total + document.f1.main4.value * (document.f1.main4Price.value);
	qty_main = qty_main + eval(document.f1.main4.value);
	}
	
	if (document.f1.main5)
	{ 
	total = total + document.f1.main5.value * (document.f1.main5Price.value);
	qty_main = qty_main + eval(document.f1.main5.value);
	}
	
	if (document.f1.main6)
	{ 
	total = total + document.f1.main6.value * (document.f1.main6Price.value);
	qty_main = qty_main + eval(document.f1.main6.value);
	}
	
	if (document.f1.main7)
	{ 
	total = total + document.f1.main7.value * (document.f1.main7Price.value);
	qty_main = qty_main + eval(document.f1.main7.value);
	}
	
	if (document.f1.main8)
	{ 
	total = total + document.f1.main8.value * (document.f1.main8Price.value);
	qty_main = qty_main + eval(document.f1.main8.value);
	}
	if (document.f1.main9)
	{ 
	total = total + document.f1.main9.value * (document.f1.main9Price.value);
	qty_main = qty_main + eval(document.f1.main9.value);
	}
}

function addgenoa(){
	qty_genoa = 0
	if (document.f1.genoa1)
	{ 
	total = total + document.f1.genoa1.value * (document.f1.genoa1Price.value);
	qty_genoa = qty_genoa + eval(document.f1.genoa1.value);
	}
	
	if (document.f1.genoa2)
	{ 
	total = total + document.f1.genoa2.value * (document.f1.genoa2Price.value);
	qty_genoa = qty_genoa + eval(document.f1.genoa2.value);
	}
	
	if (document.f1.genoa3)
	{ 
	total = total + document.f1.genoa3.value * (document.f1.genoa3Price.value);
	qty_genoa = qty_genoa + eval(document.f1.genoa3.value);
	}
	
	if (document.f1.genoa4)
	{ 
	total = total + document.f1.genoa4.value * (document.f1.genoa4Price.value);
	qty_genoa = qty_genoa + eval(document.f1.genoa4.value);
	}
}

function addjib(){
	qty_jib = 0
	if (document.f1.jib1)
	{ 
	total = total + document.f1.jib1.value * (document.f1.jib1Price.value);
	qty_jib = qty_jib + eval(document.f1.jib1.value);
	}
	
	if (document.f1.jib2)
	{ 
	total = total + document.f1.jib2.value * (document.f1.jib2Price.value);
	qty_jib = qty_jib + eval(document.f1.jib2.value);
	}
	
	if (document.f1.jib3)
	{ 
	total = total + document.f1.jib3.value * (document.f1.jib3Price.value);
	qty_jib = qty_jib + eval(document.f1.jib3.value);
	}
	
	if (document.f1.jib4)
	{ 
	total = total + document.f1.jib4.value * (document.f1.jib4Price.value);
	qty_jib = qty_jib + eval(document.f1.jib4.value);
	}
	
	if (document.f1.jib5)
	{ 
	total = total + document.f1.jib5.value * (document.f1.jib5Price.value);
	qty_jib = qty_jib + eval(document.f1.jib5.value);
	}
	if (document.f1.jib6)
	{ 
	total = total + document.f1.jib6.value * (document.f1.jib6Price.value);
	qty_jib = qty_jib + eval(document.f1.jib6.value);
	}
	if (document.f1.jib7)
	{ 
	total = total + document.f1.jib7.value * (document.f1.jib7Price.value);
	qty_jib = qty_jib + eval(document.f1.jib7.value);
	}
	if (document.f1.jib8)
	{ 
	total = total + document.f1.jib8.value * (document.f1.jib8Price.value);
	qty_jib = qty_jib + eval(document.f1.jib8.value);
	}
}

function addspi(){
	qty_spi = 0

	if (document.f1.spi1)
	{ 
	total = total + document.f1.spi1.value * (document.f1.spi1Price.value);
	qty_spi = qty_spi + eval(document.f1.spi1.value);

	}
	
	if (document.f1.spi2)
	{ 
	total = total + document.f1.spi2.value * (document.f1.spi2Price.value);
	qty_spi = qty_spi + eval(document.f1.spi2.value);
	}
	
	if (document.f1.spi3)
	{ 
	total = total + document.f1.spi3.value * (document.f1.spi3Price.value);
	qty_spi = qty_spi + eval(document.f1.spi3.value);
	}
	
	if (document.f1.spi4)
	{ 
	total = total + document.f1.spi4.value * (document.f1.spi4Price.value);
	qty_spi = qty_spi + eval(document.f1.spi4.value);
	}
	
	if (document.f1.spi5)
	{ 
	total = total + document.f1.spi5.value * (document.f1.spi5Price.value);
	qty_spi = qty_spi + eval(document.f1.spi5.value);
	}
	
	if (document.f1.spi6)
	{ 
	total = total + document.f1.spi6.value * (document.f1.spi6Price.value);
	qty_spi = qty_spi + eval(document.f1.spi6.value);
	}
	
	if (document.f1.spi7)
	{ 
	total = total + document.f1.spi7.value * (document.f1.spi7Price.value);
	qty_spi = qty_spi + eval(document.f1.spi7.value);
	}
	
	if (document.f1.spi8)
	{ 
	total = total + document.f1.spi8.value * (document.f1.spi8Price.value);
	qty_spi = qty_spi + eval(document.f1.spi8.value);
	}
	
	if (document.f1.spi9)
	{ 
	total = total + document.f1.spi9.value * (document.f1.spi9Price.value);
	qty_spi = qty_spi + eval(document.f1.spi9.value);
	}
	
	if (document.f1.spi10)
	{ 
	total = total + document.f1.spi10.value * (document.f1.spi10Price.value);
	qty_spi = qty_spi + eval(document.f1.spi10.value);
	}
}


function addoptionals(){
	qty_optionals = 0
	if (document.f1.optional1) {
		if (document.f1.optional1.checked) {
	 	total = total + eval(document.f1.optional1Price.value);
		qty_optionals = qty_optionals + 1;
		}
	}
	
	if (document.f1.optional2) {
		if (document.f1.optional2.checked) {
	 	total = total + eval(document.f1.optional2Price.value);	
		qty_optionals = qty_optionals + 1;
		}
	}
	
	if (document.f1.optional3) {
		if (document.f1.optional3.checked) {
	 	total = total + eval(document.f1.optional3Price.value);
		qty_optionals = qty_optionals + 1;
		}
	}
	
	if (document.f1.optional4) {
		if (document.f1.optional4.checked) {
	 	total = total + eval(document.f1.optional4Price.value);	
		qty_optionals = qty_optionals + 1;
		}
	}
	
	if (document.f1.optional5) {
		if (document.f1.optional5.checked) {
	 	total = total + eval(document.f1.optional5Price.value);	
		qty_optionals = qty_optionals + 1;
		}
	}
	
	if (document.f1.optional6) {
		if (document.f1.optional6.checked) {
	 	total = total + eval(document.f1.optional6Price.value);	
		qty_optionals = qty_optionals + 1;
		}
	}
	
	if (document.f1.optional7) {
		if (document.f1.optional7.checked) {
	 	total = total + eval(document.f1.optional7Price.value);	
		qty_optionals = qty_optionals + 1;
		}
	}
	
	if (document.f1.optional8) {
		if (document.f1.optional8.checked) {
	 	total = total + eval(document.f1.optional8Price.value);	
		qty_optionals = qty_optionals + 1;
		}
	}
}

function addacc(){
	qty_acc = 0
	shippingacc = 0
	if (document.f1.acc1)
	{ 
	total = total + document.f1.acc1.value * (document.f1.acc1Price.value);
	qty_acc = qty_acc + eval(document.f1.acc1.value);
	shippingacc = shippingacc + eval(document.f1.acc1.value) * eval(document.f1.shipacc1.value);
	}
	
	if (document.f1.acc2)
	{ 
	total = total + document.f1.acc2.value * (document.f1.acc2Price.value);
	qty_acc = qty_acc + eval(document.f1.acc2.value);
	shippingacc = shippingacc + eval(document.f1.acc2.value) * eval(document.f1.shipacc2.value);
	}
	
	if (document.f1.acc3)
	{ 
	total = total + document.f1.acc3.value * (document.f1.acc3Price.value);
	qty_acc = qty_acc + eval(document.f1.acc3.value);
	shippingacc = shippingacc + eval(document.f1.acc3.value) * eval(document.f1.shipacc3.value);
	}
	
	if (document.f1.acc4)
	{ 
	total = total + document.f1.acc4.value * (document.f1.acc4Price.value);
	qty_acc = qty_acc + eval(document.f1.acc4.value);
	shippingacc = shippingacc + eval(document.f1.acc4.value) * eval(document.f1.shipacc4.value);
	}
	
	if (document.f1.acc5)
	{ 
	total = total + document.f1.acc5.value * (document.f1.acc5Price.value);
	qty_acc = qty_acc + eval(document.f1.acc5.value);
	shippingacc = shippingacc + eval(document.f1.acc5.value) * eval(document.f1.shipacc5.value);
	}
	
	if (document.f1.acc6)
	{ 
	total = total + document.f1.acc6.value * (document.f1.acc6Price.value);
	qty_acc = qty_acc + eval(document.f1.acc6.value);
	shippingacc = shippingacc + eval(document.f1.acc6.value) * eval(document.f1.shipacc6.value);
	}
	
	if (document.f1.acc7)
	{ 
	total = total + document.f1.acc7.value * (document.f1.acc7Price.value);
	qty_acc = qty_acc + eval(document.f1.acc7.value);
	shippingacc = shippingacc + eval(document.f1.acc7.value) * eval(document.f1.shipacc7.value);
	}
	
	if (document.f1.acc8)
	{ 
	total = total + document.f1.acc8.value * (document.f1.acc8Price.value);
	qty_acc = qty_acc + eval(document.f1.acc8.value);
	shippingacc = shippingacc + eval(document.f1.acc8.value) * eval(document.f1.shipacc8.value);
	}
	
	if (document.f1.acc9)
	{ 
	total = total + document.f1.acc9.value * (document.f1.acc9Price.value);
	qty_acc = qty_acc + eval(document.f1.acc9.value);
	shippingacc = shippingacc + eval(document.f1.acc9.value) * eval(document.f1.shipacc9.value);
	}
	
	if (document.f1.acc10)
	{ 
	total = total + document.f1.acc10.value * (document.f1.acc10Price.value);
	qty_acc = qty_acc + eval(document.f1.acc10.value);
	shippingacc = shippingacc + eval(document.f1.acc10.value) * eval(document.f1.shipacc10.value);
	}
	
	if (document.f1.acc11)
	{ 
	total = total + document.f1.acc11.value * (document.f1.acc11Price.value);
	qty_acc = qty_acc + eval(document.f1.acc11.value);
	shippingacc = shippingacc + eval(document.f1.acc11.value) * eval(document.f1.shipacc11.value);
	}
	
}

function calcroyalties()
{  
qty_sails = qty_main + qty_genoa + qty_jib + qty_spi;
royalties =  qty_sails * document.f1.classfees.value;
 }
 
function calcshipping()
{  
shipping = 0 
qty_sails = qty_main + qty_genoa + qty_jib + qty_spi
//*** accessories shipping charges calculated above

	// 1 sail only
	if (qty_sails == 1 ) 
	
	{ 
		if (qty_main == 1) {	shipping = eval(document.f1.shipmain.value); }
		if (qty_jib == 1)  {	shipping = eval(document.f1.shipjib.value);  }
		if (qty_genoa == 1)  {	shipping = eval(document.f1.shipgenoa.value);  }
		if (qty_spi == 1)  {	shipping = eval(document.f1.shipspi.value);  }
		
 	}
	
	
	// 2 sails
	if (qty_sails == 2 ) 
	{
		if (qty_spi == 2)   					{	shipping = eval(document.f1.shipspi.value);  }
		if ((qty_main == 2) || (qty_jib ==2 ) || (qty_genoa ==2 )) 	
												{	shipping = eval(document.f1.shipfull.value); }
												
		if ((qty_main == 1) && (qty_jib ==1 )) 	{	shipping = eval(document.f1.shipfull.value); }
		if ((qty_main == 1) && (qty_genoa ==1 )) {	shipping = eval(document.f1.shipfull.value); }
		
		if ((qty_spi == 1) && (qty_main ==1 ))  {	shipping = eval(document.f1.shipmain.value);  }
		if ((qty_spi == 1) && (qty_jib ==1 ))  	{	shipping = eval(document.f1.shipjib.value);  }
		if ((qty_spi == 1) && (qty_genoa ==1 )) {	shipping = eval(document.f1.shipgenoa.value);  }
		
 	}
	
	// 3-4 sails
	if ((qty_sails == 3 ) || (qty_sails == 4))
	{
		shipping = eval(document.f1.shipfull.value);
 	}
	
	// sum with accessory shipping charges + sail shipping charges

	shipping = shipping + shippingacc;
	
	
	// 5 plus sails
	if ((qty_sails >= 5 ) || (shipping >= 1000))
	{
		shipping = "call";
 	}
	
}