// Startup variables
var imageTag = false;
var theSelection = false;
// Check for Browser & Platform for PC & IE specific bits
// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version
var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
&& (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
&& (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
var is_moz = 0;
var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac = (clientPC.indexOf("mac")!=-1);
// Helpline messages
b_help = "Texte gras: [b]texte[/b]  (alt+b)";
i_help = "Texte italique: [i]texte[/i]  (alt+i)";
u_help = "Texte souligné: [u]texte[/u]  (alt+u)";
q_help = "Citation: [quote]texte cité[/quote]  (alt+q)";
c_help = "Afficher du code: [code]code[/code]  (alt+c)";
l_help = "Liste: [list]texte[/list]  (alt+l)";
o_help = "Liste ordonnée: [list=]texte[/list]  (alt+o)";
p_help = "Insérer une image: [img]http://image_url/[/img]  (alt+p)";
w_help = "Insérer un lien: [url]http://url/[/url] ou [url=http://url/]Nom[/url]  (alt+w)";
a_help = "Fermer toutes les balises BBCode ouvertes";
s_help = "Couleur du texte: [color=red]texte[/color]  Astuce: #FF0000 fonctionne aussi";
f_help = "Taille du texte: [size=x-small]texte en petit[/size]";
k_help = "Texte Défilant: [scroll]texte[/scroll]  (alt+k)";
e_help = "Texte Pâle: [fade]texte[/fade]  (alt+e)";
r_help = "Texte Flou: [blur]texte[/blur]  (alt+r)";
j_help = "Texte Renversé: [flipv]texte[/flipv]  (alt+v)";
v_help = "Texte Renversé: [fliph]texte[/fliph]  (alt+j)";
d_help = "Texte défilant de haut en bas: [updown]texte[/updown]  (alt+d)";
t_help = "Texte centré: [center]texte[/center]  (alt+t)";
g_help = "Texte aligné à droite: [right]texte[/right]  (alt+g)";
x_help = "Texte barré: [strike]texte[/strike]  (alt+x)";
y_help = " Insérer une image ";
z_help = "Insérer une émoticon dans votre message";
h_help = "Texte visible par ceux qui ont posté dans ce sujet : [hide]texte[/hide] (alt+h)";
sp_help = "Texte caché et affiché en cliquant dessus: [spoiler]texte[/spoiler] (alt+o) ";
_help = "";

// Define the bbCode tags
bbcode = new Array();
bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[quote]','[/quote]','[code]','[/code]','[list]','[/list]','[list=]','[/list]','[img]','[/img]','[url]','[/url]','[scroll]','[/scroll]','[fade]','[/fade]','[blur]','[/blur]','[flipv]','[/flipv]','[fliph]','[/fliph]','[updown]','[/updown]','[center]','[/center]','[right]','[/right]','[strike]','[/strike]','[embed-flash(width,height)]','[/embed-flash]');
bbtags[40] = '[hide]';
bbtags[41] = '[/hide]';
bbtags[42] = '[spoiler]';
bbtags[43] = '[/spoiler]';

imageTag = false;
// Shows the help messages in the helpline window
function helpline(help) {
	document.post.helpbox.value = eval(help + "_help");
}
// Replacement for arrayname.length property
function getarraysize(thearray) {
	for (i = 0; i < thearray.length; i++) {
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
		return i;
	}
	return thearray.length;
}
// Replacement for arrayname.push(value) not implemented in IE until version 5.5
// Appends element to the array
function arraypush(thearray,value) {
	thearray[ getarraysize(thearray) ] = value;
}
// Replacement for arrayname.pop() not implemented in IE until version 5.5
// Removes and returns the last element of an array
function arraypop(thearray) {
	thearraysize = getarraysize(thearray);
	retval = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	return retval;
}
function checkForm() {
	formErrors = false;
	if (document.post.message.value.length < 3) {
		formErrors = "Vous devez entrer un message avant de poster.";
	}
	if (formErrors) {
		return false;
	} else {
		bbstyle(-1);
		//formObj.preview.disabled = true;
		//formObj.submit.disabled = true;
		return true;
	}
}
function emoticon(text) {
	var txtarea = document.post.message;
	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
		txtarea.focus();
	} else {
		txtarea.value  += text;
		txtarea.focus();
	}
}
// Emoticons : Frame
function emoticonp(text) {
	text = ' ' + text + ' ';
	if (parent.document.forms['post'].message.createTextRange && parent.document.forms['post'].message.caretPos) {
		var caretPos = parent.document.forms['post'].message.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		parent.document.forms['post'].message.focus();
	} else {
		parent.document.forms['post'].message.value  += text;
		parent.document.forms['post'].message.focus();
	}
}
// Emoticons : Window
function emoticonw(text) {
	text = ' ' + text + ' ';
	if (opener.document.forms['post'].message.createTextRange && opener.document.forms['post'].message.caretPos) {
		var caretPos = opener.document.forms['post'].message.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		opener.document.forms['post'].message.focus();
	} else {
		opener.document.forms['post'].message.value  += text;
		opener.document.forms['post'].message.focus();
	}
}
function bbfontstyle(bbopen, bbclose) {
	var txtarea = document.post.message;
	if ((clientVer >= 4) && is_ie && is_win) {
		theSelection = document.selection.createRange().text;
		if (!theSelection) {
			txtarea.value += bbopen + bbclose;
			txtarea.focus();
			return;
		}
		document.selection.createRange().text = bbopen + theSelection + bbclose;
		txtarea.focus();
		return;
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, bbopen, bbclose);
		return;
	}
	else
	{
		txtarea.value += bbopen + bbclose;
		txtarea.focus();
	}
	storeCaret(txtarea);
}
function bbstyle(bbnumber) {
	var txtarea = document.post.message;
	donotinsert = false;
	theSelection = false;
	bblast = 0;
	if (bbnumber == -1) { // Close all open tags & default button names
	while (bbcode[0]) {
		butnumber = arraypop(bbcode) - 1;
		txtarea.value += bbtags[butnumber + 1];
		buttext = eval('document.post.addbbcode' + butnumber + '.value');
		eval('document.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
	}
	imageTag = false; // All tags are closed including image tags :D
	txtarea.focus();
	return;
	}
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text; // Get text selection
		if (theSelection) {
			// Add tags around selection
			document.selection.createRange().text = bbtags[bbnumber] + theSelection + bbtags[bbnumber+1];
			txtarea.focus();
			theSelection = '';
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, bbtags[bbnumber], bbtags[bbnumber+1]);
		return;
	}
	// Find last occurance of an open tag the same as the one just clicked
	for (i = 0; i < bbcode.length; i++) {
		if (bbcode[i] == bbnumber+1) {
			bblast = i;
			donotinsert = true;
		}
	}
	if (donotinsert) {		// Close all open tags up to the one just clicked & default button names
	while (bbcode[bblast]) {
		butnumber = arraypop(bbcode) - 1;
		txtarea.value += bbtags[butnumber + 1];
		buttext = eval('document.post.addbbcode' + butnumber + '.value');
		eval('document.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
		imageTag = false;
	}
	txtarea.focus();
	return;
	} else { // Open tags
	if (imageTag && (bbnumber != 14)) {		// Close image tag before adding another
	txtarea.value += bbtags[15];
	lastValue = arraypop(bbcode) - 1;	// Remove the close image tag from the list
	document.post.addbbcode14.value = "Img";	// Return button back to normal state
	imageTag = false;
	}
	// Open tag
	txtarea.value += bbtags[bbnumber];
	if ((bbnumber == 14) && (imageTag == false)) imageTag = 1; // Check to stop additional tags after an unclosed image tag
	arraypush(bbcode,bbnumber+1);
	eval('document.post.addbbcode'+bbnumber+'.value += "*"');
	txtarea.focus();
	return;
	}
	storeCaret(txtarea);
}
// From http://www.massless.org/mozedit/
function mozWrap(txtarea, open, close)
{
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2)
	selEnd = selLength;
	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1 + open + s2 + close + s3;
	return;
}
// Insert at Claret position. Code from
// http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

