/***********************************************************************
	Une création Loïc Doumerc
	Version du 12 décembre 2008 à 13h42
***********************************************************************/

function RoLib( id , bgcolor1 , bgcolor2 , bgrollover )
{
	this.id = id;
	this.bgcolor1 = bgcolor1;
	this.bgcolor2 = bgcolor2;
	this.bgrollover = bgrollover;
	
	if( RoLib.arguments[4] != null )
	{
		this.startTR = RoLib.arguments[4];
	}
	else
	{
		this.startTR = 0;
	}

	this.object = null;

	//Lancement du loadeur dans window.load
	var me = this;
	this.addLoadEvent(
		function()
		{
			me.init_table();
		});

}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') 
	{
		window.onload = func;
	}
	else
	{
		window.onload = function() 
		{
			if (oldonload) 
			{
				oldonload();
			}
			
			func();
		};
	}
}



function colorById( id_color )
{
	if( id_color == 0 )
	{
		return this.bgcolor1;
	}
	else
	{
		return this.bgcolor2;
	}
} 

function wLink( page )
{
	window.location.href = page;
}

function wOpen( page )
{
	window.open(page);
}

function init_table()
{

	this.object = document.getElementById(this.id);
	
	if( this.object )
	{
		objectsTR = this.object.getElementsByTagName("tr");
				
		var c_ligne = 0;
		for( var i = this.startTR ; i < objectsTR.length; i++) 
		{ 
			
			var link = objectsTR[i].getAttribute('link');
			if( link != "undefined" && link != null  )
			{
				var link1 = link;
				objectsTR[i].onclick = 
				function()
				{
					wLink(this.getAttribute('link'));
				};
			}
			
			
			var open = objectsTR[i].getAttribute('open');
			if( open != "undefined" && open != null  )
			{
				var open1 = open;
				objectsTR[i].onclick = 
				function()
				{
					wOpen(this.getAttribute('open'));
				};
			}			
			
			
			var bgcolor = this.colorById( c_ligne );
			if( objectsTR[i].style.background == "" )
			{
				objectsTR[i].style.background = bgcolor;
			}
			
			var temp = this.bgrollover;
			objectsTR[i].onmouseover = 
			function()
			{
				t_color = this.style.background;
				this.style.background = temp;
			};
			
			objectsTR[i].onmouseout = 
			function()
			{
				if( typeof t_color != "undefined" )
				{
					this.style.background = t_color;
				}
			};			
			
			
			c_ligne = (c_ligne + 1) % 2;
		}
		
	}
}

RoLib.prototype.init_table = init_table;
RoLib.prototype.colorById = colorById;
RoLib.prototype.addLoadEvent = addLoadEvent;
