function Comments(id,rootdir)
{
	this.id			 = id;
	this.div		 = document.getElementById('comments');
	this.showDiv	 = document.getElementById('vc_show');
	this.hideDiv	 = document.getElementById('vc_hide');
	this.postType	 = document.getElementById('c_type');
	this.postName	 = document.getElementById('name');
	this.postText	 = document.getElementById('comment');
	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(':::',3);
					var err_code = response[0];
					var capcha_src = response[1];
						oThis.postCaptcha.src = capcha_src;
					var comment_txt = response[2];
					switch(err_code)
					{	
						case '0':
							oThis.div.innerHTML += comment_txt;
							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);
			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('comments');
            el.style.display="block" ;
			var el = document.getElementById('show');
            el.style.display="none" ;
			ajax.runAJAX();
		}
		else
		{
			alert(this.err);
			this.err = '';
		}
	}
}