var currentDivAction;
currentDivAction = '';

function getDiv(divName,source) {
	var div;
	if (document.getElementById) {
		if(source == 'opener') div = window.opener.document.getElementById(divName);
		else div = document.getElementById(divName);
	}
	else if (document.all) {
		if(source == 'opener') renduObjetButton = window.opener.document.all[divName];
		else div = document.all[divName];
	}
	return div;
}

function setTheme(form) {
	//image:0et1|130B0B|D89F27|0000FF|222DDD|000000|F9F405|Arial|16
	//FFFFFF|130B0B|D89F27|0000FF|222DDD|000000|F9F405|Comic_Sans_MS|16
	//|130B0B|D89F27|0000FF|222DDD|000000|F9F405|Comic_Sans_MS|16
	
	var theme = form.selectTheme.options[form.selectTheme.selectedIndex].value;
	//alert(theme);
	if(theme) {
		
	var tabDesign = theme.split('|'); 

	//Fond
	form.elements['txtcoulFond'].value = '';
	form.elements['buttcoulFond'].style.backgroundImage = '';
	form.elements['buttcoulFond'].style.borderColor = '';
	form.elements['buttcoulFond'].style.backgroundColor = '';
	getDiv('renducoulFond').style.backgroundColor = '';
	getDiv('renducoulFond').style.backgroundImage = '';
	
	if(tabDesign[0] != '') {
		form.elements['txtcoulFond'].value = tabDesign[0];
		// couleur
		if(tabDesign[0].indexOf('image') == -1) {
			form.elements['buttcoulFond'].style.borderColor = tabDesign[0];
			form.elements['buttcoulFond'].style.backgroundColor = tabDesign[0];
			getDiv('renducoulFond').style.backgroundColor = tabDesign[0];
		}
		// image
		else {
			tabDesign[0] = Remplace(tabDesign[0],'image:','');
			var imageUrl = '/uploads/_bgs/'+tabDesign[0]+'.png';
			form.elements['buttcoulFond'].style.backgroundImage = 'url('+imageUrl+')';
			getDiv('renducoulFond').style.backgroundImage = 'url('+imageUrl+')';
		}
	}
	
	
	//Titre
	form.elements['txtcoulTitre'].value = tabDesign[1];
	form.elements['buttcoulTitre'].style.borderColor = tabDesign[1];
	form.elements['buttcoulTitre'].style.backgroundColor = tabDesign[1];
	getDiv('renducoulTitre').style.color = tabDesign[1];
	getDiv('renducoulButton').style.color = tabDesign[1];
	
	//description
	form.elements['txtcoulDescription'].value = tabDesign[2];
	form.elements['buttcoulDescription'].style.borderColor = tabDesign[2];
	form.elements['buttcoulDescription'].style.backgroundColor = tabDesign[2];
	getDiv('renducoulDescription').style.color = tabDesign[2];
	
	//Lien
	form.elements['txtcoulLien'].value = tabDesign[3];
	form.elements['buttcoulLien'].style.borderColor = tabDesign[3];
	form.elements['buttcoulLien'].style.backgroundColor = tabDesign[3];
	getDiv('renducoulLien').style.color = tabDesign[3];
	
	//Question
	form.elements['txtcoulQuestion'].value = tabDesign[4];
	form.elements['buttcoulQuestion'].style.borderColor = tabDesign[4];
	form.elements['buttcoulQuestion'].style.backgroundColor = tabDesign[4];
	getDiv('renducoulQuestion').style.color = tabDesign[4];
	
	//Reponse
	form.elements['txtcoulReponse'].value = tabDesign[5];
	form.elements['buttcoulReponse'].style.borderColor = tabDesign[5];
	form.elements['buttcoulReponse'].style.backgroundColor = tabDesign[5];
	getDiv('renducoulReponse').style.color = tabDesign[5];
	
	//Bouton
	form.elements['txtcoulBouton'].value = '';
	form.elements['buttcoulBouton'].style.borderColor = '';
	form.elements['buttcoulBouton'].style.backgroundColor = '';
	getDiv('renducoulButton').style.backgroundColor = '';
	
	if(tabDesign[6] != '') {
		form.elements['txtcoulBouton'].value = tabDesign[6];
		form.elements['buttcoulBouton'].style.borderColor = tabDesign[6];
		form.elements['buttcoulBouton'].style.backgroundColor = tabDesign[6];	
		getDiv('renducoulButton').style.backgroundColor = tabDesign[6];
	}
	
	//Textes - police
	var selectPolice = form.selectPolice
	tabDesign[7] = Remplace(tabDesign[7],'_',' ');
	for(var i=0;i<selectPolice.length;i++) {
		if(selectPolice.options[i].value == tabDesign[7]) selectPolice.options[i].selected=true;
	}
		
	//Textes - taille
	var selectTaille = form.selectTaille
	for(var i=0;i<selectTaille.length;i++) {
		if(selectTaille.options[i].value == tabDesign[8]) selectTaille.options[i].selected=true;
	}
	
	// rendu
	setPoliceToRendu(form);
	
	}
}
// setPoliceToRendu(form)
function setPoliceToRendu(form) {
	var selectPolice = form.selectPolice.options[form.selectPolice.selectedIndex].value;
	var selectTaille = form.selectTaille.options[form.selectTaille.selectedIndex].value;
	var renducoulButton = form.renducoulButton;
		
	if (document.getElementById) renduObjetFond=document.getElementById('renducoulFond');
	else if (document.all) renduObjetFond=document.all['renducoulFond'];
			
	var params = 'normal '+selectTaille+'px '+selectPolice;
	var paramsBold = 'bold '+selectTaille+'px '+selectPolice;
	//alert(params)
	//renduObjetFond.style.font = 'italic small-caps bold 12pt serif';
	renduObjetFond.style.font = params;
	renducoulButton.style.font = paramsBold;
	
	generateCodeRendu(form.name);
}

