/* Liste de fonctions javascript */
var DHTML = 0, DOM = 0, MS = 0, NS = 0, OP = 0;
function trim(string){
	return string.replace(/^\s+/, '').replace(/\s+$/, '');
}
function showSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}
function hideSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}
function showFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "visible";
	}

	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "visible";
	}
}
function hideFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "hidden";
	}
	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "hidden";
	}
}
function getPageSize(){
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}
function rmTva(tva, id, input){
	var tvaValue = new Number(getElem('id', tva).value);
		tvaValue = (tvaValue + 100) / 100;
	var ttcValue = new Number(input.value);
	var htValue = ttcValue / tvaValue;
	getElem('id', id).value = htValue;
//	getElem('id', id).value = htValue.toFixed(2);
}
function addTva(tva, id, input){

	var tvaValue = new Number(getElem('id', tva).value);
		tvaValue = (tvaValue + 100) / 100;
	var htValue = new Number(input.value);
	var ttcValue = htValue * tvaValue;
	getElem('id', id).value = ttcValue;
//	getElem('id', id).value = ttcValue.toFixed(2);
}
function doubleOnly(input){
	tmp = '';
	value = input.value;
	for(i=0; i < value.length; i++){
		if(value == ',' || value == '.') tmp='';
		else if(value.charAt(i) == ',' && value.indexOf('.') == -1) tmp+='.';
		else if(!isNaN(value.charAt(i)) && value.charAt(i) != ' ' || value.charAt(i) == '.' && value.substr(0, i).indexOf('.') == -1 || i == 0 && value.charAt(i) == '-') tmp+=value.charAt(i);
	}
	input.value = tmp;
}
function intOnly(input){
	tmp = '';
	value = input.value;
	for(i=0; i < value.length; i++){
		if(!isNaN(value.charAt(i)) && value.charAt(i) != ' ') tmp+=value.charAt(i);
	}
	input.value = tmp;
}
function getWindowHeight() {
	// renvoi la hauteur de la page
	/* 	Liste des variables
	 *	return		: entier				: hauteur de la page
	 */

	var windowHeight = 0;
	if(typeof(window.innerHeight)=='number')
		windowHeight = window.innerHeight;
	else if(document.documentElement && document.documentElement.clientHeight)
		windowHeight = document.documentElement.clientHeight;
	else if(document.body && document.body.clientHeight)
		windowHeight = document.body.clientHeight;
	return windowHeight;
}
function getWindowWidth() {
	// renvoi la hauteur de la page
	/* 	Liste des variables
	 *	return		: entier				: hauteur de la page
	 */

	var windowWidth = 0;
	if(typeof(window.innerWidth)=='number')
		windowWidth = window.innerWidth;
	else if(document.documentElement && document.documentElement.clientWidth)
		windowWidth = document.documentElement.clientWidth;
	else if(document.body && document.body.clientWidth)
		windowWidth = document.body.clientWidth;
	return windowWidth;
}
function resizeTradPopup(){
	// retaille le cache si necessaire

	if (document.getElementById){

		var taille = document.getElementById('cont_popup').offsetHeight + 0;
//		alert(taille);
		taille = (document.getElementById('body').offsetHeight > taille) ? document.getElementById('body').offsetHeight : taille;
//		alert(taille);
		taille = (getWindowHeight() > taille) ? getWindowHeight() : taille;
//		alert(taille);

		document.getElementById('cache').style.height = taille + 0+"px";

	} else if (document.all){

		var taille = document.all['popup'].offsetHeight;
		taille = (document.all['body'].offsetHeight > taille) ? document.all['body'].offsetHeight : taille;
		taille = (getWindowHeight() > taille) ? getWindowHeight() : taille;

		document.all['cache'].style.height = taille +0 +"px";

	} else if (document.layers) {

		var taille = document.layers['popup'].offsetHeight;
		taille = (document.layers['body'].offsetHeight > taille) ? document.layers['body'].offsetHeight : taille;
		taille = (getWindowHeight() > taille) ? getWindowHeight() : taille;

		document.layers['cache'].style.height = taille + 0 + "px";

	}
}


