/*-----------------------------------------------------------+
 | addLoadEvent: Add event handler to body when window loads |
 +-----------------------------------------------------------*/
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != "function") {
		window.onload = func;
	} else {
		window.onload = function () {
			oldonload();
			func();
		}
	}
}
/*------------------------------------+
 | Functions to run when window loads |
 +------------------------------------*/
addLoadEvent(function () {
	initChecklist();
});

/*----------------------------------------------------------+
 | initChecklist: Add :hover functionality on labels for IE |
 +----------------------------------------------------------*/
function initChecklist() {
	if (document.all && document.getElementById) {
		// Get all unordered lists
		var lists = document.getElementsByTagName("ul");
		for (i = 0; i < lists.length; i++) {
			var theList = lists[i];
			// Only work with those having the class "checklist"
			if (theList.className.indexOf("checklist") > -1) {
				var labels = theList.getElementsByTagName("label");
				// Assign event handlers to labels within
				for (var j = 0; j < labels.length; j++) {
					var theLabel = labels[j];
					theLabel.onmouseover = function() { this.className += " hover"; };
					theLabel.onmouseout = function() { this.className = this.className.replace(" hover", ""); };
				}
			}
		}
	}
}

function AddText(startTag,endTag,textera){
	var clientPC = navigator.userAgent.toLowerCase();
	var clientVer = parseInt(navigator.appVersion);
	var is_ie = ((clientPC.indexOf('msie') != -1) && (clientPC.indexOf('opera') == -1));
	var is_win = ((clientPC.indexOf('win') != -1) || (clientPC.indexOf('16bit') != -1));

	theSelection = false;
	textera.focus();
	if ((clientVer >= 4) && is_ie && is_win) {
		// Get text selection
		theSelection = document.selection.createRange().text;
		if (theSelection) {
			// Add tags around selection
			document.selection.createRange().text = startTag + theSelection + endTag;
			textera.focus();
			theSelection = '';
			return;
		}
	} else if (textera.selectionEnd && (textera.selectionEnd - textera.selectionStart > 0)) {
		mozWrap(textera, startTag, endTag);
		textera.focus();
		theSelection = '';
		return;
	}

	//The new position for the cursor after adding the bbcode
	var caret_pos = getCaretPosition(textera).start;
	var new_pos = caret_pos + startTag.length;

	// Open tag
	insert_text(startTag + endTag, textera);

	// Center the cursor when we don't have a selection
	// Gecko and proper browsers
	if (!isNaN(textera.selectionStart)) {
		textera.selectionStart = new_pos;
		textera.selectionEnd = new_pos;
	}
	// IE
	else if (document.selection) {
		var range = textera.createTextRange(); 
		range.move("character", new_pos); 
		range.select();
		storeCaret(textera);
	}
	textera.focus();
	return;
}

/**
* Insert text at position
*/
function insert_text(text, textera){
	if (!isNaN(textera.selectionStart)) {
		var sel_start = textera.selectionStart;
		var sel_end = textera.selectionEnd;
		mozWrap(textera, text, '')
		textera.selectionStart = sel_start + text.length;
		textera.selectionEnd = sel_end + text.length;
	} else if (textera.createTextRange && textera.caretPos) {
		if (baseHeight != textera.caretPos.boundingHeight) {
			textera.focus();
			storeCaret(textera);
		}	
		var caret_pos = textera.caretPos;
		caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) == ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text;
	} else {
		textera.value = textera.value + text;
	}
	textera.focus();
}

/**
* From http://www.massless.org/mozedit/
*/
function mozWrap(txtarea, open, close){
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	var scrollTop = txtarea.scrollTop;
	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;
	txtarea.selectionStart = selEnd + open.length + close.length;
	txtarea.selectionEnd = txtarea.selectionStart;
	txtarea.focus();
	txtarea.scrollTop = scrollTop;
	return;
}

/**
* Insert at Caret 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();
	}
}

/**
* Caret Position object
*/
function caretPosition(){
	var start = null;
	var end = null;
}