function generateCodeRendu(formName) {
	
	form=document.forms[formName];
		
	if(form.elements['code_integration']) {
		var code = form.code_integration;
		var value = code.value;

		// si value contient | > perso du design
		if(value.indexOf("|") != -1 ) {
			// recup dans value les donnees de design
			var pos1 = value.indexOf("design=")+7;
			var pos2 = value.indexOf(" ",pos1);
			var oldDesign = value.substring(pos1,pos2);
				//alert(oldDesign);
			
			txtselectPolice = Remplace(form.selectPolice.options[form.selectPolice.selectedIndex].value,' ','_');
			txtselectTaille = form.selectTaille.options[form.selectTaille.selectedIndex].value;
			// genere nouveaux params
			var newDesign = form.txtcoulFond.value+'|'+form.txtcoulTitre.value+'|'+form.txtcoulDescription.value+'|'+form.txtcoulLien.value+'|'+form.txtcoulQuestion.value+'|'+form.txtcoulReponse.value+'|'+form.txtcoulBouton.value+'|'+txtselectPolice+'|'+txtselectTaille;
			//alert(newDesign);
			newDesign = Remplace(newDesign,'#','');
			value = Remplace(value,oldDesign,newDesign);
			
		}
		
		// si on est en iframe > height=300 width=500
		if( (value.indexOf("iframe") != -1 ) && (value.indexOf("fb:js") == -1 ) ) {
			// modif du height
			var pos1 = value.indexOf("height=");
			var pos2 = value.indexOf(" ",pos1);
			var oldHeight = value.substring(pos1,pos2);
			var newHeight = 'height='+form.code_hauteur.value;
			value = Remplace(value,oldHeight,newHeight);
			
			// modif du width
			var pos1 = value.indexOf("width=");
			var pos2 = value.indexOf(" ",pos1);
			var oldWidth = value.substring(pos1,pos2);
			var newWidth = 'width='+form.code_largeur.value;
			value = Remplace(value,oldWidth,newWidth);
						
			// modif du border
			var pos1 = value.indexOf("border:black ");
			var pos2 = value.indexOf("solid",pos1);
			var oldBorder=value.substring(pos1,pos2); // border:black 0px
			var newBorder = 'border:black '+form.selectBordure.options[form.selectBordure.selectedIndex].value+'px ';
			value = Remplace(value,oldBorder,newBorder);
		}
	
		code.value = value;
		code.select();
	}
	
}
		
// selectInteg
function selectInteg(td,code) {
		var td1;
		var td2;
		var td3;
		var td4;
		var td5;
		
		if (document.getElementById) {
			td1=document.getElementById("tdIntegFlash");
			td2=document.getElementById("tdIntegFrame");
			td3=document.getElementById("tdIntegJavascript");
			td4=document.getElementById("tdIntegForum");
			td5=document.getElementById("tdIntegFacebook");

		}
		else if (document.all) {
			td1=document.all["tdIntegFlash"];
			td2=document.all["tdIntegFrame"];
			td3=document.all["tdIntegJavascript"];
			td4=document.all["tdIntegForum"];
			td5=document.all["tdIntegFacebook"];
        }
        
        td1.className="";
        td2.className="";
        td3.className="";
        td4.className="";
        td5.className="";
        
        td.className="barreActive2";
        document.formBarre.code_integration.value=code;
        document.formBarre.code_integration.select();
        
        // visibilite de la partie bordure et dimension reservé au mode frame
        if(td.id == 'tdIntegFrame') { showLayer2('divIntegFrame'); }
    	else hiddeLayer2('divIntegFrame');
        
        if( (td.id == 'tdIntegFacebook') || (td.id == 'tdIntegForum') ) { 
        	hiddeLayer2('divDesign'); 
        	//showLayer2('divDesignCompte');
        }
    	else {
    		showLayer2('divDesign');
    		//hiddeLayer2('divDesignCompte'); 
        }
        generateCodeRendu('formBarre');
}


function selectOpenBarre(td) {
		var td1;
		var td2;
		var td3;
		var td4;
		var td5;
		var td6;
		var td7;
		var td8;
		
		if (document.getElementById) {
			td1=document.getElementById("tdBarre1");
			td2=document.getElementById("tdBarre2");
			td3=document.getElementById("tdBarre3");
			td4=document.getElementById("tdBarre4");
			td5=document.getElementById("tdBarre5");
			td6=document.getElementById("tdBarre6");
			td7=document.getElementById("tdBarre7");
			td8=document.getElementById("tdBarre8");
		}
		else if (document.all) {
			td1=document.all["tdBarre1"];
			td2=document.all["tdBarre2"];
			td3=document.all["tdBarre3"];
			td4=document.all["tdBarre4"];
			td5=document.all["tdBarre5"];
			td6=document.all["tdBarre6"];
			td7=document.all["tdBarre7"];
			td8=document.all["tdBarre8"];
        }
        
        td1.className="";
        td2.className="";
        td3.className="";
        td4.className="";
        td5.className="";
        td6.className="";
        td7.className="";
        td8.className="";
        
        td.className="barreActive";
}

