var vorne_commerce_data = [
	{ item_id: "index.html",						product: "Form: Lean Intro Email List",	category: "Forms",			price: "2000" },
	{ item_id: "xl-index-free-trial",				product: "Form: XL Trial (XL Page)",	category: "Forms",			price: "2000" },
	{ item_id: "forms/xl-free-trial.htm",			product: "Form: XL Trial",				category: "Forms",			price: "2000" },
	{ item_id: "forms/xl-movie-free-trial.htm",		product: "Form: XL Trial (Movie)",		category: "Forms",			price: "2000" },
	{ item_id: "forms/xl-webinar.htm",				product: "Form: XL Webinar",			category: "Forms",			price: "1000" },
	{ item_id: "forms/info-request.htm",			product: "Form: General Info",			category: "Forms",			price: "1000" },
	{ item_id: "forms/mailing-list.htm",			product: "Form: Mailing List",			category: "Forms",			price: "25" },
	{ item_id: "forms/free-trial-units.htm",		product: "Form: General Trial",			category: "Forms",			price: "100" },
	{ item_id: "xl-movie/index.html",				product: "XL Movie",					category: "XL Presentation",price: "50" },
	{ item_id: "PDF/XL800.pdf",						product: "Data Sheet: XL800",			category: "Data Sheets",	price: "10" },
	{ item_id: "PDF/XL600.pdf",						product: "Data Sheet: XL600",			category: "Data Sheets",	price: "10" },
	{ item_id: "PDF/XL400.pdf",						product: "Data Sheet: XL400",			category: "Data Sheets",	price: "10" },
	{ item_id: "PPT/xl-productivity-appliance.pps",	product: "XL Powerpoint",				category: "XL Presentation",price: "25" }
];


var get_iso_date_string = function(date) {
	
	var zero_pad = function(number) {
		return (number < 10 ? "0" : "") + number;
	};
	
	var month = zero_pad(date.getMonth() + 1);
	var day = zero_pad(date.getDate());
	var hour = zero_pad(date.getHours());
	var minute = zero_pad(date.getMinutes());
	var second = zero_pad(date.getSeconds());
	var date_string = "" + date.getFullYear() + "-" + month + "-" + day;
	var time_string = "" + hour + ":" + minute + ":" + second;
	
	return date_string + "T" + time_string;
};
	
var get_commerce_transaction_id = function() {
	
	var random = Math.floor(Math.random() * 1000);
	var transaction_id = get_iso_date_string(new Date()) + "-" + random;
	
	return transaction_id;
};

var do_commerce_action = function(item_id) {
	
	var item = null;
	
	vorne_commerce_data.some(function(row) {
		if (row.item_id == item_id) {
			item = row;
			return true;
		}
		return false;
	});
	

	if (item) {
		var transaction_id = get_commerce_transaction_id();
		var affiliation = navigator.appName + " " + navigator.appVersion;
		var sku = window.document.URL || "UNKNOWN SOURCE";

		item.product = item.product || "UNKNOWN PRODUCT";
		item.category = item.category || "UNKNOWN CATEGORY";
		item.price = item.price || "0.42";
		
		pageTracker._addTrans(transaction_id, affiliation, item.price, "", "", "", "", "");

		// The current URL becomes the SKU, because GA doesn't seem to have easy tracking for
		// where a transaction came from.
		//
		pageTracker._addItem(transaction_id, sku, item.product, item.category,
							item.price, "1");
		pageTracker._trackTrans();
	}
	
	return true;
};