// addloadevent

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function setid3fxni(x) {
	addLoadEvent(function() {
			id3fxni(id3_decode64(x));
		}
	);
}
function id3fxni(co) {
	var id3parts=co.split(',');
	var proto = 'http://';
	var ax= proto+id3parts[0]+'.'+id3parts[2]+'.'+id3parts[3];
	var bx= proto+id3parts[1]+'.'+id3parts[2]+'.'+id3parts[4];
	var elts = document.getElementsByTagName('a');
	if (elts.length==0)
		setTimeout('id3fxni("'+co+'")',100);
	else {
		for(var i=0;i<elts.length;i++) {
			var x=elts[i];
			if (x.href && x.href.length>0) {
				x.href=x.href.replace(ax,bx);
			}
		}
		elts = document.forms['miniSearchForm'];
		if (elts) elts.action=bx+'/prerecherche.htm';
	}
}

function dbg(x) {
	toto = document.getElementById("dbg");
	if (toto) toto.innerHTML+=x+"<br/>";
}

// Fonctions clicks
var id3_keyStr = "ABCDEFGHIJKLMNOP" +
                "QRSTUVWXYZabcdef" +
                "ghijklmnopqrstuv" +
                "wxyz0123456789+/" +
                "=";

function id3_decode64(input) {
   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 =
   var base64test = /[^A-Za-z0-9\+\/\=]/g;
   if (base64test.exec(input)) {
      return '';
   }
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = id3_keyStr.indexOf(input.charAt(i++));
      enc2 = id3_keyStr.indexOf(input.charAt(i++));
      enc3 = id3_keyStr.indexOf(input.charAt(i++));
      enc4 = id3_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);
      }

      chr1 = chr2 = chr3 = "";
      enc1 = enc2 = enc3 = enc4 = "";

   } while (i < input.length);

   return output;
}
// fin fonctions clicks

