/* Fonction pour passer d'une étape à l'autre par le menu */
function UserValidationEtape(etape,arriere) {
    if (arriere) {
        document.WizForm.action+='&suivante='+etape;
        document.WizForm.submit();
    } else {
        if (ValidationForm(document.WizForm)) {
            document.WizForm.action+='&suivante='+etape;
            document.WizForm.submit();
        }
    }
}

/* fonction pour l'ouverture de l'aide */
function openAide() {
    displayElt(getElt('infopart2'));
    getElt('lire_la_suite').innerHTML='';
}

/* Fonctions pour le check des langues */

function desactiv2ndLangue(obj) {
activAll();

obj.checked = false;
obj.disabled=true;

}

function activAll () {

temp = document.WizForm.elements.length;
for (i=0; i < temp; i++)
	{
	document.WizForm.elements[i].disabled=false;
	}
}

function countChecked (n, obj) {
    if (n != '-1') {
        var nbre = 0;
        temp = document.WizForm.elements.length;
        for (i=0; i < temp; i++) {
            if (document.WizForm.elements[i].checked) {
                nbre++;
            }
        }
        if (nbre > n) {
            alert("Attention, votre pack est prévu pour "+n+" langues uniquement. Pour bénéficier de plus de langue, il vous suffit de changer de pack.");
            obj.checked=false;
        }
    }
}



/* Validation des perso */

function OpenUpConfirm() {

    if (isDisplay(getElt('confirm_perso'))) {
        nodisplayElt(getElt('transparente'));
        nodisplayElt(getElt('div_preview'));
        nodisplayElt(getElt('confirm_perso'));
        var preview_fix=false;
        getElt('div_preview').onmouseout =function(){inactif =setTimeout('nodisplayElt(getElt(\'div_preview\'))', 500);};
        getElt('div_preview').onmouseover=function(){clearTimeout(inactif); displayElt(getElt('div_preview'));} ;
        //getElt('div_preview').onClick="javascript:preview_fix=!preview_fix;";
        scrollTo(0,0);
    } else {
        displayElt(getElt('transparente')); // On affiche la div de fond de transparence
        displayElt(getElt('div_preview')); // On affiche la preview
        displayElt(getElt('confirm_perso')); // On affiche la div de fond de transparence
        var preview_fix=true;
        var inactif;
        getElt('div_preview').onmouseout =function(){void(0);};
        getElt('div_preview').onmouseover=function(){void(0);};
        getElt('div_preview').onclick=function(){void(0);};
        scrollTo(0,0);
    }

}

function validation(div_a_cacher) {
    showElt (getElt('div_chargement')); // On affiche la div de chargement
    hideElt (getElt('main_personnalisation')); // On cache la div de personnalisation
    hideElt (getElt('boutons_perso')); // On cache les boutons d'apercu
    hideElt (getElt('boutons_perso_bas')); // On cache les boutons d'apercu
    nodisplayElt(getElt(div_a_cacher)); // On cache la div de personnalisation en cours
    nodisplayElt(getElt('transparente')); // On cache la div de fond de transparence
    return true; // Et on valide le form
}

/* Affichage des div perso */
function OpenUp() {

    if (isDisplay(getElt(arguments[0]))) {
         nodisplayElt(getElt(arguments[0]));
         nodisplayElt(getElt('transparente'))
      //   showElt (getElt('div_perso'));
     } else {
         displayElt(getElt(arguments[0]));
         displayElt(getElt('transparente'))
      //   hideElt(getElt('div_perso'));
     }
       scrollTo(0,0);
}
function openUpText() {
    if (isDisplay(getElt("div_"+arguments[0]))) {
        nodisplayElt(getElt("div_"+arguments[0]));
     } else {
         displayElt(getElt("div_"+arguments[0]));
     }
}

