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;
	}
}

// {{{ 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;
}// }}}

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;
	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";
			}
			//document.getElementById("messages").innerHTML+= '1 : &#x2714;';
		}
		if ( req.readyState == 2 && onload == 1 ) {
			onload ++;
			//document.getElementById("messages").innerHTML+=' / 2 : &#x2714;';
		}
		if ( req.readyState == 3 && onload == 2 ) {
			onload ++;
			//document.getElementById("messages").innerHTML+=' / 3 : &#x2714;';
		}
		if ( req.readyState == 4 && onload == 3 ) {
			onload ++;
			if ( req.status == 200 ) {
				document.getElementById("loading").innerHTML='';
				//document.getElementById("loading").className="hidden";
				//document.getElementById("messages").innerHTML+=' / 4 : &#x2714;<br />';
				obj = document.getElementById(div);
				obj.innerHTML = utf8_decode(utf8_encode(req.responseText));
				if (d!='' && b!='album') { document.getElementById(d).focus(); }
				if (mess == 'false') {
					document.getElementById("messages").innerHTML='';
					document.getElementById("messages").className="hidden";
				}
			} 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 (postdata != "") 
			postdata += "&";
			postdata += obj1.elements[i].name + "=" + escape(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").innerHTML='Op&eacute;ration en cours : <br />1 : &#x2714;';
			document.getElementById("messages").focus();
			document.getElementById(div).innerHTML='<div align="center" class="normalb">Chargement en cours ...</div>';
		}
		if ( req1.readyState == 2 && onload1 == 1 ) {
			onload1 ++;
			//document.getElementById("messages").innerHTML += ' / 2 : &#x2714;';
		}
		if ( req1.readyState == 3 && onload1 == 2 ) {
			onload1 ++;
			//document.getElementById("messages").innerHTML += ' / 3 : &#x2714;';
		}
		if ( req1.readyState == 4 && onload1 == 3 ) {
			onload1 ++;
			if ( req1.status == 200 ) {
				obj2 = document.getElementById("messages");
				//obj2.innerHTML += ' / 4 : &#x2714;<br />' + utf8_decode(utf8_encode(req1.responseText)) + '<br />';
				obj2.innerHTML = utf8_decode(utf8_encode(req1.responseText));
				g_ajax(fichier,
					((b=='deconnexion' || b=='post')?
						''
						:((b=='login' || b=='del_membre')?
							'membres'
							:((b=='modifier_membre')?
								'voir_membre'
								:((b=='ajout_actualite' || b=='modifier_actualite' || b=='del_actualite')?
									'actualites'
									:((b=='modifier_albums')?
										'albums'
										:((b=='modifier_fan_club')?
											'fan_club'
											:((b=='modifier_coloriages')?
												'coloriages'
												:((b=='modifier_gifs')?
													'gifs'
													:b
												)
											)
										)
									)
								)
							)
						)
					),p1,p2,p3,'true',d,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 );
	}
}