// selectInteg
function selectPartager(td) {
		var td1;
		var td2;
		var td3;
				
		if (document.getElementById) {
			td1=document.getElementById("tdPartagerDefier");
			td2=document.getElementById("tdPartagerPublier");
			td3=document.getElementById("tdPartagerInviter");
		}
		else if (document.all) {
			td1=document.all["tdPartagerDefier"];
			td2=document.all["tdPartagerPublier"];
			td3=document.all["tdPartagerInviter"];		
        }
        
        td1.className="";
        td2.className="";
        td3.className="";
               
        td.className="barreActive2";
}

/////////////////////////// Infobulle et Layers /////////////////////////////////
function isIE6() {
	var isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
	return isIE6;
}

// showLayer2(layerName)
function showLayer2(layerName) {
  if (document.layers) {document.layers[layerName].visibility="show";}
  if (document.all) {document.all[layerName].style.visibility="visible";}
  else if (document.getElementById) {document.getElementById(layerName).style.visibility="visible";}
}

//  hiddeLayer2(layerName)
function hiddeLayer2(layerName) {
  if (document.layers) document.layers[layerName].visibility="hide";
  if (document.all) document.all[layerName].style.visibility="hidden";
  else if (document.getElementById) document.getElementById(layerName).style.visibility="hidden";
}

//  hiddeShowLayer2(layerName)
function hiddeShowLayer2(layerName) {
	if(isVisibleLayer(layerName)) hiddeLayer2(layerName);
	else showLayer2(layerName);
}

//  isVisibleLayer(layerName)
function isVisibleLayer(layerName) {
  if (document.layers) {
 
  	if (document.layers[layerName].visibility == "show") return true;
  }
  if (document.all) {
  	if (document.all[layerName].style.visibility == "visible") return true;
  }
  else if (document.getElementById) {
  	if (document.getElementById(layerName).style.visibility == "visible") return true;
  }

  return false;
}

function getEvent() {
	if(document.all) return event.srcElement;
	else return event.target;
}

function getRelatedTarget(e)
{
var t = e.relatedTarget;
if ( !t )
{
if (e.type == "mouseout")
{
t = e.toElement;
}
else if ( e.type == "mouseover" )
{
t = e.fromElement;
}
}
return t;
}

function stoprop(layerName,what,e)
{
var E = e || event;  
	e.stopPropagation();
}

/////////////////////////// Infobulle V2 /////////////////////////////////
var IB=new Object;
var posX=0;posY=0;
var xOffset=10;yOffset=10;