/**
* Get the caret position in an textarea
*/
function getCaretPosition(txtarea){
	var caretPos = new caretPosition();
	// simple Gecko/Opera way
	if (txtarea.selectionStart || txtarea.selectionStart == 0) {
		caretPos.start = txtarea.selectionStart;
		caretPos.end = txtarea.selectionEnd;
	}
	// dirty and slow IE way
	else if (document.selection) {
		// get current selection
		var range = document.selection.createRange();

		// a new selection of the whole textarea
		var range_all = document.body.createTextRange();
		range_all.moveToElementText(txtarea);
	
		// calculate selection start point by moving beginning of range_all to beginning of range
		var sel_start;
		for (sel_start = 0; range_all.compareEndPoints('StartToStart', range) < 0; sel_start++) {	
			range_all.moveStart('character', 1);
		}
		txtarea.sel_start = sel_start;
		// we ignore the end value for IE, this is already dirty enough and we don't need it
		caretPos.start = txtarea.sel_start;
		caretPos.end = txtarea.sel_start;		
	}
	return caretPos;
}

//Fonction renvoyant le code de la touche appuyée lors d'un événement clavier
function getKeyCode(evenement)
{
    for (prop in evenement)
	{
        if (prop == 'which')
		{
            return evenement.which;
        }
    }
    return event.keyCode;
}

// {{{ html_entity_decode
function html_entity_decode( string ) {
    // Convert all HTML entities to their applicable characters
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_html_entity_decode/
    // +       version: 808.2912
    // +   original by: john (http://www.jd-tech.net)
    // +      input by: ger
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // %          note: table from http://www.the-art-of-web.com/html/character-codes/
    // *     example 1: html_entity_decode('Kevin &amp; van Zonneveld');
    // *     returns 1: 'Kevin & van Zonneveld'
    
    var histogram = {}, histogram_r = {}, code = 0;
    var entity = chr = '';
    
    histogram['34'] = 'quot';
    histogram['38'] = 'amp';
    histogram['60'] = 'lt';
    histogram['62'] = 'gt';
    histogram['160'] = 'nbsp';
    histogram['161'] = 'iexcl';
    histogram['162'] = 'cent';
    histogram['163'] = 'pound';
    histogram['164'] = 'curren';
    histogram['165'] = 'yen';
    histogram['166'] = 'brvbar';
    histogram['167'] = 'sect';
    histogram['168'] = 'uml';
    histogram['169'] = 'copy';
    histogram['170'] = 'ordf';
    histogram['171'] = 'laquo';
    histogram['172'] = 'not';
    histogram['173'] = 'shy';
    histogram['174'] = 'reg';
    histogram['175'] = 'macr';
    histogram['176'] = 'deg';
    histogram['177'] = 'plusmn';
    histogram['178'] = 'sup2';
    histogram['179'] = 'sup3';
    histogram['180'] = 'acute';
    histogram['181'] = 'micro';
    histogram['182'] = 'para';
    histogram['183'] = 'middot';
    histogram['184'] = 'cedil';
    histogram['185'] = 'sup1';
    histogram['186'] = 'ordm';
    histogram['187'] = 'raquo';
    histogram['188'] = 'frac14';
    histogram['189'] = 'frac12';
    histogram['190'] = 'frac34';
    histogram['191'] = 'iquest';
    histogram['192'] = 'Agrave';
    histogram['193'] = 'Aacute';
    histogram['194'] = 'Acirc';
    histogram['195'] = 'Atilde';
    histogram['196'] = 'Auml';
    histogram['197'] = 'Aring';
    histogram['198'] = 'AElig';
    histogram['199'] = 'Ccedil';
    histogram['200'] = 'Egrave';
    histogram['201'] = 'Eacute';
    histogram['202'] = 'Ecirc';
    histogram['203'] = 'Euml';
    histogram['204'] = 'Igrave';
    histogram['205'] = 'Iacute';
    histogram['206'] = 'Icirc';
    histogram['207'] = 'Iuml';
    histogram['208'] = 'ETH';
    histogram['209'] = 'Ntilde';
    histogram['210'] = 'Ograve';
    histogram['211'] = 'Oacute';
    histogram['212'] = 'Ocirc';
    histogram['213'] = 'Otilde';
    histogram['214'] = 'Ouml';
    histogram['215'] = 'times';
    histogram['216'] = 'Oslash';
    histogram['217'] = 'Ugrave';
    histogram['218'] = 'Uacute';
    histogram['219'] = 'Ucirc';
    histogram['220'] = 'Uuml';
    histogram['221'] = 'Yacute';
    histogram['222'] = 'THORN';
    histogram['223'] = 'szlig';
    histogram['224'] = 'agrave';
    histogram['225'] = 'aacute';
    histogram['226'] = 'acirc';
    histogram['227'] = 'atilde';
    histogram['228'] = 'auml';
    histogram['229'] = 'aring';
    histogram['230'] = 'aelig';
    histogram['231'] = 'ccedil';
    histogram['232'] = 'egrave';
    histogram['233'] = 'eacute';
    histogram['234'] = 'ecirc';
    histogram['235'] = 'euml';
    histogram['236'] = 'igrave';
    histogram['237'] = 'iacute';
    histogram['238'] = 'icirc';
    histogram['239'] = 'iuml';
    histogram['240'] = 'eth';
    histogram['241'] = 'ntilde';
    histogram['242'] = 'ograve';
    histogram['243'] = 'oacute';
    histogram['244'] = 'ocirc';
    histogram['245'] = 'otilde';
    histogram['246'] = 'ouml';
    histogram['247'] = 'divide';
    histogram['248'] = 'oslash';
    histogram['249'] = 'ugrave';
    histogram['250'] = 'uacute';
    histogram['251'] = 'ucirc';
    histogram['252'] = 'uuml';
    histogram['253'] = 'yacute';
    histogram['254'] = 'thorn';
    histogram['255'] = 'yuml';
    
    // Reverse table. Cause for maintainability purposes, the histogram is 
    // identical to the one in htmlentities.
    for (code in histogram) {
        entity = histogram[code];
        histogram_r[entity] = code; 
    }
    
    return string.replace(/(\&([a-zA-Z]+)\;)/g, function(full, m1, m2){
        if (m2 in histogram_r) {
            return String.fromCharCode(histogram_r[m2]);
        } else {
            return m2;
        }
    });    
}// }}}

