﻿function getFees() {
    var valid = true;
    var selState = document.getElementById("selStates");
    var selProduct = document.getElementById("selProducts");
    var state = selState.options[selState.selectedIndex].value;
    var product = selProduct.options[selProduct.selectedIndex].value;
    if (state == "") { valid = false; }
    if (product == "") { valid = false; }
    if (valid) {
	var stateProdCombo = state + "," + product;
	var fees = data[stateProdCombo];
	var standard = fees.split(",")[0];
	var rush = fees.split(",")[1];
	document.getElementById("standardFee").value = standard;
	document.getElementById("rushFee").value = rush;
	
	document.getElementById("standard").value = standardPackage;
	document.getElementById("rush").value = rushPackage;

	var standardTotal = convertPrice(standard) + convertPrice(standardPackage);
	var rushTotal = convertPrice(rush) + convertPrice(rushPackage);
	standardTotal = standardTotal.toFixed(2);
	rushTotal = rushTotal.toFixed(2);
	document.getElementById("standardTotal").value = "$" + standardTotal;
	document.getElementById("rushTotal").value = "$" + rushTotal;
    }
}

function getFeesFQ() {
    var valid = true;
    var selState = document.getElementById("selStates");
    var selNewState = document.getElementById("newStates");
    var selProduct = document.getElementById("selProducts");
    var state = selState.options[selState.selectedIndex].value;
    var newstate = selNewState.options[selNewState.selectedIndex].value;
    var product = selProduct.options[selProduct.selectedIndex].value;
    if (state == "") { valid = false; }
    if (newstate == "") { valid = false; }
    if (product == "") { valid = false; }
    if (valid) {
	var stateProdCombo = state + "," + product;
	var fees = data[stateProdCombo];
	var standard = fees.split(",")[0];
	var rush = fees.split(",")[1];
	document.getElementById("standardFee").value = standard;
	document.getElementById("rushFee").value = rush;
	
	var newStateProdCombo = newstate + "," + product;
	var newFees = fqdata[newStateProdCombo];
	var newStandard = newFees.split(",")[0];
	var newRush = newFees.split(",")[1];
	document.getElementById("fqstandardFee").value = newStandard;
	document.getElementById("fqrushFee").value = newRush;

	document.getElementById("standard").value = fqstandardPackage;
	document.getElementById("rush").value = fqrushPackage;

	var standardTotal = convertPrice(standard) + convertPrice(newStandard) + convertPrice(fqstandardPackage);
	var rushTotal = convertPrice(rush) + convertPrice(newRush) + convertPrice(fqrushPackage);
	standardTotal = standardTotal.toFixed(2);
	rushTotal = rushTotal.toFixed(2);
	document.getElementById("standardTotal").value = "$" + standardTotal;
	document.getElementById("rushTotal").value = "$" + rushTotal;
    }
}

function listStates() {
    var state = "";
    for (i in data) {
	var nextstate = i.split(",")[0];
	if (nextstate !== state) {
	    document.write("<option value='" + nextstate + "'>" + nextstate);
	}
	var state = nextstate;
    }
}

function convertPrice(price) {
	if (price == "n/a") { price = "$0.00"; }
	newPrice = parseFloat(price.replace(/\$/,''));
	return newPrice;
}