function Aff(texte,type) {

var contenu;
var codeImage;
var codeColor;
var filetype;
var urlImage = '/images/infobulle/';
if(!type) type='help';

//texte = '<table cellpadding=0 cellspacing=0 border=0><tr><td width=12><img src='+urlImage+'1.gif border=0></td><td bgcolor=white></td><td width=14 style=background-image:url('+urlImage+'verti2.gif);background-repeat:repeat-y;><img src='+urlImage+'2.gif border=0></td></tr><tr><td width=12 bgcolor=white></td><td bgcolor=white>'+texte+'</td><td style=background-image:url('+urlImage+'verti2.gif);background-repeat:repeat-y;></td></tr><tr><td width=12><img src='+urlImage+'4.gif border=0></td><td bgcolor=white></td><td width=14 style=background-image:url('+urlImage+'verti2.gif);background-repeat:repeat-y;><img src='+urlImage+'3.gif border=0></td></tr></table>';

// Tout petit
if(type == '0') {
	contenu="<TABLE border=0 cellspacing=0 cellpadding="+IB.NbPixel+"><TR bgcolor='"+IB.ColContour+"'><TD><TABLE border=0 cellpadding=2 cellspacing=0 bgcolor='"+IB.ColFond+"'><TR><TD><FONT size='-1' face='arial' color='"+IB.ColTexte+"'>"+texte+"</FONT></TD></TR></TABLE></TD></TR></TABLE>&nbsp;";
}
else {
	
// Notation > FCFECC
if( (type == 'notation') || (type == 'orange') )  {
	codeImage = 'b';
	codeColor = '#FCFECC';
	filetype='gif';
}
// Quizz > FFFFE1
else if( (type == 'quizz') || (type == 'vert') ) {
	codeImage = 'd';
	codeColor = '#FFFFE1';
	filetype='gif';
}
// Help > FFFFE1
else {
	codeImage = 'c';
	codeColor = '#FFFFE1';
	filetype='gif';
}

codeImage = '';
codeColor = 'white';
filetype='png';

if(isIE6()) {
	codeImage = 'e';
	codeColor = 'white';
	filetype='gif';
}

contenu = '<table cellpadding=0 cellspacing=0 border=0><tr><td valign=bottom><img src='+urlImage+'1'+codeImage+'.'+filetype+' border=0></td><td style=background-image:url('+urlImage+'hori1'+codeImage+'.'+filetype+');background-repeat:repeat-x;></td><td valign=bottom><img src='+urlImage+'2'+codeImage+'.'+filetype+' border=0></td></tr><tr><td  style=background-image:url('+urlImage+'verti1'+codeImage+'.'+filetype+');background-repeat:repeat-y;></td><td style=background-color:'+codeColor+'><div class=moyenNobold style=padding-right:10px;>'+texte+'</div></td><td style=background-image:url('+urlImage+'verti2'+codeImage+'.'+filetype+');background-repeat:repeat-y;></td></tr><tr><td valign=top><img src='+urlImage+'4'+codeImage+'.'+filetype+' border=0></td><td style=background-image:url('+urlImage+'hori2'+codeImage+'.'+filetype+');background-repeat:repeat-x;>&nbsp;</td><td  valign=top><img src='+urlImage+'3'+codeImage+'.'+filetype+' border=0></td></tr></table>';

}

  var finalPosX=posX-xOffset;
  if (finalPosX<0) finalPosX=0;
  if (document.layers) {
    document.layers["bulle"].document.write(contenu);
    document.layers["bulle"].document.close();
    document.layers["bulle"].top=posY+yOffset;
    document.layers["bulle"].left=finalPosX;
    document.layers["bulle"].visibility="show";}
  if (document.all) {
    //var f=window.event;
    //doc=document.body.scrollTop;
    bulle.innerHTML=contenu;
    document.all["bulle"].style.top=posY+yOffset;
    document.all["bulle"].style.left=finalPosX;//f.x-xOffset;
    document.all["bulle"].style.visibility="visible";
  }
  //modif CL 09/2001 - NS6 : celui-ci ne supporte plus document.layers mais document.getElementById
  else if (document.getElementById) {
    document.getElementById("bulle").innerHTML=contenu;
    document.getElementById("bulle").style.top=posY+yOffset;
    document.getElementById("bulle").style.left=finalPosX;
    document.getElementById("bulle").style.visibility="visible";
  }
}
function getMousePos(e) {
  if (document.all) {
  posX=event.x+document.body.scrollLeft; //modifs CL 09/2001 - IE : regrouper l'évènement
  posY=event.y+document.body.scrollTop;
  }
  else {
  posX=e.pageX; //modifs CL 09/2001 - NS6 : celui-ci ne supporte pas e.x et e.y
  posY=e.pageY; 
  }
}
function Hide() {
	if (document.layers) {document.layers["bulle"].visibility="hide";}
	if (document.all) {document.all["bulle"].style.visibility="hidden";}
	else if (document.getElementById){document.getElementById("bulle").style.visibility="hidden";}
}

function InitBulle(ColTexte,ColFond,ColContour,NbPixel) {
	IB.ColTexte=ColTexte;IB.ColFond=ColFond;IB.ColContour=ColContour;IB.NbPixel=NbPixel;
	if (document.layers) {
		window.captureEvents(Event.MOUSEMOVE);window.onMouseMove=getMousePos;
		document.write("<LAYER name='bulle' top=0 left=0 visibility='hide'></LAYER>");
	}
	if (document.all) {
		document.write("<DIV id='bulle' style='position:absolute;z-index:100;top:0;left:0;visibility:hidden;'></DIV>");
		document.onmousemove=getMousePos;
	}
	//modif CL 09/2001 - NS6 : celui-ci ne supporte plus document.layers mais document.getElementById
	else if (document.getElementById) {
	        document.onmousemove=getMousePos;
	        document.write("<DIV id='bulle' style='position:absolute;top:0;left:0;visibility:hidden;z-index:100;'></DIV>");
	}

}

InitBulle("black","#FFFFCC","#333399",1);
// InitBulle(couleur de texte, couleur de fond, couleur de contour taille contour)

/////////////////////////// Chaines de caracteres /////////////////////////////////
//  Remplace(expr,a,b)
 function Remplace(expr,a,b) {
 	//alert('Remplace '+a+' par '+b+' dans '+expr);
      var i=0
      while (i!=-1) {
         i=expr.indexOf(a,i);
         if (i>=0) {
            expr=expr.substring(0,i)+b+expr.substring(i+a.length);
            i+=b.length;
         }
      }
      //alert('donne '+expr);
      return expr
   }



/////////////////////////// NEED Ajax /////////////////////////////////

 function ajouteTexteDiv(divname,texte)
  {
  if (document.getElementById)
    {
    	//alert(document.getElementById(divname)); 
    	//alert(document.getElementById(divname).innerHTML);
    	//alert(texte); 
    document.getElementById(divname).innerHTML = texte;
    	//alert(document.getElementById(divname).innerHTML);
    }
  else if (document.all)
    {
    document.all[divname].innerHTML = texte;
    }
  }



/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}


function ajaxMe(URL,params,divname) {

/* assuming you already have XHConn.js included in your HTML file */
var myConn = new XHConn();
if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
var fnWhenDone = function (oXML) {
	loadingMgt('hidden'); 
	ajouteTexteDiv(divname,oXML.responseText);
	
	// pour resultat de quizz, envoi vers input
	if(false && (divname == "formulaire") ) {
		// recup de la zone qui nous interesse entre <!-- resultats debut --> et <!-- resultats fin -->
		var tableResultats = oXML.responseText;
		tableResultats=tableResultats.substring(tableResultats.indexOf("<!-- resultats debut -->"),tableResultats.indexOf("<!-- resultats fin -->"));
		
		// suppr des " et '
		tableResultats = Remplace(tableResultats,'"','');
		tableResultats = Remplace(tableResultats,"'","");
		
		// envoi dans le hidden
		if(document.sendResultat) document.sendResultat.resultats.value=tableResultats;
	}
};

//alert(URL+' '+params+' '+divname);
myConn.connect(URL, "POST", params, fnWhenDone);
}