// {{{ htmlentities
function htmlentities(string){
    // Convert all applicable characters to HTML entities
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_htmlentities/
    // +       version: 808.2715
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // %          note: table from http://www.the-art-of-web.com/html/character-codes/
    // *     example 1: htmlentities('Kevin & van Zonneveld');
    // *     returns 1: 'Kevin &amp; van Zonneveld'
    
    var histogram = {}, code = 0, tmp_arr = [];
    
    histogram['34'] = 'quot';
    histogram['38'] = 'amp';
    histogram['60'] = 'lt';
    histogram['62'] = 'gt';
    histogram['160'] = 'nbsp';
    histogram['161'] = 'iexcl';
    histogram['162'] = 'cent';
    histogram['163'] = 'pound';
    histogram['164'] = 'curren';
    histogram['165'] = 'yen';
    histogram['166'] = 'brvbar';
    histogram['167'] = 'sect';
    histogram['168'] = 'uml';
    histogram['169'] = 'copy';
    histogram['170'] = 'ordf';
    histogram['171'] = 'laquo';
    histogram['172'] = 'not';
    histogram['173'] = 'shy';
    histogram['174'] = 'reg';
    histogram['175'] = 'macr';
    histogram['176'] = 'deg';
    histogram['177'] = 'plusmn';
    histogram['178'] = 'sup2';
    histogram['179'] = 'sup3';
    histogram['180'] = 'acute';
    histogram['181'] = 'micro';
    histogram['182'] = 'para';
    histogram['183'] = 'middot';
    histogram['184'] = 'cedil';
    histogram['185'] = 'sup1';
    histogram['186'] = 'ordm';
    histogram['187'] = 'raquo';
    histogram['188'] = 'frac14';
    histogram['189'] = 'frac12';
    histogram['190'] = 'frac34';
    histogram['191'] = 'iquest';
    histogram['192'] = 'Agrave';
    histogram['193'] = 'Aacute';
    histogram['194'] = 'Acirc';
    histogram['195'] = 'Atilde';
    histogram['196'] = 'Auml';
    histogram['197'] = 'Aring';
    histogram['198'] = 'AElig';
    histogram['199'] = 'Ccedil';
    histogram['200'] = 'Egrave';
    histogram['201'] = 'Eacute';
    histogram['202'] = 'Ecirc';
    histogram['203'] = 'Euml';
    histogram['204'] = 'Igrave';
    histogram['205'] = 'Iacute';
    histogram['206'] = 'Icirc';
    histogram['207'] = 'Iuml';
    histogram['208'] = 'ETH';
    histogram['209'] = 'Ntilde';
    histogram['210'] = 'Ograve';
    histogram['211'] = 'Oacute';
    histogram['212'] = 'Ocirc';
    histogram['213'] = 'Otilde';
    histogram['214'] = 'Ouml';
    histogram['215'] = 'times';
    histogram['216'] = 'Oslash';
    histogram['217'] = 'Ugrave';
    histogram['218'] = 'Uacute';
    histogram['219'] = 'Ucirc';
    histogram['220'] = 'Uuml';
    histogram['221'] = 'Yacute';
    histogram['222'] = 'THORN';
    histogram['223'] = 'szlig';
    histogram['224'] = 'agrave';
    histogram['225'] = 'aacute';
    histogram['226'] = 'acirc';
    histogram['227'] = 'atilde';
    histogram['228'] = 'auml';
    histogram['229'] = 'aring';
    histogram['230'] = 'aelig';
    histogram['231'] = 'ccedil';
    histogram['232'] = 'egrave';
    histogram['233'] = 'eacute';
    histogram['234'] = 'ecirc';
    histogram['235'] = 'euml';
    histogram['236'] = 'igrave';
    histogram['237'] = 'iacute';
    histogram['238'] = 'icirc';
    histogram['239'] = 'iuml';
    histogram['240'] = 'eth';
    histogram['241'] = 'ntilde';
    histogram['242'] = 'ograve';
    histogram['243'] = 'oacute';
    histogram['244'] = 'ocirc';
    histogram['245'] = 'otilde';
    histogram['246'] = 'ouml';
    histogram['247'] = 'divide';
    histogram['248'] = 'oslash';
    histogram['249'] = 'ugrave';
    histogram['250'] = 'uacute';
    histogram['251'] = 'ucirc';
    histogram['252'] = 'uuml';
    histogram['253'] = 'yacute';
    histogram['254'] = 'thorn';
    histogram['255'] = 'yuml';
    
    for (i = 0; i < string.length; ++i) {
        code = string.charCodeAt(i);
        if (code in histogram) {
            tmp_arr[i] = '&'+histogram[code]+';';
        } else {
            tmp_arr[i] = string.charAt(i);
        }
    }
    
    return tmp_arr.join('');
}// }}}

