function JscriptRequest() {
    this.headLoc = document.getElementsByTagName("head").item(0);
    this.scriptId = 'YJscriptId' + JscriptRequest.scriptCounter++;
}

JscriptRequest.scriptCounter = 1;

JscriptRequest.prototype.buildScriptTag = function () {

    this.scriptObj = document.createElement("script");
    
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("src", this.fullUrl);
    this.scriptObj.setAttribute("id", this.scriptId);
    //this.scriptObj.onload = function() {alert('a');};

    //this.scriptObj.setAttribute("defer", true);
}
 
JscriptRequest.prototype.removeScriptTag = function () {
    this.headLoc.removeChild(this.scriptObj);  
}

JscriptRequest.prototype.addScriptTag = function () {
    // Create the script tag
    this.headLoc.appendChild(this.scriptObj);
}


/*
top.document.title = document.title;
var str = location.search;
var writeFrames = (str.indexOf("nowritefs")) 
     && (top.window.length == 0);
if (writeFrames)
{
  if (str == "")
  {
    var bodyFrame = window.location + "?nowritefs";
  }
  else
  {
    var bodyFrame = window.location + "&nowritefs";
  }
  document.write(
  '<FRAMESET FRAMEBORDER="0" ROWS="*,0">',
      '<FRAME SRC="', bodyFrame, '" NAME="bodyframe" noresize>',
      '<FRAME SRC="about:blank" NAME="trackerFrame" scrolling="no" noresize marginwidth="0" marginheight="0">',
  '</FRAMESET>'
  );
}
*/
var obj;

function addScript(fullUrl)
{
	obj=new JscriptRequest();
  obj.fullUrl = fullUrl;      
  obj.buildScriptTag(); // Build the script tag      
  obj.addScriptTag(); // Execute (add) the script tag
  
}//end addScript
 

function deleteObj()
{
  obj.removeScriptTag();
}
function readall_ita()
{
	var a_tags = new Array('A','AREA');
	var s,pos1,pos2;
	var el,tt, count, dt;
	
	tt = 60;
	
	
	for (var cc=0; cc<2; cc++)
	{
		el = document.getElementsByTagName(a_tags[cc]);
		for (var i=0; i<el.length; i++)
		{
			
			if ( ( String(el[i].href).charAt(String(el[i].href).length-1) == '#' || String(el[i].href).indexOf('#') < 0 ) && el[i].getAttribute("notrack") != '' )
				if ( el[i].onclick != null )
				{
					s = String(el[i].onclick);
					pos1 = s.indexOf('{')+1;
					s = s.substring(pos1, s.length);
					pos2 = s.indexOf('}')-1;
					s = s.substring(0,pos2);
					el[i].onclick=new Function('track(this.href,1);'+s+';if(String(this.href).indexOf("#")>0) return false;');
				}
				else
					el[i].onclick=new Function('return track(this.href,1);');
						
				/*
				var prova = document.createElement('div');
				prova.style.background = '#ddff11';
				prova.style.width = '30px';
				prova.style.height = '2px';
				prova.style.position = 'absolute';
				
				if (el[i].id == '')
					el[i].insertAdjacentElement('afterEnd',prova);
					*/
		}
	}
	/*
	var pr;
	for(count=0;count<_m.length;count++)
	{
		if (count == 1) continue;
		dt = String(_m[count][0]).split(",");
		pr = document.createElement('div');
		pr.style.left = '790px';
		pr.style.top = tt+'px';
		pr.style.position = 'absolute';
		pr.appendChild(document.createTextNode(_m[count][1]));
		document.getElementsByTagName('body')[0].insertAdjacentElement('afterBegin',pr);
		tt = tt+15;
		for(var ct = 0; ct<dt.length; ct++)
		{
			pr = document.createElement('div');
			pr.style.left = '795px';
			pr.style.top = tt+'px';
			pr.style.position = 'absolute';
			pr.appendChild(document.createTextNode(_mi[dt[ct]][1]));
			document.getElementsByTagName('body')[0].insertAdjacentElement('afterBegin',pr);
			tt = tt+15;
		}
		tt = tt+15;
	}
	*/
}
function track(b,c)
{
	var s = String(unescape(document.location));
	var url_filtered = b.substring(b.lastIndexOf('/')+1);
	var self_urlfiltered = s.substring(s.lastIndexOf('/')+1);
	var sfr = '687474703A2F2F636C69656E74692E7264692E69742F426C6D67726F7570';
	//var sfr = '687474703A2F2F6C6F63616C686F73742F74657374';
	
	if ( b.indexOf('#') < 0 )
		document.location = b;

	addScript(decd(sfr)+'/tracker.asp?m='+encode64(unescape(self_urlfiltered))+'&d='+encode64(unescape(url_filtered))+'&s='+c);

	deleteObj();
	
	return false;
}
function decd(s)
{
	var x,q,a;
	x=s.split("");
	q="";
	for(a=0;a<s.length;a++)
	{
		q+="%"+x[a]+x[a+1];
		a++
	}
	return unescape(q)
}
function encode64(input) {
	 var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/$";
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}

function decode64(input) {
	 var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}
