
/*  
	Magnat Sp z o.o.
	© All rights reserved
*/

var mwcms_comments = {
	
	animate : true,
	acomcnt : 0,
	comment_box : Object,
	notbusy : true,
	
	ajax : function () 
	{
		var xhttp;
			  
		if (!xhttp && typeof XMLHttpRequest != "undefined") 
		{
			try 
			{
				xhttp = new XMLHttpRequest();
			} catch (e) {
				xhttp = false;
			}
		}
		
		return xhttp;
	},

	animate_comment_box : function() {
		this.acomcnt+=7;
		if(this.acomcnt<205)
		{
			this.comment_box.style.height = (this.acomcnt) + "px";
			setTimeout("mwcms_comments.animate_comment_box()",4);	
		} else { this.acomcnt = 0; }
	},

	onlylogged : function(caption) {
		var comment_caption = document.getElementById("comment_caption");
		comment_caption.innerHTML = caption;
		comment_caption.style.background = '';
		comment_caption.style.width = '50%';
		comment_caption.style.margin = '-5px 10px 0px 0px';
	},

	closeform : function(divid) {
		this.comment_box = document.getElementById(divid);
		this.comment_box.style.display = 'none';
		this.comment_box.innerHTML = '';
	},

	showform : function(divid,item_id,type,action,topic,comment,submit,subname,re,content,closeico) {
		this.comment_box = document.getElementById(divid);
		var form_obj;
		var form_id = 1;
		while(form_id>0)
		{
			form_obj = document.getElementById('comment_form_'+form_id);
			if(form_obj!=null) 
			{ 
				form_id++;
				form_obj.style.height = '';
				this.comment_box.innerHTML = '';
				form_obj.style.display = 'none';
			} else {form_id = 0; }
		}
		
		this.comment_box.innerHTML = '<form action="'+action+'" method="post">'+
								'<div style="padding: 3px; margin-top: 1px;">'+
								'<div style="float: left;">'+topic+':</div><div style="float: right;"><img class="pointer" src="'+closeico+'" onclick="javascript:mwcms_comments.closeform(\''+divid+'\');" alt="X" /></div>'+
								'<div style="clear: both;"><input type="text" class="inputs" style="width: 100%" value="'+re+'" maxlength="150" name="commenttopic" /></div>'+
								comment+':'+
								'<div><textarea class="inputs" style="width: 100%; height: 120px;" name="commentcontent">'+content+'</textarea></div>'+
								'<input type="hidden" value="'+item_id+'" name="item_id" />'+
								'<input type="hidden" value="'+type+'" name="type" />'+
								'<input type="hidden" value="false" name="clear_post_vars" />'+
								'<div style="text-align: right; padding: 3px;"><input type="submit" name="'+subname+'" value="'+submit+'" class="button" /></div></div></form>';
		if(this.animate)
		{   
			this.comment_box.style.height = "1px";
			this.comment_box.style.display = 'block';
			this.animate_comment_box();
		} else {
			this.comment_box.style.display = 'block';
		}
	
	},

	edit : function(url,divid,item_id,type,action,topic,comment,submit,subname,re,closeico) {
		if(this.notbusy)
		{
			this.notbusy = false;
			var request = this.ajax();
			if(request!=false)
			{
				request.onreadystatechange = function(){ 
				if( request.readyState == 4 && request.status == 200 ) 
					{  
					mwcms_comments.showform(divid,item_id,type,action,topic,comment,submit,subname,re,request.responseText,closeico);
					mwcms_comments.notbusy=true;
					}
				}
				request.open("GET", url, true);
				request.send(null);
			}
		}
	}

}
