// forum stuff
$(document).ready(function(){
						   
				  $('.vastabtn').live('click',function(){
							    //id of the answerbox
								var thisid = $(this).attr('rel');
								
								//check if the user isnt the last answerer
								//$('#lp'+thisid+':last-child').text() != $('#user_poster').text() && 
								if($('#lp'+thisid+'_last').text() != $('#user_poster').text()){
								//if the textarea isnt there
								//we open a new one 
								if($('#t'+thisid).val() == undefined) {
								var obj_exist = $('.q'+thisid+':last').html() != null ? $('.q'+thisid+':last') : $('#main_'+thisid);	
								obj_exist.after('<textarea name="replay" id="t'+thisid+'"></textarea>');	
								}else{
									if($('#t'+thisid).val() != ''){
									//output answer
									var answer = $('#t'+thisid).val();
									
									//strip html tags just in case :)	
									var obj_exist = $('.q'+thisid+':last').html() != null ? $('.q'+thisid+':last') : $('#main_'+thisid);
									splited = thisid.replace('q','');
									$.post('ajax/foorumposts.php',{ term : 'postquete',answer : answer,aid : splited  },
										function(data){
											obj_exist.after(data);
											$('#lp'+thisid+'_last').removeAttr('id').attr('id','lp'+thisid);
																								  
										});
									//remove textarea
									$('#t'+thisid).remove();
									}else{
										//remove textarea
										$('#t'+thisid).remove();		
									}
								}
								//user is allready last poster
								}
													   });
					$('#post_answer').live('click',function(){	
							//check if user is logged 
							if($('#user_poster').text() != ''){
								//check if textarea is not opend
								if($('#replay_main_box').val() == undefined) {		
									$('.forumbtntop').after('<textarea name="replay_main" id="replay_main_box"></textarea>');	
								}else{	
									if($('#replay_main_box').val() != ''){
										var thisid = $(this).attr('rel');
									//post message
									$.post('ajax/foorumposts.php',
										   { term : 'postanswer',content: $('#replay_main_box').val(),aid : thisid }
										   ,function(data){																										
													$('.forumBoxInner:last').after(data);	
									});
									}
									//remove texarea
									$('#replay_main_box').remove();
								}
							}
													 });
					$('#post_answer2').live('click',function(){	
						//check if user is logged 
						if($('#user_poster').text() != ''){
							//check if textarea is not opend
							if($('#replay_main_box2').val() == undefined) {		
								$('.forumbtnbottom').after('<textarea name="replay_main" id="replay_main_box2"></textarea>');	
							}else{	
								if($('#replay_main_box2').val() != ''){
									var thisid = $(this).attr('rel');
								//post message
								$.post('ajax/foorumposts.php',
									   { term : 'postanswer',content: $('#replay_main_box2').val(),aid : thisid }
									   ,function(data){																										
												$('.forumBoxInner:last').after(data);	
								});
								}
								//remove texarea
								$('#replay_main_box2').remove();
							}
						}
												 });
					$('.quetebox-del-btn').live('click',function(){
							if(confirm($('#delMessage').text())){
								var id = $(this).attr('rel');
								var sid = id.split('_');
								$.post('ajax/foorumposts.php',{ term : 'delquete',aid : sid[0]  });
								$('.qq'+sid[1]).each(function(){
									if($(this).attr('rel') == sid[0]){
										$(this).remove();
									}
									});
							}
															});
				  
						   });