//Suppression des espaces/sauts de ligne inutiles (http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256C0C0062AC78)
function trim(value)
{
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = /  /g;
   while (temp.match(obj)) { temp = temp.replace(obj, " "); }
   return temp;
}

//Fonction donnant la largeur en pixels du texte donné (merci SpaceFrog !)
function getTextWidth(texte)
{
	//Valeur par défaut : 150 pixels
	var largeur = 150;
	if(trim(texte) == "")
	{
		return largeur;
	}
	//Création d'un span caché que l'on "mesurera"
	var span = document.createElement("span");
	span.style.visibility = "hidden";
	span.style.position = "absolute";
	//Ajout du texte dans le span puis du span dans le corps de la page
	span.appendChild(document.createTextNode(texte));
	document.getElementsByTagName("body")[0].appendChild(span);
	//Largeur du texte
	largeur = span.offsetWidth;
	//Suppression du span
	document.getElementsByTagName("body")[0].removeChild(span);
	span = null;
	return largeur;
}

function substr_count(haystack, needle, offset, length) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // *     example 1: substr_count('Kevin van Zonneveld', 'e');
    // *     returns 1: 3
    // *     example 2: substr_count('Kevin van Zonneveld', 'K', 1);
    // *     returns 2: 0
    // *     example 3: substr_count('Kevin van Zonneveld', 'Z', 0, 10);
    // *     returns 3: false
 
    var pos = 0, cnt = 0;
 
    haystack += '';
    needle += '';
    if (isNaN(offset)) {offset = 0;}
    if (isNaN(length)) {length = 0;}
    offset--;
 
    while ((offset = haystack.indexOf(needle, offset+1)) != -1){
        if (length > 0 && (offset+needle.length) > length){
            return false;
        } else{
            cnt++;
        }
    }
 
    return cnt;
}

