// Created by Nathanael Black for use by students at Bob Jones University
function Calculate_() {
var myform = window.document.form1;
var calcforcat;
var subtotal;
var calcforrow;
var counter2;
var calculatedvalue;

if (myform.opt[0].checked) {
calcforcat = myform.selcategory.value;
for (counter2 = 1; counter2 < 6; counter2++) {
    if (myform.elements["c" + counter2].value == calcforcat){
    break;
    }
}
calculatedvalue = (myform.total.value - 100 * mathprocess_(calcforcat)[0]) / myform.elements["wc" + counter2].value;
myform.elements["pc" + counter2].value = calculatedvalue;
myform.elements["r" + counter2].value = calculatedvalue/100 * myform.elements["wc" + counter2].value;
}
else if (myform.opt[1].checked) {
form1.total.value = 100 * mathprocess_(0)[0];
}
else {
alert("Please select an option to solve for.");
}
// function to check valid entries which should start as null string
// highlight cells without correct values
// add error message for each incorrect element

function mathprocess_(exclude){
var myform = window.document.form1;
var counter;
var totals = new Array(2);
totals[0] = 0;
for (counter = 1; counter < 6; counter++) {
    myform.elements["r" + counter].value = 0
    if (!(myform.elements["c" + counter].value == 0 || myform.elements["c" + counter].value == exclude) ){
    totals[1] = myform.elements["pc" + counter].value / 100 * myform.elements["wc" + counter].value;
    myform.elements["r" + counter].value = totals[1];
    totals[0] += totals[1];
    }
}
return totals;
}
}