// ---------------

function showhide(vari) {
	if (vari.style.display=="none") {
		vari.style.display="";
	} else {
		vari.style.display="none";
	}
}

function insert_search_menu(session_id) {
	session_input = (session_id ? '<input type="hidden" name="sid" value="'+session_id+'" />' : '');
	session_id = (session_id ? '?sid='+session_id : '');
	document.write('<div id="search_menu" style="display:none;position:absolute"><form action="/search.forum" method="get"><table class="forumline" cellpadding="3" cellspacing="0" border="0"><tr><th class="thHead">Rechercher</th></tr><tr><td class="row2" align="center"><input type="text" class="post" name="search_keywords" size="24" /> <input type="submit" class="button" value="Go" /></td></tr><tr><td class="row2" align="center" nowrap="nowrap"><span class="genmed">&nbsp;Résultats par : &nbsp; <input id="rposts" type="radio" name="show_results" value="posts" /><label for="rposts">&nbsp;Messages</label> <input id="rtopics" type="radio" name="show_results" value="topics" checked="checked" /><label for="rtopics">&nbsp;Sujets</label>&nbsp;</td></tr><tr><td class="row2" align="center"><span class="genmed"><hr><a href="/search.forum'+session_id+'"><img src="http://illiweb.com/fa/icon_mini_search.gif" width="12" height="13" border="0" hspace="3" />&nbsp;Recherche avancée</a><span></td></tr></table>'+session_input+'</form></div>');
}

function insert_search_menu_new(session_id) {
	session_input = (session_id ? '<input type="hidden" name="sid" value="'+session_id+'" />' : '');
	session_id = (session_id ? '?sid='+session_id : '');
	document.write('<div class="overview row3" id="search_menu" style="display:none;position:absolute;width: 350px;"><form action="/search.forum" method="get"><p class="title-overview row2">Rechercher</p><p class="center-overview"><input type="text" class="inputbox medium" name="search_keywords" />'+session_input+'<input type="submit" class="button1" value="Go" /><br />Résultats par :  <label for="rposts"><input id="rposts" type="radio" name="show_results" value="posts" /> Messages</label> <label for="rtopics"><input id="rtopics" type="radio" name="show_results" value="topics" checked="checked" /> Sujets</label></p><hr class="dashed" /><p class="center-overview"><a href="/search.forum'+session_id+'"><img src="http://illiweb.com/fa/icon_mini_search.gif" width="12" height="13" alt="" /> Recherche avancée</a></p>'+session_input+'</form></div>');
}

function insert_plus_menu(search_where,session_id) {
	search_where = '&amp;search_where='+search_where;
	session_id = (session_id ? '&amp;sid='+session_id : '');
	document.write('<a href="javascript:showhide(document.getElementById(\'plus_menu\'))">Plus !</a><br><div id="plus_menu" style="display:none;position:absolute;right:9px"><table class="forumline" cellpadding="3" cellspacing="0" border="0"><tr><th class="thHead">Plus !</th></tr><tr><td class="row1" nowrap="nowrap"><span class="gensmall"><b><a href="/search.forum?search_id=newposts'+search_where+session_id+'">Voir les nouveaux messages depuis votre dernière visite</a><br><a href="/search.forum?search_id=egosearch'+search_where+session_id+'">Voir ses messages</a><br><a href="/search.forum?search_id=unanswered'+search_where+session_id+'">Voir les messages sans réponses</a><br><a href="/search.forum?search_id=watchsearch'+search_where+session_id+'">Sujets surveillés</a><br><hr><a href="/tell_friend.forum?f='+search_where+session_id+'">Envoyer à un ami</a><br><a href="'+self.location.href+'" onclick="link_bbcode();return false">Copier l’adresse BBCode de la page</a></b></span></td></tr></table></div>');
}

