// $Id: AjaxCurl.js,v 1.4 2008/04/08 14:40:28 dlask Exp $
// Janmedia Interactive

importScript("/js/Cookies.js");

var Affiliate = {
	MAIN_SERVER_NAME: "net.fwo",
	MAIN_SERVER_PORT: 8080,
	update: function()
	{
		var ref = document.referrer;
		if (!ref) return;

		var loc= document.location.href;
		if (!loc) return;

		var i = ref.indexOf('/',8);
		if (i<0) i = ref.length();

		ref = ref.substr(0,i);
		if (loc.indexOf(ref)==0) return;

		var days = 90;
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var code = 'jm='+ref;
		Cookies.setCookie('affiliate',code,'/',date.toGMTString());


		// oznacz affiliate na gównym serwisie
		if (document.location.hostname!=Affiliate.MAIN_SERVER_NAME)
		{
			var img = new Image();
			img.src="http://"+Affiliate.MAIN_SERVER_NAME+":"+Affiliate.MAIN_SERVER_PORT+"/rf/affiliate?id="+escape(code+","+document.location.hostname)+"&"+Math.random();
		}
	}
}

Affiliate.update();
