var baseprice1 = 0;
var baseprice2 = 0;
var baseprice3 = 0;
var baseprice4 = 0;


function loadbaseprice() {
	baseprice1 = parseFloat(document.getElementById('totalprice1').innerHTML);
	baseprice2 = parseFloat(document.getElementById('totalprice2').innerHTML);
	baseprice3 = parseFloat(document.getElementById('totalprice3').innerHTML);
	baseprice4 = parseFloat(document.getElementById('totalprice4').innerHTML);


	//baseprice = parseFloat(MM_getTextOfLayer(totalprice));
	//alert(baseprice1);
	
}

function recalculateform(form){
	var total1=baseprice1;
	var total2=baseprice2;
	var total3=baseprice3;
	var total4=baseprice4;
	called=true;
	
	allNodes = document.getElementsByAttribute("config1", "select");
	for(i = 0; i < allNodes.length; i++) {
     total1 += parseFloat(allNodes[i].value);
	}
	
	allNodes = document.getElementsByAttribute("config2", "select");
	for(i = 0; i < allNodes.length; i++) {
     total2 += parseFloat(allNodes[i].value);
	}

	allNodes = document.getElementsByAttribute("config3", "select");
	for(i = 0; i < allNodes.length; i++) {
     total3 += parseFloat(allNodes[i].value);
	}

	allNodes = document.getElementsByAttribute("config4", "select");
	for(i = 0; i < allNodes.length; i++) {
     total4 += parseFloat(allNodes[i].value);
	}


	/*
	// finance!
	rates.frmCalc(form,total);
	*/
	
	total1 = includeCents(total1);	
	total2 = includeCents(total2);	
	total3 = includeCents(total3);	
	total4 = includeCents(total4);	


    var theConfigSummary = "";
	var thisConfigChoice = form.configchoice.value;
	var theConfigChoice = "config" + thisConfigChoice;
	var theConfigTotal = "total" + thisConfigChoice;
	//alert(theConfigChoice);
	
	allNodes = document.getElementsByAttribute(theConfigChoice, "select");
	theConfigSummary = theConfigChoice + " --- ";
	
	for(i = 0; i < allNodes.length; i++) {
		theConfigSummary += allNodes[i].value;
		theConfigSummary += " --- ";
	}
	
	//alert (theConfigSummary);
	form.configsummary.value = theConfigSummary;
	if (thisConfigChoice == 1) {form.chosenprice.value = total1};
	if (thisConfigChoice == 2) {form.chosenprice.value = total2};
	if (thisConfigChoice == 3) {form.chosenprice.value = total3};
	if (thisConfigChoice == 4) {form.chosenprice.value = total4};


	
	var theCustomerState = form.recipients.selectedIndex;
	
	if (theCustomerState == 1) { form.customerstate.value ="QLD" }
	else if (theCustomerState == 2) { form.customerstate.value ="NSW" }
	else if (theCustomerState == 3) { form.customerstate.value ="ACT" }
	else if (theCustomerState == 4) { form.customerstate.value ="VIC" }
	else if (theCustomerState == 5) { form.customerstate.value ="TAS" }
	else if (theCustomerState == 6) { form.customerstate.value ="SA" }
	else if (theCustomerState == 7) { form.customerstate.value ="WA" }
	else if (theCustomerState == 8) { form.customerstate.value ="NT" }
	
	//alert(chosenprice.value);
	
	
	// one or more of these may fail, but that's OK
	
	MM_setTextOfLayer('totalprice1','',total1);
	MM_setTextOfLayer('totalprice2','',total2);
	MM_setTextOfLayer('totalprice3','',total3);
	MM_setTextOfLayer('totalprice4','',total4);
	
}

function MM_setTextOfLayer(objId,x,newText) { //v9.0
  with (document) if (getElementById && ((obj=getElementById(objId))!=null))
    with (obj) innerHTML = unescape(newText);
}

function includeCents(theValue) {

	if (theValue.toFixed) {
		theValue = theValue.toFixed(2);
	//theValue = "$"+theValue;
	}
	else {
		theValue = Math.round(theValue*100)/100;
		//theValue = "$"+theValue;
		if (theValue.charAt(theValue.length-2) == ".") { theValue = theValue+"0" };
	}
	return theValue;
}