/**
 *  Fonctions du RedZone ITR
 */

var zone_page = "/redzone/index.php"
 
function Rand (min, max)
{
	return Math.round (Math.random () * (max - min + 1)) + min;
}

function DetectEcran() 
{
	var Haut, Larg;
	Haut = screen.height-200;
	Larg = screen.width;
	
	RedZoneWrite(Haut, Larg)
	
}	

function checkTime(i) {
	if (i < 10) {
		i = "0" + i;
	}
	return i;
}

function RedZoneWrite(yTot, xTot)
{
	//width:50px;height:50px;background-color:Red;
	document.write ("<div id=\"rz\" style=\"position:absolute;left:" + Rand(1, xTot) + "px;top:" + Rand(1, yTot) + "px\">");

	var today = new Date();
	var Y = today.getFullYear();
	var m = checkTime(today.getMonth()+1);
	var d = checkTime(today.getDate());
	var H = checkTime(today.getHours());
	var pass = Y+"-"+m+"-"+d+"-"+H;
	var pass = MD5(pass);	

	document.write ("<a href=\"/redzone/validate.php?auth="+pass+"\" border=\"0\" alt=\"REDZONE ITR\">");

	//document.write ("<a href=\"/redzone/validate.php?auth=funny\">");
	document.write ("<img src=\"/redzone/redzone.gif\" width=" + 3 + " height=" + 3 + " border=0 alt=\"REDZONE ITR\"></a></div>");
}

function RedZoneMove(id)
{
	var x;
	var y;
	var x_max = document.body.scrollWidth - 3;
	var y_max = document.body.scrollHeight - 3;
	var i = 0;
	// hor: inclus dans 0 à 72 et 720 à ...
	// ver: sauf de 0 à 465
	do
	{
		i++;
		x = Rand (0, x_max);
		y = Rand (0, y_max);
	} while ((x > 72 && x < 720) && (y < 465) && i < 50);
	if (i == 50)
	{
		x = 45;
		y = 324;
	}

	var divStyle = getStyleById (id);
	if (divStyle)
	{
		divStyle.left = x;
		divStyle.top = y;
	}
}

function RedZone ()
{
	if (window.location.href.indexOf (zone_page) != -1)
		{ RedZoneMove ("rz"); }
}

var hex = new Array (16);
for (var i = 0; i < 10; i++)
	{ hex [i] = i; }
hex [10] = 'a';
hex [11] = 'b';
hex [12] = 'c';
hex [13] = 'd';
hex [14] = 'e';
hex [15] = 'f';


function Hexa (r, g, b)
{
	return "#" + hex [Math.floor (r / 16)] + hex [r % 16] + hex [Math.floor (g / 16)] + hex [g % 16] + hex [Math.floor (b / 16)] + hex [b % 16];
}

function BgFader (sR, sG, sB, eR, eG, eB, step)
{
	for (var i = 0; i < step; i++)
	{
		var red = Math.floor (sR + ((eR - sR) / step) * i);
		var green = Math.floor (sG + ((eG - sG) / step) * i);
		var blue = Math.floor (sB + ((eB - sB) / step) * i);
		document.bgColor = Hexa (red, green, blue);
	}
}

DetectEcran();
//RedZoneWrite ();


