﻿function ecommerceArgs()
{
	this.transactionId	= null;
	this.total			= 0; // no taxes included
	this.tax			= 0; // taxes
	this.shipping		= 0; // shipping
	this.products		= [];
	this.nameStore      = null; 
}

function ecommerceProduct()
{
	this.code		= null;
	this.name		= null;
	this.category	= null;
	this.price		= 0;
	this.quantity	= 0;
}

function EcommerceTracking(args)
{
	//Init Tracker
	//_gaq.push(['_setLocalRemoteServerMode']);
	_gaq.push(['._initData']);
	
	if(args.transactionId == null)
	{
		// Some simple code to create a fake order ID
		var timeObj      = new Date;
		var unixTimeMs   = timeObj.getTime();
		var unixTime     = parseInt(unixTimeMs / 1000);
		args.transactionId    = pageTracker._visitCode() + '-' + unixTime;
	}
	
	// Pass Data to Tracker
	_gaq.push(
	[
		'_addTrans'
		,args.transactionId	// OrderId *
		,args.nameStore		    // Affiliate or Store Name
		,args.total			// Total *
		,args.tax				// Tax
		,args.shipping		// Shipping
		,'vivatravel.gr'		// City
		,'vivatravel.gr'		// State
		,'vivatravel.gr'		// Country
	]);

	var products = args.products;
	for(var i = 0; i < products.length; i++)
	{
		var product = products[i];
		var productAveragePrice = (product.price / product.quantity);
		_gaq.push(
		[
			'_addItem'
			,args.transactionId	// OrderId *
			,product.id			// StockKeeping Unit aka SKU
			,product.name			// Product Name
			,product.category		// Product Category
			,productAveragePrice		// Unit Price *
			,product.quantity		// Quantity *
		]);
	};

	//* = required
	_gaq.push(['_trackTrans']);
}
