// 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. No longer used.
var UpdateRentalPrice = function(idRentPerSel,idRentalPriceSpan,idQty,idRentalTotalPriceSpan) {
	var objRentPerSel = document.getElementById(idRentPerSel);
	var RentPerIDPrice = objRentPerSel[objRentPerSel.selectedIndex].value;
	var arrRentPerIDPrice = RentPerIDPrice.split('|');
	var Price = arrRentPerIDPrice[1];
	
	// Update the rental period price
	document.getElementById(idRentalPriceSpan).innerHTML = '$' + CurrencyFormat(Price);
	
	// If ids for qty and total price have been provided, update the total price too
	if (idQty && idRentalTotalPriceSpan) {
		// Get the rental qty
		var Qty = document.getElementById(idQty).value;
		// Calc the total price
		var TotalPrice = Qty * Price;
		// Set the total price span
		document.getElementById(idRentalTotalPriceSpan).innerHTML = '$' + CurrencyFormat(TotalPrice);
	}
}

// Used by select-type attributes (hard-coded) 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;
}

// Selectively linked to attributes. We only need a CartItemID or OrdItemID value where multiple products with attributes can be displayed together 
var AttribOnChange = function(FormName, idDivProdNewPrice, CartItemID, OrdItemID){
	if (typeof(CartItemID) == 'undefined')
		CartItemID = '';
	if (typeof(OrdItemID) == 'undefined')
		OrdItemID = '';
		
	// Save the CF Loading... message HTML
	var Orig_cf_loadingtexthtml = _cf_loadingtexthtml;
	
	// Temporarily clear the CF Loading... message HTML
	_cf_loadingtexthtml="";
	
	ColdFusion.navigate('prod_new_price.cfm?cartitem_id=' + CartItemID + '&orditem_id=' + OrdItemID + '&formname=' + FormName, idDivProdNewPrice, callback, myErrorHandler, 'POST', FormName);
	
	// Restore the CF Loading... message HTML
	_cf_loadingtexthtml = Orig_cf_loadingtexthtml;
}

var Product = {
	// Displays additional embroidery text lines in succession
	AddEmbroidTextLine : function(objBtn, ProdPersLocID, MaxNumLines, AdditionalID) {
		if (typeof(AdditionalID) == 'undefined')
			AdditionalID = '';
		// Hidden input containing the number of lines currently displayed
		var objDisplayedLetteringNumLines = document.getElementById('DisplayedLetteringNumLines' + ProdPersLocID + AdditionalID);
		
		if (parseInt(objDisplayedLetteringNumLines.value) < MaxNumLines) {
			var NextLineNum = parseInt(objDisplayedLetteringNumLines.value) + 1;
			var objLine = document.getElementById('CARTITEMPERS_Content' + NextLineNum + ProdPersLocID + AdditionalID);
			objLine.style.display = '';
			objLine.focus();
			objDisplayedLetteringNumLines.value = '' + NextLineNum;
			if (NextLineNum == MaxNumLines)
				objBtn.style.display = 'none';
		}
	}
}

