// Initialisation des param�tres
function paramText ()
	{	
		for (var p in param)
			if ( expText.test(p) )
				param_text[p] = param[p];
	}
// Mise � jour des param�tres actifs
function validText ()
	{		
		for (var p in param)
		{	
			if ( expText.test(p) )
				param[p] = param_text[p];
		}
		loadIframe();
		document.getElementById('popup_text').style.display = 'none'; 
	}
// Initialisation des �l�ments de la popup
function initText ()
	{				
		initTextPreview ();
		initTextField ();
		
		document.getElementById('popup_text').style.display = 'block'; 
	}
// Initialise la partie pr�visualisation
function initTextPreview ()
	{				
		// Structure de la previsualisation
		var txtPopup = new Array ();
		txtPopup = getElementsByClass ("sf_style");
		for (var i = 0 ; i < txtPopup.length ; i ++)
		{
			txtPopup[i].style.color = "red"; // MARCHE PAS ENCORE //
		}
		document.getElementById("view_work").style.background = param['color'+param['tpl_color_work']];			
		document.getElementById("view_work").style.color = readingColor(param['color'+param['tpl_color_work']]);
		
		document.getElementById("view_menu").style.background = param['color'+param['tpl_color_menu']];	
		document.getElementById("view_link").style.background = param['color'+param['tpl_color_link']];	
		if (param['tpl_number'] == "0") 
			document.getElementById("view_left").style.display = "none";
		else
		{
			document.getElementById("view_left").style.background = param['color'+param['tpl_color_left']];
			document.getElementById("view_left").style.display = "table-cell";
		}
		if (param['tpl_number'] == "5" || param['tpl_number'] == "6") 
		{
			document.getElementById("view_right").style.background = param['color'+param['tpl_color_right']];
			document.getElementById("view_right").style.display = "table-cell";
		}
		else
			document.getElementById("view_right").style.display = "none";
			
		// Textes de la pr�visualisation
		var filterBtn = new RegExp("btn", "i"); 
		var filterMnu = new RegExp("mnu", "i"); 
		
		var view = document.getElementsByName("textView");
		for (var i = 0 ; i < view.length ; i ++)
		{
			idParam = 'text_'+Id2Element (view[i].id);
			view[i].style.fontFamily = param_text['text_text_family'];
			view[i].style.fontSize = param_text[idParam+'_size']+"px";
			view[i].style.fontWeight = param_text[idParam+'_weight'];
			view[i].style.fontStyle = param_text[idParam+'_style'];
			view[i].style.textDecoration = param_text[idParam+'_decoration'];
			var textcolor = param_text[idParam+'_color'];
			view[i].style.color = param['color'+textcolor];
			
			if ( filterMnu.test(idParam) )
				 textBkgChange (idParam+"_bkgcolor", param_text[idParam+'_bkgcolor']); 
				 
			if ( filterBtn.test(idParam) )
			{
				 textBordChange (idParam+"_bordcolor", param_text[idParam+'_bordcolor']);
				 textBkgChange (idParam+"_bkgcolor", param_text[idParam+'_bkgcolor']); 
			}
		}
	}
