var vorne_commerce_data = [
	{ item_id: "xl-trial-request",				product: "XL Trial Request",			category: "Form",		price: "2000",	submitted: false },
	{ item_id: "xl-info-request",				product: "XL Info Request",				category: "Form",		price: "1000",	submitted: false },
	{ item_id: "xl-webinar-signup",				product: "XL Webinar Signup",			category: "Form",		price: "1000",	submitted: false },
	{ item_id: "oee-webinar-signup",			product: "OEE Webinar Signup",			category: "Form",		price: "500",	submitted: false },
	{ item_id: "general-trial",					product: "General Trial",				category: "Form",		price: "100",	submitted: false },
	{ item_id: "mailing-list-signup",			product: "Mailing List Signup",			category: "Form",		price: "50",	submitted: false },
	{ item_id: "xl-flash-movie",				product: "XL Flash Movie",				category: "Video",		price: "10",	submitted: false },
	{ item_id: "xl-powerpoint-presentation",	product: "XL PowerPoint Presentation",	category: "PowerPoint",	price: "10",	submitted: false },
	{ item_id: "xl-pdf-data-sheet",				product: "XL PDF Data Sheet",			category: "Flyer",		price: "10",	submitted: false },
	{ item_id: "xl-web-page",					product: "XL Web Page",					category: "Link",		price: "10",	submitted: false }
];

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 && !item.submitted) {
		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();
		item.submitted = true;
	}
	
	return true;
};
