/**
 * Event tracking form handler
 *
 * @id              $Id$
 * @author          Daniel Rolls
 * @modifiedby      $LastChangedBy: blundenr $
 * @copyright       Copyright Flight Centre Ltd. All rights reserved.
 * @version         $Revision: 1692 $
 * @lastmodified    $Date: 2011-10-20 15:36:32 +1000 $
 * @requires        FCHK.SETTINGS, FCL.DATETIME, FCL.UTIL, FCL.FORMS, FCL.GIMP
 */

;FCHK.TRACKING =
{
    name: 'FCHK.TRACKING',
    
    
    /**
     * This performs the tracking
     * @return Object
     */
    track: function( trackObj )
    {
        // See if product details are available
        trackObj.product = this.parseProductProperties();
        
        // Perform enquiry tracking for Google Analytics
        if(trackObj.action == 'enquiry' && _gaq)
        {
            document.write("<iframe src='http://uhost.hk/~flightce/marketing/conversion/fchk-conversion.html' height='0' width='0' marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder='0' ></iframe>");
            
            if( typeof trackObj.product.sku == 'undefined' )
            {
                // This is a general enquiry
                _gaq.push(['_trackEvent', 'general', trackObj.action, trackObj.type]);
	    }
            else
            {
                // This is a product enquiry
                _gaq.push(['_setCustomVar', 1, 'category', trackObj.product['category'] ]);
                _gaq.push(['_setCustomVar', 2, 'destination', trackObj.product['destination'] ]);
                _gaq.push(['_setCustomVar', 3, 'sku', trackObj.product['sku'] ]);
                _gaq.push(['_setCustomVar', 4, 'price', trackObj.product['price'].replace(/[$,]/g,'') ]);
                _gaq.push(['_trackEvent', 'product', trackObj.action, trackObj.type]);
                }
        }
        
        
    
    },
    
    /**
     * Gets product data from meta tags if it exists.
     * @return Object
     */
    parseProductProperties: function()
    {
		var _this = this;
		var productProperties = {};
        $('head').find('meta[name^="product."]').each(function()
        {
            var key = $(this).attr('name').match(/\.(.*)$/)[1];
            var value = $(this).attr('content');
            productProperties[key] = value;
        });
		return productProperties;
    }
    
    
    
}