function changer_div_texte(div_a_changer) {
    if ( choix_texte ){
        setEltBackgroundColor(getElt(choix_texte),"#E5EEF7");
        setEltBackgroundColor(getElt("div_"+choix_texte),"#E5EEF7");
      //  getElt(choix_texte).style.border = "0px #D8E6F3;"
       // getElt(choix_texte).style.borderRight = "2px solid #000000";
        getElt(choix_texte).style.textAlign = "left";
        openUpText(choix_texte);
    }
    choix_texte = div_a_changer;
    //getElt(choix_texte).style.borderLeft   = " solid 2px #000000";
    //getElt(choix_texte).style.borderTop    = " solid 2px #000000";
    //getElt(choix_texte).style.borderBottom = " solid 2px #000000";
    //getElt(choix_texte).style.borderRight = " 0px #D8E6F3";
    getElt(choix_texte).style.textAlign = "center";
    setEltBackgroundColor(getElt(choix_texte),"#D8E6F3");
    setEltBackgroundColor(getElt("div_"+choix_texte),"#D8E6F3");
    openUpText(div_a_changer);
}

function tempo(){
    showElt (getElt('main_personnalisation'));
    showElt (getElt('boutons_perso'));
    showElt (getElt('boutons_perso_bas'));
    hideElt (getElt('div_chargement'));
}

/*

Fonction de zoom des structures/déclinaisons

Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var offsetfrommouse=[15,25]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.

var defaultimageheight = 40;	// maximum image size.
var defaultimagewidth = 40;	// maximum image size.

var timer;

function gettrailobj(){
if (document.getElementById)
return document.getElementById("preview_div").style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("preview_div")
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function hidetrail(){
	gettrailobj().display= "none";
	document.onmousemove=""
	gettrailobj().left="-500px"
	clearTimeout(timer);
}

function showtrail(imagename,title,width,height){
	t = title
	w = width
	h = height
	timer = setTimeout("show('"+imagename+"',t,w,h);",100);
}

function show(imagename,title,width,height){

    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if( (navigator.userAgent.indexOf("Konqueror")==-1  || navigator.userAgent.indexOf("Firefox")!=-1 || (navigator.userAgent.indexOf("Opera")==-1 && navigator.appVersion.indexOf("MSIE")!=-1)) && (docwidth>650 && docheight>500)) {
		( width == 0 ) ? width = defaultimagewidth: '';
		( height == 0 ) ? height = defaultimageheight: '';

		width+=30;
		height+=55;
		defaultimageheight = height;
		defaultimagewidth = width;

		document.onmousemove=followmouse;


		newHTML = '<div class="border_preview" style="padding : 1em;"><div id="loader_container"><div id="loader"><div align="center">Chargement de la prévisualisation en cours ...</div><div id="loader_bg"><div id="progress"> </div></div></div></div>';
		//newHTML = newHTML + '<h2 class="title_h2">' + ' '+title + '</h2>'

    	newHTML = newHTML + '<div class="preview_temp_load"><img onload="javascript:remove_loading();" src="' + imagename + '" border="0"></div>';
		newHTML = newHTML + '</div>';

		if(navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1 ){
			newHTML = newHTML+'<iframe src="about:blank" scrolling="no" frameborder="0" width="'+width+'" height="'+height+'"></iframe>';
		}

		gettrailobjnostyle().innerHTML = newHTML;
		gettrailobj().display="block";
	}
}

function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = e.pageX - xcoord - defaultimagewidth - offsetfrommouse[0]; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < defaultimageheight + 2*offsetfrommouse[1]){
			ycoord += e.pageY - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - defaultimagewidth - offsetfrommouse[0]; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (defaultimageheight + 2*offsetfrommouse[1])){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}

var t_id = setInterval(animate,20);
var pos=0;
var dir=2;
var len=0;

function animate()
{
var elem = document.getElementById('progress');
if(elem != null) {
if (pos==0) len += dir;
if (len>32 || pos>79) pos += dir;
if (pos>79) len -= dir;
if (pos>79 && len==0) pos=0;
elem.style.left = pos+"px";
elem.style.width = len+"px";
}
}

function remove_loading() {
this.clearInterval(t_id);
var targelem = document.getElementById('loader_container');
targelem.style.display='none';
targelem.style.visibility='hidden';
var t_id = setInterval(animate,60);
}


function zoom(img) {
    getElt('img_preview').src=img;
    displayElt(getElt('div_zoom'));
}


/***************************** DEBUT DES SCRIPTS D'AFFICHAGE POUR LA personnalISATION *************************/
/* Les fonctions set* appliquent les modifications et les fonctions  init* sont appellées lors de l'affichage*/
/* des formulaires, pour faire apparaitre dans l'interface et les div les bonnes couleurs, font...           */
/*************************************************************************************************************/
function setFontColor(elt,couleur){
//if ( (elt =="slogan") || (elt=="contact")){
//} else {
    getElt(elt).style.color=couleur;
//}
}