function insert_plus_menu_new(search_where,session_id) {
	search_where = '&amp;search_where='+search_where;
	session_id = (session_id ? '&amp;sid='+session_id : '');
	document.write('<a href="javascript:showhide(document.getElementById(\'plus_menu\'))">Plus !</a><br /><div class="overview row3" id="plus_menu" style="display:none;position:absolute;width:400px;right:20px;margin-top: 8px;z-index:10;"><p class="title-overview row2"><strong>Plus !</strong></p><p class="left-overview"><strong><a href="/search.forum?search_id=newposts'+search_where+session_id+'">Voir les nouveaux messages depuis votre dernière visite</a><br /><a href="/search.forum?search_id=egosearch'+search_where+session_id+'">Voir ses messages</a><br /><a href="/search.forum?search_id=unanswered'+search_where+session_id+'">Voir les messages sans réponses</a><br /><a href="/search.forum?search_id=watchsearch'+search_where+session_id+'">Sujets surveillés</a><br /></strong></p><hr class="dashed" /><p class="left-overview"><strong><a href="/tell_friend.forum?f='+search_where+session_id+'">Envoyer à un ami</a><br /><a href="'+self.location.href+'" onclick="link_bbcode();return false">Copier l’adresse BBCode de la page</a></strong></p></div>');
}

function insert_plus_album(search_where,session_id) {
	session_id = (session_id ? '&amp;sid='+session_id : '');
	document.write('<a href="javascript:showhide(document.getElementById(\'plus_menu\'))">Plus !</a><br><div id="plus_menu" style="display:none;position:absolute;right:100px"><table class="forumline" cellpadding="3" cellspacing="0" border="0"><tr><th class="thHead">Plus !</th></tr><tr><td class="row1" nowrap="nowrap"><span class="gensmall"><b><a href="/tell_friend.forum?album='+search_where+session_id+'">Envoyer à un ami</a></b></span></td></tr></table></div>');
}

function insert_plus_album_new(search_where,session_id) {
	session_id = (session_id ? '&amp;sid='+session_id : '');
	document.write('<a href="javascript:showhide(document.getElementById(\'plus_menu\'))">Plus !</a><br /><div class="overview row3" id="plus_menu" style="display:none;margin: 8px 20px 0px 0px;position:absolute;right:20px;width: 200px;"><p class="title-overview row2">Plus !</p><p class="left-overview"><strong><a href="/tell_friend.forum?album='+search_where+session_id+'">Envoyer à un ami</a></strong></p></div>');
}

function insert_plus_pic(search_where,session_id) {
	session_id = (session_id ? '&amp;sid='+session_id : '');
	document.write('<a href="javascript:showhide(document.getElementById(\'plus_menu\'))">Plus !</a><br><div id="plus_menu" style="display:none;position:absolute;right:100px"><table class="forumline" cellpadding="3" cellspacing="0" border="0"><tr><th class="thHead">Plus !</th></tr><tr><td class="row1" nowrap="nowrap"><span class="gensmall"><b><a href="/tell_friend.forum?pic='+search_where+session_id+'">Envoyer à un ami</a></b></span></td></tr></table></div>');
}

function insert_plus_pic_new(search_where,session_id) {
	session_id = (session_id ? '&amp;sid='+session_id : '');
	document.write('<a href="javascript:showhide(document.getElementById(\'plus_menu\'))">Plus !</a><br /><div class="overview row3" id="plus_menu" style="display:none;position:absolute;right:20px;margin-top:20px;"><p class="title-overview row2">Plus !</p><p class="left-overview"><strong><a href="/tell_friend.forum?pic='+search_where+session_id+'">Envoyer à un ami</a></strong></p></div>');
}

function link_bbcode() {
	intext = "[url="+self.location.href+"]"+window.document.title+"[/url]";
	if(document.all && !window.opera)
	{
		window.clipboardData.setData('Text', intext);
	}
	else
	{
		prompt('',intext);
	}
}

function ShowHideLayer(layer_open, layer_close) {
	if (layer_open != '') {
		expandLayer(layer_open);
	}
	if (layer_close != '') {
		expandLayer(layer_close);
	}
}

function ShowHideMenu(layer_open, layer_close, page_id, new_class) {
    if (layer_open != '') {
		expandLayer(layer_open);
	}
    
	if (layer_close != '') {
		expandLayer(layer_close);
	}
    
    if (document.getElementById(page_id).className == new_class)
    {
        document.getElementById(page_id).className = '';
    }
    else
    {
        document.getElementById(page_id).className = new_class;
    }
    
}

function expandLayer(name) {
	var itm = null;

	if (document.getElementById) {
		itm = document.getElementById(name);
	} else if (document.all) {
		itm = document.all[name];
	} else if (document.layers) {
		itm = document.layers[name];
	}

	if (!itm) {
		// Just don't panik, it's ok
	} else if (itm.style) {
		if (itm.style.display == "none") {
			itm.style.display = "";
		} else {
			itm.style.display = "none";
		}
	} else {
		itm.visibility = "show";
	}
}

function fa_endpage() {
	if (parent.wbo1_ferme) wbo1_ferme();
	//if (parent.slide_close) slide_close();
}

function hdr_ref(object)
{
	if (document.getElementById)
	{
		return document.getElementById(object);
	}
	else if (document.all)
	{
		return eval('document.all.' + object);
	}
	else
	{
		return false;
	}
}

function hdr_expand(object)
{
	var object = hdr_ref(object);

	if( !object.style )
	{
		return false;
	}
	else
	{
		object.style.display = '';
	}

	if (window.event)
	{
		window.event.cancelBubble = true;
	}
}

