/* plg_comment javascript */
var plg_comment_getting_comments = false;
var plg_comment_saving_comment = false; 
var text_message_obj = null;

function plg_comment_post_comment(page,callback,div,group,item,id,parent_level)
{
	if(plg_comment_saving_comment==true) return;
	plg_comment_saving_comment = true;
	var form_obj = document.getElementById(id);
	var post_text_obj = document.getElementById(id+'-post-text');
	var validcode = document.getElementById('validcode').value;
	text_message_obj = document.getElementById(id+'-message');
	text_message_obj.innerHTML = plg_comment_sending_comment;
	
	var plg_comment_send_connect_callback =  
	{  
		success: function(o)
		{
			window.location = window.location;
			//alert(o.argument);
			//var el = null; 
			plg_comment_saving_comment = false;
			//el = document.getElementById(o.argument); el.innerHTML = o.responseText;
		},  
		failure: function(o) { plg_comment_getting_comments = false; text_message_obj.innerHTML=_plg_comment_server_busy; },
		timeout: 10000,
		cache:false,
		argument: div
	};
	
	post = "page="+page+"&div="+div+"&group="+group+"&item="+item+'&level='+parent_level+'&validcode='+validcode+'&text='+encodeURIComponent(post_text_obj.value);	
	YAHOO.util.Connect.asyncRequest('POST', callback, plg_comment_send_connect_callback,post);
}

function plg_comment_post_score(page,callback,div,group,item,id,parent_level,direction)
{
	if(plg_comment_saving_comment==true) return;
	plg_comment_saving_comment = true;
	var form_obj = document.getElementById(id);
	var post_text_obj = document.getElementById(id+'-post-text');
	var validcode = document.getElementById('validcode').value;
	text_message_obj = document.getElementById(id+'-message');
	text_message_obj.innerHTML = plg_comment_sending_comment;
	
	var plg_comment_send_connect_callback =  
	{  
		success: function(o)
		{
			var el = null; 
			plg_comment_saving_comment = false;
			el = document.getElementById(o.argument); el.innerHTML = o.responseText;
		},  
		failure: function(o) { plg_comment_getting_comments = false; text_message_obj.innerHTML=_plg_comment_server_busy; },
		timeout: 10000,
		cache:false,
		argument: div
	}
	
	post = "page="+page+"&div="+div+"&group="+group+"&item="+item+'&level='+parent_level+'&dir='+direction+'&validcode='+validcode;	
	YAHOO.util.Connect.asyncRequest('POST', callback, plg_comment_send_connect_callback,post);
}

function plg_comment_post_spam(page,callback,div,group,item,id,parent_level)
{
	if(plg_comment_saving_comment==true) return;
	plg_comment_saving_comment = true;
	var form_obj = document.getElementById(id);
	var post_text_obj = document.getElementById(id+'-post-text');
	var validcode = document.getElementById('validcode').value;
	text_message_obj = document.getElementById(id+'-message');
	text_message_obj.innerHTML = plg_comment_sending_comment;
	
	var plg_comment_send_connect_callback =  
	{  
		success: function(o)
		{
			var el = null; 
			plg_comment_saving_comment = false;
			el = document.getElementById(o.argument); el.innerHTML = o.responseText;
		},  
		failure: function(o) { plg_comment_getting_comments = false; text_message_obj.innerHTML=_plg_comment_server_busy; },
		timeout: 10000,
		cache:false,
		argument: div
	}
	
	post = "page="+page+"&div="+div+"&group="+group+"&item="+item+'&level='+parent_level+'&validcode='+validcode;	
	YAHOO.util.Connect.asyncRequest('POST', callback, plg_comment_send_connect_callback,post);
	
	alert(plg_comment_spam_note);
}



function plg_comment_get_page(page,callback,div,group,item)
{
	// Already fetching comments?
	if(plg_comment_getting_comments==true) return;
	plg_comment_getting_comments = true;
	
	var plg_comment_get_connect_callback =  
	{  
		success: function(o)
		{
			var el = null; 
			plg_comment_getting_comments = false;
			el = document.getElementById(o.argument); el.innerHTML = o.responseText;
		},  
		failure: function(o) { plg_comment_getting_comments = false; el = document.getElementById(o.argument); el.innerHTML=_plg_comment_server_busy; },
		timeout: 10000,
		cache:false,
		argument: div
	}
	
	el = document.getElementById(div);
	height = el.offsetHeight+'px';
	el.innerHTML = '<div class="wait" style="height:'+height+';">&nbsp;</div>';

	post = "page="+page+"&div="+div+"&group="+group+"&item="+item;
	
	YAHOO.util.Connect.asyncRequest('POST', callback, plg_comment_get_connect_callback,post);
}

function plg_comment_threshold_change(val,page,callback,div,group,item)
{
	// Already fetching comments?
	if(plg_comment_getting_comments==true) return;
	plg_comment_getting_comments = true;
	threshold = -50000;
	
	switch(val)
	{
		case 'EXCELLENT': threshold = 10; break;
		case 'GREAT': threshold = 5; break;
		case 'GOOD': threshold = 0; break;
		case 'AVERAGE': threshold = -5; break;
		case 'POOR': threshold = -10; break;
		default: threshold = -50000; break;
	}

	var plg_comment_get_connect_callback =  
	{  
		success: function(o)
		{
			var el = null; 
			plg_comment_getting_comments = false;
			el = document.getElementById(o.argument); el.innerHTML = o.responseText;
		},  
		failure: function(o) { plg_comment_getting_comments = false; el = document.getElementById(o.argument); el.innerHTML=_plg_comment_server_busy; },
		timeout: 10000,
		cache:false,
		argument: div
	}
	
	el = document.getElementById(div);
	height = el.offsetHeight+'px';
	el.innerHTML = '<div class="wait" style="height:'+height+';">&nbsp;</div>';

	post = "page="+page+"&div="+div+"&group="+group+"&item="+item+"&threshold="+threshold;
	
	YAHOO.util.Connect.asyncRequest('POST', callback, plg_comment_get_connect_callback,post);
}

function plg_comment_show_form(id)
{
	el = document.getElementById(id);
	el.style.height='auto';
}

function plg_comment_hide_form(id)
{
	el = document.getElementById(id);
	el.style.height='0px';	
}

function plg_comment_character_count(ta_obj,reportid)
{
	el = document.getElementById(reportid);
	length = 500-ta_obj.value.length;
	if(length>=0)
	{
		el.innerHTML = plg_comment_characters_remaining+length.toString();
	}
	else
	{
		length = Math.abs(length);
		el.innerHTML = plg_comment_characters_over+length.toString();
	}
}

function plg_comment_focus(ta_obj)
{
	ta_obj.value = ta_obj.value.replace(/^\s+|\s+$/g,"");
}

