/***** Fonction pour affichage un block de background *****/

//Variables globales pour affichage du block
var Block_Before_Scroll_Positions;
var Block_Before_Body_Overflow_Style;


function Get_Window_Dimensions() {
	//Obtiens la largeur et hauteur interieur de la fenetre selon le navigateur
	var Window_Width = 0, Window_Height = 0;
	if( typeof( window.innerWidth ) == 'number' ) { 
		//Non-IE
		Window_Width = window.innerWidth;
		Window_Height = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		Window_Width = document.documentElement.clientWidth;
		Window_Height = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		Window_Width = document.body.clientWidth;
		Window_Height = document.body.clientHeight;
	};
	return [Window_Width, Window_Height];
};

function Get_Scroll_Positions() {
	var scrOfX = 0, scrOfY = 0;
 	if( typeof( window.pageYOffset ) == 'number' ) {
    	//Netscape compliant
    	scrOfY = window.pageYOffset;
    	scrOfX = window.pageXOffset;
  	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    	//DOM compliant
    	scrOfY = document.body.scrollTop;
    	scrOfX = document.body.scrollLeft;
  	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    	//IE6 standards compliant mode
    	scrOfY = document.documentElement.scrollTop;
    	scrOfX = document.documentElement.scrollLeft;
  	}
  	return [ scrOfX, scrOfY ];
};

/***** Fonction affichage des messages erreur et de confirmation *****/
//Variables globales pour affichage du block
var Scroll_Positions;

//Affiche un message erreur
function Show_Error(Texte) {
	alert("ERREUR:\n"+Texte);
};

//Affiche un message de confirmation
function Show_Confirm(Texte) {
	alert(Texte);
};

/***** Fonction affichage de traitement en cours *****/

//Affichage un block div et un background
function Show_Block(Block_Id,Background_Id) {
	//Obtiens les donnees sur les scrolls et les sauvegarde pour reaffichage
	Block_Before_Scroll_Positions = Get_Scroll_Positions();
	Block_Before_Body_Overflow_Style = document.body.style.overflow;
	//Cache le scroll-bar
	//document.body.style.overflow = "hidden";
	
	//Obtient les scroll positions apres avoir cache la scroll bar
	Scroll_Positions = Get_Scroll_Positions();
	
	//Obtient les dimensions de la fenetre
	Window_Dimensions = Get_Window_Dimensions();

	//Affiche le block avec les donnees de la date
	Block = document.getElementById(Block_Id);
	if (Block != null) {
		Block.style.display = "block";
		//Centre le block dans la fenetre
		//Left ((Largeur de fenetre - Largeur du block) / 2) + Position de scroll gauche
		Block.style.left = (Math.round((Window_Dimensions[0]-Block.offsetWidth)/2)+Scroll_Positions[0])+"px";
		//Top ((Hauteur de fenetre - hauteur du block)/2) + Position du scroll top
		Block.style.top = (Math.round((Window_Dimensions[1]-Block.offsetHeight)/2)+Scroll_Positions[1])+"px";
		
		//Affiche le block de Background		
		Block_Background = document.getElementById(Background_Id);
		if (Block_Background != null) {
			Block_Background.style.display = "block";
			Block_Background.style.top = "0px";
			Block_Background.style.left = "0px";
			Block_Background.style.width = Window_Dimensions[0]+"px";
			
			if (document.getElementById('pied')!=null) {
			//Position, hauteur du pied
				var PosPied = document.getElementById('pied').offsetTop; 
				var HautPied = document.getElementById('pied').offsetHeight;
			} else {
				var PosPied = 0; 
				var HautPied = 0;
			};
			
			//On definit la hauteur de fond du popup
			if( (PosPied + HautPied) > Window_Dimensions[1] ) {
				//Si le contenu de la page est plus grand que la fenetre
				Block_Background.style.height = PosPied + HautPied + 'px'; 
			} else {
				//Si le contenu de la page est plus petit que la fenetre
				Block_Background.style.height = Window_Dimensions[1] + 'px'; 
			};
			
		};
		
	};
	
};

//Desaffichage un block div et un background
function Erase_Block(Block_Id,Background_Id) {
	
	Block = document.getElementById(Block_Id);
	if (Block != null) {
		Block.style.display = "none";
	};
	
	Block_Background = document.getElementById(Background_Id);
	if (Block_Background != null) {
		Block_Background.style.display = "none";
	};
	//Affiche le scroll-bar
	//document.body.style.overflow = "visible";
	
	//Rescroll a la bonne position dans la page
	window.scrollTo(Block_Before_Scroll_Positions[0],Block_Before_Scroll_Positions[1]);
};

/***** Fonction de traitement des objets avec le DOM *****/

//Creation une ligne dans la table
function CreateRow(ID) {
	CurrentRow = document.createElement("TR");
	CurrentRow.setAttribute("id",ID);
	return CurrentRow;
};

//Creation une cellule de contenu dans la table
function CreateCell(Colone,Alignement_Vertical,Alignement_Horizontal,Largeur) {
	CurrentCell = document.createElement("TD");
	CurrentCell.setAttribute("align",Alignement_Vertical);
	CurrentCell.setAttribute("colSpan",Colone);
	if (Alignement_Horizontal != null) {
		CurrentCell.vAlign="top";
	};
	if (Largeur != null) {
		CurrentCell.setAttribute("width",Largeur);
	};
	return CurrentCell;
};

//Creation une table
function CreateTable(ID) {
	Table = document.createElement("TABLE");
	Table.setAttribute("width","100%");
	Table.setAttribute("class","content");
	Table.setAttribute("border",0);
	Table.setAttribute("cellPadding",0);
	Table.setAttribute("cellSpacing",0);
	Table.setAttribute("id",ID);
	return Table;
};

//Creation un lien
function CreateLien(ID,Adresse) {
	Lien = document.createElement("A");
	Lien.setAttribute("href",Adresse);
	Lien.setAttribute("class","content");
	Lien.setAttribute("id",ID);
	return Lien;
};

//Creation un bloc div
function CreateDiv(ID) {
	Div = document.createElement("DIV");
	Div.setAttribute("id",ID);
	return Div;
};

//Creation un bloc span
function CreateSpan(ID) {
	Span = document.createElement("SPAN");
	Span.setAttribute("id",ID);
	return Span;
};

//Creation une image
function CreateImage(ID,Source,Border,Name,Title) {
	Image_Picture = document.createElement("img");
	Image_Picture.setAttribute("border",Border);
	Image_Picture.setAttribute("id",ID);
	Image_Picture.setAttribute("name",Name);
	Image_Picture.setAttribute("src",Source);
	Image_Picture.setAttribute("title",Title);
	Image_Picture.setAttribute("alt",Title);
	return Image_Picture;
};

/***** Fonction de traitement du texte avec le DOM *****/

//Remplace le texte
function replaceText(el, text) {
  if (el != null) {
    clearText(el);
    var newNode = document.createTextNode(text);
    el.appendChild(newNode);
  }
}

//Efface le texte
function clearText(el) {
  if (el != null) {
    if (el.childNodes) {
      for (var i = 0; i < el.childNodes.length; i++) {
        var childNode = el.childNodes[i];
        el.removeChild(childNode);
      }
    }
  }
}

//Recupere le texte
function getText(el) {
  var text = "";
  if (el != null) {
    if (el.childNodes) {
      for (var i = 0; i < el.childNodes.length; i++) {
        var childNode = el.childNodes[i];
        if (childNode.nodeValue != null) {
          text = text + childNode.nodeValue;
        }
      }
    }
  }
  return text;
}