function initColor(elt,couleur){
    if (elt==null) {
        return;
    }

//if ((elt =="slogan") || (elt=="contact") || (elt=="bande_haut")){
    setFontColor(elt,couleur);
    setFontColor(elt+"_interface",couleur);
//}
}

function setUnderline(){
    if (arguments[1]){
        getElt(arguments[0]).style.textDecoration="underline";
    } else {
        getElt(arguments[0]).style.textDecoration="";
    }
}
function initUnderline(elt,underline){
    if (underline=="underline") setUnderline(elt,true);
    if (underline=="underline") setUnderline(elt+'_interface',true);
}

function setBold(){
    if (arguments[1]){
        getElt(arguments[0]).style.fontWeight="bold";
    } else {
        getElt(arguments[0]).style.fontWeight="";
    }
}

function initBold(elt,recup){
    if (recup=="bold") setBold(elt,true);
    if (recup=="bold") setBold(elt+"_interface",true);
}

function setItalic(){
    if (arguments[1]){
        getElt(arguments[0]).style.fontStyle="italic";
    } else {
        getElt(arguments[0]).style.fontStyle="normal";
    }
}

function initItalic(elt,recup){
    if (recup=="italic") setItalic(elt,true);
    if (recup=="italic") setItalic(elt+"_interface",true);
}

function setFontFamily(){
    getElt(arguments[0]).style.fontFamily=arguments[1];
}

function initFontFamily(elt,recup){
    setFontFamily(elt,recup);
    setFontFamily(elt+"_interface",recup);
}

function setFontSize(){
    if (arguments[1] != '') {
        if (isNaN(arguments[1])) {
            var size=arguments[1];
        } else {
            var size=arguments[1]+"px";
        }
        getElt(arguments[0]).style.fontSize=size;
    }
}

function initFontSize(elt,recup){
    setFontSize(elt,recup);
    setFontSize(elt+'_interface',recup);
}




/***************************** FIN DES SCRIPTS D'AFFICHAGE POUR LA personnalISATION *************************/


/* fonction d'affichage de l'aide */

function showAide(item) {
    if (isDisplay(getElt('showAide'))) {
        nodisplayElt(getElt('showAide'));
    } else {
        if (item == 'pages') {
            getElt('showAide').innerHTML = "Les pages correspondent à .... ";
        } else if (item == 'documents') {
            getElt('showAide').innerHTML = "Les documents correspondent à .... ";
        } else if (item == 'langues') {
            getElt('showAide').innerHTML = "Les langues correspondent à .... ";
        } else if (item == 'domaine') {
            getElt('showAide').innerHTML = "Nom de domaine ";
        } else if (item == 'formulaire') {
            getElt('showAide').innerHTML = "formulaire ";
        } else if (item == 'actualites') {
            getElt('showAide').innerHTML = "actualités !!!!!!!!";
        } else if (item == 'diaporama') {
            getElt('showAide').innerHTML = "DIAPORAMA IN DA PLACE !!! ";
        } else if (item == 'statistiques') {
            getElt('showAide').innerHTML = "Stats !";
        }


    displayElt(getElt('showAide'));
    }
}

function alerte_b(txt1) {
    txt = "Cette fonctionnalité n'est pas encore disponible.\n\n";
    txt += txt1;
    alert(txt);
}