/////////////////////////// Misc /////////////////////////////////
function moveTheme(act) {
	var select = document.getElementById('selectTheme');
	var selectedIndex = select.selectedIndex;
	var length = select.length;
	var newIndex = 0;
	
	if(act == 'next') {
		if(selectedIndex == (length-1)) newIndex = 0;
		else newIndex = selectedIndex + 1;
	}
	else if(act == 'previous') {
		if(selectedIndex == 0) newIndex = length - 1;
		else newIndex = selectedIndex - 1;
	}
	
	select.selectedIndex = newIndex
	setTheme(select.form);
}

function popup_color_picker(id,root,form)
		{
			var width = 500;
			var height = 600;
			//alert(root+'/quizz/color_picker.php?objet='+id);
			window.open(root+'/quizz/color_picker.php?objet='+id+'&form='+form, 'popup_color', 'resizable=no, location=no, width='
						+width+', height='+height+', menubar=no, status=no, scrollbars=no, menubar=no');
		}

// insert smilies fixes for Mozilla
function mozInsert(txtarea, openTag, closeTag) {
   var scrollTop = ( typeof(txtarea.scrollTop) == 'number' ? txtarea.scrollTop : -1 );
   if (txtarea.selectionEnd > txtarea.value.length) {
      txtarea.selectionEnd = txtarea.value.length;
   }

   var startPos = txtarea.selectionStart;
   var endPos = txtarea.selectionEnd + openTag.length;
   txtarea.value = txtarea.value.slice(0, startPos) + openTag + txtarea.value.slice(startPos);
   txtarea.value = txtarea.value.slice(0, endPos) + closeTag + txtarea.value.slice(endPos);
   txtarea.selectionStart = startPos + openTag.length;
   txtarea.selectionEnd = endPos;
   txtarea.focus();
   if (scrollTop >= 0) {
      txtarea.scrollTop = scrollTop;
   }
}

//  setPointerClass(obj,theclass)
function setPointerClass(obj,theclass) {
	//alert(obj+'c'+theclass);
	obj.className=theclass;
}

// loadingMgt(visibility) > chargement d'une image type loading
function loadingMgt(visibility) {
	if(document.images['imgLaunch']) {
		var imageSrc;
		
		if(visibility == 'visible') imageSrc = '/images/loading.gif';
		else if(visibility == 'hidden') imageSrc = '/images/pixel.gif';
		else alert('visibility not recognized');
	
		document.images['imgLaunch'].src=imageSrc;
		//alert(document.images['imgLaunch'].src);
	}
}

// connexion
function connectIt(login,password) {
	//alert(login+","+password+","+document.location);
	document.loginConnexion.pseudo.value=login;
	document.loginConnexion.password.value=password;
	document.loginConnexion.ref.value=document.location;
	document.loginConnexion.submit();
}


// checkEmail
function convertEmail(str) {
		var DEBUG = false;
		if(DEBUG) alert('Enter checkEmail for '+str);
		
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.lastIndexOf(dot)

		// Si extension > 2 caracts, verif que c'est com, info, net, org, biz,name, pro, aero, asia, cat, 
		//coop, edu, gov, int, jobs, mil, mobi, museum, tel, travel
		var extension = str.substring(ldot+1);
		var lext = extension.length;
		if(lext == 0) {
			if(DEBUG) alert('Error Code 1');
			return false;
		}
		if(lext > 2) {
			
			if( (extension != 'com') && (extension != 'info') && (extension != 'net') && (extension != 'org') && 
			(extension != 'biz') && (extension != 'name') && (extension != 'pro') && (extension != 'aero') && 
			(extension != 'asia') && (extension != 'cat') && (extension != 'coop') && (extension != 'edu') && 
			(extension != 'gov') && (extension != 'int') && (extension != 'jobs') && (extension != 'mil') && 
			(extension != 'mobi') && (extension != 'museum') && (extension != 'tel') && (extension != 'travel') ) {
				if(DEBUG) alert('Error Code 2');
				return false;
			}
			
			
		}		

		if (str.indexOf(at)==-1){
		   if(DEBUG) alert('Error Code 3');
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   if(DEBUG) alert('Error Code 4');
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    if(DEBUG) alert('Error Code 5');
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    if(DEBUG) alert('Error Code 6');
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    if(DEBUG) alert('Error Code 7');
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    if(DEBUG) alert('Error Code 8');
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    if(DEBUG) alert('Error Code 9');
		    return false
		 }



 		 return true					
	
}

function isDefined(variable)
{
return (!(!(document.getElementById(variable))))
}
		
/////////////////////////// Not Used /////////////////////////////////
// retourne la position en pixel du 1er frame nommé quizz.biz de la page parent
// aurait pu s'utiliser avec parent.scrollTo(0,getPosQuizz()-30)
function getPosQuizz() {
 var iVal = 0;
 var taboObj = parent.document.getElementsByName('quizz.biz');
 var oObj = taboObj[0]; 
 while (oObj && oObj.tagName != 'BODY') {
  iVal += oObj.offsetTop;
  oObj = oObj.offsetParent;
 }
 return iVal;
}


