/************************************************************************************************
*	Programmeur :		Daniel Rioux											*
*																		*
*	Date de céation :		14 Décembre 2008										*
*																		*
*	Description :		Classe de construction de tables (tableaux).							*
************************************************************************************************/
function clsTable()
{
	//---------------------Les variables internes-----------------------
	var Rows;
	var Cols;
	var ColContent;
	var Table = null;
	var Caption;
	var CaptionText;
	var Thead;
	var Tbody;
	var TFoot;
	var Container;
	
	if (arguments.length)
	{
		Table = arguments[0];
	}
	
	//------------------------Les propriétés---------------------------
	
	//Les entêtes de tableau
	this.headAlign = headAlign;
	var HeadAlign;
	
	this.headValign = headValign;
	var HeadValign;
	
	//Les corps de tableau
	this.bodyAlign = bodyAlign;
	var BodyAlign;
	
	this.bodyValign = bodyValign;
	var BodyValign;
	
	//Les pieds de tableau
	this.footAlign = footAlign;
	var FootAlign;
	
	this.footValign = footValign;
	var FootValign;
	
	//Les cellules
	this.setColHeight = colHeight;
	var ColHeight;
	
	this.setColWidth = colWidth;
	var ColWidth;
	
	this.setColAlign = colAlign;
	var ColAlign;
	
	this.setColClass = colClass;
	var ColClass;
	
	this.setColId = colId;
	var ColId;
	
	this.setColValign = colValign;
	var ColValign;
	
	this.setColText = colText;
	var ColText;
	
	this.setColSpan = colSpan;
	var ColSpan;
	
	this.setRowSpan = rowSpan;
	var RowSpan;
	
	this.setColChild = colChild;
	var ColChild;
	
	//Les lignes
	this.setRowHeight = rowHeight;
	var RowHeight;
	
	this.setRowWidth = rowWidth;
	var RowWidth;
	
	this.setRowAlign = rowAlign;
	var RowAlign;
	
	this.setRowClass = rowClass;
	var RowClass;
	
	this.setRowId = rowId;
	var RowId;
	
	this.setRowValign = rowValign;
	var RowValign;
	
	//Le tableau
	this.caption;
	this.tableClass;
	this.tableId;
	this.name;
	this.border;
	
	//-------------------------Méthodes-------------------------
	
	//Construction du tableau dans le document
	this.append = table;
	this.newRow = row;
	this.newCol = columns;
	this.head = thead;
	this.body = tbody;
	this.foot = tfoot;
	
	function thead()
	{
		Thead = document.createElement("THEAD");
		
		if (HeadAlign != null)
		{
			setAttribute(Thead,"align",HeadAlign)
		}
		
		if (HeadValign != null)
		{
			setAttribute(Thead,"valign",HeadValign)
		}
		
		Thead.appendChild(Rows);
	}
	
	function headAlign(Align)
	{
		HeadAlign = Align;
	}
	
	function headValign(Valign)
	{
		HeadValign = Valign;
	}
	
	function tbody()
	{
		Tbody = document.createElement("TBODY");
		
		if (BodyAlign != null)
		{
			setAttribute(Tbody,"align",BodyAlign)
		}
		
		if (BodyValign != null)
		{
			setAttribute(Tbody,"valign",BodyValign)
		}
		
		Tbody.appendChild(Rows);
	}
	
	function bodyAlign(Align)
	{
		BodyAlign = Align;
	}
	
	function bodyValign(VAlign)
	{
		BodyValign = Valign;
	}
	
	function tfoot()
	{
		TFoot = document.createElement("TFOOT");
		
		if (FootAlign != null)
		{
			setAttribute(TFoot,"align",FootAlign)
		}
		
		if (FootValign != null)
		{
			setAttribute(TFoot,"valign",FootValign)
		}
		
		TFoot.appendChild(Rows);
	}
	
	function footAlign(Align)
	{
		FootAlign = Align;
	}
	
	function footValign(Valign)
	{
		FootValign = Valign;
	}
	
	function row()
	{
		
		if (arguments.length)
		{
			if ((arguments[0] != "head") && (arguments[0] != "body") && (arguments[0] != "foot"))
			{
				return false;
			}
			else
			{
				Container = arguments[0];
			}
		}
	
		Rows = document.createElement("TR");
		
		if (RowHeight != null)
		{
			setAttribute(Rows,"height",RowHeight);
		}
		
		if (RowWidth != null)
		{
			setAttribute(Rows,"width",RowWidth);
		}
		
		if (RowAlign != null)
		{
			setAttribute(Rows,"align",RowAlign);
		}
		
		if (RowClass != null)
		{
			
			setAttribute(Rows,"class",RowClass);
		}
		
		if (RowId != null)
		{
			setAttribute(Rows,"id",RowId);
		}
		
		if (RowValign != null)
		{
			setAttribute(Rows,"valign",RowValign);
		}
	}
	
	function rowHeight(Height)
	{
		RowHeight = Height;
	}
	
	function rowWidth(Width)
	{
		RowWidth = Width;
	}
	
	function rowAlign(Align)
	{
		RowAlign = Align;
	}
	
	function rowClass(ClassName)
	{
		RowClass = ClassName;
	}
	
	function rowId(Id)
	{
		RowId = Id;
	}
	
	function rowValign(Valign)
	{
		RowValign = Valign;
	}
	
	function rowSpan(RowsNum)
	{
		RowSpan = RowsNum;
	}
	
	function columns()
	{
		if (arguments[0] == "td")
		{
			Cols = document.createElement("TD");
		}
		else if (arguments[0] == "th")
		{
			Cols = document.createElement("TH");
		}
		else
		{
			Cols = document.createElement("TD");
		}
		
		if (ColHeight != null)
		{
			setAttribute(Cols,"height",ColHeight);
		}
		
		if (ColWidth != null)
		{
			setAttribute(Cols,"width",ColWidth);
		}
		
		if (ColAlign != null)
		{
			setAttribute(Cols,"align",ColAlign);
		}
		
		if (ColClass != null)
		{
			setAttribute(Cols,"class",ColClass);
		}
		
		if (ColId != null)
		{
			setAttribute(Cols,"id",ColId);
		}
		
		if (ColValign != null)
		{
			setAttribute(Cols,"valign",ColValign);
		}
		
		if (ColSpan != null)
		{
			setAttribute(Cols,"colspan",ColSpan);
		}
		
		if (RowSpan != null)
		{
			setAttribute(Cols,"rowspan",RowSpan);
		}
		
		if (ColText != null)
		{			
			ColContent = document.createTextNode(ColText);
			Cols.appendChild(ColContent);
			ColText = null;
		}
		
		if (ColChild != null)
		{
			Cols.appendChild(ColChild);
			ColChild = null;
		}
		
		Rows.appendChild(Cols);
	}
	
	function colHeight(Height)
	{
		ColHeight = Height;
	}
	
	function colWidth(Width)
	{
		ColWidth = Width;
	}
	
	function colAlign (Align)
	{
		ColAlign = Align;
	}
	
	function colClass(ClassName)
	{
		ColClass = ClassName;
	}
	
	function colId (Id)
	{
		ColId = Id;
	}
	
	function colValign(Valign)
	{
		ColValign = Valign;
	}
	
	function colText(Text)
	{
		ColText = Text;
	}
	
	function colSpan(ColsNum)
	{
		ColSpan = ColsNum;
	}
	
	function colChild (ObjElement)
	{
		ColChild = ObjElement;
	}
	
	function table()
	{
		if (Table != null)
		{
			if (this.caption != null)
			{
				setCaption();
			}
			
			if (Thead != null)
			{
				Table.appendChild(Thead);
			}
			else if (Tbody != null)
			{
				Table.appendChild(Tbody);
			}
			else if (TFoot != null)
			{
				Table.appendChild(TFoot);
			}
			else
			{
				if (NavigatorType == "Mozilla")
				{
					Table.appendChild(Rows);
				}
				else
				{
					Table.firstChild.nextSibling.appendChild(Rows);
				}
			}
		}
		else
		{
			alert("Vide");
		}
	}
	
	function setAttribute(Element,AttributeName,AttributeValue)
	{
		var Attr;
		
		Attr = document.createAttribute(AttributeName);
		Attr.nodeValue = AttributeValue;
		Element.setAttributeNode(Attr);
		
	}
	
	function setCaption()
	{
		Caption = document.createElement("CAPTION");
		CaptionText = document.createTextNode(this.caption);
		
		Caption.appendChild(CaptionText);	
	}
}




