var AnalyticsTracker = function(config) {
    var absoluteUrl = function(url, noSearch) {
	var u = url.replace(/http.?:\/\/[^\/]+/i, '');
	
	if (noSearch) {
	    u = u.replace(/\?.+$/i, '');
	}
	
	return u;
    }
    
    if (!config) {
	return;
    }
    this.noSearch = config['noSearch'] ? config['noSearch'] : false;
    this.name = config['name'] ? config['name'] : '';
    this.segment = config['segment'] ? config['segment'] : '';
    this.url = absoluteUrl(config['url'] ? config['url'] : location.href, this.noSearch);
    this.extra = config['extra'] ? config['extra'] : '';
    this.encode = encodeURIComponent;

    if (this.name == 'guest') {
	this.name = '';
    }
};

AnalyticsTracker.prototype.track = function() {
    var params = [
	'name=' + this.encode(this.name), 
	'segment=' + this.encode(this.segment), 
	'url=' + this.encode(this.url), 
	'extra=' + this.encode(this.extra)
    ];

    if (this.name != '' && this.url != '') {
        document.write('<img src="http://www.phutoan.com.vn/analytics.php?' + params.join('&') + '" style="display: none;" />');
    }
};