function Harvester(doc) {
	var loc=document.location.host.indexOf("www.")!=-1?document.location.host.substr(4):document.location.host;
	var ref=parseUri(document.referrer).host.indexOf("www.")!=-1?parseUri(document.referrer).host.substr(4):parseUri(document.referrer).host;
	
	
	this.ref=(loc!=ref)?ref:"SELF";
	this.page=loc;
	this.doc=doc;
	this.prot=document.location.protocol;
	if (this.prot=="file:") this.prot="http:";
}

Harvester.prototype.stop=function() {
	document.getElementById("harvester").src=("http://harvester.ext.square-enix-europe.com/handler_pro.php?exit");
}

Harvester.prototype.start=function() {
	var im=document.createElement("img");
	im.id="harvester";
	im.style.display="none";
	im.src=this.prot+"//harvester.ext.square-enix-europe.com/handler_pro.php?r="+this.ref+"&d="+this.doc+"&e="+screen.width+"x"+screen.height+"&p="+this.page;
	document.body.appendChild(im);
	
	window.onunload=this.stop;
}

Harvester.prototype.track=function(cat,tag,label) {
	document.getElementById("harvester").src=this.prot+"//harvester.ext.square-enix-europe.com/handler_pro.php?track&d="+this.doc+"&c="+cat+"&t="+tag+"&l="+label+"&p="+this.page;
}

function parseUri (str) {
	var	o   = parseUri.options,
		m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
		uri = {},
		i   = 14;

	while (i--) uri[o.key[i]] = m[i] || "";

	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
		if ($1) uri[o.q.name][$1] = $2;
	});

	return uri;
};

parseUri.options = {
	strictMode: false,
	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	q:   {
		name:   "queryKey",
		parser: /(?:^|&)([^&=]*)=?([^&]*)/g
	},
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};

function flash_track(cat,tag,label) {
	H.track(cat,tag,label);
}

