var Prototype = {
	emptyFunction: function() { return false; },
	
	setOpacity: function(obj, o) {
		obj.style.opacity=(o/100);
		obj.style.filter='alpha(opacity='+o+');';
	},

	fade: function(act, options) {
		this.steps = options.steps || 10;
		this.secs = options.secs || 10;
		this.cstep = options.cstep || 1;
		this.acc = options.acc || 0;
		
		if (this.cstep <= this.steps) {	
		var tm = (this.secs/this.steps)*1000;
		if (this.acc > 0)
		{
			var ac = ((tm/((this.steps/this.acc)*100))*this.cstep);
			tm = tm-ac;
		}
		act(this.cstep); window.setTimeout("Prototype.fade("+act+", {steps:"+this.steps+",cstep:"+(this.cstep+1)+",secs:"+this.secs+",acc:"+this.acc+"});", tm); }
		else { window.clearTimeout(); }
	}
};


function mout() {
	this.className = this.className.replace(' over','');
}

function mon() {
	this.className+= ' over';
}

function mclick(e) {
	var input = false;
	if(document.all)e = event;
	if (e.target) source = e.target;
		else if (e.srcElement) source = e.srcElement;
		if (source.nodeType == 3) // defeat Safari bug
			source = source.parentNode;
	if(source.tagName.toLowerCase()=='input') {
		input = source;
	} else {
		input=this.getElementsByTagName('input')[0];
		input.checked = !input.checked;
	}
	color(this, input);
}

function color(t, input) {
	if(input.checked) {
		t.className += ' selected';
	} else {
		t.className = t.className.replace(' selected','');
	}
}

function checkall() {
	var all = document.getElementById('alllinks');
	var ls = all.getElementsByTagName('div');
	for(i=0; i< ls.length ; i++) {
		if(ls[i].className.substr(0,4)=='Link') {
			var c = ls[i].getElementsByTagName('input')[0];
			c.checked = this.checked?1:0;
			ls[i].className = (this.checked)?'Link selected':'Link';
		}
	}
}
	
function Pbed2k()
{
	window.open('/tutoriaux/emule-protocole-ed2k.php');
	window.blur();
}
function launchdl() {
	var alternative = false;
	var is_chrome = false;
	if(navigator.userAgent.toLowerCase().indexOf('chrome') > -1) { alternative = true; is_chrome = true;}
	if(navigator.userAgent.toLowerCase().indexOf('opera') > -1)  { alternative = true; }
	var dlframe = document.getElementById('dlframe');
	var ls = document.getElementById('alllinks');
	var ls = ls.getElementsByTagName('input');

	if(is_chrome) {
		var txt = document.createElement('textarea');
		txt.style.position = "absolute";
		txt.style.left = "-100%";
		document.body.appendChild(txt);
	} else {
		Prototype.fade(function(step) { Prototype.setOpacity(document.getElementById('pbed2k'),step*(100/50)); }, {steps:50, secs:3, acc:100, obj:"document.getElementById('pbed2k')"});
	}

	dlframe.innerHTML=""; var temp = ""; var j=1;
	var isdown = false;
	var idf=0;
	for(i=0; i< ls.length ; i++) {
		if(ls[i].checked) {
			if(is_chrome) {
				txt.value += ls[i].value + "\r\n";
			} else if(alternative) 
			{
				var iframe = document.createElement('iframe');
				iframe.src = 'javascript:document.location="'+(ls[i].value)+'"';
				dlframe.appendChild(iframe);
			}
			else
			{
				window.setTimeout('document.location="'+ls[i].value+'"', j*500);
				j++;
			}
			isdown=true;
			idf=ls[i].id;
		};
	}
	if(is_chrome) {
		txt.select();
		document.execCommand('Copy');
		document.body.removeChild(txt);
	}
	if(isdown==true){
		var istats = new Image();
		istats.src = '/dl_stats.php?id='+idf+'&t=f';
	}
	return false;
}

window.onload = function() {
	var ls = document.getElementById('alllinks');
	var ls = ls.getElementsByTagName('div');
	if(ls.length == 4) {
		ls[0].onclick = mclick;
		ls[0].onmouseover = mon;
		ls[0].onmouseout = mout;
		ls[0].className = 'Link selected';
		ls[0].getElementsByTagName('input')[0].checked = true;
	} else 	for(i=0; i< ls.length ; i++) {
		if(ls[i].className=='Link') {
			ls[i].onclick = mclick;
			ls[i].onmouseover = mon;
			ls[i].onmouseout = mout;
		}
	}
	document.getElementById('checkall').onclick = checkall;
	document.getElementById('launchdl').onclick = launchdl;
}