// Initialisation de la partie sup�rieure
function initTextField ()
	{				
		// Famille de police
		var font_name = new Array ();
		font_name = param['text_text_family'].split(" ");
		document.getElementById(font_name[0]).selected = true;
		
		for (var p in param_text)
		{
			if ( filterColor.test(p) ) // Les couleurs
			{
				document.getElementById(p).options[param[p]].selected = true;
				document.getElementById(p).style.background = param['color'+param[p]];
			}
			else if ( filterSize.test(p) ) // Les tailles
			{
				if(document.getElementById(p+'_'+param[p]))document.getElementById(p+'_'+param[p]).selected = true;
			}
			else if ( filterWeight.test(p) ) // Les autres caract�ristiques
			{
				if (param[p] == "bold") document.getElementById(p).checked = true;
				else if (param[p] == "normal") document.getElementById(p).checked = false;
				else alert("Erreur : probl�me lors de l'initialisation du menu POLICE/font-weight");
			}	
			else if ( filterStyle.test(p) )
			{
				if (param[p] == "italic") document.getElementById(p).checked = true;
				else if (param[p] == "normal") document.getElementById(p).checked = false;
				else alert("Erreur : probl�me lors de l'initialisation du menu POLICE/font-style");
			}
			else if ( filterDeco.test(p) )
			{
				if (param[p] == "underline") document.getElementById(p).checked = true;
				else if (param[p] == "none") document.getElementById(p).checked = false;
				else alert("Erreur : probl�me lors de l'initialisation du menu POLICE/text-decoration");
			}
		}
	}
// met a jour les polices
function textFontChange (val)
	{
		param_text['text_text_family'] = val;
		var textView = document.getElementsByName("textView");
		for (var i = 0 ; i < textView.length ; i ++)
			textView[i].style.fontFamily = param_text['text_text_family'];
	}	
// met a jour les couleurs de texte
function textColorChange (id, val)
	{
		param_text[id] = val;
		idTarg = 'view_'+Id2Element (id);
		document.getElementById(id).style.background = param['color'+val];
		document.getElementById(idTarg).style.color = param['color'+val]; 
	}
// met a jour les couleurs de survol
function textBkgChange (id, val)
	{
		param_text[id] = val;
		idTarg = 'view_'+Id2Element (id);
		if (val == "8")
		{
			document.getElementById(idTarg).style.background = "transparent"; 
			document.getElementById(id).style.background = "#fff";
		}
		else
		{
			document.getElementById(idTarg).style.background = param['color'+val]; 
			document.getElementById(id).style.background = param['color'+val];
		}
	}
// met a jour les couleurs de bordure
function textBordChange (id, val)
	{
		param_text[id] = val;
		idTarg = 'view_'+Id2Element (id);
		if (val == "8")
		{
			document.getElementById(idTarg).style.border = "0px" ;
			document.getElementById(id).style.background = "#fff";
		}
		else
		{
			document.getElementById(idTarg).style.borderColor = param['color'+val];
			document.getElementById(idTarg).style.borderWidth="1px"; 
			document.getElementById(idTarg).style.borderStyle="solid";
			document.getElementById(id).style.background = param['color'+val];
		}
	}
// met a jour la taille des textes
function textSizeChange (id, val)
	{
		param_text[id] = val;
		idTarg = 'view_'+Id2Element (id);
		document.getElementById(idTarg).style.fontSize = val+'px';
	}
// met � jour Font-weight
function textWeightChange (id)
	{		
		if ( param_text[id] == "bold" ) param_text[id] = "normal";
		else if ( param_text[id] == "normal" ) param_text[id] = "bold";
		else alert( "Erreur : le param�tre contient une valeur �ron�e" );
		
		idTarg = 'view_'+Id2Element (id);
		document.getElementById(idTarg).style.fontWeight = param_text[id];
	}
// met � jour Font-style
function textStyleChange (id)
	{		
		if ( param_text[id] == "italic" ) param_text[id] = "normal";
		else if ( param_text[id] == "normal" ) param_text[id] = "italic";
		else alert( "Erreur : le param�tre contient une valeur �ron�e" );
		
		idTarg = 'view_'+Id2Element (id);
		document.getElementById(idTarg).style.fontStyle = param_text[id];
	}
// met � jour Text-decoration
function textDecoChange (id)
	{		
		if ( param_text[id] == "underline" ) param_text[id] = "none";
		else if ( param_text[id] == "none" ) param_text[id] = "underline";
		else alert( "Erreur : le param�tre contient une valeur �ron�e" );
		
		idTarg = 'view_'+Id2Element (id);
		document.getElementById(idTarg).style.textDecoration = param_text[id];
	}
