StatsADV = function()
{
	this.staging = false;
	this.siteCode="";
	this.keysource="";
	this.key="";
	this.source="";
	this.codiceGoal="";
	this.target = "";
	this.clickon = "";
	this.host = "";

	this.referer = document.referrer;
	this.nocache = Math.floor(Math.random()*1000000);

	this._par = new Object();

	this._myUrlEncode = function (string) {if (self.encodeURIComponent) {return encodeURIComponent(string);} else {return escape(string);}}
	this._strrev = function (string) {return string.split("").reverse().join("");}


	this._initProperties = function()
	{
		this._par.codiceGoal = "";
		this._par.siteCode = "";
		this._par.referer = "";
		this._par.keysource = "";
		this._par.source = "";
		this._par.key = "";
		this._par.host = "";
		this._par.clickon = "";
		this._par.target = "";

		if (this.codiceGoal !="")
			this._par.codiceGoal = this._myUrlEncode(this.codiceGoal);
	    if (this.siteCode !="")
	    	this._par.siteCode = this._myUrlEncode(this.siteCode);

	    if (this.referer!= "")
	    {
	    	this._par.referer = this.referer.substr(0,100);
	    	this._par.referer = this._myUrlEncode(this._par.referer);
	    }
	    if (this.keysource != "")
	    {
	    	this._par.keysource = this.keysource.substr(0,100);
	    	this._par.keysource = this._myUrlEncode(this._par.keysource);
	    }
		if (this.source != "")
		{
	    	this._par.source = this.source.substr(0,100);
	    	this._par.source = this._myUrlEncode(this._par.source);
		}
		if (this.key !="")
		{
		    this._par.key = this.key.substr(0,100);
		    this._par.key = this._myUrlEncode(this._par.key);
		}
		if (this.host !="")
		{
			this._par.host = this.host.substr(0,100);
		    this._par.host = this._myUrlEncode(this._par.host);
		} else
		{
			if (document.location.host!="")
				this._par.host = document.location.host;
			else
			{
				if (document.domain!="")
					this._par.host = document.domain;
			}
			this._par.host = this._myUrlEncode(this._par.host);
		}
		if (isNaN(this.clickon))
			this._par.clickon="";
		else
			this._par.clickon=this.clickon;

		if (this.target !="")
			this._par.target = this._myUrlEncode(this.target)
	}

	this._getTrackVisitUrl = function(noreferer)
	{
	    this._initProperties();

	    var tmp = 'mode=visit&code='+this._par.siteCode;
	    if (noreferer != true && this._par.referer!="")
	    	tmp += '&referer='+this._par.referer;

	    if (this._par.keysource!="")
	        tmp += '&keysource='+this._par.keysource;
	    if (this._par.key!="")
	        tmp += '&key='+this._par.key;
	    if (this._par.source!="")
	        tmp += '&source='+this._par.source;
	    if (this._par.host!="")
	    	tmp += '&host='+this._par.host;

	    var str = 'http:/'+'/';
	    if(this.staging)
	        str += 'staging.';
	    str += 'statsadv.dada.net/sadvtrack.php?uu='+this._myUrlEncode(this._strrev(tmp))+'&p='+this.nocache;
	    return str;
	}

	this._getTrackClickUrl = function(noreferer)
	{
		this._initProperties();

	    var tmp = 'mode=click&host='+this._par.host+'&code='+this._par.siteCode;
	    if (noreferer != true && this._par.referer!="")
	    	tmp += '&referer='+this._par.referer;

	    if (this._par.keysource!="")
	        tmp += '&keysource='+this._par.keysource;
	    if (this._par.key!="")
	        tmp += '&key='+this._par.key;
	    if (this._par.source!="")
	        tmp += '&source='+this._par.source;
	    if (this._par.target!="")
	        tmp += '&target='+this._par.target;
		if (this._par.clickon!="")
	        tmp += '&clickon='+this._par.clickon;

	    var str = 'http:/'+'/';
	    if(this.staging)
	        str += 'staging.';
	    str += 'statsadv.dada.net/sadvtrack.php?uu='+this._myUrlEncode(this._strrev(tmp))+'&p='+this.nocache;
	    return str;
	}

	this._getTrackGoalUrl = function()
	{
		this._initProperties();

	    var tmp = 'mode=goal&code='+this._par.siteCode+'&referer='+this._par.referer+'&goalcode='+this._par.codiceGoal;
	    if (this._par.keysource!="")
	        tmp += '&keysource='+this._par.keysource;
	    if (this._par.key!="")
	        tmp += '&key='+this._par.key;
	    if (this._par.source!="")
	        tmp += '&source='+this._par.source;

	    var str = 'http:/'+'/';
	    if(this.staging)
	        str += 'staging.';
	    str += 'statsadv.dada.net/sadvtrack.php?uu='+this._myUrlEncode(this._strrev(tmp))+'&p='+this.nocache;
	    return str;
	}

	this.trackVisitStatsADV = function()
	{
    	if (!this.siteCode || this.siteCode=="")
	    {
	        if (this.staging == true)
	            alert("Missing site code");
	        return false;
	    }
		var tmp = this._getTrackVisitUrl();
    	var str = '<img src="'+tmp+'" height=1 width=1 border=0 style="position:absolute;top:-10000px">';
	    document.write(str);
	    return true;
	}

	this.trackClickStatsADV = function()
	{
    	if (!this.siteCode || this.siteCode=="")
	    {
	        if (this.staging == true)
	            alert("Missing site code");
	        return false;
	    }
		var tmp = this._getTrackClickUrl();
    	var str = '<img src="'+tmp+'" height=1 width=1 border=0 style="position:absolute;top:-10000px">';
	    document.write(str);
	    return true;
	}

	this.trackGoalStatsADV = function()
	{
    	if (!this.siteCode || this.siteCode=="" || this.codiceGoal=="")
	    {
	        if (this.staging == true)
	            alert("Missing site code or goal code");
	        return false;
	    }
		var tmp = this._getTrackGoalUrl();
    	var str = '<img src="'+tmp+'" height=1 width=1 border=0 style="position:absolute;top:-10000px">';
	    document.write(str);
	    return true;
	}
}