function makevisible(cur,which)
{
if(document.getElementById)
{
if (which==0)
{
if(document.all)
cur.filters.alpha.opacity=100
else
cur.style.setProperty("-moz-opacity", 1, "");
}
else
{
if(document.all)
cur.filters.alpha.opacity=50
else
cur.style.setProperty("-moz-opacity", .7, "");
}
}
}

function openCat(categorie,act) {
		  ajaxMe('/ajax/open-cat.php','INFB='+INFB+'&categorie='+escape(categorie)+'&act='+act,'ajax_cat_'+categorie);
		  if(act == 'off') document.location='#anchor_cat_'+categorie;
}


function afficheEtoile(formName,form,combo,nom) {		
	 		var note = combo.value;
	 		
	 		var starOff = "<img src='/images/star_off.gif' border=0>";
	 		var starOn = "<img src='/images/star_on.gif' border=0>";
	 		var star = "";
	 		var noteHtml = "";
	 		var theonclick = "";
	 		
	 		for(var i=0;i<10;i++) {
	 			if(note > i) star = starOn;
	 			else star = starOff;
	 			
	 			theonclick = '<a onmouseout="document.[FORMNAME].note[NOM].value=[NOTE];" onmouseover="document.[FORMNAME].note[NOM].value=[I];" href="javascript:afficheEtoile(\'[FORMNAME]\',document.[FORMNAME],document.[FORMNAME].note[NOM],\'[NOM]\')">';
	 			theonclick = Remplace(theonclick,'[I]',i+1);
	 			
	 			noteHtml += theonclick+star+"</a>";
	 		}
	 		
	 		noteHtml = Remplace(noteHtml,'[NOTE]',note);
	 		noteHtml = Remplace(noteHtml,'[NOM]',nom);
	 		noteHtml = Remplace(noteHtml,'[FORMNAME]',formName);	 		
	 			 		
	 		document.getElementById("afficheEtoile"+nom).innerHTML = noteHtml;
	 		
	 		
	 		// pour la notation des quizz
	 		if(nom != '') {
	 			
	 		var notemoyenne = form.notemoyenne;
	 		var notede1 = form.noteexactitude;
	 		var notede2 = form.noteorthographe;
	 		var notede3 = form.noteinteret;
	 		
	 		// selection de la moyenne
	 		if(nom == "moyenne") {
	 			
	 			notede1.value=notemoyenne.value;
	 			notede2.value=notemoyenne.value;
	 			notede3.value=notemoyenne.value;
	 			
			 	document.getElementById("afficheEtoileexactitude").innerHTML = Remplace(noteHtml,'moyenne','exactitude');
			 	document.getElementById("afficheEtoileorthographe").innerHTML = Remplace(noteHtml,'moyenne','orthographe');
			 	document.getElementById("afficheEtoileinteret").innerHTML = Remplace(noteHtml,'moyenne','interet');
			 	document.getElementById("afficheEtoilemoyenne").innerHTML = noteHtml;
	 		} 
	 		else {
		 		// calcul de la moyenne
		 		if( (notede1.value == "?") || (notede2.value == "?") || (notede3.value == "?") ) {}
		 		else {
		 		
		 			var moyenne =  Math.round((parseInt(notede1.value)+parseInt(notede2.value)+parseInt(notede3.value))/3);
		 			
		 			notemoyenne.value=moyenne;
		 			noteHtml = "";
		 		
		 			for(var i=0;i<10;i++) {
			 			if(moyenne > i) star = starOn;
			 			else star = starOff;
			 			
			 			theonclick = '<a onmouseout="document.[FORMNAME].note[NOM].value=[NOTE];" onmouseover="document.[FORMNAME].note[NOM].value=[I];" href="javascript:afficheEtoile(\'[FORMNAME]\',document.[FORMNAME],document.[FORMNAME].note[NOM],\'[NOM]\')">';
			 			theonclick = Remplace(theonclick,'[I]',i+1);
			 			
			 			noteHtml += theonclick+star+"</a>";
			 		}
			 		
			 		noteHtml = Remplace(noteHtml,'[NOTE]',note);
			 		noteHtml = Remplace(noteHtml,'[NOM]',"moyenne");
			 		noteHtml = Remplace(noteHtml,'[FORMNAME]',formName);	 		
			 			 		
			 		document.getElementById("afficheEtoilemoyenne").innerHTML = noteHtml;
		 			/*
			 		for(var i=0;i<10;i++) {
			 			if(moyenne > i) noteHtml += starOn;
			 			else noteHtml += starOff;
			 		}

		 			document.getElementById("afficheEtoilemoyenne").innerHTML = noteHtml;
		 			*/
		 			
		 		}
	 		}
	 		
	 		}
	 		
}

function fb_publish(message, name, description, caption, picture, link, friends, act, divAjax, form, imageName ) {
	document.images[imageName].src='/images/loading.gif';
	ajaxMe('/ajax/quizz-defiz-form.php','INFB='+INFB+'&act='+act+'&friends='+friends+'&message='+escape(message)+'&name='+escape(name)+'&description='+escape(description)+'&caption='+escape(caption)+'&picture='+escape(picture)+'&link='+escape(link)+'&form='+form,divAjax);
}

