/***********************************************************************
	Une création Loïc Doumerc
	Version du 11 février 2009 à 10h12
	
	Attribus possible sur les balise <TR> :
		- open : ouvre un lien
		- link : envoie sur une page
		- nocount : la ligne ne subit pas de traitement sur la couleur
	
***********************************************************************/

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();
		});

}

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



RoLib.prototype.colorById = function( 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);
}

RoLib.prototype.init_table = function()
{

	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 pointeurTR = objectsTR[i];
				//On ajoute la methode d'ouverture si c'est TD n'ont pas de input
				
				var pointeurTR_TD = pointeurTR.getElementsByTagName("td");
				for( var td = 0 ; td < pointeurTR_TD.length ; td++)
				{
					var pointeur_TD = pointeurTR_TD[td];
					var NombreInput = pointeur_TD.getElementsByTagName("input").length;
					
					if( NombreInput == 0 )
					{
						var link1 = link;
						pointeur_TD.style.cursor = 'pointer';
						//pointeur_TD.setAttribute("style","cursor:pointer;");
						pointeur_TD.setAttribute("link",link);
						pointeur_TD.onclick = 
						function()
						{
							wLink(this.getAttribute('link'));
						};					
					}
				}
			}	
			
			
			var open = objectsTR[i].getAttribute('open');
			if( open != "undefined" && open != null  )
			{
				var pointeurTR = objectsTR[i];
				//On ajoute la methode d'ouverture si c'est TD n'ont pas de input
				
				var pointeurTR_TD = pointeurTR.getElementsByTagName("td");
				for( var td = 0 ; td < pointeurTR_TD.length ; td++)
				{
					var pointeur_TD = pointeurTR_TD[td];
					var NombreInput = pointeur_TD.getElementsByTagName("input").length;
					
					if( NombreInput == 0 )
					{
						var open1 = open;
						pointeur_TD.setAttribute("open",open);
						pointeur_TD.style.cursor = 'pointer';
						//pointeur_TD.setAttribute("style","cursor:pointer;");
						pointeur_TD.onclick = 
						function()
						{
							wOpen(this.getAttribute('open'));
						};					
					}
				}
			}			
			
			var nocount = objectsTR[i].getAttribute('nocount');
			if( nocount == "undefined" || nocount == null  )
			{			
				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;
			}
		}
		
	}
}