function hdr_contract(object)
{
	var object = hdr_ref(object);

	if( !object.style )
	{
		return false;
	}
	else
	{
		object.style.display = 'none';
	}

	if (window.event)
	{
		window.event.cancelBubble = true;
	}
}

function hdr_toggle(object, open_close, open_icon, close_icon)
{
	var object = hdr_ref(object);
	var icone = hdr_ref(open_close);

	if( !object.style )
	{
		return false;
	}

	if( object.style.display == 'none' )
	{
		object.style.display = '';
		icone.src = close_icon;
	}
	else
	{
		object.style.display = 'none';
		icone.src = open_icon;
	}
}

function select_switch_col(nomchamp) {
	for (i=0; i<document.post.length; i++)
	{
		if (document.post.elements[i].name && (document.post.elements[i].name).substring(0,nomchamp.length) == nomchamp && document.post.elements[i].disabled != true)
		{
			document.post.elements[i].checked = !document.post.elements[i].checked;
		}
	}
}


function disabled1(choix,nomchamp) {

	var formulaire = document.getElementById(choix);
	/*
	if ( formulaire.selectedIndex != 2 )
	{
		for (i=0; i<document.post.length; i++)
		{
			if ( (document.post.elements[i].name).substring(0,nomchamp.length) == nomchamp)
			{
				document.post.elements[i].disabled = 'disabled';
			}
		}
	}
	if ( formulaire.selectedIndex == 2 )
	{
		for (i=0; i<document.post.length; i++)
		{
			if ( (document.post.elements[i].name).substring(0,nomchamp.length) == nomchamp)
			{
				document.post.elements[i].disabled = '';
			}
		}
	}
	*/
	for (i=0; i<document.post.length; i++)
	{
		if ( document.post.elements[i].type=='checkbox' && (document.post.elements[i].name).substring(0,nomchamp.length) == nomchamp)
		{
			document.post.elements[i].disabled = ((formulaire.selectedIndex != 2)?'disabled':'');
		}
	}

}

function disabled2(choix,nomchamp) {

	var formulaire = document.getElementById(choix);
	/*
	if ( formulaire.selectedIndex != 1 )
	{
		for (i=0; i<document.post.length; i++)
		{
			if ( (document.post.elements[i].name).substring(0,nomchamp.length) == nomchamp)
			{
				document.post.elements[i].disabled = 'disabled';
			}
		}
	}
	if ( formulaire.selectedIndex == 1 )
	{
		for (i=0; i<document.post.length; i++)
		{
			if ( (document.post.elements[i].name).substring(0,nomchamp.length) == nomchamp)
			{
				document.post.elements[i].disabled = '';
			}
		}
	}
	*/
	for (i=0; i<document.post.length; i++)
	{
		if ( document.post.elements[i].type=='checkbox' && (document.post.elements[i].name).substring(0,nomchamp.length) == nomchamp)
		{
			document.post.elements[i].disabled = ((formulaire.selectedIndex != 1)?'disabled':'');
		}
	}

}

var agt = navigator.userAgent.toLowerCase();
var originalFirstChild;

function createTitle(which, string, x, y)
{
	if (typeof(originalFirstChild) == 'undefined')
	{
		originalFirstChild = document.body.firstChild;
	}
    
	x = document.all ? (window.event.clientX + document.body.scrollLeft) : x;
	y = document.all ? (window.event.clientY + document.body.scrollTop) : y;

	element = document.createElement('div');
	element.style.position = 'absolute';
	element.style.zIndex = 1000;
	element.style.visibility = 'hidden';
	excessWidth = 0;
	if (document.all)
	{
		excessWidth = 50;
	}
	excessHeight = 20;
	element.innerHTML = '<div class="bodyline"><table cellspacing="0" cellpadding="0" border="0"><tr><td><span class="gen">' + string + '</span></td></tr></table></div>';
	renderedElement = document.body.insertBefore(element, document.body.firstChild);
	renderedWidth = renderedElement.offsetWidth;
	renderedHeight = renderedElement.offsetHeight;

	renderedElement.style.top = (y + 10) + 'px';
	renderedElement.style.left = (x + 10) + 'px';

	if (agt.indexOf('gecko') != -1 && agt.indexOf('win') != -1)
	{
		setTimeout("renderedElement.style.visibility = 'visible'", 1);
	}
	else
	{
		renderedElement.style.visibility = 'visible';
	}
}

function destroyTitle()
{
	if (document.body.firstChild != originalFirstChild)
	{
		document.body.removeChild(document.body.firstChild);
	}
}

function my_getcookie( name )
{
	cname = name + '=';
	cpos  = document.cookie.indexOf( cname );

	if ( cpos != -1 )
	{
		cstart = cpos + cname.length;
		cend   = document.cookie.indexOf(";", cstart);

		if (cend == -1)
		{
			cend = document.cookie.length;
		}

		return unescape( document.cookie.substring(cstart, cend) );
	}

	return null;
}

function my_setcookie( name, value, sticky )
{
	expire = "";
	domain = "";
	path   = "/";

	if ( sticky )
	{
		expire = "; expires=Wed, 1 Jan 2020 00:00:00 GMT";
	}

	document.cookie = name + "=" + value + "; path=" + path + expire + domain + ';';
}

function expandAllLayer(name, open_close, layer_open_close) {
	var itm = null;

	if (document.getElementById) {
		itm = document.getElementById(name);
	} else if (document.all) {
		itm = document.all[name];
	} else if (document.layers) {
		itm = document.layers[name];
	}

	if (!itm) {
	} else if (itm.style) {
		if (itm.style.display == "none")
		{
			if( (open_close == "open" && layer_open_close=="open") || (open_close == "close" && layer_open_close=="close") )
			{
				itm.style.display = "";
			}
		}
		else
		{
			if( (open_close == "close" && layer_open_close=="open")  || (open_close == "open" && layer_open_close=="close") )
			{
				itm.style.display = "none";
			}
		}
	}
	else
	{
		itm.visibility = "show";
	}

}