function _popup_erreur(myLink, html, title, width, height, draggable, close, top, left, borderColor, titleBackgroundColor, titleFontColor, cache){
	_popup(myLink, html, title, width, height, draggable, close, top, left, '#FF0000', '#FF6666', '#000000', cache);
}
function DHTML_init() {
	if (window.opera) { 			OP = 1;	}
	if(document.getElementById) { 	DHTML = 1;	DOM = 1; }
	if(document.all && !OP) { 		DHTML = 1;	MS = 1; }
	if(document.layers && !OP) { 	DHTML = 1; 	NS = 1; }
}
function effect_show(id){
	show('loading');
	if(document.getElementById && document.getElementById(id).style.display == "none"){
		new Effect.Appear(id, {duration:1, afterFinish:function(){ if(document.getElementById('loading')) mask('loading'); }});
	}
}
function effect_show(id){
	show('loading');
	if(document.getElementById && (document.getElementById(id).style.display == "" || document.getElementById(id).style.display == "block")){
		new Effect.Fade(id, {duration:1, afterFinish:function(){ if(document.getElementById('loading')) mask('loading'); }});
	}
}
function show(id){
	document.getElementById(id).style.display = "block";
}
function mask(id){
	document.getElementById(id).style.display = "none";
}
function popupWin(pop, ySize, xSize){
	// affiche un popup
	/*	Liste des variables :
	 *	pop			: chaine			: URL de la page  afficher
	 *	ySize		: entier			: hauteur de la popup
	 *	xSize		: entier			: largeur de la popup
	 */

	var gauche = (screen.width - xSize)/2
	var haut =  (screen.height - ySize)/2
	var fenetre = window.open(pop,"","HEIGHT="+ySize+",WIDTH="+xSize+", left="+gauche+", top="+haut+",scrollbars=yes, status=no, toolbar=no, menubar=no, resizable=yes, title=Fichier, dependent=yes");
}
function getElem(p1,p2,p3) {
	var Elem;
	DHTML_init();
	if(DOM) {
		if(p1.toLowerCase()=="id") {
			if (typeof document.getElementById(p2) == "object")
				Elem = document.getElementById(p2);
			else Elem = void(0);
			return(Elem);
		} else if(p1.toLowerCase()=="name") {
			if (typeof document.getElementsByName(p2) == "object")
				Elem = document.getElementsByName(p2)[p3];
			else Elem = void(0);
			return(Elem);
		} else if(p1.toLowerCase()=="tagname") {
			if (typeof document.getElementsByTagName(p2) == "object" ||	(OP && typeof document.getElementsByTagName(p2) == "function"))
				Elem = document.getElementsByTagName(p2)[p3];
			else Elem = void(0);
			return(Elem);
		} else return void(0);
	}
	else if(MS) {
		if(p1.toLowerCase()=="id") {
			if (typeof document.all[p2] == "object")
				Elem = document.all[p2];
			else Elem = void(0);
			return(Elem);
		} else if(p1.toLowerCase()=="tagname") {
			if (typeof document.all.tags(p2) == "object")
				Elem = document.all.tags(p2)[p3];
			else Elem = void(0);
			return(Elem);
		} else if(p1.toLowerCase()=="name") {
			if (typeof document[p2] == "object")
				Elem = document[p2];
			else Elem = void(0);
			return(Elem);
		} else return void(0);
	}
	else if(NS) {
		if(p1.toLowerCase()=="id" || p1.toLowerCase()=="name") {
			if (typeof document[p2] == "object")
				Elem = document[p2];
			else Elem = void(0);
			return(Elem);
		} else if(p1.toLowerCase()=="index") {
			if (typeof document.layers[p2] == "object")
				Elem = document.layers[p2];
			else Elem = void(0);
			return(Elem);
		} else return void(0);
	}
}