/******************************************** PALETTE *********************************/

		// Déposé par Frosty sur www.toutjavascript.com
		/*****************************************************************
		* Script Color Picker écrit par Frosty (Maxime Pacary) - Mai 2003
		******************************************************************/


		// conversion decimal (0-255) => hexa
		function dechex(n) {
			return strhex.charAt(Math.floor(n/16)) + strhex.charAt(n%16);
		}

		// détection d'un clic/mouvement souris sur la "palette" (à gauche)
		function compute_color(e,clef)
		{
            x = e.offsetX ? e.offsetX : (e.target ? e.clientX-e.target.x : 0);x-=20;if (x<0) {x=0;}
			y = e.offsetY ? e.offsetY : (e.target ? e.clientY-e.target.y : 0);

            try {
                // enlève le scroll vertical
                // ne marche pas sous IE
                y += window.scrollY;
            } catch(E) {
            }

			// calcul de la couleur à partir des coordonnées du clic
			var part_width = getElt('color_picker_'+clef).width/6;
			var part_detail = detail/2;
			var im_height = getElt('color_picker_'+clef).height;


			var red = (x >= 0)*(x < part_width)*255
					+ (x >= part_width)*(x < 2*part_width)*(2*255 - x * 255 / part_width)
					+ (x >= 4*part_width)*(x < 5*part_width)*(-4*255 + x * 255 / part_width)
					+ (x >= 5*part_width)*(x < 6*part_width)*255;
			var blue = (x >= 2*part_width)*(x < 3*part_width)*(-2*255 + x * 255 / part_width)
					+ (x >= 3*part_width)*(x < 5*part_width)*255
					+ (x >= 5*part_width)*(x < 6*part_width)*(6*255 - x * 255 / part_width);
			var green = (x >= 0)*(x < part_width)*(x * 255 / part_width)
					+ (x >= part_width)*(x < 3*part_width)*255
					+ (x >= 3*part_width)*(x < 4*part_width)*(4*255 - x * 255 / part_width);

			var coef = (im_height-y)/im_height;

			// composantes de la couleur choisie sur la "palette"
			red = 128+(red-128)*coef;
			green = 128+(green-128)*coef;
			blue = 128+(blue-128)*coef;

			// mise à jour de la couleur finale
			changeFinalColor('#' + dechex(red) + dechex(green) + dechex(blue),clef);

			// mise à jour de la barre de droite en fonction de cette couleur
			for(i = 0; i < detail; i++)
			{
				if ((i >= 0) && (i < part_detail))
				{
					var final_coef = i/part_detail ;
					var final_red = dechex(255 - (255 - red) * final_coef);
					var final_green = dechex(255 - (255 - green) * final_coef);
					var final_blue = dechex(255 - (255 - blue) * final_coef);
				}
				else
				{
					var final_coef = 2 - i/part_detail ;
					var final_red = dechex(red * final_coef);
					var final_green = dechex(green * final_coef);
					var final_blue = dechex(blue * final_coef);
				}
				color = final_red + final_green + final_blue ;
				getElt('gs'+i+clef).style.backgroundColor = '#'+color;
			}

		}

		// pour afficher la couleur finale choisie
		function changeFinalColor(color,clef)
		{
			getElt('btn_choose_color_'+clef).style.backgroundColor = color;
			getElt('btn_choose_color_'+clef).style.borderColor = color;
		}

		// "renvoyer" la couleur en cliquant sur OK
		function send_color(clef,elt)
		{

			   var new_color = getElt('btn_choose_color_'+clef).style.backgroundColor;
			   exp_rgb = new RegExp("rgb","g");
			   if (exp_rgb.test(new_color))
			   {
			   	exp_extract = new RegExp("[0-9]+","g");
			   	var tab_rgb = new_color.match(exp_extract);

			      new_color = '#'+dechex(parseInt(tab_rgb[0]))+dechex(parseInt(tab_rgb[1]))+dechex(parseInt(tab_rgb[2]));
			   }
			   if (elt != "null") {initColor(elt,new_color);}
			   changeFinalColor(new_color,clef+'_2');
               getElt(clef).value = new_color;

		}

	/*    FIN des fonctions pour la palette */

