function ac_show(a){
	if(typeof(a)=='object'){
		ac_reset();
		var ref = a.parentNode.parentNode.parentNode;
		var cl = ref.childNodes;
		for(var j=0;j<cl.length;j++){
			var e = cl[j];
			if(e.className=='ac_cc'){
				e.show();
				var t = e.getElementsByClassName('ac_tx');
				t[0].focus();
				break;
			}
		}
	}
}

function ac_reset(v)
{
	if(typeof(v)=='string' && v.length>0){
		$(v).value = 'Add your comment';
	}
	var ls = $$('.ac_cc');
	for(var i=0;i<ls.length;i++){
		var e = ls[i];
		e.hide();
	}
}

function ac_c_save(a)
{
	var d = a.parentNode;
	var ac = d.getAttribute('id');
	ac = ac.replace('l_','');
	var tx = 'Q_'+ac;
	trimiput(tx);
	var c = $(tx).value;
	if(c.length==0 || c=='Add your comment')
	{
		alert('Please enter text');
		$(tx).focus();
		return false;
	}
	var ex = getexpara();
	ac_reset(tx);
	var url = '/inc/activityhandler.php';
	if(typeof(ac_c_p_type)=='object' && ac_c_p_type.m=='m')
	{
		var url = '/inc/activityhandler.php?m=n_c';
	}
	new Ajax.Request(url, { 
		  method: 'post',
		  asynchronous: true,
		  parameters: {action:'ac_c_s',ac:ac,c:c,ex:ex},
		  onSuccess: function(response){
					  	if(200 == response.status)
					  		var res = eval(response.responseText);
					  		if(res.length>0 && res[0]==1)
					  		{
					  			var cname = res[1];
					  			var ih = $(cname).innerHTML;
					  			ih = res[2] + ih;
					  			{$(cname).update(ih);}
					  		}else
					  		{
					  			// error
					  		}
					  },
		  onFailure:  function(){}
		  });
	
}

function getexpara()
{
	if(typeof(sd)=='object'){
		return document.location.href;
	}
	return '';
}

function ac_rm_c(r,a){
	
	if(!confirm('Are you sure, you want to delete this comment?')){
		return false;
	}
	
	if(typeof(a)=='number' && typeof(r)=='object')
	{
		var t = r.parentNode;
		new Ajax.Request('/inc/activityhandler.php', { 
			  method: 'post',
			  asynchronous: true,
			  parameters: {action:'ac_rm_c',ac:a},
			  onSuccess: function(response){
						  	if(200 == response.status)
						  		var res = eval(response.responseText);
						  		if(res.length>0 && res[0]==1)
						  		{
						  			var cname = res[1];
						  			var h = res[2];
						  			if(h==1){$(cname).hide();}else{alert('error');}
						  		}else
						  		{
						  			// error
						  		}
						  },
			  onFailure:  function(){}
			  });
	}
}

function ac_shr_post(a)
{
	var alb = $('pl_sh_w');
	var ctype = alb.style.display;
	if(ctype=='block'){
		return false;
	}
	var d = $('shareposttext'); 
	trimiput(d);
	if(typeof(d)=='object')
	{
		var tx = d.value;
		if(typeof(ac_share_info)=='object'){
			var id = ac_share_info.id;
			var ptype = ac_share_info.ptype;
			var stx = ac_share_info.stx;
			if(typeof(tx)=='string'){
				if(tx.length>0 && tx!=stx){
					
						alt_showhide('pl_sh_w',1);
						var id = ac_share_info.id;
						var ptype = ac_share_info.ptype;
						new Ajax.Request('/inc/activityhandler.php', { 
							  method: 'post',
							  asynchronous: true,
							  parameters: {action:'ac_share_post',id:id,ptype:ptype,post:tx},
							  onSuccess: function(response){
										  	if(200 == response.status){
										  		var res = eval(response.responseText);
										  		if(res.length>0 && res[0]==1){
										  			var isa = res[1];
										  			if(isa){
										  				var isug = res[2];
										  				var isul = res[3];
										  				var txg = res[4];
										  				var txl = res[5];
                                                                                                                
										  				var cong = 'sh_area';
										  				var conl = 'post_list';
										  				if(isug==1){
										  					if(typeof(txg)=='string' && txg.length>0 && $(cong)!=null)
										  					{
										  						$(cong).update(txg);	
										  						ac_link_fix('.sh_con_tb a');
										  					}
										  				} 
										  				if(isul==1){
										  					if(typeof(txl)=='string' && txl.length>0 && $(conl)!=null)
										  					{
										  						var t = $(conl).innerHTML;
										  						t = txl + t;
										  						$(conl).update(t);
										  						ac_link_fix('#post_list a');
										  					}
										  				}
										  				$('shareposttext').value = stx;
										  			}else{
										  				alert('error');
										  			}
										  		}else{
										  			// error
										  		}
										  	}
										  	alt_showhide('pl_sh_w',0);
										  },
							  onFailure:  function(){alt_showhide('pl_sh_w',0);}
							  });
					
				}else{
					d.focus();
					alert('Please Insert Text');
					return false;
				}
			}
		}
	}
}

