function createXhrObject(){
	if (window.XMLHttpRequest)
        return new XMLHttpRequest();
    if (window.ActiveXObject){
        var names = ["Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.3.0","Msxml2.XMLHTTP","Microsoft.XMLHTTP"];
        for(var i in names){try{ return new ActiveXObject(names[i]);}catch(e){}}
    }
	window.alert("Votre navigateur ne prend pas en charge l'objet XMLHTTPRequest.");
	return null;
}
function getEventType(e){
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3)
		targ = targ.parentNode;
	return targ;
}
function captcha(nbcar){
	var listeCar = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
	var chaine = '';
	var val = '';
	
	for(i = 0; i < nbcar; i++){
		chaine = chaine+'<div id="';
		var car = listeCar[Math.floor(Math.random()*listeCar.length)];
		chaine = chaine+car;
		val = val+car;
		chaine = chaine+'" ></div>';
	}
	if(document.getElementById("codeIn"))
		document.getElementById("codeIn").value = val;
	if(document.getElementById("verifComsIn"))
		document.getElementById("verifComsIn").value = val;
	if(document.getElementById("captcha1"))
		document.getElementById("captcha1").innerHTML = chaine;
	else if (document.getElementById("captcha2"))
		document.getElementById("captcha2").innerHTML = chaine;
}
function testField(e){
	var targ = getEventType(e);
	var alertCom = document.getElementById('AlertCommentaire');
	if(targ.id=="emailCommentaire"){
		var expressionRemail = new RegExp('^[a-zA-Z0-9\-\_]+[a-zA-Z0-9\.\-\_]*@[a-zA-Z0-9\_]+[a-zA-Z0-9\.\-\_]*[\.]{1}[a-zA-Z]{2,5}$','g');
		if(targ.value==''){ alertCom.style.display='inline'; alert.innerHTML="<span class='rouge'>champ vide!</span>"; }
		else if(!expressionRemail.test(targ.value)){ alertCom.style.display='inline'; alertCom.innerHTML="<span class='rouge'>email invalide!</span>"; }
		else{ alertCom.style.display='none'; alertCom.innerHTML=""; }
	}
	else if(targ.id=="pseudoCommentaire"){
		if(targ.value == ""){ alertCom.style.display='inline'; alertCom.innerHTML="<span class='rouge'>champ vide!</span>"; }
		else{ alertCom.style.display='none'; alertCom.innerHTML=""; }
	}
	else if(targ.id=="textareaCommentaire"){
		if(targ.value == ""){ alertCom.style.display='inline'; alertCom.innerHTML="<span class='rouge'>champ vide!</span>"; }
		else{ alertCom.style.display='none'; alertCom.innerHTML=""; }
	}
	else if(targ.id=="verifComsOut"){
		if(targ.value.toLowerCase() != document.getElementById('verifComsIn').value){ alertCom.style.display='inline'; alertCom.innerHTML="<span class='rouge'>code diff&eacute;rent</span>"; }
		else{ alertCom.style.display='none'; alertCom.innerHTML=""; }
	}
	else if(targ.id=="nomMessage"){
		targ.style.backgroundColor ="#CCCCCC";
		targ.style.color ="#777777";
		if(targ.value == ""){
			document.getElementById('AlertNomMessage').style.display='inline';
			document.getElementById('AlertNomMessage').innerHTML="<img src='/images/invalide.png' width='30' height='30' alt='invalide' />";
		}
		else{
			document.getElementById('AlertNomMessage').style.display='inline';
			document.getElementById('AlertNomMessage').innerHTML="<img src='/images/valide.png' width='30' height='30' alt='valide' />";
		}
	}
	else if(targ.id=="prenomMessage"){
		targ.style.backgroundColor ="#CCCCCC";
		targ.style.color ="#777777";
		if(targ.value == ""){
			document.getElementById('AlertPrenomMessage').style.display='inline';
			document.getElementById('AlertPrenomMessage').innerHTML="<img src='/images/invalide.png' width='30' height='30' alt='invalide' />";
		}
		else{
			document.getElementById('AlertPrenomMessage').style.display='inline';
			document.getElementById('AlertPrenomMessage').innerHTML="<img src='/images/valide.png' width='30' height='30' alt='valide' />";
		}
	}
	else if(targ.id=="emailMessage"){
		targ.style.backgroundColor ="#CCCCCC";
		targ.style.color ="#777777";
		var expressionRemail = new RegExp('^[a-zA-Z0-9\-\_]+[a-zA-Z0-9\.\-\_]*@[a-zA-Z0-9\_]+[a-zA-Z0-9\.\-\_]*[\.]{1}[a-zA-Z]{2,5}$','g');
		if(targ.value == ""){ 
			document.getElementById('AlertEmailMessage').style.display='inline';
			document.getElementById('AlertEmailMessage').innerHTML="<img src='/images/invalide.png' width='30' height='30' alt='invalide' />";
		}	
		else if(!expressionRemail.test(targ.value)){
			document.getElementById('AlertEmailMessage').style.display='inline';
			document.getElementById('AlertEmailMessage').innerHTML="<span class='rouge'>xxx@xxx.xxx</span>";
		}    
		else{
			document.getElementById('AlertEmailMessage').style.display='inline';
			document.getElementById('AlertEmailMessage').innerHTML="<img src='/images/valide.png' width='30' height='30' alt='valide' />";
		}
	}
	else if(targ.id=="confirmationEmailMessage"){
		targ.style.backgroundColor ="#CCCCCC";
		targ.style.color ="#777777";
		if(targ.value != document.getElementById('emailMessage').value || targ.value==''){ 
			document.getElementById('AlertConfirmationEmailMessage').style.display='inline';
			document.getElementById('AlertConfirmationEmailMessage').innerHTML="<img src='/images/invalide.png' width='30' height='30' alt='invalide' />";
		}	  
		else{
			document.getElementById('AlertConfirmationEmailMessage').style.display='inline';
			document.getElementById('AlertConfirmationEmailMessage').innerHTML="<img src='/images/valide.png' width='30' height='30' alt='valide' />";
		}
	}
	else if(targ.id=="message"){
		targ.style.backgroundColor ="#CCCCCC";
		targ.style.color ="#777777";
		if(targ.value == ""){ 
			document.getElementById('AlertMessage').style.display='inline';
			document.getElementById('AlertMessage').innerHTML="<img src='/images/invalide.png' width='30' height='30' alt='invalide' />";
		}	  
		else{
			document.getElementById('AlertMessage').style.display='inline';
			document.getElementById('AlertMessage').innerHTML="<img src='/images/valide.png' width='30' height='30' alt='valide' />";
		}
	}
	else if(targ.id=="objetMessage"){
		targ.style.backgroundColor ="#CCCCCC";
		targ.style.color ="#777777";
	}
	else if(targ.id=="siteMessage"){
		targ.style.backgroundColor ="#CCCCCC";
		targ.style.color ="#777777";
	}
	else if(targ.id=="codeOut"){
		targ.style.backgroundColor ="#CCCCCC";
		targ.style.color ="#777777";
		if(targ.value.toLowerCase() != document.getElementById('codeIn').value){
			document.getElementById('AlertCodeMessage').style.display='inline';
			document.getElementById('AlertCodeMessage').innerHTML="<span class='rouge'>code diff&eacute;rent</span>"; 
		}
		else{ 
			document.getElementById('AlertCodeMessage').style.display='inline'; 
			document.getElementById('AlertCodeMessage').innerHTML="<img src='/images/valide.png' width='30' height='30' alt='valide' />"; 
		}
	}
	else if(targ.id=="emailMdp"){
		var expressionRemail = new RegExp('^[a-zA-Z0-9\-\_]+[a-zA-Z0-9\.\-\_]*@[a-zA-Z0-9\_]+[a-zA-Z0-9\.\-\_]*[\.]{1}[a-zA-Z]{2,5}$','g');
		if(targ.value==''){ 
			document.getElementById('AlertEmailMdp').style.display='inline';
			document.getElementById('AlertEmailMdp').innerHTML="<img src='/images/invalide.png' width='30' height='30' alt='invalide' />";
		}	
		else if(!expressionRemail.test(targ.value)){
			document.getElementById('AlertEmailMdp').style.display='inline';
			document.getElementById('AlertEmailMdp').innerHTML="<span class='rouge'>xxx@xxx.xxx</span>";
		}    
		else{
			document.getElementById('AlertEmailMdp').style.display='inline';
			document.getElementById('AlertEmailMdp').innerHTML="<img src='/images/valide.png' width='30' height='30' alt='valide' />";
		}
	}
	else if(targ.id=="emailInscription"){
		var expressionRemail = new RegExp('^[a-zA-Z0-9\-\_]+[a-zA-Z0-9\.\-\_]*@[a-zA-Z0-9\_]+[a-zA-Z0-9\.\-\_]*[\.]{1}[a-zA-Z]{2,5}$','g');
		if(targ.value==''){ 
			document.getElementById('AlertEmailInscription').style.display='inline';
			document.getElementById('AlertEmailInscription').innerHTML="<img src='/images/invalide.png' width='30' height='30' alt='invalide' />";
		}	
		else if(!expressionRemail.test(targ.value)){
			document.getElementById('AlertEmailInscription').style.display='inline';
			document.getElementById('AlertEmailInscription').innerHTML="<img src='/images/invalide.png' width='30' height='30' alt='invalide' /><span class='rouge'>xxx@xxx.xxx</span>";
		}    
		else{
			document.getElementById('AlertEmailInscription').style.display='inline';
			document.getElementById('AlertEmailInscription').innerHTML="<img src='/images/valide.png' width='30' height='30' alt='valide' />";
		}
	}
	else if(targ.id=="jourInscription" || targ.id=="moisInscription" || targ.id=="anneeInscription"){
		if(targ.value=="0"){
			document.getElementById('AlertDateDeNaissance').style.display='inline';
			document.getElementById('AlertDateDeNaissance').innerHTML="<img src='/images/invalide.png' width='30' height='30' alt='invalide' />";
		}	   
		else{
			document.getElementById('AlertDateDeNaissance').style.display='inline';
			document.getElementById('AlertDateDeNaissance').innerHTML="<img src='/images/valide.png' width='30' height='30' alt='valide' />";
		}
	}
	else if(targ.id=="mdpInscription"){
		expressionRmdp = new RegExp('^[a-zA-Z0-9]{6,}','g');
		if(targ.value==''){ 
			document.getElementById('AlertMotDePasseInscription').style.display='inline';
			document.getElementById('AlertMotDePasseInscription').innerHTML="<img src='/images/invalide.png' width='30' height='30' alt='invalide' />";
		}
		else if(!expressionRmdp.test(targ.value)){
			document.getElementById('AlertMotDePasseInscription').style.display='inline';
			document.getElementById('AlertMotDePasseInscription').innerHTML="<img src='/images/invalide.png' width='30' height='30' alt='invalide' /> 6 caract&egrave;res minimum!";
		}
		else{
			document.getElementById('AlertMotDePasseInscription').style.display='inline';
			document.getElementById('AlertMotDePasseInscription').innerHTML="<img src='/images/valide.png' width='30' height='30' alt='valide' />";
		}
	}
	else if(targ.id=="mdpInscriptionConfirmation"){
		if(targ.value != document.getElementById('mdpInscription').value){ 
			document.getElementById('AlertConfirmationMotDePasse').style.display='inline';
			document.getElementById('AlertConfirmationMotDePasse').innerHTML="<img src='/images/invalide.png' width='30' height='30' alt='invalide' />";
		}	   
		else{
			document.getElementById('AlertConfirmationMotDePasse').style.display='inline';
			document.getElementById('AlertConfirmationMotDePasse').innerHTML="<img src='/images/valide.png' width='30' height='30' alt='valide' />";
		}
	}
}
function onFocus(e){
	var targ = getEventType(e);
	targ.style.backgroundColor ="#FFFFFF";
	targ.style.color ="#000000";
}
function submitFormMdp(){
	expressionRemail = new RegExp('^[a-zA-Z0-9\-\_]+[a-zA-Z0-9\.\-\_]*@[a-zA-Z0-9\_]+[a-zA-Z0-9\.\-\_]*[\.]{1}[a-zA-Z]{2,5}$','g');
	if((document.getElementById('emailMdp').value=="")|| (!expressionRemail.test(document.getElementById('emailMdp').value))){
		document.getElementById('AlertEmailMdp').style.display='inline';
		document.getElementById('AlertEmailMdp').innerHTML="<span class='rouge'>Entrez v&ocirc;tre adresse email.</span>";
	}
	else{
		xhrZ = null;
		xhrZ = createXhrObject();
		xhrZ.onreadystatechange = function() {
			if(xhrZ.readyState == 1 || xhrZ.readyState == 2 || xhrZ.readyState == 3 ){ document.getElementById('AlertEmailMdp').style.display='inline'; document.getElementById('AlertEmailMdp').innerHTML="<img src='/images/loader.gif' width='16' height='16' alt='chargement' />"; }
			else if (xhrZ.readyState == 4) { document.getElementById('AlertEmailMdp').innerHTML=""; document.getElementById('AlertEmailMdp').style.display='inline'; document.getElementById('AlertEmailMdp').innerHTML=xhrZ.responseText; } 
		}
		xhrZ.open('POST', '/scripts/traitementMdp.php', true);
		xhrZ.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xhrZ.send('email='+document.getElementById('emailMdp').value);
	}
}
function submitFormInscription(){
	var expressionRemail = new RegExp('^[a-zA-Z0-9\-\_]+[a-zA-Z0-9\.\-\_]*@[a-zA-Z0-9\_]+[a-zA-Z0-9\.\-\_]*[\.]{1}[a-zA-Z]{2,5}$','g');
	expressionRmdp = new RegExp('^[a-zA-Z0-9]{6,}','g');
	if((document.getElementById('jourInscription').value=="0")||(document.getElementById('moisInscription').value=="0")||(document.getElementById('anneeInscription').value=="0")||(document.getElementById('emailInscription').value=="")||(!expressionRemail.test(document.getElementById('emailInscription').value))||(document.getElementById('mdpInscription').value=="")|| (!expressionRmdp.test(document.getElementById('mdpInscription').value))||(document.getElementById('mdpInscriptionConfirmation').value != document.getElementById('mdpInscription').value)){
		document.getElementById('AlertInscription').style.display='inline'; document.getElementById('AlertInscription').innerHTML="<span class='rouge'>Remplir tous les champs !</span>";
	}
	else{
		xhrI = null;
		xhrI = createXhrObject();
		xhrI.onreadystatechange = function(){
			if(xhrI.readyState != 4){ document.getElementById('AlertInscription').style.display='inline';document.getElementById('AlertInscription').innerHTML="<img src='/images/loader.gif' width='16' height='16' alt='chargement' />"; }
			else if(xhrI.readyState == 4){ document.getElementById('AlertInscription').innerHTML=""; document.getElementById('AlertInscription').style.display='inline'; document.getElementById('AlertInscription').innerHTML= xhrI.responseText;}		
		}
		xhrI.open('POST', '/scripts/traitementInscription.php', true);
		xhrI.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xhrI.send('email='+document.getElementById('emailInscription').value+'&mdp='+document.getElementById('mdpInscription').value+'&jour='+document.getElementById('jourInscription').value+'&mois='+document.getElementById('moisInscription').value+'&annee='+document.getElementById('anneeInscription').value+'&newsletter='+document.getElementById('newsletter').checked);
	}
}
function photo(){
	xhrP = null;
	xhrP = createXhrObject();
	xhrP.onreadystatechange = function(){
		if(xhrP.readyState == 4) document.getElementById("photo").innerHTML = xhrP.responseText;
	}
	xhrP.open("GET", "/scripts/photo.php", true);
	xhrP.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhrP.send(null);
}
function temps(){
	xhrT = null;
	xhrT = createXhrObject();
	xhrT.onreadystatechange = function(){
		if(xhrT.readyState == 4) document.getElementById("time").innerHTML = xhrT.responseText;
	}
	xhrT.open("GET", "/scripts/time.php", true);
	xhrT.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhrT.send(null);
}
function online(){
	xhrO = null;
	xhrO = createXhrObject();
	xhrO.onreadystatechange = function(){
		if(xhrO.readyState == 4) document.getElementById("online").innerHTML = xhrO.responseText;
		else if(xhrO.readyState == 3) document.getElementById("online").innerHTML = "chargement";
	}
	xhrO.open("GET", "/scripts/online.php", true);
	xhrO.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhrO.send(null);
}
function search(){
	xhrSearch = null;
	xhrSearch = createXhrObject();
	xhrSearch.onreadystatechange = function(){
		if (xhrSearch.readyState == 4){
			if(document.getElementById('champRecherche').value==""){ document.getElementById('searchresult').innerHTML=""; document.getElementById('searchresult').style.display='none'; }
			else{ 
			document.getElementById('searchresult').innerHTML=""; 
			document.getElementById('searchresult').style.display='block';
			document.getElementById('searchresult').innerHTML=xhrSearch.responseText; }
		}	
	}
	xhrSearch.open('POST', '/scripts/search.php', true);
	xhrSearch.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhrSearch.send('searchvalue='+document.getElementById('champRecherche').value);
}
function resolution() {
	xhrRes = null;
	xhrRes = createXhrObject();
	xhrRes.onreadystatechange = function(){ if(xhrRes.readyState == 4) var donnee = xhrRes.responseText; }
	xhrRes.open('POST', '/scripts/resolutionEcran.php', true);
	xhrRes.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhrRes.send('width='+this.screen.width+'&height='+this.screen.height+'&colorDepth='+this.screen.colorDepth);
}
function chat(){
	if(document.getElementById("chat")){
		xhrCh = null;
		xhrCh = createXhrObject();
		xhrCh.onreadystatechange = function(){
			if(xhrCh.readyState == 4) document.getElementById("chat").innerHTML = xhrCh.responseText;
			else if(xhrCh.readyState == 3) document.getElementById("chat").innerHTML = "chargement";
		}
		xhrCh.open("GET", "/scripts/getChat.php", true);
		xhrCh.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhrCh.send(null);
	}
}
function sendFormChat(ip){
	if(document.getElementById('pseudoChat').value ==""){
		document.getElementById('alertChat').innerHTML = "<span class='rouge'>pseudo vide!</span>";
	}
	else{
		document.getElementById('alertChat').innerHTML = "";
		xhrSfm = null;
		xhrSfm = createXhrObject();
		xhrSfm.onreadystatechange = function(){
			if (xhrSfm.readyState == 4){
				if(xhrSfm.responseText==1){
					
				}
				else{
					//document.getElementById('formChat').innerHTML = "";
					document.getElementById('controlchat').innerHTML = xhrSfm.responseText;
				}
			}	
		}
		xhrSfm.open('POST','/scripts/sendFormMessage.php', true);
		xhrSfm.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xhrSfm.send('ip='+ip+'&pseudo='+document.getElementById('pseudoChat').value);
	}
}
function sendMessage(){
	xhrSm = null;
	xhrSm = createXhrObject();
	xhrSm.onreadystatechange = function(){
		if (xhrSm.readyState == 4){
			//document.getElementById('alertMessage').innerHTML=xhrSm.responseText;
		}	
	}
	xhrSm.open('POST', '/scripts/sendMessage.php', true);
	xhrSm.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhrSm.send('chat='+document.getElementById('dialog').value);
}