var vorne_commerce_data = [
	{ item_id: "xl",											product: "Form: XL Trial (XL Page)",category: "Forms",			price: "1000" },
	{ item_id: "forms/xl-free-trial.htm",						product: "Form: XL Trial",			category: "Forms",			price: "1000" },
	{ item_id: "forms/xl-movie-free-trial.htm",					product: "Form: XL Trial (Movie)",	category: "Forms",			price: "1000" },
	{ item_id: "forms/xl-webinar.htm",							product: "Form: XL Webinar",		category: "Forms",			price: "250" },
	{ item_id: "forms/info-request.htm",						product: "Form: General Info",		category: "Forms",			price: "100" },
	{ item_id: "forms/mailing-list.htm",						product: "Form: Mailing List",		category: "Forms",			price: "10" },
	{ item_id: "forms/free-trial-units.htm",					product: "Form: General Trial",		category: "Forms",			price: "10" },
	{ item_id: "xl-movie/index.html",							product: "XL Movie",				category: "XL Presentation",price: "5" },
	{ item_id: "PDF/XL800.pdf",									product: "Data Sheet: XL 800",		category: "Data Sheets",	price: "5" },
	{ item_id: "PPT/xl-productivity-appliance.pps",				product: "XL Powerpoint",			category: "XL Presentation",price: "5" },
	{ item_id: "xl-executive-summary.htm",						product: "XL Executive Summary",	category: "XL Pages",		price: "5" },
	{ item_id: "xl/xl.htm",										product: "Product Page: XL",		category: "XL Pages",		price: "5" },
	{ item_id: "displays/xl400-lean-manufacturing-tool.htm",	product: "Product Page: XL 400",	category: "XL Pages",		price: "5" },
	{ item_id: "displays/xl600-lean-manufacturing-tool.htm",	product: "Product Page: XL 600",	category: "XL Pages",		price: "5" },
	{ item_id: "displays/xl800-lean-manufacturing-tool.htm",	product: "Product Page: XL 800",	category: "XL Pages",		price: "5" },
	{ item_id: "mailto:sales@vorne.com",						product: "Email: Sales",			category: "Email",			price: "0.01" },
	{ item_id: "mailto:support@vorne.com",						product: "Email: Support",			category: "Email",			price: "0.01" },
	{ item_id: "learning-center",								product: "Learning Center Page",	category: "Education",		price: "0.01" },
	{ item_id: "pdf/fast-guide-to-oee.pdf",						product: "Fast Guide to OEE",		category: "Education",		price: "0.01" }, 
	{ item_id: "images/press-releases/oee-website/OEE-Pocket-Guide-300px-wide.jpg",
																product: "OEE Pocket Guide",		category: "Education",		price: "0.01" },
	{ item_id: "mailto:?subject=Andon Information", 			product: "Andon email",				category: "Email",			price: "0.01" },
	{ item_id: "mailto:?subject=TPS (Toyota Production System) Information",
																product: "KPIs email",				category: "Email",			price: "0.01" },
	{ item_id: "mailto:?subject=Kaizen/Continuous Improvement Information",
																product: "Kaizen email",			category: "Email",			price: "0.01" },
	{ item_id: "mailto:?subject=KPIs (Key Performance Indicators) Information",
																product: "Lean Manufacturing email",category: "Email",			price: "0.01" },
	{ item_id: "mailto:?subject=OEE (Overall Equipment Effectiveness) Information",
																product: "OEE email",				category: "Email",			price: "0.01" },
	{ item_id: "mailto:?subject=SMED (Single Minute Exchange of Die)/Quick Changeover Information",
																product: "SMED email",				category: "Email",			price: "0.01" },
	{ item_id: "mailto:?subject=Takt Time Information",
																product: "Takt Time email",			category: "Email",			price: "0.01" },
	{ item_id: "mailto:?subject=TPM (Total Productive Maintenance) Information",
																product: "TPM email",				category: "Email",			price: "0.01" },
	{ item_id: "mailto:?subject=TPS (Toyota Production System) Information",
																product: "TPS email",				category: "Email",			price: "0.01" },
	{ item_id: "mailto:?subject=Visual Factory Information",
																product: "Visual Factory email",	category: "Email",			price: "0.01" }
];


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;
};