// Mail and Fax order form


function clearFields(){
	
	for( i=0; i<document.getElementsByTagName('input').length; i++){
		document.getElementsByTagName('input')[i].value = "";
	}
	document.getElementById('totalButton').value = 'Calculate Total';
}

function makePrice( price, qty, id ){
	var a = price * +qty;
	var totalPrice = a.toFixed(2);
	document.getElementById(id).innerHTML = totalPrice;
}

function makeSubTotal(){
//gather mini subtotals of items and add them all together...
	var masterSub = 0;
	for(i=1; i<38; i++){
		var id = 'miniSub' + i;
		var subtotal = Number(document.getElementById(id).innerHTML);
		masterSub += subtotal;
	}
	document.getElementById('subtotal').innerHTML = masterSub.toFixed(2);
	
//now check if they are from ontario or canada and tax accordingly
	var taxRST = masterSub * 0.08;
	if(document.getElementById("rstcheck").checked == true){
		document.getElementById('rst').innerHTML = taxRST.toFixed(2);
		if(document.getElementById("gstcheck").checked != true){
			document.getElementById("gstcheck").checked = true;
		}
	}else{
		document.getElementById('rst').innerHTML = "";
		taxRST = 0;
	}
	
	var taxGST = masterSub * 0.05;
	if(document.getElementById("gstcheck").checked == true){
		document.getElementById('gst').innerHTML = taxGST.toFixed(2);
	}else{
		document.getElementById('gst').innerHTML = "";
		taxGST = 0;
	}
	
//now calculate the total!
	var masterTotal = masterSub + taxRST + taxGST;
	document.getElementById('total').innerHTML = masterTotal.toFixed(2);
}

function checkIt(){
//this just checks the canadian resident box when the ontario box is checked
	if(document.getElementById("rstcheck").checked == true){
		document.getElementById("gstcheck").checked = true;
	}else{
		//document.getElementById("gstcheck").checked = false;
	}
}