﻿// Réalisé par infoconcept
function TabNav() {
	this.tabArray = new Array();
	this.id = arguments[0];
	this.avecButton = arguments[1];
	this.current =0;
	this.startingTab = 0;
}
TabNav.prototype.addTab = function () {
	this.tabArray.push(arguments[0]);
	arguments[0].no = this.tabArray.length-1;
}
TabNav.prototype.render = function () {
	var str = '<ul class="tabnav">';
	for (i=0;i<this.tabArray.length;i++) {
		if (this.avecButton) {
			this.tabArray[i].addButtons(this.tabArray.length-1)
		}
		str += this.tabArray[i].getHtml(i);
	}
	str += "</ul>";
	str += gid(this.id).innerHTML;
	gid(this.id).innerHTML = str;
	/* pour éviter la validation lors de la création*/
		this.current = this.startingTab;
		this.resetState();
		gid(this.tabArray[this.startingTab].li).className = "current";
		gid(this.tabArray[this.startingTab].id).style.display="block";
	//this.setCurrent("0",gid(this.tabArray[0].a));
}
TabNav.prototype.setStartingTab = function () {
	this.startingTab= arguments[0];
}
TabNav.prototype.setCurrent = function () {
	if (this.tabArray[this.current].validation()) {
		this.current = arguments[0];
		this.resetState();
		gid(this.tabArray[arguments[0]].li).className = "current";
		gid(this.tabArray[arguments[0]].id).style.display="block";
	}
}
TabNav.prototype.resetState = function() {
	for (i=0;i<this.tabArray.length;i++) {
		gid(this.tabArray[i].li).className = "";
		gid(this.tabArray[i].id).style.display="none";
	}	
}
function Tab() {
	this.name = arguments[0];
	this.funcVal = arguments[1];
	this.id = arguments[2];
	this.li = "";
	this.a = "";
	this.no=0;
}
Tab.prototype.addButtons = function() {
	var btn1 = "";/*"<br /><hr style=\"margin-bottom:5px;background-color:\" />"*/
	var tmp = 0;
	if (this.no != 0) {
		tmp = this.no-1;
		btn1 += '<input class="btn" type="button" value="Étape précédente" onclick="tabNav.setCurrent(\'' + tmp +'\')" />&nbsp;';
	} else { btn1 = "<br><br>"}
	if (arguments[0] != this.no) {
		tmp = this.no+1;
		btn1 = '<input style="float:right" class="btn" type="button" value="Étape suivante" onclick="tabNav.setCurrent(\'' + tmp +'\')" />'+btn1;
	}
	gid(this.id).innerHTML = gid(this.id).innerHTML + '<br /><br /><hr style=\"margin-bottom:5px;background-color:\" />' +btn1;
}
Tab.prototype.getHtml = function () {
	this.li = 'tabnavli'+arguments[0];
	this.a = 'tabnava'+arguments[0];
	return '<li id="tabnavli'+arguments[0]+'"><a href="#" id="tabnava'+arguments[0]+'" onclick="tabNav.setCurrent(\''+arguments[0]+'\')">'+ this.name +'</a></li>';
}
Tab.prototype.validation = function() {
	if ((eval(this.funcVal)) || (this.funcVal.length==0)) {
	    return true;
	}
	return false;
}
function valInfo() {
	return true;
}
/*function TabVal() {
	this.valArray = new Array();
}
TabVal.prototype.add = function() {
	this.valArray.push(arguments[0]);
}
TabVal.prototype.KeyVal = function () {
	var tmpObj = new Array();
	for(var i=0;i<this.valArray.length;i++) {
		tmpObj = this.valArray[i];
		gid(this.valArray[i].id).onkeyup = function() {
			if (!tmpObj.validate()) {
				gid(tmpObj.id).style.backgroundColor="#FFB9B9";
			 } else {
				gid(tmpObj.id).style.backgroundColor="#fff";
			 }
		};
	}
}
function Validation() {
	this.id = arguments[0];
	this.funcVal= arguments[1];
	this.error = arguments[2];
	this.requis = arguments[3];
}
Validation.prototype.validate = function() {
	if (eval(this.funcVal)) {
		return true;
	}
	return false;
}*/