function PrepareSubtotal() {
	var typeFilm = document.reelDupes.typeFilm[0].value;
	var eightMM1 = document.reelDupes.eightMM1;
	var eightMM2 = document.reelDupes.eightMM2;
	var eightMM3 = document.reelDupes.eightMM3;
	var sixTeenMM1 = document.reelDupes.sixteenMM1;
	var sixTeenMM2 = document.reelDupes.sixteenMM2;
	var sixTeenMM3 = document.reelDupes.sixteenMM3;
	var sixTeenMM4 = document.reelDupes.sixteenMM4;
	var sixTeenMM5 = document.reelDupes.sixteenMM5;
	var transferSubtotal = document.reelDupes.transferSubtotal;

   if (document.reelDupes.typeFilm[0].checked == true) {
		eightMM1.disabled = false;
		eightMM2.disabled = false;
		eightMM3.disabled = false;	
		sixTeenMM1.disabled = true;
		sixTeenMM1.value = "";
		sixTeenMM2.disabled = true;
		sixTeenMM2.value = "";
		sixTeenMM3.disabled = true;
		sixTeenMM3.value = "";
		sixTeenMM4.disabled = true;
		sixTeenMM4.value = "";
		sixTeenMM5.disabled = true;
		sixTeenMM5.value = "";
		
   } else {
		eightMM1.disabled = true;
		eightMM1.value = "";
		eightMM2.disabled = true;
		eightMM2.value = "";
		eightMM3.disabled = true;
		eightMM3.value = "";	
		sixTeenMM1.disabled = false;
		sixTeenMM2.disabled = false;	
		sixTeenMM3.disabled = false;
		sixTeenMM4.disabled = false;	
		sixTeenMM5.disabled = false;	
   }
   transferSubtotal.value = "0.00"
}

function GetTransferQuantity() {
	var total = 0;
	if (document.reelDupes.typeFilm[0].checked == true) {
		var eightMM1Size = 50;
		var eightMM2Size = 200;
		var eightMM3Size = 400;
		var eightMM1 = parseInt(document.reelDupes.eightMM1.value);
		var eightMM2 = parseInt(document.reelDupes.eightMM2.value);
		var eightMM3 = parseInt(document.reelDupes.eightMM3.value);

		if (isNaN(eightMM1)) {eightMM1 = 0;}
		if (isNaN(eightMM2)) {eightMM2 = 0;}
		if (isNaN(eightMM3)) {eightMM3 = 0;}
		total = (eightMM1 * eightMM1Size) + (eightMM2 * eightMM2Size) + (eightMM3 * eightMM3Size);
			
	} else if (document.reelDupes.typeFilm[1].checked == true) {
		var sixTeenMM1Size = 50;
		var sixTeenMM2Size = 100;
		var sixTeenMM3Size = 400;
		var sixTeenMM4Size = 800;
		var sixTeenMM5Size = 1600;
		var sixTeenMM1 = parseInt(document.reelDupes.sixteenMM1.value);
		var sixTeenMM2 = parseInt(document.reelDupes.sixteenMM2.value);
		var sixTeenMM3 = parseInt(document.reelDupes.sixteenMM3.value);
		var sixTeenMM4 = parseInt(document.reelDupes.sixteenMM4.value);
		var sixTeenMM5 = parseInt(document.reelDupes.sixteenMM5.value);
		
		if (isNaN(sixTeenMM1)) {sixTeenMM1 = 0;}
		if (isNaN(sixTeenMM2)) {sixTeenMM2 = 0;}
		if (isNaN(sixTeenMM3)) {sixTeenMM3 = 0;}
		if (isNaN(sixTeenMM4)) {sixTeenMM4 = 0;}
		if (isNaN(sixTeenMM5)) {sixTeenMM5 = 0;}
		total = (sixTeenMM1 * sixTeenMM1Size) + (sixTeenMM2 * sixTeenMM2Size) + (sixTeenMM3 * sixTeenMM3Size) + (sixTeenMM4 * sixTeenMM4Size) + (sixTeenMM5 * sixTeenMM5Size);
	}
	return total;
}