function heriter(classeEnfant, classeParent)
{
	function heritage() {}
	heritage.prototype = classeParent.prototype;
	
	classeEnfant.prototype 				= new heritage();
	classeEnfant.prototype.constructor 	= classeEnfant;
	classeEnfant.constructeurParent 	= classeParent;
	classeEnfant.classeParent			= classeParent.prototype;
}

function select_texte(textarea) {
	document.getElementById(textarea).focus;
	document.getElementById(textarea).select();
}

function newRecherche(ElementId) {
	new AutoCompleteur(ElementId, ElementId+'_update', 'recherche.php', {
		Global: {
			nbrMaxItem: 30,
			nbrCharsStart: 1,
			classToIgnore: " "
		},
		Ajax: {
			paramName: 'pseudo'
		},
		Extra: {
			afterValidate: function (element,updateElement,elementValide,text) {
				if (!elementValide) document.getElementById(ElementId).value = element.text;
				else document.getElementById(ElementId).value = elementValide.id.split('+')[1];
			},
			openEffect: 'blind',
			hideEffect: 'slide'
		}
	});
}

function getAjax() {
	var xmlhttp;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e)	{
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp = false;
		}
	}
	return xmlhttp;
}

// {{{ in_array
function in_array(needle, haystack, strict) {
    // Checks if a value exists in an array
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_in_array/
    // +       version: 804.1712
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true

    var found = false, key, strict = !!strict;

    for (key in haystack) {
        if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
            found = true;
            break;
        }
    }

    return found;
}// }}}

function invert(formu, nomchamp, valueindex)
{
	field=document.forms[formu].elements;
	for (i=0;i<field.length; i++) {
		if (field[i].name==nomchamp && field[i].id!=valueindex) field[i].checked=false;
	}
}

function CheckAll(form)
{
	obj1 = document.forms[form];
	for (i=0; i<obj1.elements.length; i++) {
		if (obj1.elements[i].type.toLowerCase() == 'checkbox') 
		obj1.elements[i].checked = 'checked';
	}
}

function redirect(url) { window.location=url }

function UnCheckAll(form)
{
	obj1 = document.forms[form];
	for (i=0; i<obj1.elements.length; i++) {
		if (obj1.elements[i].type.toLowerCase() == 'checkbox') 
		obj1.elements[i].checked = '';
	}
}