// fb_selectFriend(div,id,type)
// type vaut mouseover, mouseout ou click / scope vaut defier ou inviter
function fb_selectFriend(div,id,type,scope) {
	var friendListObj = document.getElementById('fb_friends');
	var friendList = friendListObj.value;
	
	if(friendList == '') friendList = ',';
	
	// id deja selectionné ?
	var inList;
	if(friendList.indexOf(','+id+',') == -1) inList = false;
	else inList = true;
	
	if( (type == 'mouseover') && (!inList) ) div.className = 'barreOverGray';
	if( (type == 'mouseout') && (!inList) ) div.className = 'barreNonActive';
	if( type == 'click' ) {
		// il y est deja, on l'enleve
		if(inList) {
			friendList = Remplace(friendList, ','+id+',' , ',' );
			div.className = 'barreNonActive';
		}
		// il y est pas, on l'ajoute
		else {
			// INVITER : limitation a 15 personnes
			if(scope == 'inviter') {
				var tabAmis = friendList.split(',');
				if(tabAmis.length > 16) {
					alert('Vous ne pouvez pas sélectionner plus de 15 personnes !');
				}
				else {
					friendList = friendList + id+',' ;
					div.className = 'barreActive3';
				}
			}
			else if(scope == 'defier') {
				friendList = friendList + id+',' ;
				div.className = 'barreActive3';
			}
		}
		friendListObj.value=friendList;
				
	}
}

function fb_selectFriends(type) {
	var friendListObj = document.getElementById('fb_friends');
	var friendAllListObj = document.getElementById('fb_all_friends');
	var div;
	var ami;
	
	if(type == 'all') friendListObj.value = friendAllListObj.value;
	else if(type == 'none') friendListObj.value = ',';
	
	// pour chaque amis, on change la class du div correspondant	
	var tabAmis = friendAllListObj.value.split(',');
	for(var x=0;x<tabAmis.length;x++) {
		ami = tabAmis[x];
		if(ami != '') {
			div = document.getElementById('fb_div_'+ami);
			if(type == 'all') div.className = 'barreActive3';
			else if(type == 'none') div.className = 'barreNonActive';
		}
	}
	
}


// addBasket
function addBasket(id) {	
			var form = eval("document.form"+id)
			var option = "";
			
			// va voir si il existe un select pour cet id
			for(var i=0;i<form.length;i++) {
				if(form.elements[i].name == "selectAttributs"+id ) {
					var select = form.elements[i];
					
					option = "&attribut="+encodeURIComponent(select.options[select.selectedIndex].value);
				}
			}
			
			var url = "/boutique.php?id="+id+option;
			
			top.location=url;
			
}

function setFormCommande(nombre,type,go,idDiv) {
	
	if(nombre == "cadeaux") top.location="/cadeaux/index.php";
	else if(nombre == "compte") top.location="/compte/compte.php";
	else ajaxMe('/ajax/utilisation-radiz.php','idDiv='+idDiv+'&nombre='+nombre+'&go='+go+'&type='+type,'divConsoRadiz'+idDiv);										
	
}

function openPodium(login,type,id) {
	// si le meme deja ouvert, on le ferme
	var url;
	var params;
	
	if( document.getElementById('ajaxPodium').innerHTML.indexOf( '<!-- PODIUM '+type+' -->') == -1 ) {
		url='podium.php';
		params="INFB="+INFB+"&id="+id+"&login="+escape(login)+"&type="+escape(type);
	}
	else {
		url='persistence.php';
		params='y=0';
	}
	ajaxMe("/ajax/"+url,params,"ajaxPodium");
}


function getEncartAide(type,act) {
		  ajaxMe('/ajax/encart-aide.php','INFB='+INFB+'&type='+escape(type)+'&act='+act,'aide_'+type);
}

// option=refresf
function getEncartAct(type,act,param1,param2,options) {
		  ajaxMe('/ajax/encart-act.php','INFB='+INFB+'&type='+escape(type)+'&act='+escape(act)+'&param1='+escape(param1)+'&param2='+escape(param2),'act_'+type);
		  if(options == 'refresh') window.setTimeout('refreshDefiBox()',2000);
}

function refreshDefiBox() {
	 ajaxMe('/ajax/recherche-mp.php','INFB='+INFB+'&contextForce=defi&options=recu-non-releve&p=0&search=','divMessages');
}

function showMoreSuggestions(type,objet,limit,id) {
	 ajaxMe('/ajax/show-suggestions.php','INFB='+INFB+'&type='+type+'&objet='+objet+'&limit='+limit+'&id='+id,'divMoreSuggestions');
}

function activeSuggestions(nom,checked,divName) {
	ajaxMe('/ajax/active-suggestions.php','INFB='+INFB+'&type='+nom+'&checked='+checked,divName);		
}		
		
function changeClassActive(td, theClass) {
	if(td.className != 'barreActive2') td.className = theClass;
}

function changeClassActiveBarre(td, theClass) {
	if(td.className != 'barreActive') td.className = theClass;
}

function isdefined(variable) { 
	if(typeof(variable) !="undefined") return true; 
	else return false; 
} 

