function E(x){ return document.getElementById(x) }
function W(x){ return document.write(x) }
function U(x){ return encodeURIComponent(x) }
function D(x){ return typeof x!="undefined" }

var base="http://"+location.hostname+"/";
var IE=/*cc_on!@*/false;

//----------------------------------------------//

function getdata(p){
	var req=new XMLHttpRequest();
	req.open("GET",base+"inc/"+p,false);
	req.send();
	return eval("("+req.responseText+")");
}

function post(p,vars){
	var req=new XMLHttpRequest();
	req.open("POST",base+"inc/"+p,false);
	req.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	req.send(vars);
	return req.responseText;
}

//----------------------------------------------//

function swf(url,args,bg,w,h){
	var id,obj,p,i;

	id=url+"swf";
	url="/swf/"+url+".swf?"+args;

	obj="<object id='"+id+"' name='"+id+"' width='"+w+"' height='"+h+"' "+
	(IE?
		"classid='clsid:D27CDB6E-AE6D-11CF-96B8-444553540000' codebase='http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab'>":
		"type='application/x-shockwave-flash' data='"+url+"'>"
	);

	var p={
		movie:url,
		bgcolor:bg,
		wmode:"transparent",
		allowFullScreen:"true",
		allowScriptAccess:"always",
		scale:"noScale",
		salign:"TL"
	};
	for(var i in p)
		obj+="<param name='"+i+"' value='"+p[i]+"'>";
	return obj+"</object>";
}

//----------------------------------------------//

var fade={
	open:function(o){
		var e=document.documentElement;
		var b=document.body;
		o.style.display=E("overlay").style.display="block";
		window.onscroll=function(){
			o.style.left=(e.scrollLeft+(e.clientWidth -o.offsetWidth )/2)+"px";
			o.style.top =(e.scrollTop +(e.clientHeight-o.offsetHeight)/2)+"px";
		};
		(window.onresize=function(){
			var w,h;
			E("overlay").style.width=0;
			if(IE)
				w=Math.max(b.scrollWidth,b.offsetWidth);
			else
				w=e.scrollWidth;
			h=Math.max(b.scrollHeight,e.clientHeight);
			E("overlay").style.width =w+"px";
			E("overlay").style.height=h+"px";
			window.onscroll();
		})();
		o.parentNode.insertBefore(E("overlay"),o);
	},
	close:function(o){
		o.style.display=E("overlay").style.display="none";
		window.onresize=null;
	}
};

//----------------------------------------------//

var login={
	open:function(){
		fade.open(E("loginform"));
		E("loginuser").focus();
	},

	close:function(){
		fade.close(E("loginform"));
	},

	form:function(){W(
		"<div id='loginform' style='display:none;position:absolute;width:400px'>"+
			"<table class='tbl1' width='310' align='center'>"+
				"<tr>"+
					"<td align='left' width='100'>Pseudo:</td>"+
					"<td align='right'><input type='text' id='loginuser' size='25' maxlength='25'></td>"+
				"</tr>"+
				"<tr>"+
					"<td align='left'>Mot de passe:</td>"+
					"<td align='right'><input type='password' id='loginpass' size='25'></td>"+
				"</tr>"+
				"<tr>"+
					"<td colspan='2'>"+
						"<p>"+
							"<label><input type='checkbox' id='loginremember'> Se souvenir de moi</label><br>"+
							"<a href='javascript:login.forgot()' id='loginforgot1'>Mot de passe oublié?</a>"+
						"</p>"+
						"<button onclick='login.submit1()'><div><b>Valider</b></div></button>&nbsp;"+
						"<button onclick='login.close()'><div><b>Annuler</b></div></button>"+
						"<div id='loginforgot2' style='display:none'>"+
							"<hr><b>Pseudo ou mot de passe oublié?</b>"+
							"<br>Entrez votre adresse email pour recevoir votre pseudo et un nouveau mot de passe:"+
							"<br><input type='text' id='loginemail' style='width:289px;margin:10px 0'>"+
							"<br><button onclick='login.submit2()'><div><b>Valider</b></div></button>"+
						"</div>"+
					"</td>"+
				"</tr>"+
			"</table>"+
			"<div id='loginmsg' class='tbl1' style='display:none;padding:10px;margin-top:30px'></div>"+
		"</div>"
	)},

	forgot:function(){
		E("loginforgot1").style.display="none";
		E("loginforgot2").style.display="block";
	},

	msg:function(x){
		E("loginmsg").style.display="block";
		E("loginmsg").innerHTML="<b>"+x+".</b>";
	},

	submit1:function(){
		var name=E("loginuser").value;
		var pass=E("loginpass").value;
		if(name=="" || pass==""){
			this.msg("Entrez votre pseudo et mot de passe");
			return;
		}
		switch(post("login.php",
			"act=login"+
			"&name="+U(name)+
			"&pass="+U(pass)+
			"&rem=" +E("loginremember").checked
		)){
			case "0": this.msg("Pseudo ou mot de passe invalide");break;
			case "1": this.msg("Ce compte n'est pas confirmé"   );break;
			case "2": window.location.reload();
		}
	},

	submit2:function(){
		var email=E("loginemail").value;
		if(email==""){
			this.msg("Entrez votre email");
			return;
		}
		switch(post("login.php","act=forgot&email="+U(email))){
			case "0": this.msg("Aucun membre ne correspond à l'adresse email spécifiée"); break;
			case "1": this.msg("Votre pseudo et un lien pour réinitialiser le mot de passe ont été envoyés à <u>"+email.replace(/</g,"&lt;")+"</u>");
		}
	}
};

