var sfrms=new Array();
var descon=1;
var shown,nom,courriel,www,contenu,prive;
window.onload=function(){
	if (document.getElementById){
		ntr=new ntr_type();
		cmt=new frm_type();
		//document.getElementById("bltitre").onclick=function(){bringdesc();return false;}
		document.getElementById("encourriel").href=document.getElementById("encourriel").href.replace("[at]","@");
		document.getElementById("frcourriel").href=document.getElementById("encourriel").href.replace("[at]","@");
	}
	if(typeof navto=="function"){
		document.getElementById("navvn").onclick=function(){navto(this.id);return false;}
		document.getElementById("naven").onclick=function(){navto(this.id);return false;}
		navto("navvn");
	}
}
function ntr_type(){
	if(document.getElementsByTagName){
		tag=document.getElementsByTagName("a");
	}
	else if(document.all){
		tag=document.all.tags("a");
	}
	for(i=0;i<tag.length;i++){
		if(tag[i].id.indexOf("ntr-")!=-1){
			ref=tag[i].id.split("-")[1];
			this[ref]=tag[i];
			this[ref].ref=ref;
			this[ref].content=document.getElementById("cnt-"+this[ref].ref);
			this[ref].onclick=function(){show(this.ref);return false;}
		}
	}
}
function frm_type(){
	if(document.getElementsByTagName){
		tag=document.getElementsByTagName("form");
	}
	else if(document.all){
		tag=document.all.tags("form");
	}
	for(i=0;i<tag.length;i++){
		if(tag[i].id.indexOf("fcmt-")!=-1){
			ref=tag[i].id.split("-")[1];
			this[ref]=tag[i];
			this[ref].ref=ref;
			this[ref].linkto=document.getElementById("tfcmt-"+this[ref].ref);
			this[ref].linkto.ref=this[ref].ref;
			this[ref].linkto.style.cursor="pointer";
			this[ref].linkto.onmouseover=function(){this.style.color="#ffffff";}
			this[ref].linkto.onmouseout=function(){this.style.color="#381c10";}
			this[ref].linkto.onclick=function(){showfrm(this.ref);return false;}
			this[ref].comments=document.getElementById("cmt-"+this[ref].ref);
			this[ref].fnom=document.getElementById("nom-"+this[ref].ref);
			this[ref].fcourriel=document.getElementById("courriel-"+this[ref].ref);
			this[ref].fwww=document.getElementById("www-"+this[ref].ref);
			this[ref].fcomment=document.getElementById("commentaire-"+this[ref].ref);
			this[ref].fpriv=document.getElementById("priv-"+this[ref].ref);
			this[ref].sub=document.getElementById("sub-"+this[ref].ref);
			this[ref].sub.ref=this[ref].ref;
			this[ref].sub.onclick=function(){sendcmt(this.ref);return false;}
			this[ref].status=document.getElementById("status-"+this[ref].ref);
			this[ref].status.innerHTML="sending comment.envoi du commentaire";
			this[ref].style.display="none";
		}
	}
}
/*function bringdesc(){
	if(descon==1){
		document.getElementById("subcnt").style.display="none";
		descon=0;
	}
	else{
		if(shown)ntr[shown].content.style.display="none";
		shown="";
		document.getElementById("subcnt").style.display="block";
		descon=1;
	}
}*/
function show(ref){
	//document.getElementById("subcnt").style.display="none";
	if(shown)ntr[shown].content.style.display="none";
	if(ref!=shown){
		ntr[ref].content.style.display="block";
		shown=ref;
	}
	else{
		shown="";
	}
}
function showfrm(ref){
	if(sfrms[ref]==1){
		cmt[ref].style.display="none";
		sfrms[ref]=0;
	}
	else{
		cmt[ref].style.display="block";
		sfrms[ref]=1;
	}
}
function sendcmt(ref){
	cmt[ref].status.style.display="block";
	cmt[ref].style.display="none";
	nom=escape(cmt[ref].fnom.value);
	courriel=escape(cmt[ref].fcourriel.value);
	www=escape(cmt[ref].fwww.value);
	contenu=escape(cmt[ref].fcomment.value);
	(cmt[ref].fpriv.checked)?prive="on":prive="off";
	if(!makeHttpRequest("comment.php?rf="+ref+"&nom="+nom+"&courriel="+courriel+"&www="+www+"&commentaire="+contenu+"&prive="+prive, "getresponse(\""+ref+"\",\"\")"))return true;
}
function getresponse(ref,rep){
	if(rep=="ok"){
		cmt[ref].status.innerHTML="successfully sent.envoyé";
		ajout="<div class=\"bloc\" title=\""+nom;
		if(www)ajout+=" @ "+www;
		moment=new Date();
		jour=moment.getDate();
		mois=moment.getMonth();
		annee=moment.getYear();
		contenu=contenu.replace("%3C","");
		contenu=contenu.replace("%3E","");
		ajout+="on.le "+annee+"-"+mois+"-"+jour+"\"><a id=\"cmt-"+ref+"-z\" href=\"#cmt-z\">"+unescape(contenu)+"</a></div>";
		cmt[ref].comments.innerHTML+=ajout;
		cmt[ref].innerHTML="";
	}
	else{
		cmt[ref].status.style.display="none";
		cmt[ref].style.display="block";
		alert("An error occured while the comment was sent. Please try to submit again. If this error is seen more than once, please contact the site's administrator.\n\nUne erreur est survenue au moment de transmettre le commentaire. Nous vous prions de le soumettre à nouveau. Si l'erreur persiste, veuillez contacter l'administrateur du site.");
	}
}
function makeHttpRequest(url, callback_function){
	var http_request = false;

	if(window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
	}
	else if(window.ActiveXObject) {
		try{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e) {
			try{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e) {}
		}
	}

	if(!http_request) {
		return false;
	}
	http_request.onreadystatechange = function(){
		if(http_request.readyState == 4) {
			if(http_request.status == 200) {
				rtxt=escape(http_request.responseText);
				callback_function=callback_function.replace("\"\"","\""+rtxt+"\"");
				eval(callback_function+";");
			}
			else{
				message(2,'There was a problem with the request.(Code: ' + http_request.status + ')');
			}
		}
	}
	http_request.open('GET', url, true);
	http_request.send(null);
}