// This file and the accompanying form (estimator.html) are copyright © 2003 - 2010 David White

// "global" version variables (loaded when file is loaded)
var hosMaxDrivingTime = 11 // hours (updated for 2008)
var truckGuaranteedSpeed = 45 // used for transit time/co-driver calculation
var estimatorVersion = "1.05"
var ratesEffectiveDate = "January 1, 2009"
var today = new Date()
var year = today.getFullYear()
var htmlNoticeOfCopyright = "Copyright &copy; 2003 - " + year + " David White. All rights reserved."
var javascriptNoticeOfCopyright = "Copyright © 2003 - " + year + " David White. All rights reserved."

function isNumber(num)
{
	var validSet = "0123456789."
	var numString = num.toString()
	for(i = 0; i < numString.length; i++)
		// if not in valid set, then return false
		if(validSet.indexOf(numString[i]) == -1)
			return false
	return true
}

//alert(typeof(invoiceAmount))
// isNaN(x) returns true if value is "not a number," false if it is a number
// Math.ceil(x) to round up, Math.floor(x) to round down
// toFixed(x) returns a String padded with zeros or rounded to x decimal places
// since toFixed() returns a String, parseFloat() must be used to convert amount back into a Number to perform additional math

function calculateRate(estimatorForm)
{
	// check for valid input from fields
	if(estimatorForm.distance.value == "" || estimatorForm.distance.value <= 0)
	{
		alert("Please enter the freight's distance.")
		estimatorForm.distance.focus()
		estimatorForm.distance.select()
		return
	}
	if(isNaN(estimatorForm.distance.value))
	{
		alert("Please enter a valid number for the freight's distance. (Do not include commas.)")
		estimatorForm.distance.focus()
		estimatorForm.distance.select()
		return
	}
	if(estimatorForm.weight.value == "" || estimatorForm.distance.value <= 0)
	{
		alert("Please enter the freight's weight.")
		estimatorForm.weight.focus()
		estimatorForm.weight.select()
		return
	}
	if(isNaN(estimatorForm.weight.value))
	{
		alert("Please enter a valid number for the freight's weight. (Do not include commas.)")
		estimatorForm.weight.focus()
		estimatorForm.weight.select()
		return
	}
	if(estimatorForm.fuelPrice.value != "" && isNaN(estimatorForm.fuelPrice.value))
	{
		alert("Please enter a valid number for the fuel price. (Do not include dollar sign.)")
		estimatorForm.fuelPrice.focus()
		estimatorForm.fuelPrice.select()
		return
	}

	// mileage rates (in US dollars, charged per loaded mile)
	var ALoadRate1 = 1.30 // 0 - 250 miles
	var ALoadRate2 = 1.20 // 250.1 - 500 miles
	var ALoadRate3 = 1.10 // 500.1+ miles

	var BLoadRate1 = 1.50 // 0 - 250 miles
	var BLoadRate2 = 1.40 // 250.1 - 500 miles
	var BLoadRate3 = 1.30 // 500.1+ miles

	// included for completeness - not implemented
	// var BPlusLoadRate1 = 1.69 // 0 - 199.9 miles
	// var BPlusLoadRate2 = 1.64 // 200 - 299.9 miles
	// var BPlusLoadRate3 = 1.56 // 300 - 399.9 miles
	// var BPlusLoadRate4 = 1.48 // 400+ miles

	var CLoadRate1 = 2.00 // 0 - 250 miles
	var CLoadRate2 = 1.90 // 250.1 - 500 miles
	var CLoadRate3 = 1.80 // 500.1+ miles

	var DLoadRate1 = 2.20 // 0 - 250 miles
	var DLoadRate2 = 2.10 // 250.1 - 500 miles
	var DLoadRate3 = 2.00 // 500.1+ miles

	var ELoadRate1 = 3.00 // 0 - 250 miles
	var ELoadRate2 = 2.90 // 250.1 - 500 miles
	var ELoadRate3 = 2.80 // 500.1+ miles

	// minimum charges (in US dollars) for each load
	var ALoadMinCharge = 50
	var BLoadMinCharge = 70
	// var BPlusLoadMinCharge = 80 // included for completeness - not being used
	var CLoadMinCharge = 120
	var DLoadMinCharge = 150
	var ELoadMinCharge = 250

	// accessorial charges (in US dollars)
	var nightCharge = 15
	var coDriverRate = 0.25 // per loaded mile
	var customsClearanceCharge = 60
	var pickupCharge = 40
	var stopOffCharge = 40
	var layoverCharge = 150 // per 10 hours
	var detentionTimeCharge = 10.00 // per 15 minutes
	var handMovingCharge = 35 // per hour
	var liftgateCharge = 50
	var tarpingCharge = 25 // flatbed
	var nycServiceCharge = 50

	// other constants used in script
	var businessMileageRate = 0.55 // per round trip mile (updated for January 1, 2009)
	var vanPercentage = 0.70
	var cubeVanPercentage = 0.75
	var truckPercentage = 0.80
	var companyDriverPercentage = 0.40
	var truckLoadedMilePayRate = 1.25 // dollars per mile
	var truckEmptyMilePayRate = 0.50 // dollars per mile
	var cargoVanAverageMpg = 13 // used for FSC calculation, average 13 - 15 gas
	var cubeVanAverageMpg = 10 // used for FSC calculation, average 10 - 12 gas
	var straightTruckAverageMpg = 8 // used for FSC calculation, average 8 - 9 (sometimes 10) diesel
	var tractorTrailerAverageMpg = 5 // used for FSC calculation, average 5 - 6 diesel
	var fuelSurchargeBenchmarkPrice = 1.10  // used for FSC calculation, effective cost per gallon of fuel
	var vanGuaranteedSpeed = 50 // used for transit time calculation
	// var truckGuaranteedSpeed = 45 // moved to global var
	var localLoadMiles = 75 // anything "less than 75"
	var detentionFreeTime = 60 // minutes
	var maxComchekPercent = 0.55 // 55%

	// variables from form
	var pounds = Math.round(estimatorForm.weight.value) // round in case of decimal
	var miles = estimatorForm.distance.value
	var equipmentType = estimatorForm.equipment.value

	// calculation variables used in script
	var linehaulCharge = 0 // initialize to zero
	var mileagePay = 0 // initialize to zero
	var fscAverageMpg // set based on equipment type
	var fuelSurcharge = 0 // initialize to zero
	var payAmount = 0 // initialize to zero
	var officeAmount = 0 // initialize to zero
	var loadClass // A, B, C, D, or E
	var isMinCharge = false // is minimum charge, initialize to false
	var payPercent = 0 // initialize to zero
	var officePercent = 0 // initialize to zero
	var detailString // report each variable value

	// determine load class
	var weightClass
	var unitClass

	if(pounds > 0 && pounds <= 500)
		weightClass = 'A'
	else if(pounds > 500 && pounds <= 2500)
		weightClass = 'B'
	else if(pounds > 2500 && pounds <= 5000)
		weightClass = 'C'
	else if(pounds > 5000 && pounds <= 13000)
		weightClass = 'D'
	else if(pounds > 13000 && pounds <= 44000)
		weightClass = 'E'
	else if(pounds > 44000)
	{
		alert("The weight is too much. The maximum that can be hauled with one truck is 44,000 lbs. Please call dispatch for information on possibly dividing the freight among multiple vehicles.")
		return
	}
	else // shouldn't need, but safety just in case
	{
		alert("Invalid weight entered.")
		estimatorForm.weight.focus()
		return
	}

	if(equipmentType == "Car")
		unitClass = 'A'
	else if(equipmentType == "Extended Cargo Van" || equipmentType == "Cargo Van")
		unitClass = 'B'
	else if(equipmentType == "Straight Truck" || equipmentType == "Flatbed Truck" || equipmentType == "Cube Van" || equipmentType == "Cargo Trailer")
		unitClass = 'C' // or D depending on truck specifications
	else if(equipmentType == "Tractor Trailer" || equipmentType == "Flatbed Tractor Trailer")
		unitClass = 'C' // enforce 'E' class?
	else
	{
		alert("Error: Unit class cannot be determined!")
		return
	}

	if(unitClass > weightClass)
		loadClass = unitClass
	else loadClass = weightClass

	// if A load goes through Customs or to an airport, charge B load
	if(loadClass == "A" && (estimatorForm.customsLoad.checked == true || estimatorForm.airportLoad.checked == true))
		loadClass = 'B'

	// determine pay percentage and fuel economy
	if(estimatorForm.payType.value == "Owner Operator")
	{
		if(equipmentType == "Tractor Trailer" || equipmentType == "Flatbed Tractor Trailer")
		{
			payPercent = truckPercentage
			fscAverageMpg = tractorTrailerAverageMpg
		}
		else if(equipmentType == "Straight Truck" || equipmentType == "Flatbed Truck" || equipmentType == "Cargo Trailer")
		{
			payPercent = truckPercentage
			fscAverageMpg = straightTruckAverageMpg
		}
		else if(equipmentType == "Cube Van")
		{
			payPercent = cubeVanPercentage
			fscAverageMpg = cubeVanAverageMpg
		}
		else // cargo van or similar
		{
			payPercent = vanPercentage
			fscAverageMpg = cargoVanAverageMpg
		}
	}
	else if(estimatorForm.payType.value == "Company Driver")
		payPercent = companyDriverPercentage
	else if(estimatorForm.payType.value == "JWG") // JWG does not get paid
		payPercent = 0
	else if(estimatorForm.payType.value == "JWG's Co-Driver") // JWG is paying a co-driver (whether required or not)
		payPercent = 0
	else if(estimatorForm.payType.value == "Office Employee")
		payPercent = 0
	officePercent = 1 - payPercent // whatever percent is not paid

	// determine the mileage rate and calculate the linehaul charge
	if(loadClass == 'A')
	{
		if(miles > 0 && miles <= 250)
			linehaulCharge = miles * ALoadRate1
		else if(miles > 250 && miles <= 500)
			linehaulCharge = miles * ALoadRate2
		else if(miles > 500)
			linehaulCharge = miles * ALoadRate3

		if(linehaulCharge < ALoadMinCharge) // impose minimum charge if necessary
		{
			isMinCharge = true
			if(estimatorForm.nightLoad.checked == false)
				linehaulCharge = ALoadMinCharge
			else
				linehaulCharge = BLoadMinCharge // charge minimum B rate if night load
		}
		if(estimatorForm.returnLoad.checked == true) // charge half the regular linehaul charge if load is a return load
			linehaulCharge /= 2
	}
	else if(loadClass == 'B')
	{
		if(miles > 0 && miles <= 250)
			linehaulCharge = miles * BLoadRate1
		else if(miles > 250 && miles <= 500)
			linehaulCharge = miles * BLoadRate2
		else if(miles > 500)
			linehaulCharge = miles * BLoadRate3

		if(linehaulCharge < BLoadMinCharge) // impose minimum charge if necessary
		{
			isMinCharge = true
			linehaulCharge = BLoadMinCharge
		}
		if(estimatorForm.returnLoad.checked == true) // charge half the regular linehaul charge if load is a return load
			linehaulCharge /= 2
	}
	else if(loadClass == 'C')
	{
		if(miles > 0 && miles <= 250)
			linehaulCharge = miles * CLoadRate1
		else if(miles > 250 && miles <= 500)
			linehaulCharge = miles * CLoadRate2
		else if(miles > 500)
			linehaulCharge = miles * CLoadRate3

		if(linehaulCharge < CLoadMinCharge) // impose minimum charge if necessary
		{
			isMinCharge = true
			linehaulCharge = CLoadMinCharge
		}
		if(estimatorForm.returnLoad.checked == true) // charge half the regular linehaul charge if load is a return load
			linehaulCharge /= 2
	}
	else if(loadClass == 'D')
	{
		if(miles > 0 && miles <= 250)
			linehaulCharge = miles * DLoadRate1
		else if(miles > 250 && miles <= 500)
			linehaulCharge = miles * DLoadRate2
		else if(miles > 500)
			linehaulCharge = miles * DLoadRate3

		if(linehaulCharge < DLoadMinCharge) // impose minimum charge if necessary
		{
			isMinCharge = true
			linehaulCharge = DLoadMinCharge
		}
		if(estimatorForm.returnLoad.checked == true) // charge half the regular linehaul charge if load is a return load
			linehaulCharge /= 2
	}
	else if(loadClass == 'E')
	{
		if(miles > 0 && miles <= 250)
			linehaulCharge = miles * ELoadRate1
		else if(miles > 250 && miles <= 500)
			linehaulCharge = miles * ELoadRate2
		else if(miles > 500)
			linehaulCharge = miles * ELoadRate3

		if(linehaulCharge < ELoadMinCharge) // impose minimum charge if necessary
		{
			isMinCharge = true
			linehaulCharge = ELoadMinCharge
		}
		if(estimatorForm.returnLoad.checked == true) // charge half the regular linehaul charge if load is a return load
			linehaulCharge /= 2
	}
	else // shouldn't need, but safety just in case
	{
		alert("Error: Load class linehaul charge cannot be determined!")
		return
	}

	// round linehaul charge here to match database field
	linehaulCharge = parseFloat(linehaulCharge.toFixed(2))

	// add fuel surcharge
	if(!estimatorForm.useStandardFsc.checked)
		fuelSurcharge = parseFloat((linehaulCharge * estimatorForm.fscTriggerPoints.value).toFixed(2)) // old method (used through first half of 2005)
	else
		// if the fuel price is greater than the benchmark price then calculate the fuel surcharge
		if(!isNaN(estimatorForm.fuelPrice.value) && estimatorForm.fuelPrice.value > fuelSurchargeBenchmarkPrice)
			fuelSurcharge = parseFloat(((estimatorForm.fuelPrice.value - fuelSurchargeBenchmarkPrice) * (miles / fscAverageMpg)).toFixed(2))
	// determine PERSON RESPONSIBLE FOR PAYING FOR FUEL to Pass-Through to Cost Bearer
	if(estimatorForm.payType.value == "Owner Operator" || estimatorForm.payType.value == "Office Employee")
		payAmount += fuelSurcharge
	else if(estimatorForm.payType.value == "JWG" || estimatorForm.payType.value == "JWG's Co-Driver" || estimatorForm.payType.value == "Company Driver")
		officeAmount += fuelSurcharge

	// compare FSC alert
	if(estimatorForm.compareFsc.checked && !isNaN(estimatorForm.fuelPrice.value) && estimatorForm.fuelPrice.value > fuelSurchargeBenchmarkPrice)
		alert("EWEI 2005 FSC: $" + (linehaulCharge * estimatorForm.fscTriggerPoints.value).toFixed(2) + " (" + estimatorForm.fscTriggerPoints.value * 100 + "%)" + "\nIndustry Standard FSC: $" + ((estimatorForm.fuelPrice.value - fuelSurchargeBenchmarkPrice) * (miles / fscAverageMpg)).toFixed(2) + " (" + ((((estimatorForm.fuelPrice.value - fuelSurchargeBenchmarkPrice) * (miles / fscAverageMpg)) / linehaulCharge) * 100).toFixed(2) + "%)")


//alert("EWEI 2005 FSC: $" + (linehaulCharge * estimatorForm.fscTriggerPoints.value).toFixed(2) + " (" + estimatorForm.fscTriggerPoints.value * 100 + "%)" + "\nIndustry Standard FSC: $" + ((estimatorForm.fuelPrice.value - fuelSurchargeBenchmarkPrice) * (miles / fscAverageMpg)).toFixed(2) + " (" + ((((estimatorForm.fuelPrice.value - fuelSurchargeBenchmarkPrice) * (miles / fscAverageMpg)) / linehaulCharge) * 100).toFixed(2) + "%)")
//                                                                                                                                                                                                                                                    fuelSurcharge = parseFloat(((estimatorForm.fuelPrice.value - fuelSurchargeBenchmarkPrice) * (miles / fscAverageMpg)).toFixed(2))

	// add Customs clearance charge if applicable
	if(estimatorForm.customsLoad.checked == true)
		payAmount += customsClearanceCharge

	// add liftgate charge if applicable
	if(estimatorForm.liftgate.checked == true)
		payAmount += liftgateCharge

	// add tarping charge if applicable
	if(estimatorForm.tarping.checked == true)
		payAmount += tarpingCharge

	// add night charge if applicable
	if(isMinCharge && estimatorForm.nightLoad.checked)
		payAmount += nightCharge

	// add NYC metro charge if applicable
	if(estimatorForm.nycMetro.checked == true)
		payAmount += nycServiceCharge

	// only charge pickup or stop-off if not a minimum charge load
	if(estimatorForm.pickup.value > 0 && !isMinCharge)
	{
		payAmount += pickupCharge * estimatorForm.pickup.value * payPercent
		officeAmount += pickupCharge * estimatorForm.pickup.value * officePercent
	}
	if(estimatorForm.pickup.value > 0 && isMinCharge)
	{
		switch(loadClass)
		{
			case 'A':
				payAmount += ALoadMinCharge * estimatorForm.pickup.value * payPercent
				officeAmount += ALoadMinCharge * estimatorForm.pickup.value * officePercent
				break
			case 'B':
				payAmount += BLoadMinCharge * estimatorForm.pickup.value * payPercent
				officeAmount += BLoadMinCharge * estimatorForm.pickup.value * officePercent
				break
			case 'C':
				payAmount += CLoadMinCharge * estimatorForm.pickup.value * payPercent
				officeAmount += CLoadMinCharge * estimatorForm.pickup.value * officePercent
				break
			case 'D':
				payAmount += DLoadMinCharge * estimatorForm.pickup.value * payPercent
				officeAmount += DLoadMinCharge * estimatorForm.pickup.value * officePercent
				break
			case 'E':
				payAmount += ELoadMinCharge * estimatorForm.pickup.value * payPercent
				officeAmount += ELoadMinCharge * estimatorForm.pickup.value * officePercent
				break
		}
	}

	// only charge pickup or stop-off if not a minimum charge load
	if(estimatorForm.stopOff.value > 0 && !isMinCharge)
	{
		payAmount += stopOffCharge * estimatorForm.stopOff.value * payPercent
		officeAmount += stopOffCharge * estimatorForm.stopOff.value * officePercent
	}
	if(estimatorForm.stopOff.value > 0 && isMinCharge)
	{
		switch(loadClass)
		{
			case 'A':
				payAmount += ALoadMinCharge * estimatorForm.stopOff.value * payPercent
				officeAmount += ALoadMinCharge * estimatorForm.stopOff.value * officePercent
				break
			case 'B':
				payAmount += BLoadMinCharge * estimatorForm.stopOff.value * payPercent
				officeAmount += BLoadMinCharge * estimatorForm.stopOff.value * officePercent
				break
			case 'C':
				payAmount += CLoadMinCharge * estimatorForm.stopOff.value * payPercent
				officeAmount += CLoadMinCharge * estimatorForm.stopOff.value * officePercent
				break
			case 'D':
				payAmount += DLoadMinCharge * estimatorForm.stopOff.value * payPercent
				officeAmount += DLoadMinCharge * estimatorForm.stopOff.value * officePercent
				break
			case 'E':
				payAmount += ELoadMinCharge * estimatorForm.stopOff.value * payPercent
				officeAmount += ELoadMinCharge * estimatorForm.stopOff.value * officePercent
				break
		}
	}

	// add hand loading & unloading charges if applicable
	if(estimatorForm.handLoadTime.value > 0 || estimatorForm.handUnloadTime.value > 0)
		alert("Hand loading and unloading must be preapproved. Please call for more information.")
	payAmount += (estimatorForm.handLoadTime.value / 60) * handMovingCharge
	payAmount += (estimatorForm.handUnloadTime.value / 60) * handMovingCharge

	// add detention time charges if applicable
	// this code must preceed the layover charge section
	if(estimatorForm.pickupDetentionTime.value > detentionFreeTime)
		if(((estimatorForm.pickupDetentionTime.value - detentionFreeTime) / 15) * detentionTimeCharge > layoverCharge)
		{
			alert("The pickup detention time charge exceeds the charge for a layover. You will be charged for a layover instead of hourly detention time.")
			estimatorForm.pickupDetentionTime.value = 0 // set the pickup detention time to 0
			estimatorForm.pickupLayover.checked = true // check the pickup layover box
		}
		else
		{
			payAmount += ((estimatorForm.pickupDetentionTime.value - detentionFreeTime) / 15) * (detentionTimeCharge * payPercent) // add portion of charged detention time to be paid
			officeAmount += ((estimatorForm.pickupDetentionTime.value - detentionFreeTime) / 15) * (detentionTimeCharge * officePercent) // add office's portion of charged detention time
		}
	// add delivery detention time charges - same as pickup detention time charges
	if(estimatorForm.deliveryDetentionTime.value > detentionFreeTime)
		if(((estimatorForm.deliveryDetentionTime.value - detentionFreeTime) / 15) * detentionTimeCharge > layoverCharge)
		{
			alert("The delivery detention time charge exceeds the charge for a layover. You will be charged for a layover instead of hourly detention time.")
			estimatorForm.deliveryDetentionTime.value = 0 // set the delivery detention time to 0
			estimatorForm.deliveryLayover.checked = true // check the delivery layover box
		}
		else
		{
			payAmount += ((estimatorForm.deliveryDetentionTime.value - detentionFreeTime) / 15) * (detentionTimeCharge * payPercent) // add portion of charged detention time to be paid
			officeAmount += ((estimatorForm.deliveryDetentionTime.value - detentionFreeTime) / 15) * (detentionTimeCharge * officePercent) // add office's portion of charged detention time
		}

	// add layover charges if applicable
	// this code must be after the detention time section
	if(estimatorForm.pickupLayover.checked == true)
		payAmount += layoverCharge
	if(estimatorForm.deliveryLayover.checked == true)
		payAmount += layoverCharge

	// add co-driver charge if applicable (required if straight through with over hosMaxDrivingTime hours of transit time for trucks)
	if(estimatorForm.coDriver.checked == true)
	{
		if(estimatorForm.payType.value != "JWG's Co-Driver")
			payAmount += parseFloat((coDriverRate * miles).toFixed(2)) // driver gets 100% of the co-driver charge
		else // this is JWG's co-driver
			officeAmount += parseFloat((coDriverRate * miles).toFixed(2)) // office gets the charge and pays the co-driver mileage
	}

	// split the linehaul charge
	if(estimatorForm.payMethod[0].checked || isMinCharge) // percentage
		mileagePay = linehaulCharge * payPercent
	else if(estimatorForm.payMethod[1].checked) // mileage
	{
		if(estimatorForm.fuelType[1].checked) // diesel
			mileagePay = miles * truckLoadedMilePayRate + miles * truckEmptyMilePayRate
	}
	mileagePay = parseFloat(mileagePay.toFixed(2)) // round mileage pay here to match database field
	payAmount += mileagePay
	officeAmount += linehaulCharge - mileagePay

	// special pricing conditions
	if(estimatorForm.payType.value == "JWG")
	{
		officeAmount += payAmount // give any charges normally paid to the office
		payAmount = 0 // JWG (the trailer) does not get paid - it all goes into the office account
	}
	else if(estimatorForm.payType.value == "JWG's Co-Driver") // JWG is paying a co-driver (whether required or not)
	{
		officeAmount += payAmount // give any charges normally paid to the office
		payAmount = coDriverRate * (miles * 2) // JWG's co-driver gets paid per round trip mile
		officeAmount -= payAmount // office gets everything except the co-driver's pay
	}
	else if(estimatorForm.payType.value == "Office Employee")
	{
		payAmount += businessMileageRate * (miles * 2) // add businessMileageRate per round trip mile to any accessorial charges paid
		officeAmount -= businessMileageRate * (miles * 2) // subtract pay from what office gets
//split fees based on percentage do not get charged?
	}

	invoiceAmount.value = '$' + (officeAmount + payAmount).toFixed(2)

	// calculate guaranteed transit time
	var guaranteedTransitTime // in minutes
	var guaranteedSpeed // in MPH
	if(estimatorForm.fuelType[0].checked) // gas (cargo van)
		guaranteedSpeed = vanGuaranteedSpeed
	else if(estimatorForm.fuelType[1].checked) // diesel (straight truck or tractor trailer)
		guaranteedSpeed = truckGuaranteedSpeed
	if(miles < localLoadMiles)
		guaranteedTransitTime = Math.round(localLoadMiles / (guaranteedSpeed / 60))
	else guaranteedTransitTime = Math.round(miles / (guaranteedSpeed / 60))
	if(estimatorForm.customsLoad.checked == true)
		guaranteedTransitTime += 60 // add an hour if Customs load
	transitTime.value = Math.floor(guaranteedTransitTime / 60) + " Hour(s) and " + guaranteedTransitTime % 60 + " Minute(s)"

	loadPay.value = '$' + payAmount.toFixed(2)

	// calculate maximum Comchek allowed
	// maxComchek = maxComchekPercent * mileagePay rounded down to $25 increment unless it is within $5 (then rounded up)
	var maxComchek = ((mileagePay * maxComchekPercent) % 100) // round this number to multiple of 25 (modulus by 100 will always return the tens digit and everything to the right of it)
	if(maxComchek >= 0 && maxComchek < 20)
		maxComchek = 0
	else if(maxComchek >= 20 && maxComchek < 45)
		maxComchek = 25
	else if(maxComchek >= 45 && maxComchek < 70)
		maxComchek = 50
	else if(maxComchek >= 70 && maxComchek < 95)
		maxComchek = 75
	else if(maxComchek >= 95 && maxComchek < 100)
		maxComchek = 100
	maxComchek = ((Math.floor((mileagePay * maxComchekPercent) / 100)) * 100) + maxComchek // var used as temp prior
	maxComchekAmount.value = '$' + maxComchek.toFixed(2)

	grossProfit.value = '$' + officeAmount.toFixed(2)

	// load details
	detailString = "Load Class: " + loadClass + "\nLinehaul Charge: $" + linehaulCharge.toFixed(2) + "\nFuel Surcharge: $" + fuelSurcharge.toFixed(2) + "\nPay Percent: " + payPercent * 100 + "%" + "\nMileage Pay: $" + mileagePay.toFixed(2)
	if(displayType[2].checked)
		alert(detailString)

	// notify user if calculation or rounding error occurred
//	if(parseFloat((parseFloat(payAmount.toFixed(2)) + parseFloat(officeAmount.toFixed(2))).toFixed(2)) != parseFloat((officeAmount + payAmount).toFixed(2)))
//		alert("It appears a rounding error has occurred. The office amount is probably plus or minus one cent off.\n" + payAmount + " + " + officeAmount + " != " + (officeAmount + payAmount))
}
