(function()
{
	var last1=null;
	var last2=null;
	
	window.shcomtable=function(tid, bid)
	{
		if(last1 && last1!=$(tid))
		{
			last1.style.display = 'none';
			last2.style.backgroundColor = '#71002E';
		}
		
		if ($(tid).style.display=='block')
		{
			$(tid).style.display = 'none';
			$(bid).style.backgroundColor = '#71002E';
		}
		else
		{
			$(tid).style.display = 'block';
			$(bid).style.backgroundColor = '#8D8D8D';
			$(tid).appendChild($('form_x'));
			var ref_id=$(tid).id.substring('answercomment'.length);
			if(!ref_id) ref_id=0;
			$('i_answer_id').value=ref_id;
		}
		
		last1=$(tid);
		last2=$(bid);
	}
	
	window.hideform=function()
	{
		if(!last1) return;
		
		last1.style.display = 'none';
		last2.style.backgroundColor = '#71002E';
		$('form_x').getElementsByTagName('textarea')[0].value='';
		$('newcomment').appendChild($('form_x'));
	}
})();

handlers['comment_error']=function(text)
{
	var tmp = $('logjerk2').innerHTML;
	$('logjerk2').innerHTML=text;
	
	showlog('logjerk2');
	setTimeout(function(){$q("#logjerk2").hide("fast");}, 3000);
};

handlers['comment_add']=function(text)
{
	var id = /^(.+?)\|/.exec(text);
	id = parseInt (id[1],10);
	
	text = text.replace(/.+?\|/, "");
	
	if(id)
	var table	= $('table_comment'+id);
	else if( $('last_table'))
	var table	= $('last_table').previousSibling;
	else
	var table	= $('first_table');
	
	text	= $e('span',{innerHTML:text}).getElementsByTagName('table')[0];
	table.parentNode.insertBefore(text,table.nextSibling);
	
	hideform();
};

var U_comment=
{
	deletex:function(id)
	{
		AC.simple('?ZRP=comment.delete&args={}','POST',{"i_com_id":id},function(text)
		{
			var txt = json_decode(text);
			if(!txt) alert(text);
			
			if(!txt[1])
			{
				window.location.hash='';
				window.location.href=window.location.href;
				return;
			}
			
			var table=$('table_comment'+txt[0]);
			
			if(!table) return;
			hideform();
			table.parentNode.removeChild(table);
		});
	},
	subscribe:function(flag)
	{
		var proc		= $('com_subscribe_proc');
		var subscr		= $('com_subscribe');
		var unsubscr	= $('com_unsubscribe');
		
		subscr.style.display=unsubscr.style.display='none';
		proc.style.display='';
		
		AC.simple('','POST',{'submit_subscribe':1,"b_subscribe":flag},function(text)
		{
			proc.style.display='none';
			
			if(text=='1')
			{
				subscr.style.display	= 'none';
				unsubscr.style.display	= '';
				return;
			}
			
			subscr.style.display	= '';
			unsubscr.style.display	= 'none';
			
			return;
		});
	}
};

(function()
{
	if(!$("default_open"))
	return;
	
	shcomtable('newcomment', 'addnewcomment', 0);
})();

(function()
{
	var IE = (document.all ? true : false);

	// If NS -- that is, !IE -- then set up for mouse capture
	if (!IE) document.captureEvents(Event.MOUSEMOVE);
	
	function getMouseXY(e)
	{
	  if (IE)	// grab the x-y pos.s if browser is IE
	  {
	    tempX = event.clientX + document.documentElement.scrollLeft;
	    tempY = event.clientY + document.documentElement.scrollTop;
	  }
	  else	// grab the x-y pos.s if browser is NS
	  {
	    tempX = e.pageX
	    tempY = e.pageY
	  }  
	  
	  
	  if (tempX < 0){tempX = 0}
	  if (tempY < 0){tempY = 0}
	  
	  // show the position values in the form named Show
	  // in the text fields named MouseX and MouseY
	 // document.Show.MouseX.value = tempX
	  //document.Show.MouseY.value = tempY
	  return true;
	}
	
	// Set-up to use getMouseXY function onMouseMove
	document.onmousemove = getMouseXY;
	
	// Temporary variables to hold mouse x-y pos.s
	var tempX = 0
	var tempY = 0
	
	// Main function to retrieve mouse x-y pos.s

	window.showlog=function(id)
	{
		if(!id) id="logjerk";
		
		var s = $(id);
		
		s.style.left = tempX + "px";
		s.style.top = tempY + "px";
		$q("#"+id).show("fast");
		
		if(id=="logjerk")
		setTimeout(function(){$q("#logjerk").hide("fast");}, 3000);
	}
})()