function GlamourAjaxComment() 
{
	this.reqComment = null;
}

GlamourAjaxComment.reqComment = null;

GlamourAjaxComment.send = function(url,target) 
{
	document.getElementById(target).innerHTML = '';
	if (window.XMLHttpRequest) 
	{
		GlamourAjaxComment.reqComment = new XMLHttpRequest();
		GlamourAjaxComment.reqComment.onreadystatechange = function() {GlamourAjaxComment.ajaxCallback(target);};
		GlamourAjaxComment.reqComment.open("GET", url, true);
		GlamourAjaxComment.reqComment.send(null);
	}
	else if (window.ActiveXObject) 
	{
		GlamourAjaxComment.reqComment = new ActiveXObject("Microsoft.XMLHTTP");
		if (GlamourAjaxComment.reqComment) 
		{
			GlamourAjaxComment.reqComment.onreadystatechange = function() {GlamourAjaxComment.ajaxCallback(target);};
			GlamourAjaxComment.reqComment.open("GET", url, true);
			GlamourAjaxComment.reqComment.send();
		}
	}
};
	
GlamourAjaxComment.loadComment = function(nid) 
{
	GlamourAjaxComment.send("/applications/comment/load.php?nid=" + nid, "div_comment");
};
	
GlamourAjaxComment.submitComment = function()
{
	if (!GlamourAjaxComment.checkCommentForm()) return;

	url = "/applications/comment/submit.php";
	target = "div_comment";
	
	data = "comment-form-nid=" + GlamourAjaxComment.escape($("comment-form-nid").value)
			+	"&comment-form-authz=" + GlamourAjaxComment.escape($("comment-form-authz").value)
			+	"&comment-form-challenge=" + GlamourAjaxComment.escape($("comment-form-challenge").value)
			+	"&comment-form-name=" + GlamourAjaxComment.escape($("comment-form-name").value)
			+	"&comment-form-mail=" + GlamourAjaxComment.escape($("comment-form-mail").value)
			+	"&comment-form-subject=" + GlamourAjaxComment.escape($("comment-form-subject").value)
			+	"&comment-form-comment=" + GlamourAjaxComment.escape($("comment-form-comment").value);
		
	document.getElementById(target).innerHTML = '';
	if (window.XMLHttpRequest) 
	{
		GlamourAjaxComment.reqComment = new XMLHttpRequest();
		GlamourAjaxComment.reqComment.onreadystatechange = function() {GlamourAjaxComment.ajaxCallback(target);};
		GlamourAjaxComment.reqComment.open("POST", url, true);
		GlamourAjaxComment.reqComment.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=utf-8');
		GlamourAjaxComment.reqComment.send(data);
	}
	else if (window.ActiveXObject) 
	{
		GlamourAjaxComment.reqComment = new ActiveXObject("Microsoft.XMLHTTP");
		if (GlamourAjaxComment.reqComment) {
			GlamourAjaxComment.reqComment.onreadystatechange = function() {GlamourAjaxComment.ajaxCallback(target);};
			GlamourAjaxComment.reqComment.open("POST", url, true);
			GlamourAjaxComment.reqComment.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			GlamourAjaxComment.reqComment.send(data);
		}
	}
};
	
GlamourAjaxComment.ajaxCallback = function(target)
{
	if (GlamourAjaxComment.reqComment.readyState == 4) 
	{
		if (GlamourAjaxComment.reqComment.status == 200) 
		{
			results = GlamourAjaxComment.reqComment.responseText;
			document.getElementById(target).innerHTML = results;
		}
		else 
		{
			document.getElementById(target).innerHTML="MyAjax error:\n" +
				GlamourAjaxComment.reqComment.statusText;
		}
	}
};
	
GlamourAjaxComment.escape = function(txt) 
{
	return txt.replace(/&/g, escape("&"));
};
	
GlamourAjaxComment.checkCommentForm = function()
{
	var formComment = $("comment-form");
	var captcha = formComment.getElementsByTagName("EM")[0];
	if (captcha) 
	{
		var captcha_challenge = $("comment-form-challenge");
		try {
			if (!(captcha_challenge.value && eval(captcha.innerHTML) == captcha_challenge.value))
			{
				alert("Réponse au filtre anti-spam incorrecte.");
				captcha_challenge.focus();
				return false;
			}
		}
		catch (e)
		{
			alert("Réponse au filtre anti-spam incorrecte.");
			captcha_challenge.focus();
			return false;		
		}
	}
	
	var pseudo = $("comment-form-name");
	var mail = $("comment-form-mail");
	var commentaire = $("comment-form-comment");
	
	if (pseudo.value == "")
	{
		alert("Veuillez indiquer votre pseudo.");
		pseudo.focus();
		return false;
	}
	
	if (mail.value == "")
	{
		alert("Veuillez indiquer votre e-mail.");
		mail.focus();
		return false;
	}
	if (mail.value != "" && VerifMail(mail.value, false) == false)
	{
		alert("Votre e-mail est incorrecte, veuillez entrer une adresse e-mail valide.");
		mail.focus();
		return false;
	}

	if (commentaire.value == "")
	{
		alert("Veuillez entrer un commentaire.");
		commentaire.focus();
		return false;
	}
	
	return true;	
}
