function getXhr()
{
	var xhr = null; 
	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 
	{ 
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest"); 
		xhr = false; 
	} 
	return xhr;
}

function replaceInUri(uri, param, value)
{
	//echo '<br>uri='.$uri.' param='.$param.' value='.$value;
	if ((pos = uri.indexOf("?")) < 0)
	{
		//Aucun param
		//echo '<br>1-'.$uri.'?'.$param.'='.$value;
		return uri+"?"+param+"="+value;
	}

	if ((pos = uri.indexOf("?"+param+"=")) < 0)
	{
		//Pas ?param
		if ((pos = uri.indexOf("&"+param+"=")) < 0)
		{
			//echo '<br>2-'.$uri.'&'.$param.'='.$value;
			return uri+"&"+param+"="+value;
		}
		else
		{
			//&param
			//echo '<br>param pos='.$pos;
			tmp = "&";
		}
	}
	else
	{
		//?param
		//echo '<br>param pos='.$pos;
		tmp = "?";
	}

	if ((pos2 = uri.indexOf("&", pos + 1)) < 0)
	{
		//Dernier param
		//echo '<br>3-'.substr($uri, 0, $pos).$tmp.$param.'='.$value;
		return uri.substr(0, pos)+tmp+param+"="+value;
	}
	else
	{
		//Pas dernier param
		//echo '<br>param suivant pos='.$pos2;
		//echo '<br>4-'.substr($uri, 0, $pos).$tmp.$param.'='.$value.substr($uri, $pos2);
		return uri.substr(0, pos)+tmp+param+"="+value+uri.substr(pos2);
	}
}
	
function replaceInCurrentUri(param, value)
{
	return replaceInUri(window.location.href, param, value);
}	

function addInFavorites()
{
 	if (window.sidebar) 
	{ 
		window.sidebar.addPanel('Sortir entre Filles', 'http://www.sortirentrefilles.com', ''); 
	} 
	else if( document.all ) 
	{ 
		window.external.AddFavorite('http://www.sortirentrefilles.com', 'Sortir entre Filles'); 
	} 
}

function checknewsaccueil(check) 
{
	//accueil_xxx_check
	
	//alert("checknewsaccueil "+check.name+" "+check.checked);
	pos = check.name.indexOf("_")+1; 
	pos2 = check.name.indexOf("_", pos); 
	name = "tr_accueil_"+check.name.substring(pos, pos2); 
	
	if (check.checked == true)
	{
		showtr(name); 
	}
	else
	{
		hidetr(name);
	}
}

function highlight(id, text)
{
	var obj = getMyElementById(id);
	
	if (!text)
	{
		text = getText(id); 
	}
	
	var speed = 50;
	var hex = new Array("00","14","28","3C","50","64","78","8C","A0","B4","C8","DC","F0");
	var r=1;
	var g=1;
	var b=1;
	var seq=1;

	function changetext()
	{
		color = "#" + hex[r] + hex[g] + hex[b];
		obj.style.color = color;
	}
	
	var timer = setInterval(function change()
	{
		if (seq==6)
		{
			b--;
			if (b==0)
				seq=1;
		}
		
		if (seq==5)
		{
			r++;
			if (r==12)
				seq=6;
		}
		
		if (seq==4)
		{
			g--;
			if (g==0)
				seq=5;
		}
		
		if (seq==3)
		{
			b++;
			if (b==12)
				seq=4;
		}
		
		if (seq==2)
		{
			r--;
			if (r==0)
				seq=3;
		}
		
		if (seq==1)
		{
			g++;
			if (g==12)
				seq=2;
		}
		
		changetext();
	}, speed);
}

function convertEmoticons(text)
{
	if (text)
	{
		var tab_emoticons = new Array();
		tab_emoticons[':sourire:'] = 'Sourire';
		tab_emoticons[':rire:'] = 'Rire';
		tab_emoticons[':lol:'] = 'Mort de rire';
		tab_emoticons[':salut:'] = 'Salut !';
		tab_emoticons[':clin:'] = 'Clin d\'oeil';
		tab_emoticons[':moque:'] = 'Moqueur';
		tab_emoticons[':super:'] = 'Super !';
		tab_emoticons[':langue:'] = 'Tire la langue';
		tab_emoticons[':star:'] = 'Fait sa star';
		tab_emoticons[':yes:'] = 'Yes !';
		tab_emoticons[':baille:'] = 'Baille';
		tab_emoticons[':honte:'] = 'Honteux';
		tab_emoticons[':decu:'] = 'Déçu';
		tab_emoticons[':pleure:'] = 'Pleure';
		tab_emoticons[':hallu:'] = 'Hallucine';
		tab_emoticons[':malade:'] = 'Malade';
		tab_emoticons[':mechant:'] = 'Méchant';
		tab_emoticons[':mecontent:'] = 'Mécontent';
		tab_emoticons[':nonnon:'] = 'Non ! Non ! Non !';
		tab_emoticons[':enerve:'] = 'Enervé';

		pos = 1;

		for (emoticon in tab_emoticons)
		{
			var regex = new RegExp(emoticon, "g");
			text = text.replace(regex, '<img src="http://www.sortirentrefilles.com/img/emoticons/simple/'+pos+'.gif" alt="'+tab_emoticons[emoticon]+'" border="0"/>');
			pos++;			
		}
	}
	
	if (!text)
		text = ''; 
		
	return text;
}

function log(text)
{
	setTextHtml('log', getTextHtml('log') + '<br>' + text);
}
