var BarreOutil = null;

function TTexteTools(Parent, Doc) {
	this.FDoc = Doc;
	this.FParent = Parent;
	this.FfontSize = 100;
	this.InitBarre = InitBarre;
	this.CreateBtn = CreateBtn;	
	this.FUrl = "";
	this._AggPolice = _AggPolice;
	this._RedPolice = _RedPolice;
	this._Print = _Print;
	this._ViewComment = _ViewComment;
	this.ModifyFontSize = ModifyFontSize;
	this.InitBarre();
}
function DocHasAncre(ancrename){
	var res = false;
	var i = 0;
	while((i < document.anchors.length) && (res == false)){
	  res = document.anchors[i].name == ancrename;
	  i++;
	}
	return res;
}
function InitBarre(){
	if (this.FParent != null){
		Btn = this.CreateBtn("BtnRedPolice", "Réduire la taille du texte");
		Btn.onclick = function() {RedPolice(this);return false;};
		Btn = this.CreateBtn("BtnAggPolice", "Augmenter la taille du texte");
		Btn.onclick = function() {AggPolice(this); return false;};
		Btn = this.CreateBtn("BtnPrint", "Imprimer");
		Btn.onclick = function() {Print(this); return false;};	
		if (DocHasAncre("comment")){
			Btn = this.CreateBtn("BtnViewComment", "Voir les commentaires");
			Btn.onclick = function() {ViewComment(this); return false;};				
		}
	}		
}
function CreateBtn(ClassBtn, Hint){
	var btn = document.createElement("a");
	var url = "#";
	var txt = document.createTextNode(" ");		
	btn.setAttribute("href", url);
	btn.setAttribute("title", Hint);
	btn.className = ClassBtn;
	btn.appendChild(txt);
	this.FParent.appendChild(btn);		
	return btn;
}
function ModifyFontSize(Increment){
	var par = document.getElementById(this.FDoc); 
	this.FfontSize = this.FfontSize + Increment;
	par.style.fontSize = this.FfontSize + "%";	
}
function _AggPolice(){
  this.ModifyFontSize(10);
}
function _RedPolice(){
  this.ModifyFontSize(-10);
}
function AggPolice(){
	if (BarreOutil != null)
		BarreOutil._AggPolice();
}
function RedPolice(){
	if (BarreOutil != null)
		BarreOutil._RedPolice();
}
function _Print(){
	var par = document.getElementById(this.FDoc); 
	
    var Headers = '<!DOCTYPE HTML PUBLIC ><HTML><HEAD>'+
    '<link rel="stylesheet" type="text/css" href="styles/print.css"/>'+
    '</HEAD><BODY onload="window.print();">'+
    '<DIV class="headprint">www.rouenalternatif.com</DIV>'+
    '<DIV class="corpsprint">'; 
    var Footers = "</DIV></BODY></HTML>";
    var txt = par.innerHTML ;
    var f = window.open("", "ZoneImpr");
    // Définit le Style de la page
	f.document.body.style.color = '#000000';
	f.document.body.style.backgroundColor = '#FFFFFF';
	// Ajoute les Données
	f.document.write ("" + Headers + txt +Footers);
	f.document.close();	
}
function _ViewComment(){
	if (BarreOutil.FUrl == "")
		BarreOutil.FUrl = document.URL;
	location = BarreOutil.FUrl + "#comment";
}
function Print(){
	if (BarreOutil != null)
		BarreOutil._Print();
}
function ViewComment(){
	if (BarreOutil != null)
		BarreOutil._ViewComment();
}