// JavaScript Document

function get_total()
{
/*######### GET_TOTAL ##########*/
	//alert("we are in the get_total function");
	var oform = document.forms[1]; //could be order form or quotes form


	var shipping    = oform.elements["shipvia"];
	//var bustypeflag = oform.elements["bustype"];  appears to not be necessary
	
	var bustypeindex = oform.elements["bustype"].selectedIndex;
	var bustypevalue = oform.elements["bustype"].options[bustypeindex].value;
	
	// Products
	var anziomanual  = oform.elements["anziomanual"];
	var litenew   = oform.elements["litenew"];
	var liteup    = oform.elements["liteup"];
	var winnew    = oform.elements["winnew"];
	var winup     = oform.elements["winup"];
	var pwnew     = oform.elements["pwnew"];
	var pwup      = oform.elements["pwup"];
	var pwse3new  = oform.elements["pwse3new"];
	var pwse3up   = oform.elements["pwse3up"];
	var pwse6new  = oform.elements["pwse6new"];
	var pwse6up   = oform.elements["pwse6up"];
	var pwse10new = oform.elements["pwse10new"];
	var pwse10up  = oform.elements["pwse10up"];
	var pwsenew   = oform.elements["pwsenew"];
	var pwseup    = oform.elements["pwseup"];
	var weponew   = oform.elements["weponew"];
	var wepoup    = oform.elements["wepoup"];
	var addcd     = oform.elements["addcd"];
	var shtotal = 0;	// shipping total
	var total = 0;		// grand total
	var shtemp = 0;
	var ptotal = 0;     // product subtotal

	
// Reseller / Educ discount
//new
	var discount = 1;
	if (bustypevalue == "RegReseller")
	//if (document.Orderform.rrs.checked == true) 
	{
		discount = .75;
	}
	if (bustypevalue == "Educational") 
	{
		discount = .80;
	}
	if (bustypevalue == "Library") 
	{
		discount = .80;
	}



// Handle Golden Rule below as fixed value on AnzioWin

// Anzio Lite
	if (litenew.value != 0)
   	{
		var each = 40;
		
		if (litenew.value > 9)    { each = 36; }
		if (litenew.value > 24)   { each = 32; }
		if (litenew.value > 49)   { each = 29; }
		if (litenew.value > 99)   { each = 26; }
		if (litenew.value > 149)  { each = 23; }
		if (litenew.value > 249)  { each = 21; }
		if (litenew.value > 499)  { each = 19; }
		if (litenew.value > 999)  { each = 17; }
		if (litenew.value > 2499) { each = 15; }
		if (litenew.value > 4999) { each = 14; }
		if (litenew.value > 9999) { each = 13; }
		
 		var litenewtot = litenew.value * each * discount;
		
		ptotal = ptotal + litenewtot;
		total = total + litenewtot;
	}
	
	if (liteup.value != 0)
	{
		var each = 40;
		
		if (liteup.value > 9)   { each = 36; }
		if (liteup.value > 24)  { each = 32; }
		if (liteup.value > 49)  { each = 29; }
		if (liteup.value > 99)  { each = 26; }
		if (liteup.value > 149) { each = 23; }
		if (liteup.value > 249) { each = 21; }
		if (liteup.value > 499) { each = 19; }
		if (liteup.value > 999) { each = 17; }
		
		var liteuptot = liteup.value * each * .50 * discount;  //added discount multiplier and commented below
     	//if (bustypeflag.value == "RegReseller")
		//{
		//    liteuptot = liteup.value * each * .50 * discount;
		//}
		
		ptotal = ptotal + liteuptot;
		total = total + liteuptot;
	}

// AnzioWin
	if (winnew.value != 0) 
	{
		var each = 150;
		
		if (winnew.value > 9)    { each = 120; }
		if (winnew.value > 24)   { each = 96; }
		if (winnew.value > 49)   { each = 77; }
		if (winnew.value > 99)   { each = 62; }
		if (winnew.value > 149)  { each = 50; }
		if (winnew.value > 249)  { each = 40; }
		if (winnew.value > 499)  { each = 32; }
		if (winnew.value > 999)  { each = 26; }
		if (winnew.value > 2499) { each = 21; }
		if (winnew.value > 4999) { each = 17; }
		if (winnew.value > 9999) { each = 14; }
		
  		var winnewtot = winnew.value * each * discount;
		
		//alert(winnewtot);
		ptotal = ptotal + winnewtot;
		total = total + winnewtot;
	}
	if (winup.value != 0)
	{

		var each = 150;
      
	  	if (winup.value > 9)   { each = 120; }
      	if (winup.value > 24)  { each = 96; }
      	if (winup.value > 49)  { each = 77; }
      	if (winup.value > 99)  { each = 62; }
      	if (winup.value > 149) { each = 50; }
      	if (winup.value > 249) { each = 40; }
      	if (winup.value > 499) { each = 32; }
      	if (winup.value > 999) { each = 26; }

      	var winuptot = winup.value * each * .50 * discount;  //added discount and commented below
     	//if (bustypeflag.value == "RegReseller")
		//{
		//    winuptot = winup.value * each * .50 * discount;
		//}
		
		ptotal = ptotal + winuptot;
      	total = total + winuptot;
   }

// Print Wizard
	if (pwnew.value != 0) 
	{
		var each = 99;
		
		if (pwnew.value > 4)   { each = 64; }
		if (pwnew.value > 9)   { each = 48; }
      	if (pwnew.value > 19)  { each = 38; }
      	if (pwnew.value > 49)  { each = 30; }
      	if (pwnew.value > 99)  { each = 24; }
      	if (pwnew.value > 249) { each = 17; }
      	if (pwnew.value > 999) { each = 11; }
      
	  	var pwnewtot = pwnew.value * each * discount;

		ptotal = ptotal + pwnewtot;
      	total = total + pwnewtot;
	}
	if (pwup.value != 0) 
	{
		var each = 99;
		if (pwup.value > 4)   { each = 64; }
		if (pwup.value > 9)   { each = 48; }
		if (pwup.value > 19)  { each = 38; }
		if (pwup.value > 49)  { each = 30; }
		if (pwup.value > 99)  { each = 24; }
		if (pwup.value > 249) { each = 17; }
		if (pwup.value > 999) { each = 11; }
		
		var pwuptot = pwup.value * each * .50 * discount;  //added discount, commented below
     	//if (bustypeflag.value == "RegReseller")
		//{
		//    pwuptot = pwup.value * each * .50 * discount;
		//}
		ptotal = ptotal + pwuptot;
		total = total + pwuptot;
	}

// Print Wizard Server Edition
	var pwsealltot = 0;

	if (pwse3new.value != 0) 
	{
    	var each = 300;
    	var pwse3newtot = pwse3new.value * each * discount;
		
    	pwsealltot = pwsealltot + pwse3newtot;
		
		ptotal = ptotal + pwse3newtot;
		total = total + pwse3newtot;
   	}
	if (pwse3up.value != 0) 
	{
    	var each = 300;
    	var pwse3uptot = pwse3up.value * each * .50 * discount;  //added discount, commented below

    	pwsealltot = pwsealltot + pwse3uptot;
		
		ptotal = ptotal + pwse3uptot;
		total = total + pwse3uptot;
	}
   	if (pwse6new.value != 0) 
	{
    	var each = 600;
    	var pwse6newtot = pwse6new.value * each * discount;
		
    	pwsealltot = pwsealltot + pwse6newtot;
		
    	ptotal = ptotal + pwse6newtot;
		total = total + pwse6newtot;
	}
	if (pwse6up.value != 0) 
	{
    	var each = 600;
    	var pwse6uptot = pwse6up.value * each * .50 * discount; //added discount, commented below

    	pwsealltot = pwsealltot + pwse6uptot;
		
    	ptotal = ptotal + pwse6uptot;
		total = total + pwse6uptot;
	}
	if (pwse10new.value != 0) 
	{
    	var each = 1000;
    	var pwse10newtot = pwse10new.value * each * discount;
		
    	pwsealltot = pwsealltot + pwse10newtot;
		
		ptotal = ptotal + pwse10newtot;
		total = total + pwse10newtot;
	}
	if (pwse10up.value != 0) 
	{
    	var each = 1000;
    	var pwse10uptot = pwse10up.value * each * .50 * discount; //added discount, commented below

    	pwsealltot = pwsealltot + pwse10uptot;
		
		ptotal = ptotal + pwse10uptot;
		total = total + pwse10uptot;
	}
	if (pwsenew.value != 0) 
	{
    	var each = 1800;
    	var pwsenewtot = pwsenew.value * each * discount;
		
    	pwsealltot = pwsealltot + pwsenewtot;
		
    	ptotal = ptotal + pwsenewtot;
		total = total + pwsenewtot;
	}
	if (pwseup.value != 0) 
	{
    	var each = 1800;
    	var pwseuptot = pwseup.value * each * .50 * discount; //added discount, commented below

    	pwsealltot = pwsealltot + pwseuptot;
		
    	ptotal = ptotal + pwseuptot;
		total = total + pwseuptot;
	}

// Discount on PWSE total
	var pwsealldisc = 0;
	if (pwsealltot != 0) 
	{
    	var pwsediscount = 0;
    	if (pwsealltot > 1499)   {pwsediscount = .2; }
    	if (pwsealltot > 3749)   {pwsediscount = .35; }
    	if (pwsealltot > 7499)   {pwsediscount = .5; }
    	if (pwsealltot > 14999)  {pwsediscount = .6; }
    	if (pwsealltot > 22499)  {pwsediscount = .67; }
    	if (pwsealltot > 37499)  {pwsediscount = .75; }
    	if (pwsealltot > 74999)  {pwsediscount = .8; }
    	if (pwsealltot > 149999) {pwsediscount = .85; }
    	
		if (pwsediscount != 0) 
		{
        	pwsealldisc = (pwsealltot * pwsediscount);
        	pwsealldisc = pwsealldisc * -1;
        	ptotal = ptotal + pwsealldisc;
			total = total + pwsealldisc;     // should be negative now
		}
	}

// WePO
	if (weponew.value != 0) 
	{
    	var each = 1500;
    	//discount = 1;
    	var weponewtot = weponew.value * each * discount;
    	ptotal = ptotal + weponewtot;
		total = total + weponewtot;
	}
	if (wepoup.value != 0) 
	{
    	var each = 1500;
    	//discount = 1;
    	var wepouptot = wepoup.value * each * .50 * discount; //added discount, commented below
    	ptotal = ptotal + wepouptot;
		total = total + wepouptot;
	}
	

	
// Addt'l
	if (addcd.value != 0) 
	{
    	var each = 2;
    	var addcdtot = each * addcd.value;
    	ptotal = ptotal + addcdtot;
		total = total + addcdtot;
		
	}
	if (anziomanual.value != 0) 
	{
    	var each = 10;
    	var anziomanualtot = each * anziomanual.value;
		ptotal = ptotal + anziomanualtot;
    	total = total + anziomanualtot;
	}





if(oform.name == "Orderform")
{
	var shipvia = document.getElementById("shipvia"); // stores the shipvia option in a var
	
	// checks to see if addcd or anziomanual is > 0
	var qt = 0;
	qt = qt + addcd.value + anziomanual.value ;
	
	// if qt > 0 then user cannot select Download
	if (qt > 0)
	  {
		// takes out the download option so that the user can see that there will be a cost
		if (shipvia.value == 'Download')
		  { 
			shipvia.options[4].selected = "selected";  //ground is default
			document.getElementById("no-download").innerHTML = '**You have selected to have a manual or CD shipped to you.  If you would like to download only, please change your "Ship Anzio Manual" and/or "Additional CDs" order to 0.';
		  }
	   // if(shipvia.options[0].value == 'Download') 
	   // {
	   //   shipvia.options[5].selected = "selected";
	   // }
	  }
	else
	{
		document.getElementById("no-download").innerHTML = "";
	}
} //end of if document.getElementById("shipvia").innerHTML

// Ship Via Calc
	//alert(shipping.value);
if(oform.name == "Orderform")
{
	switch(shipping.value)
	{
		case "2nd Day":
			shtotal = 16;
			if (anziomanual.value != 0)
			{
				shtemp = anziomanual.value * 2.5;
				shtotal = shtotal + shtemp;
			}
			break;
		case "Overnight":
			shtotal = 23;
			if (anziomanual.value != 0)
			{
				shtemp = anziomanual.value * 15;
				shtotal = shtotal + shtemp;
			}
			break;
		case "Ground":
			shtotal = 5;
			if (anziomanual.value != 0)
			{
				shtemp = anziomanual.value * 2.5;
				shtotal = shtotal + shtemp;
			}
			break;
		case "International":
			shtotal = 40;
			if (anziomanual.value != 0)
			{
				shtemp = anziomanual.value * 10;
				shtotal = shtotal + shtemp;
			}
			break;
		default:
			break;
	} 
} //end of if(shipping.value)



// Minimum order is $10... just in case...
	if ((total < 10) && (total > 1)) 
	{ 
    	mintot = 1;
    	total = 10; 
	}


	total = total + shtotal;
	var psubtotal = ptotal;
	//alert(total);
	if(oform.name == "Orderform")
	{
		document.getElementById("view_ptotal").innerHTML=Number(ptotal).toFixed(2);
		document.getElementById("view_psubtotal").innerHTML=Number(psubtotal).toFixed(2);
		document.getElementById("view_shtotal").innerHTML=Number(shtotal).toFixed(2);
		document.getElementById("view_total").innerHTML=Number(total).toFixed(2);	
		document.getElementById("ptotal").value=Number(ptotal).toFixed(2);
		document.getElementById("shtotal").value=Number(shtotal).toFixed(2);
	}	


	document.getElementById("total").value=Number(total).toFixed(2);
	//below are invisible form inputs to pass to orderscript	
	document.getElementById("litenewtot").value=Number(litenewtot).toFixed(2);
	document.getElementById("liteuptot").value=Number(liteuptot).toFixed(2);
	document.getElementById("winnewtot").value=Number(winnewtot).toFixed(2);
	document.getElementById("winuptot").value=Number(winuptot).toFixed(2);
	document.getElementById("pwnewtot").value=Number(pwnewtot).toFixed(2);
	document.getElementById("pwuptot").value=Number(pwuptot).toFixed(2);
	document.getElementById("pwse3newtot").value=Number(pwse3newtot).toFixed(2);
	document.getElementById("pwse3uptot").value=Number(pwse3uptot).toFixed(2);
	document.getElementById("pwse6newtot").value=Number(pwse6newtot).toFixed(2);
	document.getElementById("pwse6uptot").value=Number(pwse6uptot).toFixed(2);
	document.getElementById("pwse10newtot").value=Number(pwse10newtot).toFixed(2);
	document.getElementById("pwse10uptot").value=Number(pwse10uptot).toFixed(2);
	document.getElementById("pwsenewtot").value=Number(pwsenewtot).toFixed(2);
	document.getElementById("pwseuptot").value=Number(pwseuptot).toFixed(2);
	document.getElementById("pwsediscount").value=Number(pwsealldisc).toFixed(2);
	document.getElementById("weponewtot").value=Number(weponewtot).toFixed(2);
	document.getElementById("wepouptot").value=Number(wepouptot).toFixed(2);
	document.getElementById("addcdtot").value=Number(addcdtot).toFixed(2);
	document.getElementById("anziomanualtot").value=Number(anziomanualtot).toFixed(2);
/*####### End of GET_TOTAL #########*/
}