function GetTransferCost() {
	var totalcost = 0;
	var transferSubtotal = document.reelDupes.transferSubtotal;
	if (document.reelDupes.typeFilm[0].checked == true) {
		var eightMM1Cost = 7.5;
		var eightMM2Cost = 25;
		var eightMM3Cost = 49;
		var eightMM1 = parseInt(document.reelDupes.eightMM1.value);
		var eightMM2 = parseInt(document.reelDupes.eightMM2.value);
		var eightMM3 = parseInt(document.reelDupes.eightMM3.value);
		if (isNaN(eightMM1)) {eightMM1 = 0;}
		if (isNaN(eightMM2)) {eightMM2 = 0;}
		if (isNaN(eightMM3)) {eightMM3 = 0;}
		totalcost = (eightMM1 * eightMM1Cost) + (eightMM2 * eightMM2Cost) + (eightMM3 * eightMM3Cost);	
	} else {
		var sixTeenMM1Cost = 8.5;
		var sixTeenMM2Cost = 15;
		var sixTeenMM3Cost = 55
		var sixTeenMM4Cost = 105;
		var sixTeenMM5Cost = 200;
		var sixTeenMM1 = parseInt(document.reelDupes.sixteenMM1.value);
		var sixTeenMM2 = parseInt(document.reelDupes.sixteenMM2.value);
		var sixTeenMM3 = parseInt(document.reelDupes.sixteenMM3.value);
		var sixTeenMM4 = parseInt(document.reelDupes.sixteenMM4.value);
		var sixTeenMM5 = parseInt(document.reelDupes.sixteenMM5.value);
		if (isNaN(sixTeenMM1)) {sixTeenMM1 = 0;}
		if (isNaN(sixTeenMM2)) {sixTeenMM2 = 0;}
		if (isNaN(sixTeenMM3)) {sixTeenMM3 = 0;}
		if (isNaN(sixTeenMM4)) {sixTeenMM4 = 0;}
		if (isNaN(sixTeenMM5)) {sixTeenMM5 = 0;}
		totalcost = (sixTeenMM1 * sixTeenMM1Cost) + (sixTeenMM2 * sixTeenMM2Cost) + (sixTeenMM3 * sixTeenMM3Cost);
		totalcost = totalcost + (sixTeenMM4 * sixTeenMM4Cost) + (sixTeenMM5 * sixTeenMM5Cost);
	}	
	totalcost = totalcost.toFixed(2) 
	transferSubtotal.value = totalcost;
	document.reelDupes.orderEstimate.value = "";
	return totalcost;
}

function GetPackageTotal() {
		var packageCost = 0;
		var packageCostMultipier = 1;
		var package1Cost = 10;
		var package2Cost = 25;
		var package3Cost = 10;
		var package4Cost = 15;
		var musicCost = 20;
		var transferSubtotal = GetTransferCost();
		var packageSubtotal = document.reelDupes.packageSubtotal;
		var DVDQuantity = document.reelDupes.DVD
		var VHSQuantity = document.reelDupes.VHS
		var DDVDQuantity = document.reelDupes.DDVD
		var addMusic = document.reelDupes.addMusic;
		var totalcost;
		var quantity;
		
		
		totalcost = parseFloat(transferSubtotal);
		if (isNaN(totalcost)) {totalcost = 0;}
		
		if (document.reelDupes.typePackage[0].checked) {
			packageCost = package1Cost;
			DVDQuantity.disabled = false;			
			VHSQuantity.value = "";
			VHSQuantity.disabled = true;
			DDVDQuantity.value = "";
			DDVDQuantity.disabled = true;
		} else if(document.reelDupes.typePackage[1].checked) {
			packageCost = package2Cost;
			DVDQuantity.disabled = false;			
			VHSQuantity.value = "";
			VHSQuantity.disabled = true;
			DDVDQuantity.value = "";
			DDVDQuantity.disabled = true;
		} else if(document.reelDupes.typePackage[2].checked) {
			packageCost = package3Cost;
			DVDQuantity.value = "";
			DVDQuantity.disabled = true;
			VHSQuantity.disabled = false;
			DDVDQuantity.value = "";
			DDVDQuantity.disabled = true;
		} else if(document.reelDupes.typePackage[3].checked) {
			packageCost = package4Cost;
			DVDQuantity.value = "";
			DVDQuantity.disabled = true;
			VHSQuantity.value = "";
			VHSQuantity.disabled = true;
			DDVDQuantity.disabled = false;
		}			
		if (addMusic.checked) {
			packageCost = packageCost + musicCost;
		} 
		
		//cost is per 2000 feet of film transfered.  2001 ft - package cost doubles.  4001 ft. - package cost triples, etc.
		quantity = GetTransferQuantity();
		if (quantity > 2000) {
			if (quantity % 2000 == 0) {
				packageCostMultipier = parseInt((quantity / 2000));
			} else { 	
				packageCostMultipier = packageCostMultipier + parseInt((quantity / 2000));
			}
		}
		packageCost = (packageCostMultipier * packageCost);
		totalcost = totalcost + packageCost;
		totalcost = totalcost.toFixed(2);
		packageSubtotal.value = totalcost;
		document.reelDupes.orderEstimate.value = "";	
		return totalcost;
}

