﻿function TwlComments()
{
	this.text_comment = "";
	this.ax_request;
	
	var AxAddComment = {
		delay: 200,
		prepare: function() { 
			InputVar = new Array(myTwlVideo.IdVideo,myTwlAuth.MemberId,myTwlComments.text_comment);
		},
		call: proxies.AjaxFunc.AddCommentVideo,
		finish: function (p) 
		{ 
			document.getElementById("TwlCommentsNb").innerHTML = "Commentaires (" + p + ")";
			myTwlComments.UpdateComments("1");
			myTwlComments.ShowComments();	
		},
		onException: ajax.alertException
	}
	
	
	this.AddComment = function ()
	{

		if (myTwlAuth.NoMember)
		{
			
			document.getElementById("TwlCommentsAdd").style.display = "none";
			document.getElementById("TwlLoginFixed").style.display = "";
			myTwlAuth.CallBack = function () { myTwlComments.AddComment(); };
		}
		else
		{
			
			document.getElementById("TwlLoginFixed").style.display = "none";	
			document.getElementById("TwlCommentsListe").style.display = "none";	
			document.getElementById("TwlCommentsAdd").style.display = "";
		}
	}
	
	this.ExecAddComment = function ()
	{
		myTwlComments.text_comment = document.getElementById("twl_txt_comment").value;
		if (myTwlComments.text_comment != "" && myTwlComments.text_comment != "Votre commentaire")
		{
			SoapMethod = "POST";
			ajax.Start(AxAddComment);
		}
	}
	
	this.EmptyTextComment = function ()
	{
		if (document.getElementById("twl_txt_comment").value == "Votre commentaire")
			document.getElementById("twl_txt_comment").value = "";
	}
	
	this.ShowComments = function ()
	{
		document.getElementById("TwlLoginFixed").style.display = "none";	
		document.getElementById("TwlCommentsAdd").style.display = "none";
		document.getElementById("TwlCommentsListe").style.display = "";	
	}
	
	
	this.UpdateComments = function (AbsPage)
	{
		
		var url = "/ax/comments.aspx?ID_VIDEO=" + myTwlVideo.IdVideo + "&ABS_PAGE=" + AbsPage + "&t=" + String(Math.floor((new Date()).getTime() / 1000));
		myTwlComments.ax_request = GetXmlHttpObject(CallBackDisplayComments);
		SendXmlHttpRequest(myTwlComments.ax_request, url); 
	}
	
	function CallBackDisplayComments() 
	{ 
	    
		try
		{
			if (myTwlComments.ax_request.readyState == 4 || myTwlComments.ax_request.readyState == 'complete')
			{
	            
				var ax_response = myTwlComments.ax_request.responseText; 
				if (ax_response.length > 0)
				{
					document.getElementById("TwlCommentsListeItems").innerHTML = ax_response; 
				} 
			}
		}
		catch(e){}
	}

}


var myTwlComments = new TwlComments();