function rm_sh_post()
{
	if(typeof(ac_share_info)=='object'){
		var id = ac_share_info.id;
		var ptype = ac_share_info.ptype;
		alt_showhide('pl_sh_w',1);
		new Ajax.Request('/inc/activityhandler.php', { 
			  method: 'post',
			  asynchronous: true,
			  parameters: {action:'rm_share_post',id:id,ptype:ptype},
			  onSuccess: function(response){
				  			if(200 == response.status){
				  				var res = eval(response.responseText);
						  		if(res.length>0 && res[0]==1){
						  			var isa = res[1];
						  			if(isa){
						  				var isug = res[2];
						  				var isul = res[3];
						  				var txg = res[4];
						  				var txl = res[5];
						  				var hid = res[6];
						  				var cong = 'sh_area';
						  				var conl = 'post_list';
						  				if(isug==1){                                                                                    
                                                                                    if(typeof(txg)=='string' && $(cong)!=null)
                                                                                    {
                                                                                        $(cong).update(txg);
                                                                                    }
						  				} 
						  				if(isul==1){
                                                                                    if(typeof(txl)=='string' && txl.length>0 && $(conl)!=null)
                                                                                    {
                                                                                        var t = $(conl).innerHTML;
                                                                                        t = txl + t;
                                                                                        $(conl).update(t);
                                                                                    }
						  				}
						  				rm_sh_view(hid);
						  			}else{
						  				alert('error');
						  			}
						  		}else{
						  			// error
						  		}
						  	}
						  	alt_showhide('pl_sh_w',0);
						  },
			  onFailure:  function(){alt_showhide('pl_sh_w',0);}
			  });
	}
}

function rm_sh_view(a)
{
	if(typeof(a)=='string' && a.length>0){
		var con = 'aclist_'+a;
		var d = $(con);
		if(typeof(d)=='object' && d!=null){
			d.parentNode.style.display = 'none';
		}
	}
	return true;
}

function alt_showhide(id,a){
	var alb = $(id);
	if(a==1){
		alb.style.display = 'block';
	}else{
		alb.style.display = 'none';
	}
	return true;
}

function n_comm_rm(a,t,i)
{
	var id = i;
	var type = t;
	new Ajax.Request('/inc/activityhandler.php', { 
		  method: 'post',
		  asynchronous: true,
		  parameters: {action:'n_comm_rm',i:i,t:t},
		  onSuccess: function(response){
					  	if(200 == response.status){
					  		var res = eval(response.responseText);
					  		if(res.length>0 && res[0]==1){
					  			var isa = res[1];
					  			if(isa){
					  				rm_comm_con(a);
					  			}else{
					  				alert('error');
					  			}
					  		}else{
					  			// error
					  		}
					  	}
					  },
		  onFailure:  function(){}
		  });
} 

function rm_comm_con(a)
{
	if(typeof(a)=='object'){
		a.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.hide();
	}
}

function ac_link_fix(a)
{
	if(typeof(a)=='string')
	{
		var l = $$(a);
	}else
	{
		var l = $$('.ac_link_fix a');
	}
	
	for(var i=0;i<l.length;i++){
		var t = l[i];
		var tx = t.innerHTML;
		if(tx.search(/<img/i)==-1)
		{
			tx = spliter(tx,50);
		}
		t.innerHTML = tx;
	}
} 