function Comments(id,rootdir)
{
	this.id			 = id;
	this.film_id	 = document.getElementById('film_id');
	this.div		 = document.getElementById('board');
	this.showDiv	 = document.getElementById('comment');
	this.hideDiv	 = document.getElementById('board');
	this.postType	 = document.getElementById('c_type');
	this.postName	 = document.getElementById('name');
	this.postText	 = document.getElementById('comment_text');
	this.postCaptcha = document.getElementById('commentCaptcha');
	this.postCcode	 = document.getElementById('ccode');
	this.rootdir	 = rootdir;
	this.err		 = '';


	this.validate = function()
	{
		var valid = true;
		if (this.postName.value == '')
		{
			this.err = this.err + "Please, enter your name\n";
			valid = false;
		}

		if (this.postText.value == '')
		{
			this.err = this.err + "Please, enter comment\n";
			valid = false;
		}
		return valid;
	}

	this.showComments = function(show)
	{
		if (this.showDiv != null && this.hideDiv != null) {
			if (show) {
				this.div.style.display = 'block';
				this.showDiv.style.display = 'none';
				this.hideDiv.style.display = 'block';
			}
			else {
				this.div.style.display = 'none';
				this.showDiv.style.display = 'block';
				this.hideDiv.style.display = 'none';
			}
		}
	}

	this.postComment = function()
	{
		
		if (this.validate())
		{
			var oThis = this;
			var ajax = new sack();
			ajax.method = 'POST';
			ajax.encodeURIString = false;
			ajax.requestFile = this.rootdir+"/include/ajax/comments.php";
			ajax.onCompletion = function()
			{
				location.href='#postform';
				if (ajax.response != '')
				{
					var response = ajax.response.split(':::',5);
					var err_code = response[0];
					var capcha_src = response[1];
						oThis.postCaptcha.src = capcha_src;
					var comment_txt = response[2];
					var comment_txt2 = response[3];
					var comment_txt3 = response[4];
					
					
					
					var comments11='<table width="100%"><tbody><tr><td><div class="ctl"><div class="ctr"><div class="cbr"><div class="cbl"><p class="content">'+comment_txt3+'</p></div></div></div></div></td><td width="200px"><p class="author"><a href="">'+comment_txt2+'</a>'+comment_txt+'</p></td></tr></tbody></table>';
					
					
					switch(err_code)
					{	
						case '0':
							oThis.div.innerHTML = comments11 + oThis.div.innerHTML;
							oThis.showComments(true);
							
							oThis.postName.value = "";
							oThis.postText.value = "";
							oThis.postCcode.value = "";
						break;	

						case '1':
							alert('Name or comment text is not valid!');
							oThis.postCcode.value = "";
							oThis.postText.focus();
						break;	

						case '2':
							alert('Please, enter valid code');
							oThis.postCcode.value = '';
							oThis.postCcode.focus();
						break;	
					}
				}
				else
					alert("Error occured while posting your comment!\nPlease, try again!"); 
			}
			
			ajax.setVar('id', this.id.value);
			ajax.setVar('film_id', this.film_id.value);
			ajax.setVar('name', this.postName.value);
			ajax.setVar('comment', this.postText.value);
			ajax.setVar('type', this.postType.value);
			ajax.setVar('ccode', this.postCcode.value);
			var el = document.getElementById('comment');
            el.style.display="block" ;
            var el = document.getElementById('board');
            el.style.display="block" ;
   	
			
			ajax.runAJAX();
		}
		else
		{
			alert(this.err);
			this.err = '';
		}
	}
}