function check(action,formname) {

	var formnamevalue = document.forms[arguments[1]];

	field = formnamevalue.elements.length;
	switch(action)
	{	case "select":	for (i = 0; i < field; i++) {
					formnamevalue.elements[i].checked = true;
				}
				break;
		case "unselect":	for (i = 0; i < field; i++) {
	  				formnamevalue.elements[i].checked = false;
					}
					break;
	}
}

function popUP(mypage, myname, w, h, scroll, titlebar)
{
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no,menubar=no,status=no,toolbar=no'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4)
	{
		win.window.focus();
	}
}

function refresh_username(selected_username) {
	if ( (opener.document.forms['post'].username.value) && (opener.document.forms['post'].ismp) )
	{
		opener.document.forms['post'].username.value = opener.document.forms['post'].username.value + ';' + selected_username;
	}
	else
	{
		opener.document.forms['post'].username.value = selected_username;
	}
	opener.focus();
	window.close();
}

function insertChatBox(chatbox_id, chatbox_url) {
	document.getElementById(chatbox_id).innerHTML = '<iframe src="' + chatbox_url + '" id="frame_chatbox" scrolling="yes" width="100%" height="100%" marginwidth="0" marginheight="0" border="0"></iframe>';
}
function insertChatBoxNew(chatbox_id, chatbox_url) {
	document.getElementById(chatbox_id).innerHTML = '<object data="' + chatbox_url + '" id="frame_chatbox" scrolling="yes" width="100%" height="100%" type="text/html"></object>';
}
function insertChatBoxPopup(chatbox_url, l_chatbox_join) {
	document.getElementById('chatbox_popup').innerHTML = '[ <a href="' + chatbox_url + '" target="ChatBox">' + l_chatbox_join + '</a> ]';
}