// {{{ utf8_decode
function utf8_decode ( str_data ) {
    // Converts a string with ISO-8859-1 characters encoded with UTF-8   to single-byte
    // ISO-8859-1
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_utf8_decode/
    // +       version: 805.821
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +      input by: Aman Gupta
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: utf8_decode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'

    var tmp_arr = [], i = ac = c = c1 = c2 = 0;

    while ( i < str_data.length ) {
        c = str_data.charCodeAt(i);
        if (c < 128) {
            tmp_arr[ac++] = String.fromCharCode(c); 
            i++;
        } else if ((c > 191) && (c < 224)) {
            c2 = str_data.charCodeAt(i+1);
            tmp_arr[ac++] = String.fromCharCode(((c & 31) << 6) | (c2 & 63));
            i += 2;
        } else {
            c2 = str_data.charCodeAt(i+1);
            c3 = str_data.charCodeAt(i+2);
            tmp_arr[ac++] = String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }
    
    return tmp_arr.join('');
}// }}}

// {{{ utf8_encode
function utf8_encode ( string ) {
    // Encodes an ISO-8859-1 string to UTF-8
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_utf8_encode/
    // +       version: 808.2719
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: sowberry
    // *     example 1: utf8_encode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'
    
    string = string.replace(/\r\n/g,"\n");
    var utftext = "";
    var start, end;
 
    start = end = 0;
    for (var n = 0; n < string.length; n++) {
        var c = string.charCodeAt(n);
        var enc = null;
 
        if (c < 128) {
            end++;
        } else if ((c > 127) && (c < 2048)) {
            enc = String.fromCharCode((c >> 6) | 192) + String.fromCharCode((c & 63) | 128);
        } else {
            enc = String.fromCharCode((c >> 12) | 224) + String.fromCharCode(((c >> 6) & 63) | 128) + String.fromCharCode((c & 63) | 128);
        }
        if (enc != null) {
            if (end > start) {
                utftext += string.substring(start, end);
            }
            utftext += enc;
            start = end = n+1;
        }
    }
    
    if (end > start) {
        utftext += string.substring(start, string.length);
    }
 
    return utftext;
}// }}}

//Fonction renvoyant une valeur "aléatoire" pour forcer le navigateur (ie...)
//à envoyer la requête de mise à jour
function ieTrick(sep)
{
	d = new Date();
	trick = d.getYear() + "ie" + d.getMonth() + "t" + d.getDate() + "r" + d.getHours() + "i" + d.getMinutes() + "c" + d.getSeconds() + "k" + d.getMilliseconds();
	if (sep != "?")
	{
		sep = "&";
	}
	return sep + "ietrick=" + trick;
}

function g_ajax(fichier,b,p1,p2,p3,mess,d,div) {
	var onload = 0;
	url = fichier + '.php?b=' + b + '&p1=' + p1 + '&p2=' + p2 + '&p3=' + p3 + ieTrick();
	req = getAjax();
	req.onreadystatechange = function() {
		if ( req.readyState == 1 && onload == 0 ) {
			onload ++;
			document.getElementById("loading").className="show";
			document.getElementById("loading").innerHTML='<img src="images/ajax-loader.gif" width="22" height="22" border="0" alt="" />';
			if (mess == 'false') {
				document.getElementById("messages").innerHTML='';
				document.getElementById("messages").className="hidden";
			} else {
				document.getElementById("messages").className="normalb show";
			}
		}
		if ( req.readyState == 2 && onload == 1 ) {
			onload ++;
		}
		if ( req.readyState == 3 && onload == 2 ) {
			onload ++;
		}
		if ( req.readyState == 4 && onload == 3 ) {
			onload ++;
			if ( req.status == 200 ) {
				document.getElementById("loading").innerHTML='';
				document.getElementById("loading").className="hidden";
				obj = document.getElementById(div);
				obj.innerHTML = utf8_decode(utf8_encode(req.responseText));
				if (b!='album' && d!='') { document.getElementById(d).focus(); }
				if (mess == 'false') {
					document.getElementById("messages").innerHTML='';
					document.getElementById("messages").className="hidden";
				}
				if (in_array(b,['messagerie','lire_message'])) {
					eval(document.getElementById('eval').innerHTML);
				}
			} else {
				document.getElementById("messages").innerHTML='<span class="Style6">' + req.responseText + '</span>';
			}
		}
	}
	req.open("GET", url, true);
	req.setRequestHeader("Content-Type","text/html; charset=iso-8859-1");
	req.send( null );
}

function p_ajax(fichier,b,p1,p2,p3,form,d,div) {
	var onload1 = 0;
	url = fichier + '.php?b=' + b + '&p1=' + p1 + '&p2=' + p2 + '&p3=' + p3;
	var postdata = "";
	if (form!='' && form!='true') {
		obj1 = document.forms[form];
		for (i=0; i<obj1.elements.length; i++) {
			if (in_array(obj1.elements[i].type.toLowerCase(),['file','button','reset','submit'])) 
			continue;
			if (obj1.elements[i].type.toLowerCase() == 'checkbox' && obj1.elements[i].checked == '') 
			continue;
			if (obj1.elements[i].type.toLowerCase() == 'radio' && obj1.elements[i].checked == '') 
			continue;
			if (obj1.elements[i].tagName.toLowerCase() == 'select') {
				for (j=0; j<obj1.elements[i].options.length; j++) {
					if (obj1.elements[i].options[j].selected == true) {
						if (postdata != "") 
						postdata += "&";
						postdata += obj1.elements[i].name + "=" + encodeURI(obj1.elements[i].options[j].value);
					}
				}
			} else 	{
				if (postdata != "") 
				postdata += "&";
				postdata += obj1.elements[i].name + "=" + encodeURI(obj1.elements[i].value);
			}
		}
	}
	req1 = getAjax();
	req1.onreadystatechange = function() {
		if ( req1.readyState == 1 && onload1 == 0 ) {
			onload1 ++;
			document.getElementById("loading").className="show";
			document.getElementById("loading").innerHTML='<img src="images/ajax-loader.gif" width="22" height="22" border="0" alt="" />';
			document.getElementById("messages").className="normalb show";
			document.getElementById("messages").focus();
			document.getElementById(div).innerHTML='<div align="center" class="normalb">Rechargement en cours ...</div>';
		}
		if ( req1.readyState == 2 && onload1 == 1 ) {
			onload1 ++;
		}
		if ( req1.readyState == 3 && onload1 == 2 ) {
			onload1 ++;
		}
		if ( req1.readyState == 4 && onload1 == 3 ) {
			onload1 ++;
			if ( req1.status == 200 ) {
				obj2 = document.getElementById("messages");
				obj2.innerHTML = utf8_decode(utf8_encode(req1.responseText));
				g_ajax(fichier,
					((b=='connexion' || b=='deconnexion' || b=='post' || b=='inscription')?
						''
						:((b=='del_membre' || b=='verifier_mail')?
							'membres'
							:((b=='modifier_membre')?
								'voir_membre'
								:((b=='ajout_actualite' || b=='modifier_actualite' || b=='del_actualite')?
									'actualites'
									:((b=='ajout_jeux_concours_textes' || b=='del_jeux_concours_textes' || b=='modifier_jeux_concours' || b=='del_jeux_concours')?
										'jeux_concours'
										:((b=='modifier_livre_or' || b=='del_livre_or')?
											'livre_or'
											:((b=='modifier_albums' || b=='modifier_albums_fichiers')?
												'albums'
												:((b=='modifier_coloriages' || b=='modifier_coloriages_fichiers')?
													'coloriages'
													:((b=='modifier_fan_club' || b=='modifier_fan_club_fichiers')?
														'fan_club'
														:((b=='modifier_gifs' || b=='modifier_gifs_fichiers')?
															'gifs'
															:((b=='ajout_telephone_arabe_texte' || b=='del_telephone_arabe_textes' || b=='modifier_telephone_arabe' || b=='del_telephone_arabe')?
																'telephone_arabe'
																:(( ((b=='effacer_message' || b=='archiver_message') && p3=='1') || b=='ecrire_message')?
																	'messagerie'
																	:((b=='modifier_message' || (b=='effacer_message' && p3=='2'))?
																		'boite_envoi'	
																		:((b=='modifier_message_archive' || (b=='effacer_message' && p3=='3'))?
																			'boite_archive'
																			:b
																		)
																	)
																)
															)
														)
													)
												)
											)
										)
									)
								)
							)
						)
					),
					((
						(fichier=='livre dor' && b=='post' && p1=='') ||
						(fichier=='jeux_concours' && b=='post' && p1=='')
					)?
						'false'
						:p1
					),
					((
						(fichier=='livre dor' && b=='post' && p2=='') ||
						(fichier=='jeux_concours' && b=='post' && p2=='')
					)?
						'false'
						:p2
					),
					((
						(fichier=='livre dor' && b=='post' && p3=='') ||
						(fichier=='jeux_concours' && b=='post' && p3=='')
					)?
						'false'
						:((b=='inscription')?
							'connexion'
							:p3
						)
					),
					'true',
					d,
					((b=='connexion' || b=='deconnexion')?
						'general'
						:((b=='post')?
							'donnees'
							:div
						)
					)
				);
			} else {
				document.getElementById("messages").innerHTML='<br /><span class="Style6">' + req1.responseText + '</span>';
			}
		}
	}
	if (postdata != "") {
		req1.open("POST", url, true);
		req1.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		req1.send(postdata);
	} else {
		req1.open("GET", url, true);
		req1.setRequestHeader("Content-Type","text/html; charset=iso-8859-1");
		req1.send( null );
	}
}
