/* cartGoogle.js */
var googleCartAttributePrefixes = null; // array of prefixes to set

/* @googlecartBeforeAdd
 *
 * what to do before adding item to google cart
 *
 */
function googlecartBeforeAdd(xitem) {
	//Get all the attributes of the item added to cart   
	
//	alert('here before adding item to google cart');return true;
	var attribs = xitem.getCustomAttributes();

//	var s = '';
	
	var tsiTradeshow = YAHOO.util.Dom.get("tsi-attr-tradeshow").value;
	var tsiDate = YAHOO.util.Dom.get("tsi-attr-date").value;
	var tsiSpecial = YAHOO.util.Dom.get("tsi-attr-special").value;
	
	var attrVal = '';

	for (var i in attribs) { // set attribute value to those special ones defined just above
		if (attribs[i] != "") {
			attrVal = '';
			if (i == 'tradeshow') attrVal = tsiTradeshow;
			else if (i == 'date') attrVal = tsiDate;
			else if (i == 'special') attrVal = tsiSpecial;
			else attrVal = attribs[i] + '';
			if (attrVal != '') {
//				s += 'setting attrVal(' + i + ') to ' + attrVal + '.\n';
				xitem.setCustomAttribute(i, attrVal);
			}		
//			s += 'attrVal(' + i + '): ' + attrVal + ';' + '\n';
		}
	}

	//alert('googlecartBeforeAdd:\n' +  s);
	googlecart.saveCartAndRefreshWidget();
	
//	s = 'tradeshow: ' + tsiTradeshow + '; date: ' + tsiDate + '; special: ' + tsiSpecial;
//	alert('adding item, values are' + s);
	return true;
} 


/* @setGoogleCartAttributes
 *
 * takes pre-set array of prefixes and sets the passed in element's value to the value of the calulated fields
 *
 */
function setGoogleCartAttributes(attrIndex, e) {
	var v = e.value;
	
	for(i in googleCartAttributePrefixes) {
		YAHOO.util.Dom.get(googleCartAttributePrefixes[i] + attrIndex).value = v;
	}

/*
	//alert('will replace attribute ' + 'p1_' + attrIndex + ', etc. with value:' + e.value );
	YAHOO.util.Dom.get("p1_" + attrIndex).value = v;
	YAHOO.util.Dom.get("p3_" + attrIndex).value = v;
	YAHOO.util.Dom.get("p4_" + attrIndex).value = v;
*/

}

