function doqty(fieldprefix, firstprice, yearlyprice, addlprice) 
{
//Set up the dynamic quantity field
var qtyfield = eval("document.theform." + fieldprefix + "OnceQty.value");

// Do the Price Total   
if (qtyfield == "") {document.theform.elements[fieldprefix + 'Total'].value = 0;}
else if (qtyfield == "0") {document.theform.elements[fieldprefix + 'Total'].value = 0;}
else if (qtyfield == "1") {document.theform.elements[fieldprefix + 'Total'].value = firstprice;}
else if (qtyfield == "A") {document.theform.elements[fieldprefix + 'Total'].value = addlprice;}
else if (qtyfield > 1) 
{
overtwoprice = firstprice + (addlprice * (qtyfield - 1))
software = overtwoprice;
itemtotal = software;
document.theform.elements[fieldprefix + 'Total'].value = itemtotal;
}
var ordertotal = 0
    // Run through all the form fields
    for (var i=0; i < theform.elements.length; ++i) {

        // Get the current field
        form_field = theform.elements[i]

        // Get the field's name
        form_name = form_field.name

        // Is it a "Total" field?
        if (form_name.substring(6,12) == "Total") {
	        // Update the order total
			ordertotal += (document.theform.elements[form_name].value - 0);
			document.theform.GrandTotal.value = ordertotal;
			}		
	 }	 	
	 dopromo(document.theform.PromoCode.value);
}

function dototal()
{
var ordertotal = 0
    // Run through all the form fields
    for (var i=0; i < theform.elements.length; ++i) {

        // Get the current field
        form_field = theform.elements[i]

        // Get the field's name
        form_name = form_field.name

        // Is it a "Total" field?
        if (form_name.substring(6,12) == "Total") {
	        // Update the order total
			ordertotal += (document.theform.elements[form_name].value - 0);
			document.theform.GrandTotal.value = ordertotal;
			}		
	 }	 	
	 dopromo(document.theform.PromoCode.value);
}


function dopromo(thecode)
{

var peroff = 0
var curtotal = 0

    // Run through all the form fields
    for (var i=0; i < theform.elements.length; ++i) {

        // Get the current field
        form_field = theform.elements[i]

        // Get the field's name
        form_name = form_field.name

        // Is it a "Total" field?
        if (form_name.substring(6,12) == "Total") {
	        // Update the order total
			curtotal += (document.theform.elements[form_name].value - 0);
			}		
}

		if (thecode.charAt(4) == "Q" || thecode.charAt(4) == "q") {peroff = 10;}
		else if (thecode.charAt(4) == "C" || thecode.charAt(4) == "c") {peroff = 15;}
		else if (thecode.charAt(4) == "T" || thecode.charAt(4) == "t") {peroff = 20;}
		else if (thecode.charAt(4) == "N" || thecode.charAt(4) == "n") {peroff = 25;}
		else if (thecode.charAt(4) == "U" || thecode.charAt(4) == "u") {peroff = 30;}
		else if (thecode.charAt(4) == "L" || thecode.charAt(4) == "l") {peroff = 35;}
		else if (thecode.charAt(4) == "Z" || thecode.charAt(4) == "z") {peroff = 40;}
		else {peroff = 0;}
		amounttotakeoff = ((curtotal * peroff) / 100);
		if (amounttotakeoff > 0) {document.theform.PromoMinus.value = '-' + amounttotakeoff;}
		else {document.theform.PromoMinus.value = 0;}
		document.theform.GrandTotal.value = (curtotal - amounttotakeoff);
}

