function setTotal(which){
  // variables
  var lQuantity
	var fPrice
	var fPrevProductTotal
	var fProductTotal
	var fTotal
	// objects
	var oProductTotal
	var oQuantity
	var oPrice
	var oTotal
	var oForm
	
	oForm = document.forms.bookstore
	if (!oForm) return
	
	oQuantity = oForm["quantity" + which]
	if (!oQuantity) return
	lQuantity = oQuantity.value
	
	//oPrice = document.getElementById("price" + which)
	oPrice = oForm["hiddenprice" + which]
	if (!oPrice) return
	fPrice = oPrice.value
	
	//oProductTotal = document.getElementById("total" + which)
	oProductTotal = oForm["total" + which]
	if (!oProductTotal) return
	//alert(which + ":" + oProductTotal.value)
	
  fPrevProductTotal = parseFloatSafe(oProductTotal.value)

  fPrice = parseFloatSafe(fPrice)
	lQuantity = parseIntSafe(lQuantity)	
	fProductTotal = fPrice * lQuantity

	//oProductTotal.innerHTML = format_string(new String(fProductTotal),"currency")
	oProductTotal.value = format_string(new String(fProductTotal),"currency")
	
	oTotal = oForm.totalTop
	if (!oTotal) return
	fTotal = parseFloatSafe(oTotal.value)

	fTotal = (Math.round(100*(fTotal - fPrevProductTotal + fProductTotal)))/100
	oTotal.value = format_string(new String(fTotal),"currency")
	
	oTotal = oForm.totalBottom
	if (oTotal) oTotal.value = format_string(new String(fTotal),"currency")
	
	var handleSuccess = function(o) { 
	    // if (o.responseText !== undefined) result_string = o.responseText.toString().replace(/\n/gi,'');
			oQuantity.focus()
	} 
	
	var handleFailure = function(o) {
		// nothing
		oQuantity.focus()
	}
	
	var callback = 
	{ 
	  success:handleSuccess, 
	  failure: handleFailure, 
	  argument: [] 
	}; 
	
	var request = YAHOO.util.Connect.asyncRequest('POST', "update_totals.php", callback, "product_id=" + which + "&new_quantity=" + lQuantity + "&remove="); 

	return
}

function clear_total() {
  var o_form
	var o_elt
	var num_books
	
	o_form = document.forms.bookstore
	if (!o_form) return
	
	o_elt = o_form.num_books
	if (!o_elt) return
	
	num_books = parseIntSafe(o_elt.value)
	for (j = 1; j <= num_books; j++) {
	  o_elt = o_form["quantity" + j]
		if (o_elt) o_elt.value = ""
		o_elt = o_form["total" + j]
		if (o_elt) o_elt.value = ""
	}
	
	o_elt = o_form.totalTop
	if (o_elt) o_elt.value = ""
	
	o_elt = o_form.totalBottom
	if (o_elt) o_elt.value = ""
	
	o_elt = o_form.num_ordered
	if (o_elt) o_elt.value = 0
	
	var handleSuccess = function(o) { 			
	    // if (o.responseText !== undefined) result_string = o.responseText.toString().replace(/\n/gi,'');
	} 
	
	var handleFailure = function(o) {
		// nothing
	}
	
	var callback = 
	{ 
	  success:handleSuccess, 
	  failure: handleFailure, 
	  argument: [] 
	}; 
	
	var request = YAHOO.util.Connect.asyncRequest('POST', "update_totals.php", callback, "clear=1"); 

	return
}

function validate() {
  // variables
	var fTotal
	// objects
	var oTotal
	var oForm
	
	oForm = document.forms.bookstore
	if (!oForm) return false
		
	oTotal = oForm.totalTop
	if (!oTotal) return false
	
	fTotal = parseFloatSafe(oTotal.value)
	
	if (!(fTotal > 0)) alert("You have not selected any products to purchase.")
	
	return (fTotal > 0)
} 

function syncSpecialOffer(flag) {
  var oForm
	var oElt
	var value
	
	oForm = document.forms.bookstore
	if (!oForm) return
	
	if (flag == 1) { 
	  oElt = oForm.specialoffercode
		if (!oElt) return
		value = oElt.value
		oElt = oForm.specialoffercodebottom
		if (oElt) oElt.value = value
		
	} else {
	  oElt = oForm.specialoffercodebottom
		if (!oElt) return
		value = oElt.value
		oElt = oForm.specialoffercode
		if (oElt) oElt.value = value
	}
	
	return 
}

var oWnd

function shippingFees(){
	oWnd = window.open("shippingfees.htm","shippingFees","width=900,height=510,scrollbars=yes")
	return
}