function inscriptionTirage(idScore,idConc,formName) {
	if(!isdefined(INFB)) var INFB=0;
	 
	var form = document.forms[formName];
	//alert(idScore+","+idConc+","+form);
	var nom = form.elements["nom"+idConc];
	var prenom = form.elements["prenom"+idConc];
	var email = form.elements["email"+idConc];
			
	//alert(nom);
	if(prenom.value == '') { alert("Le Prénom est obligatoire !");prenom.focus();return false;}
	else if(nom.value == '') { alert("Le Nom est obligatoire !");nom.focus();return false;}
	else if(email.value == '') { alert("L'adresse Email est obligatoire !");email.focus();return false;}
	else if (email.value.indexOf("@") == -1 || email.value.indexOf(".") == -1) { alert("Email invalide !");email.focus();return false;}
	else ajaxMe('/ajax/cadeaux-inscription-tirage.php','INFB='+INFB+'&idScore='+idScore+'&idConc='+idConc+'&nom='+escape(nom.value)+'&prenom='+escape(prenom.value)+'&email='+escape(email.value),'inscriptionTirage'+idConc);
}

function affActions(id) {
	if(currentDivAction != '') {
		hiddeLayer2('actions_'+currentDivAction);
	}
   showLayer2('actions_'+id);
   currentDivAction=id;
}

function affResumeQuizz(id) {
	if(currentDivAction != '') {
		hiddeLayer2('q_'+currentDivAction);
	}
   showLayer2('q_'+id);
   currentDivAction=id;
}

function activeAlerte(nom,checked,param1,divName) {
	ajaxMe('/ajax/active-alerte.php','INFB='+INFB+'&type='+nom+'&checked='+checked+'&param1='+param1+'&div='+divName,divName);
}

function checkLogin(login) {
	ajaxMe('/ajax/check-input.php','type=login&value='+escape(login),'ajaxCheckLogin');
}

function checkEmail(email) {
	ajaxMe('/ajax/check-input.php','type=email&value='+escape(email),'ajaxCheckEmail');
}

function checkPass1(pass1,login) {
	ajaxMe('/ajax/check-input.php','type=password&value='+escape(pass1)+'&value2='+escape(login),'ajaxCheckPass1');
}
				
function checkPass2(pass1,pass2) {
	ajaxMe('/ajax/check-input.php','type=confirmpass&value='+escape(pass1)+'&value2='+escape(pass2),'ajaxCheckPass2');
}

function inscriptionComplete2() {
	var theform = document.forms["questionnaire"];

  	var selectJour = theform.selectJour.options[theform.selectJour.selectedIndex].value;
  	var selectMois = theform.selectMois.options[theform.selectMois.selectedIndex].value;
  	var selectAnnee = theform.selectAnnee.options[theform.selectAnnee.selectedIndex].value;
  	
  	var suggestions = "";
  	if(theform.suggestions.checked) suggestions = 1;
  	
  	var diffusion = "";
  	if(theform.diffusion.checked) diffusion = "on";
  	
  	var bons_plans = "";
  	if(theform.bons_plans.checked) bons_plans = "on";
   	
  	var genre = "";
  	if(theform.genre[0].checked) genre = "femme"; 	
	else if(theform.genre[1].checked) genre = "homme"; 
	
	ajaxMe("/compte/inscription.php","INFB="+INFB+"&act=ajax&inscriptionconfirmee="+escape(theform.inscriptionconfirmee.value)+"&selectJour="+escape(selectJour)+"&selectMois="+escape(selectMois)+"&selectAnnee="+selectAnnee+"&url="+escape(theform.url.value)+"&suggestions="+escape(suggestions)+"&diffusion="+diffusion+"&bons_plans="+bons_plans+"&genre="+genre,"ajax_inscription_0");
}

function inscriptionComplete() {
	var theform = document.forms["questionnaire"];
  	var country = theform.country.options[theform.country.selectedIndex].value;
  	var lang = theform.lang.options[theform.lang.selectedIndex].value;
  	var newsletter = "";
  	if(theform.newsletter.checked) newsletter = 1;

	ajaxMe("/compte/inscription.php","INFB="+INFB+"&act=ajax&inscription="+escape(theform.inscription.value)+"&email="+escape(theform.email.value)+"&pseudo="+escape(theform.pseudo.value)+"&password="+escape(theform.password.value)+"&country="+escape(theform.country.value)+"&lang="+escape(theform.lang.value)+"&newsletter="+escape(newsletter)+"&code="+escape(theform.code.value),"ajax_inscription");
}

function cacherAvis(idQuizz,idAvis,act,off,theOption) {
	ajaxMe("/ajax/getBarre.php","INFB="+INFB+"&act="+act+"&id_avis="+idAvis+"&id="+idQuizz+"&off="+off+"&option="+theOption,"barre_result");
}

function preloadImg() {
  var args = preloadImg.arguments; 
  imgs = new Array();
  for(x=0; x < args.length; x++) {
    imgs[x] = new Image();
    imgs[x].src = args[x];
  }
}

function escapeMe(text) {
	var text2 = escape(text);
	text2 = Remplace(text2,"+",";plus;");
	return text2;
}
		
preloadImg('/images/infobulle/1.png','/images/infobulle/2.png','/images/infobulle/3.png','/images/infobulle/4.png','/images/infobulle/hori1.png','/images/infobulle/hori2.png','/images/infobulle/verti1.png','/images/infobulle/verti2.png');
