var state = 'none';
function showhide(layer_ref){
	if(state == 'block'){
	state = 'none';
	}else{
	state = 'block';
	}
	if(document.all){ //IS IE 4 or 5 (or 6 beta)
	eval("document.all." +layer_ref+ ".style.display = state");
	}
	if (document.layers) { //IS NETSCAPE 4 or below
	document.layers[layer_ref].display = state;
	}
	if (document.getElementById &&!document.all) {
	hza = document.getElementById(layer_ref);
	hza.style.display = state;
	}
}

function mkvis(layer_ref){
	if(document.all){ //IS IE 4 or 5 (or 6 beta)
	eval("document.all." +layer_ref+ ".style.visibility = 'visible'");
	}
	if (document.layers) { //IS NETSCAPE 4 or below
	document.layers[layer_ref].visibility = 'visible';
	}
	if (document.getElementById &&!document.all) {
	hza = document.getElementById(layer_ref);
	hza.style.visibility = 'visible';
	}
}

function mkinvis(layer_ref){
	if(document.all){ //IS IE 4 or 5 (or 6 beta)
	eval("document.all." +layer_ref+ ".style.visibility = 'hidden'");
	}
	if (document.layers) { //IS NETSCAPE 4 or below
	document.layers[layer_ref].visibility = 'hidden';
	}
	if (document.getElementById &&!document.all) {
	hza = document.getElementById(layer_ref);
	hza.style.visibility = 'hidden';
	}
}

function connajax(){
	document.getElementById("ajaxboxerror").innerHTML="";
	var compteslogin=document.getElementById("ajaxboxlogin").value;
	var comptespass=document.getElementById("ajaxboxpass").value;
	var comptestype=document.getElementById("ajaxboxtype").value;
	var conserv=document.getElementById("ajaxboxconserv").checked;
	var xmlhttp=null;
	try {
		xmlhttp = new XMLHttpRequest(); 
	} catch(e) { 
		try { 
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
		} catch (e2) { 
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
			} catch (e) {}
		}
	}
	var datasend = "compteslogin=" + compteslogin + "&comptespass=" + comptespass + "&comptestype=" + comptestype + "&conserv=" + conserv;
	xmlhttp.open("POST", "http://www.doona.fr/comptes/connectajax.php", true);
	mkvis("ajaxloadheader");
	xmlhttp.onreadystatechange = function() {
		if((xmlhttp.readyState == 4)&&(xmlhttp.status == 200)){
			mkinvis("ajaxloadheader");
			retour=xmlhttp.responseText;
			if(retour=="manquant"){
				document.getElementById("ajaxboxerror").innerHTML="&gt; Champs manquants.";
			} else if(retour=="erreur"){
				document.getElementById("ajaxboxerror").innerHTML="&gt; Erreur.";
			} else if(retour=="noninscrit"){
				document.getElementById("ajaxboxerror").innerHTML="&gt; Mail inconnu.";
			} else if(retour=="mauvaispass"){
				document.getElementById("ajaxboxerror").innerHTML="&gt; Mauvais pass.";
			} else {
				showhide("formconn");
				affinfos=retour + " <input type='image' align='absmiddle' src='http://www.doona.fr/images/logout.gif' onclick='deconnajax();' />"
				document.getElementById("conninfos").innerHTML=affinfos;
				var doc=document.location.href.split("?");
				if((doc[0]!="http://www.doona.fr/")&&(doc[0]!="http://www.doona.fr/index.php")){
					window.location.reload();
				}
			}
		}
	}
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                  
	xmlhttp.send(datasend);
}

function deconnajax(){
	var xmlhttp=null;
	try {
		xmlhttp = new XMLHttpRequest(); 
	} catch(e) { 
		try { 
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
		} catch (e2) { 
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
			} catch (e) {}
		}
	}
	var datasend = null;
	xmlhttp.open("POST", "http://www.doona.fr/comptes/deconnectajax.php", true);
	mkvis("ajaxloadheader");
	xmlhttp.onreadystatechange = function() {
		if((xmlhttp.readyState == 4)&&(xmlhttp.status == 200)){
			mkinvis("ajaxloadheader");
			retour=xmlhttp.responseText;
			if(retour=="ok"){
				affinfos="<a onclick='showhide(\"formconn\");'>Connexion</a>"
				document.getElementById("conninfos").innerHTML=affinfos;
				var doc=document.location.href.split("?");
				if((doc[0]!="http://www.doona.fr/")&&(doc[0]!="http://www.doona.fr/index.php")){
					window.location.reload();
				}
			} else {
			}
		}
	}
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                  
	xmlhttp.send(datasend);
}

window.onload=function() {	
	showhide("formconn");
	showhide("formconn");
}
