/*
 * Framework Javascript (ToutoulJs)
 *	Fichier : database.js
 *  Auteur : Le TOULLEC Martial
 * 	Url : http://www.hackariens.fr
 *  Date création : 10 Juin 2010
 *  Date modification : 22  Décembre 2010
 *  version : 2.1
*/
function DataTable(){
	var height = 0;
	var head = [];
	var foot = [];
	var ligne = [];
	var action = [];
	var tr = [];
	var td = [];
	var div = "";
	var options = {
		actions: 0
	};
	this.SetInit = function(){
		height = 0;
		head = [];
		foot = [];
		ligne = [];
		actions = [];
		td = [];
		div = "";
		options.actions = 0;
	};
	this.SetDiv = function(espace){
		this.SetInit();
		div = espace;
	};
	this.SetAlignement = function(op1,op2){
		tr = op1;
		td = op2;
	};
	this.SetHeight = function(hauteur){
		height = hauteur;
	};
	this.SetHead = function(tableau){
		head = tableau;
	};
	this.SetFoot = function(tableau){
		foot = tableau;
	};
	this.AjouterLigne = function(tableau,actions,tr,td){
		ligne[ligne.length] = {
			'tr' : tr,
			'td' : td,
			'ligne' :	tableau,
			'actions' : actions
		};
		for(i in actions){
			options.actions = 1;
			break;
		}
	};
	this.CreerImage = function(variable){
		html = "<img";
		if(variable['style']==undefined){
			variable['style'] = 'cursor:pointer';
		}
		for(key in variable){
			html += " "+key+"='"+variable[key]+"'";
		}
		html +=" />";
		return html;
	}
	this.Afficher = function(){
		style = "one";
		var html = "<table>";
		if(head.lengh!=0){
			html += "<thead><tr>";
			for(i=0;i<head.length;i++){
				html += "<th>"+head[i]+"</th>";
			}
			if(options.actions==1){
				html += "<th>Actions</th>";
			}
			html += "</tr></thead>";
		}
		html += "<tbody>";
		for(i=0;i<ligne.length;i++){
			if(ligne[i]['tr']['class']==undefined){
				ligne[i]['tr']['class'] = style;
			}
			if(ligne[i]['tr']['valign']==undefined){
				ligne[i]['tr']['valign'] = "top";
			}
			html += "<tr";
			for(key in ligne[i]['tr']){
				html += " "+key+"=\""+ligne[i]['tr'][key]+"\"";
			}
			html += ">";
			for(j=0;j<ligne[i]['ligne'].length;j++){
				html += "<td";
				var td = ligne[i].td;
				if(td[j]!=undefined){
					for(key in td[j]){
						html += " "+key+"=\""+td[j][key]+"\"";
					}
				}
				html += ">"+ligne[i]['ligne'][j]+"</td>";
			}
			if(options.actions==1){
				html += "<td align=\"right\" valign='middle' nowrap='nowrap'>";
				if(ligne[i]['actions'].length!=0){
					for(j=0;j<ligne[i]['actions'].length;j++){
						if(j!=0){
							html += "&nbsp;";
						}
						html += ligne[i]['actions'][j];
					}
				}
				html += "</td>";
			}
			html += "</tr>";
			if(style=="one"){
				style = "two";
			}else{
				style = "one";
			}
		}
		html += "</tbody>";
		if(foot.length!=0){
			html += "<tfoot><tr>";
			for(i=0;i<foot.length;i++){
				html += "<th>"+foot[i]+"</th>";
			}
			if(options.actions==1){
				html += "<th>Actions</th>";
			}
			html += "</tr></tfoot>";
		}
		html += "</table>";
		$("#"+div).html(html);
	};
};

