var vorne_commerce_data = [
    { item_id: "xl-trial-request",				product: "Form: XL Trial",				category: "Form",		price: "2000",	submitted: false },
    { item_id: "xl-trial-request-xl-page",		product: "Form: XL Trial (XL Page)",	category: "Form",		price: "2000",	submitted: false },
    { item_id: "xl-trial-request-movie",		product: "Form: XL Trial (Movie)",		category: "Form",		price: "2000",	submitted: false },
    { item_id: "xl-webinar-signup",				product: "Form: XL Webinar",			category: "Form",		price: "1000",	submitted: false },
    { item_id: "general-trial",					product: "Form: General Trial",			category: "Form",		price: "100",	submitted: false },
    { item_id: "mailing-list-signup",			product: "Form: Mailing List",			category: "Form",		price: "50",	submitted: false },
    { item_id: "mailing-list-signup-lean-intro",product: "Form: Lean Intro Email List",	category: "Form",		price: "50",	submitted: false },
    { item_id: "general-info",					product: "Form: General Info",			category: "Form",		price: "50",	submitted: false },
    { item_id: "xl-flash-movie",				product: "XL Movie",					category: "Video",		price: "10",	submitted: false },
    { item_id: "xl-powerpoint-presentation",	product: "XL Powerpoint",				category: "PowerPoint",	price: "10",	submitted: false },
    { item_id: "xl-pdf-data-sheet-xl800",		product: "Data Sheet: XL800",			category: "Flyer",		price: "10",	submitted: false },
    { item_id: "xl-pdf-data-sheet-xl600",		product: "Data Sheet: XL600",			category: "Flyer",		price: "10",	submitted: false },
    { item_id: "xl-pdf-data-sheet-xl400",		product: "Data Sheet: XL400",			category: "Flyer",		price: "10",	submitted: false },
    { item_id: "partner-oee-mexico",			product: "Partner: OEE Mexico",			category: "Website",	price: "1",		submitted: false },
    { item_id: "partner-optimumfx",				product: "Partner: OptimumFX",			category: "Website",	price: "1",		submitted: false },
    { item_id: "partner-tqmsoft",				product: "Partner: TQMsoft",			category: "Website",	price: "1",		submitted: false },
    { item_id: "partner-workflow",				product: "Partner: Workflow",			category: "Website",	price: "1",		submitted: false },
    { item_id: "partner-tac-group",				product: "Partner: TAC Group",			category: "Website",	price: "1",		submitted: false },
    { item_id: "partner-sscx",					product: "Partner: SSCX",				category: "Website",	price: "1",		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;
};