/****************************************************
* Function that show a context menu for the chatbox	*
* date : 22/12/2006									*
* author : Vincent									*
****************************************************/
function showMenu (user_id, user_name, my_user_id, my_chat_level, my_user_level, user_chat_level, user_level, event, sid) {
	/* if the context menu is already shown or the user is not connected to the chatbox */
	if (document.getElementById('chatbox_contextmenu'))
	{
		hideMenu();
		return false;
	}
    
    var connected = false;
    if (parent.frames['sender'].document.forms[0].elements["message"])
    {
        connected = true;
    }
	
	/* ------ get mouse info for displaying the menu -------- */
	if (document.all) {
		mouseX = window.event.clientX + document.body.scrollLeft;
		mouseY = window.event.clientY + document.body.scrollTop;
	}
	else {
		mouseX = event.clientX + window.scrollX;
		mouseY = event.clientY + window.scrollY;
	}
	
	if (mouseX > 50)
		mouseX = 50;
	
	/* ---------- create the div of the menu ------------- */
	var div = document.createElement('div');
	div.setAttribute('id', 'chatbox_contextmenu');
	div.style.display = 'block';
	div.style.top = mouseY+'px';
	div.style.left = mouseX+'px';
	div.style.position = 'absolute';
	
	/* ------- create the title of the menu with close button --------- */
	var p = document.createElement('p');
	p.style.textAlign = 'left';
	p.setAttribute('class', 'close');
	p.setAttribute('className', 'close'); 
	var title_name = '  ' + ((user_name.length > 9) ? user_name.substr(0,9)+'...' : user_name);
	
	var close = document.createElement('img');
	close.onclick = new Function ('hideMenu();');
	close.setAttribute('src', 'http://illiweb.com/fa/cross.png');
	close.setAttribute('alt', 'Fermer la fenêtre');
	
	p.appendChild(close);
	p.appendChild(document.createTextNode(title_name));
	
	
	div.appendChild(p);
	
	/* --------- create the see profile link ------------- */
	var p = document.createElement('p');
	p.onmouseover = new Function ('this.className="hover";');
	p.onmouseout = new Function ('this.className="";');
	var link = document.createElement('a');
	link.appendChild(document.createTextNode("Voir le profil"));
	link.setAttribute('href', '/profile.forum?mode=viewprofile&u='+user_id+'&sid='+sid);
	link.setAttribute('target', 'profile');
	link.onclick = new Function ("hideMenu();");
	
	p.appendChild(link);
	div.appendChild(p);
	
	/* --------- create the send pm link ------------- */
	var p = document.createElement('p');
	p.onmouseover = new Function ('this.className="hover";');
	p.onmouseout = new Function ('this.className="";');
	var link = document.createElement('a');
	link.appendChild(document.createTextNode("Envoyer un MP"));
	link.setAttribute('href', '/msg.forum?mode=post&u='+user_id+'&sid='+sid);
	link.setAttribute('target', 'profile');
	link.onclick = new Function ("hideMenu();");
	
	p.appendChild(link);
	div.appendChild(p);
	
	/* --------- create the ban user link ------------- */
	if (parent.frames['sender'].document.forms[0].elements["message"] && my_chat_level == 2)
	{
		user_name = user_name.replace(/\\/g, "\\\\");
		user_name = user_name.replace(/\'/g, "\\'" );
		
		if (user_chat_level != 2)
		{
            /* -- Kick -- */
            var p = document.createElement('p');
            p.onmouseover = new Function ('this.className="hover";');
            p.onmouseout = new Function ('this.className="";');
            var link = document.createElement('a');
            link.appendChild(document.createTextNode("Kicker du chat"));
            link.setAttribute('href', 'javascript:void(0)');
            link.onclick = new Function ("return action_user('kick', '"+user_name+"', '"+sid+"');");
            p.appendChild(link);
            div.appendChild(p);
            
            /* -- Ban -- */
			var p = document.createElement('p');
			p.onmouseover = new Function ('this.className="hover";');
			p.onmouseout = new Function ('this.className="";');
			var link = document.createElement('a');
			link.appendChild(document.createTextNode("Bannir du chat"));
			link.setAttribute('href', 'javascript:void(0)');
			link.onclick = new Function ("return action_user('ban','"+user_name+"', '"+sid+"');");
		}
		
		p.appendChild(link);
		div.appendChild(p);		
		
		if (my_user_level == 1 && user_chat_level == 2 && user_level != 1 )
		{
			var p = document.createElement('p');
			p.onmouseover = new Function ('this.className="hover";');
			p.onmouseout = new Function ('this.className="";');
			var link = document.createElement('a');
			link.appendChild(document.createTextNode("Retirer modération"));
			link.setAttribute('href', 'javascript:void(0)');
			link.onclick = new Function ("return action_user('unmod','"+user_name+"', '"+sid+"');");
			
			p.appendChild(link);
			div.appendChild(p);
		}
		else if (my_user_level == 1 && user_chat_level != 2 )
		{
			var p = document.createElement('p');
			p.onmouseover = new Function ('this.className="hover";');
			p.onmouseout = new Function ('this.className="";');
			var link = document.createElement('a');
			link.appendChild(document.createTextNode("Ajout modérateur"));
			link.setAttribute('href', 'javascript:void(0)');
			link.onclick = new Function ("return action_user('mod','"+user_name+"', '"+sid+"');");
			
			p.appendChild(link);
			div.appendChild(p);
		}
	}
    
    if (connected && user_id == my_user_id)
    {
        var p = document.createElement('p');
        p.onmouseover = new Function ('this.className="hover";');
        p.onmouseout = new Function ('this.className="";');
        var link = document.createElement('a');
        link.appendChild(document.createTextNode("S’absenter"));
        link.setAttribute('href', 'javascript:void(0)');
        link.onclick = new Function ("return action_user('away', prompt('Raison',''), '"+sid+"');");
        
        p.appendChild(link);
        div.appendChild(p);
        
        var p = document.createElement('p');
        p.onmouseover = new Function ('this.className="hover";');
        p.onmouseout = new Function ('this.className="";');
        var link = document.createElement('a');
        link.appendChild(document.createTextNode("Quitter"));
        link.setAttribute('href', 'javascript:void(0)');
        link.onclick = new Function ("return action_user('exit', prompt('Raison',''), '"+sid+"');");
        
        p.appendChild(link);
        div.appendChild(p);
    }
	
	document.body.appendChild(div);
	return false;
}

function action_user (cmd, user_name, sid)
{
    if (user_name == null) user_name = '';
	parent.frames['sender'].document.forms[0].elements["message"].value = '/' + cmd + ' ' + user_name;
	parent.frames['sender'].submitmsg();
	hideMenu ();
	return false;
}


/* only delete the contextmenu from the document */
function hideMenu () 
{
	document.getElementById('chatbox_contextmenu').parentNode.removeChild(document.getElementById('chatbox_contextmenu'));
}

/* copy the user name in the message field */
function copy_user_name (user_name) 
{
	if (parent.frames['sender'].document.forms[0].elements["message"])
	{
		parent.frames['sender'].document.forms[0].elements["message"].value += user_name;
		parent.frames['sender'].document.forms[0].elements["message"].focus();
	}
		
	return false;
}

function js_urlencode(text)
{
	text = text.toString();

	// this escapes 128 - 255, as JS uses the unicode code points for them.
	// This causes problems with submitting text via AJAX with the UTF-8 charset.
	var matches = text.match(/[\x90-\xFF]/g);
	if (matches)
	{
		for (var matchid = 0; matchid < matches.length; matchid++)
		{
			var char_code = matches[matchid].charCodeAt(0);
			text = text.replace(matches[matchid], '%u00' + (char_code & 0xFF).toString(16).toUpperCase());
		}
	}

	return escape(text).replace(/\+/g, "%2B");
}

function ajax_refresh_chatbox(params)
{
	if (window.XMLHttpRequest)
	{
		// Mozilla, Safari, ...
		var http_request = new XMLHttpRequest();
	} else if (window.ActiveXObject)
	{
		// IE
		var http_request = new ActiveXObject("Microsoft.XMLHTTP");
	}

	http_request.onreadystatechange = function()
	{
		if (http_request.readyState == 4 && http_request.status == 200)
		{
			// destroyer
			var parsed_text = http_request.responseText;

            // only connected
            if ( parent.frames['ekran'].document.getElementById('message_rows') )
            {
                parent.frames['ekran'].document.getElementById('message_rows').innerHTML = parsed_text;
                parent.frames['ekran'].window.scrollTo(0,99999);
                ajax_refresh_chatterlist(params);
            }
			
			if( parsed_text.indexOf('<script>/*stop_refresh*/</script>',0) != -1 )
			{
				clearInterval(parent.frames['ekran'].Interval);
				parent.frames['ekran'].refreshing = false;
				
				var title_params = (params == '') ? '?page=front' : params + '&page=front';
				parent.frames['title'].location.href 	= '/chatbox_mod/chatbox_title.forum' + title_params;
				parent.frames['sender'].location.href 	= '/chatbox_mod/messenger_send.forum' + title_params;
			}
			else
			{
				if ( parent.frames['ekran'].refreshing == false )
				{
					parent.frames['ekran'].Interval = setInterval('parent.frames[\'ekran\'].refresh_chatbox()', 8000);
					parent.frames['ekran'].refreshing = true;
				}
			}
		}
	};

	http_request.open('GET', '/chatbox_mod/generate_messages.forum' + params , true);
	http_request.send(null);
}

function ajax_submit_chatbox(params)
{
	var data = '&nick=' + js_urlencode(document.post.nick.value);
	data += '&sent=' + js_urlencode(document.post.sent.value);
	data += '&sbold=' + document.post.sbold.value;
	data += '&sitalic=' + document.post.sitalic.value;
	data += '&sunderline=' + document.post.sunderline.value;
	data += '&sstrike=' + document.post.sstrike.value;
	data += '&scolor=' + document.post.scolor.value;

	if( document.post.sent.value == '/banlist' )
	{
		window.open('/chatbox_mod/chatbox_banlist.forum' + params, 'color','toolbar=no,menubar=no,personalbar=no,width=450,height=300,scrollbars=no,resizable=yes');
		return false;
	}	
	
	if (window.XMLHttpRequest)
	{
		// Mozilla, Safari, ...
		var http_request_submit = new XMLHttpRequest();
	} else if (window.ActiveXObject)
	{
		// IE
		var http_request_submit = new ActiveXObject("Microsoft.XMLHTTP");
	}

	http_request_submit.onreadystatechange = function()
	{
		if (http_request_submit.readyState == 4 && http_request_submit.status == 200)
		{
			// destroyer
			/*var parsed_text = http_request_submit.responseText;

			parent.frames['ekran'].document.getElementById('message_rows').innerHTML = parsed_text;
			parent.frames['ekran'].window.scrollTo(0,99999);*/
			ajax_refresh_chatbox(params);
			ajax_refresh_chatterlist(params);
		}
	};

	http_request_submit.open('POST', '/chatbox_mod/generate_messages.forum' + params, true);
	http_request_submit.setRequestHeader('Content-Type','application/x-www-form-urlencoded;');
	http_request_submit.send(data);
}

function ajax_refresh_chatterlist(params)
{
	if (window.XMLHttpRequest)
	{
		// Mozilla, Safari, ...
		var http_request_list = new XMLHttpRequest();
	} else if (window.ActiveXObject)
	{
		// IE
		var http_request_list = new ActiveXObject("Microsoft.XMLHTTP");
	}

	http_request_list.onreadystatechange = function()
	{
		if (http_request_list.readyState == 4 && http_request_list.status == 200)
		{
			// destroyer
			var parsed_text = http_request_list.responseText;

            if (parent.frames['who'].document.getElementById('chatter_rows'))
            {
			    parent.frames['who'].document.getElementById('chatter_rows').innerHTML = parsed_text;
            }
		}
	};

	http_request_list.open('GET', '/chatbox_mod/generate_chatterlist.forum' + params , true);
	http_request_list.send(null);
}

function insert_chatboxsmilie(smilie_code)
{
	opener.document.getElementById('message').value = opener.document.getElementById('message').value + smilie_code;
	opener.document.post.message.focus();
	window.close();
}


function change_display_by_icon(element,element_id,content_more,content_less,display_special)
{
	element.className=(element.className=="icon_less")?"icon_more":"icon_less";
    element.style.background ='url(\''+ ((element.className=="icon_less")?'http://illiweb.com/fa/i/tabs_less.gif':'http://illiweb.com/fa/i/tabs_more.gif') + '\') no-repeat';
	if(content_more || content_less)
	{
		element.innerHTML=(element.className=="icon_less")?content_less:content_more;
	}
	if(!display_special)
	{
		display_special = 'block';
	}
	document.getElementById(element_id).style.display = ((element.className=="icon_more")?'none':display_special);
    
    my_setcookie('display_sql_info', element.className);
}

function switchuploadaddress(file) {
	if (file) {
		document.getElementById('upfile').style.display='inline';
		document.getElementById('upurl').style.display='none';
	} 
	else {
		document.getElementById('upfile').style.display='none';
		document.getElementById('upurl').style.display='inline';
	}
}

function do_mark(mode, type)
{
	if ( type == 2 )
	{
		if ( mode == 7 )
		{
			for (i = 0; i < form.elements["mark[]"].length; ++i)
			{
				radio_box = form.elements["mark[]"][i];
				if (radio_box.checked == true)
				{
					radio_box.checked = false;
				}
				else
				{
					radio_box.checked = true;
				}
			}
		}
		else
		{
			if ( special_mark_modes[mode] == '' )
			{
				return;
			}
			for ( i = 0; i < special_mark_modes[mode].length; ++i )
			{
				radio_box = form.elements["mark[]"][special_mark_modes[mode][i]];
				if ( radio_box.checked == true )
				{
					radio_box.checked = false;
				}
				else
				{
					radio_box.checked = true;
				}
			}
		}
	}
	else
	{
		if ( type == 1 )
		{
			var value = false;
		}
		else
		{
			var value = true;
		}

		if ( mode == 7 )
		{
			for (i = 0; i < form.elements["mark[]"].length; ++i)
			{
				form.elements["mark[]"][i].checked = value;
			}
		}
		else
		{
			if ( special_mark_modes[mode] == '' )
			{
				return;
			}
			for ( i = 0; i < special_mark_modes[mode].length; ++i )
			{
				form.elements["mark[]"][special_mark_modes[mode][i]].checked = value;
			}
		}
	}
}

function checkreport()
{
	checked = false;
	if ( form.elements["mark[]"].length )
	{
		for ( i = 0; i < form.elements["mark[]"].length; ++i )
		{
			if ( form.elements["mark[]"][i].checked == true )
			{
				checked = true;
				break;
			}
		}
	}
	else
	{
		if ( form.elements["mark[]"].checked == true )
		{
			checked = true;
		}
	}
	if ( !checked )
	{
		alert('Aucun rapport selectionné!');
		return false;
	}
	if ( delete_mode )
	{
		delete_mode = false;
		if ( confirm("Êtes vous sur de vouloir supprimer le(s) rapport(s) ?") == true )
		{
			form.confirm.value = 1;
		}
		else
		{
			return false;
		}
	}
	return true;
}

function insert_smilie(smiliepath, smilieid, smilie_code)
{
	if ( parent.document.getElementById('vB_Editor_001_mode').value == 1 )
	{
		parent.vB_Editor['vB_Editor_001'].insert_text('<img src="' + smiliepath + '" smilieid="' + smilieid + '" /> ', false);
	}
	else
	{
		parent.vB_Editor['vB_Editor_001'].insert_text(smilie_code + ' ', false);
	}
}

function unban_user(user, id)
{
	opener.parent.frames['sender'].document.forms[0].elements["message"].value = '/unban ' + user;
	opener.parent.frames['sender'].submitmsg();
	
	document.getElementById(id).style.display = 'none';
}

function MM_openBrWindow(theURL,winName,features)
{
	window.open(theURL,winName,features);
}

function checkmodcp(action) {
	field = document.modcp.elements.length;
	switch(action)
	{	case "select":	for (i = 0; i < field; i++) {
					document.modcp.elements[i].checked = true;
				}
				break;
		case "unselect":	for (i = 0; i < field; i++) {
	  					document.modcp.elements[i].checked = false;
					}
					break;
	}
}

function check_rotation_radiobuttons() {
	if ( document.nuffimage_form.elements["nuff_rotation.checked"] == false)
	document.nuffimage_form.elements["nuff_rotation_d"].checked = false;
}

function select_switch_search(status) {
	for (i=0; i<document.post.length; i++) {
	document.post.elements[i].checked = status;
	}
}

function verify_select() {
	selectedfields = 0;

	for (i=0; i<document.post.length; i++) {
	 if (document.post.elements[i].checked == true)
	 {
	 	selectedfields++;
	 }
	}

	if (selectedfields == 0)
	{
		msg_error = "Veuillez sélectionner au moins un sujet";
		alert(msg_error);
		return false;
	}
	else
	{
		return true;
	}
}

function select_switch_line(numchamp) {
	for (i=(numchamp-1); i<(numchamp-1)+7; i++)
	{
		if (document.post.elements[i+6].disabled != true)
		{
			document.post.elements[i+6].checked = !document.post.elements[i+6].checked;
		}
	}
}

function select_switch_privmsg(status) {
	for (i=0; i<document.privmsg_list.length; i++) {
	document.privmsg_list.elements[i].checked = status;
	}
}


/*
* This function retrieves the search query from the URL.
*/

function GetParam(name)
{
	var match = new RegExp(name + "=([^&]+)","i").exec(location.search);
	if (match==null)
	{
		match = new RegExp(name + "=(.+)","i").exec(location.search);
	}

	if (match==null)
	{
		return null;
	}

	match = match + "";
	result = match.split(",");
	return result[1];
}


/*
* This function is required. It processes the google_ads JavaScript object,
* which contains AFS ads relevant to the user's search query. The name of
* this function <i>must</i> be <b>google_afs_request_done</b>. If this
* function is not named correctly, your page will not display AFS ads.
*/

function google_afs_request_done(google_ads)
{
	/*
	* Verify that there are actually ads to display.
	*/
	var google_num_ads = google_ads.length;
	if (google_num_ads <= 0)
	{
		return;
	}

	var wideAds = "";   // wide ad unit html text
	var narrowAds = "";   // narrow ad unit html text

	if ( google_num_ads > 1 )
	{
		for( var i = 0; i < google_num_ads; i++ )
		{
			// render a narrow ad
			narrowAds+='<div style="float:left;width:' + (728/google_num_ads) + 'px;"><a style="text-decoration:none" onmouseover="javascript:window.status=\'' +
			google_ads[i].url + '\';return true;" ' +
			'onmouseout="javascript:window.status=\'\';return true;" ' +
			'href="' + google_ads[i].url + '">' +
			'<span class="ad_line1">' + google_ads[i].line1 + '</span><br />' +
			'<span class="ad_text">' + google_ads[i].line2 + '</span><br />' +
			'<span class="ad_text">' + google_ads[i].line3 + '</span><br />' +
			'<div class="ad_url">' + google_ads[i].visible_url + '</div></a></div>';
		}
	}
	else if ( google_num_ads == 1 )
	{
		var i = 0;
		// render a wide ad
		narrowAds+='<div style="text-align:center;"><a style="text-decoration:none;" onmouseover="javascript:window.status=\'' +
		google_ads[i].url + '\';return true;" ' +
		'onmouseout="javascript:window.status=\'\';return true;" ' +
		'href="' + google_ads[i].url + '">' +
		'<span class="ad_line1">' + google_ads[i].line1 + '</span><br />' +
		'<span class="ad_text">' + google_ads[i].line2 + '</span><br />' +
		'<span class="ad_text">' + google_ads[i].line3 + '</span><br />' +
		'<div class="ad_url">' + google_ads[i].visible_url + '</div></a></div>';
	}

	if ( google_num_ads > 0 )
	{
		if (narrowAds != "")
		{
			narrowAds = narrowAds + '<a style="text-decoration:none" ' +
			'href="http://services.google.com/feedback/online_hws_feedback">' +
			'<div class="ad_header" style="text-align:right">Ads by Google</div></a>';
		}
	}

	// Write HTML for wide and narrow ads to the proper <div> elements
	if ( document.getElementById("narrow_ad_unit") )
	{
		document.getElementById("narrow_ad_unit").innerHTML = narrowAds;
	}
}

// Add/remove solved to topic subject
function set_solved(input,str)
{
	if(input)
	{
		var title = input.value;
		var reg = new RegExp("\\"+str,"g");
		input.value = ( reg.test(title) )  ? title.replace(reg,'') : str + title;
	}
}