function GetMediaTotal() {
	var DVDPrice;
	var VHSPrice = 5.0;
	var DDVDPrice = 10.0;
	var DVDQuantity = parseInt(document.reelDupes.DVD.value)
	var VHSQuantity = parseInt(document.reelDupes.VHS.value)
	var DDVDQuantity = parseInt(document.reelDupes.DDVD.value)
	var totalcost = GetPackageTotal();
	var mediaCost;
	var mediaCostMultipier = 1;
	var mediaSubtotal = document.reelDupes.mediaSubtotal;
	var quantity;
	
	if (isNaN(DVDQuantity)) {DVDQuantity = 0;}
	if (isNaN(VHSQuantity)) {VHSQuantity = 0;}
	if (isNaN(DDVDQuantity)) {DDVDQuantity = 0;}
	
	if (DVDQuantity <= 5) {
		DVDPrice = 7.5;
	} else {
		DVDPrice = 6;
	}
	
	totalcost = parseFloat(totalcost);
	if (isNaN(totalcost)) {totalcost = 0;}
	
	mediaCost = (DVDPrice * DVDQuantity) + (VHSPrice * VHSQuantity) + (DDVDPrice * DDVDQuantity);
	quantity = GetTransferQuantity();
	
	if (quantity > 2000) {
		if (quantity % 2000 == 0) {
			mediaCostMultipier = parseInt((quantity / 2000));
		} else { 	
			mediaCostMultipier = mediaCostMultipier + parseInt((quantity / 2000));
		}
	}
	mediaCost = (mediaCostMultipier * mediaCost);
	
	totalcost = totalcost + mediaCost;
	totalcost = totalcost.toFixed(2);
	mediaSubtotal.value = totalcost;
	document.reelDupes.orderEstimate.value = "";
	return totalcost;	
}

function GetRushTotal() {
	var totalcost = GetMediaTotal();
	var rushCost = 0;
	var rushOrder = document.reelDupes.rushOrder;
	var rushSubtotal = document.reelDupes.rushSubtotal;
	
	totalcost = parseFloat(totalcost);
	if (isNaN(totalcost)) {totalcost = 0;}
	
	if (rushOrder.checked) {rushCost = totalcost * 0.5}
	totalcost = totalcost + rushCost;	
	totalcost = totalcost.toFixed(2);
	rushSubtotal.value = totalcost;
	return totalcost;	
}

function GetShipTotal() {
	var totalcost = GetRushTotal();
	var shipCostStandard = 10;
	var shipCostOvernight = 40;
	var shipCostRegistered = 25;
	var shipCost = 0;
	var shipCostHalf = 0;
	var shipCostMultiplier;
	var shipSubtotal = document.reelDupes.shipSubtotal;
	var quantity;
	
	totalcost = parseFloat(totalcost);
	if (isNaN(totalcost)) {totalcost = 0;}
	
	quantity = GetTransferQuantity();
	shipCostMultipier = parseInt((quantity / 2000));
	if (quantity % 2000 == 0) {shipCostMultipier = shipCostMultipier - 1;}
	
	if (document.reelDupes.shipOption[0].checked) {
		shipCost = shipCostStandard;
		if (quantity > 2000) {
			shipCostHalf = parseFloat(shipCostStandard / 2);
		}
	} else if(document.reelDupes.shipOption[1].checked) {
		shipCost = shipCostOvernight;
		if (quantity > 2000) {
			shipCostHalf = parseFloat(shipCostOvernight / 2);
		}
	} else if(document.reelDupes.shipOption[2].checked) {
		shipCost = shipCostRegistered;
		if (quantity > 2000) {
			shipCostHalf = parseFloat(shipCostRegistered / 2);
		}
	}
	shipCost = shipCost + (shipCostMultipier * shipCostHalf);	
	totalcost = totalcost + shipCost;	
	totalcost = totalcost.toFixed(2);
	shipSubtotal.value = totalcost;
	document.reelDupes.orderEstimate.value = "";
	return totalcost;	
}

function Update() {
	var totalcost = 0;
	var orderEstimate = document.reelDupes.orderEstimate;
	totalcost = GetShipTotal();
	totalcost = parseFloat(totalcost);
	if (isNaN(totalcost)) {totalcost = 0;}
	totalcost = totalcost.toFixed(2);
	return totalcost;	
}

function FinalEstimate() {
	var orderEstimate = document.reelDupes.orderEstimate;
	var finalTotal = Update();
	orderEstimate.value = finalTotal;
}
