	/****************************************************************************************************/
	/*																									*/
	/*    Copyright : Green Elven Studio 2004															*/
	/*    Nom du fichier : fxSite.js																	*/
	/*    Version : 2.0.1																				*/
	/*    Auteur : pAPanoEL (papanoel@free.fr)															*/
	/*    Date création : 01/02/2003																	*/
	/*    Modificateur : Cap'tain Caverne																*/
	/*    Date modification : 30/10/2004																*/
	/*    Paramètres : aucun																			*/
	/*    Decription : fonctions js pour le site														*/
	/*																									*/
	/****************************************************************************************************/

	// insertion d'une balise à l'emplacement du curseur - par Freekill (freekill.free.fr)
	function countInstances(open,closed,champ) 
		{ 
		var opening = document.getElementById(champ).value.split(open); 
		var closing = document.getElementById(champ).value.split(closed); 
		return opening.length + closing.length - 2; 
		}
	
	function TAinsert(text1,text2,champ)
		{
		var ta = document.getElementById(champ);

		if (document.selection)
			{
			var str = document.selection.createRange().text;
			ta.focus();
			var sel = document.selection.createRange();
			if (text2!="")
				{ 
				if (str=="") 
					{ 
					var instances = countInstances(text1,text2,champ); 
					if (instances%2 != 0)
						{
						sel.text = sel.text + text2;
						}
					else
						{
						sel.text = sel.text + text1;
						}
					} 
				else
					{
					sel.text = text1 + sel.text + text2;
					}
				}
			else
				{
				sel.text = sel.text + text1;
				}
			}
		else if (ta.selectionStart || ta.selectionStart == 0)
			{
			if (ta.selectionEnd > ta.value.length)
				{
				ta.selectionEnd = ta.value.length;
				}

			var firstPos = ta.selectionStart;
			var secondPos = ta.selectionEnd+text1.length;
			var contenuScrollTop = ta.scrollTop;

			ta.value=ta.value.slice(0,firstPos)+text1+ta.value.slice(firstPos);
			ta.value=ta.value.slice(0,secondPos)+text2+ta.value.slice(secondPos);

			ta.selectionStart = firstPos+text1.length;
			ta.selectionEnd = secondPos;
			ta.focus();
			ta.scrollTop = contenuScrollTop;
			}
		else
			{ // Opera
			var sel = document.hop.contenu;
			var instances = countInstances(text1,text2,champ);
			if (instances%2 != 0 && text2 != "")
				{
				sel.value = sel.value + text2;
				}
			else
				{
				sel.value = sel.value + text1;
				}
			}
		}


	// Affichage d'une barre de couleur (color picker)
	// repris sur les forums MD.net
	// Pour usage non commercial (duh)
	col0=new Array(255,255,0,255,0,0);
	col1=new Array(255,0,255,255,0,0);
	col2=new Array(0,0,255,0,0,255);
	col3=new Array(0,255,0,0,255,0);

	var base_hexa="0123456789ABCDEF";
	function dec2Hexa(number)
		{
		return base_hexa.charAt(Math.floor(number / 16)) + base_hexa.charAt(number % 16);
		}

	function RGB2Hexa(TR,TG,TB)
		{
		return "#" + dec2Hexa(TR) + dec2Hexa(TG) + dec2Hexa(TB);
		}

	function lightCase(MyObject)
		{
		document.getElementById('ColorUsed').bgColor=document.getElementById(MyObject).bgColor;
		document.getElementById('ColorUsed').style.backgroundColor=document.getElementById(MyObject).bgColor;
		document.getElementById('ColorUsedMem').value=document.getElementById(MyObject).bgColor;
		}

	function highlightCase(MyObject)
		{
		document.getElementById('ColorUsed').bgColor=document.getElementById(MyObject).bgColor;
		document.getElementById('ColorUsed').style.backgroundColor=document.getElementById(MyObject).bgColor;
		}

	function backlightCase(MyObject)
		{
		document.getElementById('ColorUsed').bgColor=document.getElementById('ColorUsedMem').value;
		document.getElementById('ColorUsed').style.backgroundColor=document.getElementById('ColorUsedMem').value;
		}

	function rgb(dm,ta,index,img,explication,champ)
		{
		fm=dm + 18;
		for (i=dm;i<fm+1;i++)
			{
			r=Math.floor(ta[0] + (i-dm)*(ta[1]-ta[0])/(fm-dm));
			g=Math.floor(ta[2] + (i-dm)*(ta[3]-ta[2])/(fm-dm));
			b=Math.floor(ta[4] + (i-dm)*(ta[5]-ta[4])/(fm-dm));
			codehex=dec2Hexa(r) + '' + dec2Hexa(g) + '' + dec2Hexa(b);
			codehexB= '#'+codehex;
			document.write('<td style="cursor:pointer; padding:0px; width:3px; background-color:'+codehexB+'" onclick="TAinsert(\'[color=\'+document.getElementById(\'tableId'+index+'\').bgColor+\']\',\'[/color]\',\''+champ+'\');lightCase(\'tableId'+index+'\');\" onmouseover=\"highlightCase(\'tableId'+index+'\');" onmouseout="backlightCase();" id="tableId'+index+'" bgcolor="'+RGB2Hexa(r,g,b)+'" width="3" height="17"><img title="'+explication+' : [#'+codehex+']texte[/#'+codehex+']" src="'+img+'" alt="" width="3" height="17"/></td>\n');
			index++;
			}
		}
		
	// affichage des spoiler
	function spoil(champ)
		{
		document.getElementById(champ).style.display = (document.getElementById(champ).style.display == 'block') ? 'none' : 'block';
		}

	function getXhr()
		{
		if(window.XMLHttpRequest) // Firefox et autres
			xhr = new XMLHttpRequest(); 
		else if(window.ActiveXObject)
			{ // Internet Explorer
			try
				{
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
				}
			catch (e)
				{
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
				}
			}
		else
			{ // XMLHttpRequest non supporté par le navigateur 
			alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
			xhr = false; 
			} 
		return xhr;
		}

	// fonction qui exécute une requête Ajax
	// url : le lien a balancer, data : les paramètres, hashloc : où on doit repositionner la page, num : le logo à afficher
	function doXhr(url,data,hashloc,num)
		{
		num = typeof(num) != 'undefined' ? num : 1;

		xhr = getXhr();
		xhr.open("POST", url, true);
		xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xhr.onreadystatechange = function()
			{
			if (xhr.readyState == 4)
				{
				eval(xhr.responseText);
				if (hashloc != "") document.location.hash = hashloc;
				}
			else
				{
				if (hashloc != "")
					{
					document.getElementById(hashloc).innerHTML = '<p style="text-align:center; font-size:11px">Chargement en cours...<br /><img src="/images/site/wait'+ num +'.gif" /></p>';
					document.location.hash = hashloc;
					}
				}
			}
		xhr.send(data);
		}

	// prévisualisation d'un message avant envoi
	function previsu()
		{
		x = document.getElementById("mess").value;
		x = x.replace(/[+]/gi,"xaddsignx");
		x = encodeURIComponent(x);
		var url = "/forum/previsu.php";
		var data = "hash=" + Math.random() + "&txt=" + x;
		doXhr(url,data,"");
		}
		
	// création d'un message instantané
	function newMess(id)
		{
		posX = (screen.width - 600)/2;
		posY = (screen.height - 500)/2;
		winName = window.open('newmess-' + id + '.html','','left='+ posX +',top='+ posY +',screenX='+ posX +',screenY='+ posY +',toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=500');
		winName.focus();
		}

	// affichage d'un message instantané
	function viewMess(id)
		{
		posX = (screen.width - 600)/2;
		posY = (screen.height - 500)/2;
		winName = window.open('viewmess-' + id + '.html','','left='+ posX +',top='+ posY +',screenX='+ posX +',screenY='+ posY +',toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=yes,width=600,height=500');
		winName.focus();
		}
		
	// action sur une qté
	function mod(id,varia)
		{
		var zone = document.getElementById("zone").value;
		var url = "trait.php";
		var data = "hash=" + Math.random() + "&trait=mod&id=" + id + "&varia=" + varia + "&zone=" + zone;
		doXhr(url,data,"");
		}
	
	// annulation de commande
	function cancel(id)
		{
		result = confirm('\312tes-vous s\373r de vouloir annuler cette commande ?');
		if (result == 1)
			{
			self.location.href = "order_cancel_" + id + ".html";
			}
		}
		
	// activation de l'adresse bis
	function valAdrBis()
	{
		var fields = new Array("nom","prenom","adresse","adresse2","codePostal","ville","pays");
		if (document.getElementById("chkAdrBis").checked)
		{
			document.getElementById("adrBis").style.display = "block";
			for(i=0;i<7;i++)
			{
				document.getElementById(fields[i]+ "Alt").disabled = false;
			}
		}
		else
		{
			document.getElementById("adrBis").style.display = "none";
			for(i=0;i<7;i++)
			{
				document.getElementById(fields[i]+ "Alt").disabled = true;
			}
		}
	}
	