
// Displays a product/book's table of contents
var ToggleTOC = function(){
	var TheDiv = document.getElementById('divTOC');
	var CurrDisplayVal = TheDiv.style.display;
	
	if (CurrDisplayVal == '')
		TheDiv.style.display = 'none';
	else
		TheDiv.style.display = '';
}

// Updates the displayed price for a rental based on the selected rental period
var UpdateRentalPrice = function(idRentPerSel,idSpan) {
	var objRentPerSel = document.getElementById(idRentPerSel);
	var RentPerIDPrice = objRentPerSel[objRentPerSel.selectedIndex].value;
	var arrRentPerIDPrice = RentPerIDPrice.split('|');
	var Price = arrRentPerIDPrice[1];
	
	document.getElementById(idSpan).innerHTML = '$' + CurrencyFormat(Price);
}

// Updates the New price when an attribute is changed
var AttribOnChange = function(ProdID, ProdAttribTypeID, ProdAttribSelOptID, retailPrice, idNewPrice, ShowRetail){
	// A non-numeric ProdAttribSelOptID value means we need to get the value from a normal select, and that ProdAttribSelOptID is actually the id of the select.
	// Image selects provide the value on their own.
	if (IsNumeric(ProdAttribSelOptID)==false) {
		var objSelect = document.getElementById(ProdAttribSelOptID);
		ProdAttribSelOptID = objSelect[objSelect.selectedIndex].value;
	}
	// TRIED USING ColdFusion.navigate USING A CALL TO A CFC FUNCTION, BUT HTML IN FUNCTION RESULT WAS NOT RENDERED BY RECEIVING CFDIV - THE RAW HTML WAS DISPLAYED
	// create an instance of the proxy. 
	var e = new Products();
	e.setCallbackHandler(AttribOnChangeResult);
	e.setErrorHandler(myErrorHandler);
	e.FormatProdAttribPrice(ProdID,ProdAttribTypeID,ProdAttribSelOptID,retailPrice,idNewPrice,ShowRetail);
}

var AttribOnChangeResult = function(Res){
	// Update the New price, if we got a price
	if (Trim(Res.PRICESTR) != '')
		document.getElementById(Res.IDNEWPRICE).innerHTML = Res.PRICESTR;
}

// Used by select-type attributes that use images for selection - handles visual indication of the selected image and sets the value of a hidden field
var AttribOnClick = function(idHiddenFld, attribValue, idDiv, idImg){
	var objDiv = document.getElementById(idDiv);
	var elms = objDiv.getElementsByTagName("img");
	
	// Remove any borders on all img elements inside the div
	for (var i = 0, maxI = elms.length; i < maxI; ++i) {
		var elm = elms[i];
		elm.className = 'ImgNotSelected';
	}
	
	// Add a border to the clicked on img
	document.getElementById(idImg).className = 'ImgSelected';
	
	// Put the attribute value into the hidden field
	document.getElementById(idHiddenFld).value = attribValue;
}

var ValidateAgreementForms = function(){
	var ErrorMsg = '';
	
	if (document.RentalAgreementForm && document.RentalAgreementForm.AcceptRentalAgreement.checked==false) {
		ErrorMsg = 'You must read the Rental Terms of Use and check the I Accept box at the end before you can proceed with checkout.\n';
	}

	if (document.BTSAAckForm && document.BTSAAckForm.AcceptBTSAAgreement.checked==false) {
		ErrorMsg = ErrorMsg + 'You must read the Bill to Student Account authorization notice and check the I Accept box at the end before you can proceed with checkout.';
	}
	
	if (ErrorMsg == '') {
		window.location.href='recomm_items.cfm';
	} else {
		alert(ErrorMsg);
	}

}

