var jdkf = {
	
	infoWin:function (title, content) {
		if ($('#infowin').length) {
			$('#infowin').attr('title',title).html(content).dialog('open');
		} else {
			$(document.createElement('div')).attr('id','infowin').attr('title', title).html(content).dialog({dialogClass:'alert',resizable:false,modal:true,draggable:false, show:'slide',buttons:{OK:function(){$(this).dialog('close')}}});
		}
	},
	
	ktonaforum: function(){
  $.ajax({  
   url: "index.php",
   data:({
					's':'ax',
					'op':'ostatnionaforum'					
				}),
   success: function(msg){  
    var ob = $.parseJSON(msg);
    var t='';         
    $.each(ob, function(i, val){
     t += '<a href="http://dekordia.pl/?s=commonpanel&uid='+val['id']+'" target="_blank" >';
      if(val['nick']=='') t += val['imie']+' '+val['nazwisko']; else t+=val['nick']; 
     t += '</a><br>';
     });
     
     $('#ostatnio_box').html(t); 
    }
    });
    setTimeout("jdkf.ktonaforum()",5000);
  },
	
	edit_topic: function(id,iddzial) {
		var idname='#jdkf_edytuj_topic_'+id;
		if (iddzial==0 || iddzial=='' || !iddzial ) {return false;}
		if (!$(idname).length) {
				var afterblock = '#jdkf_topic_desc_'+id;
				$(document).scrollTo('#jdkf_row_topic_'+id, 800);
			
				$('#jdkf_edytuj_topic').clone().insertAfter(afterblock).attr('id','jdkf_edytuj_topic_'+id).addClass('clone_topic').slideDown();
				$(idname+' form').submit(function(){ jdkf.add_topic(id,iddzial); return false; });
				$(idname+' input[name="id"]').val(iddzial);
				$(idname+' input[name="nazwaTopic"]').val($('#jdkf_row_topic_'+id+' td.tytul h2 a').html());
				$(idname+' input[name="opisTopic"]').val( $('#jdkf_topic_desc_'+id).html() );
				if ($('#jdkf_row_topic_'+id+' input[name="public"]').val()=='n') {
					$(idname+' input[name="priv"]').attr('checked','checked');
				}
				if (id=='') {
					$(idname+' legend').html('Dodaj Dział');
					$(idname+' input[name="submitForm"]').val('Dodaj');
				}
			
		} else {
			$(idname).slideUp(function(){$(idname).remove()})
		}
	},
 
 set_session_var: function(vart, value){
   $.ajax({
				url:'index.php',
				data:({
					's':'ax',
					'op':'set_session_var',
					'var':vart,
					'value':value
				})
  })
	},       
	
	get_session_var: function(){
  
  },
	
	hide_shoutbox: function()
  {
   $('#shout').toggle('slow');
   if($('#shout').css('display')=='block'){
    jdkf.set_session_var('shoutbox_open','false');
    $('#zwin_shout').html('Rozwniń shoutbox');
   }
   else{
    jdkf.set_session_var('shoutbox_open','true');
    $('#zwin_shout').html('Zwiń shoutbox');
   }  
  },
	
	delete_topic: function(id) {
		if (confirm('Jesteś pewien?')) {
			$.ajax({
				url:'index.php',
				data:({
					's':'ax',
					'op':'delete_topic',
					'id':id
				}),
				success:function(msg) {
					if (msg!='') {
						re = $.parseJSON(msg);
						if (re.result=='error') {
							jdfk.infoWin('Błąd!',re.content);
						} else {
							$('tr<#jdkf_row_topic_'+id).remove();
						}
					}
				}
			});
		}
		return false;
	},
	dell_dzial: function(id) {
		if (confirm('Jesteś pewien? Wszystkie kategorie, tematy oraz posty tego forum zostaną usunięte!')) {
			$.ajax({
				url:'index.php',
				data:({
					's':'ax',
					'op':'delete_dzial',
					'id':id
				}),
				success:function(msg) {
					if (msg!='') {
						re = $.parseJSON(msg);
						if (re.result=='error') {
							jdfk.infoWin('Błąd!',re.content);
						} else {
							$('#main-content').html(re.content);
						}
					}
				}
			});
		}
		return false;
	},
  add_to_moderate: function(id_post){
   $.ajax({
				url:'index.php',
				data:({
					's':'ax',
					'op':'add_to_moderate',
					'id_post':id_post
				}),
				success:function(msg) {
					if (msg!='') {
					
						if (msg=='juzjest') {
							 $('#moderate_'+id_post).html('Twoje zgłoszenie jest przetwarzane');
						} else {
						  $('#moderate_'+id_post).html('Zgłoszenie przyjęte');							
						}
					}
				}
			});
  },
	add_topic: function(id,iddzial) {
		
		var idname='#jdkf_edytuj_topic_'+id;
    id==0?idname='#jdkf_dodaj_topic_'+iddzial:'';
		var nazwadzialu =$(idname+' input[name="nazwaTopic"]').val();
		var opisdzialu =$(idname+' input[name="opisTopic"]').val();
		var publiczny = $(idname+' input[name="priv"]').is(':checked')?'n':'y';
		var result_response=false;
		
		if ( nazwadzialu == '') {
			jdkf.infoWin('Uwaga!','Nazwa działu nie może być pusta!');
			return false;
		}
		
		$.ajax({
			url:'index.php',
			method:'post',
			data:({
				's':'ax',
				'op':id!=0?'edit_topic':'add_topic',
				id_dzial:iddzial,
				title:nazwadzialu,
				description:opisdzialu,
				'public':publiczny,
				'id':id
			}),
			success:function(msg) {
				if (msg!='') {
					var re = $.parseJSON(msg);
					if (re.result=='error') {
						jdfk.infoWin('Błąd!',re.content);
						result_response=false;
					} else {
						if (id!=0) {
							$('#jdkf_row_topic_'+id+' h2 a').html(nazwadzialu);
							$('#jdkf_topic_desc_'+id).html(opisdzialu);
							$(idname).slideUp(function(){$(idname).remove()})
							$('#jdkf_row_topic_'+id+' input[name="public"]').val(publiczny);
						} else {
							$('#main-content').html(re.content);
						}
						result_response=true;
					}
				}
			}
		});
		return result_response;
		
	},
	
  add_topic_control: function(id) {
		var idname='#jdkf_dodaj_topic_'+id;
		if (!$(idname).length) {
			var afterblock = id==0?'#right_links':'#jdkf_dzial_title_'+id;
			$('#jdkf_dodaj_topic').clone().insertAfter(afterblock).attr('id','jdkf_dodaj_topic_'+id).slideDown();
			$(idname+' form').submit(function(){ jdkf.add_topic(0,id); return false; });
			$(idname+' input[name="nazwaTopic"]').val($('#jdkf_row_topic_'+id+' td.tytul h2 a').html());
			$(idname+' input[name="opisTopic"]').val( $('#jdkf_topic_desc_'+id).html() );
				if ($('#jdkf_row_topic_'+id+' input[name="public"]').val()=='n') {
					$(idname+' input[name="priv"]').attr('checked','checked');
				}
			
		} else {
			$(idname).slideUp(function(){$(idname).remove()})
		}
	},
	add_post: function(id, id_dzial){
	 var d='';
   id_dzial!=''?d='#jdkf_edytuj_post_'+id:'#jdkf_dodaj_post';
   //alert(d);
   var nazwaposta =$(d+' input[name="nazwaTematu"]').val();
   var trescposta =$(d+' textarea[name="trescTematu"]').val();
   var czy_mail = $(d+' input[name="powiadom"]').is(':checked')?'y':'n';
	 var result_response=false;
	 //alert(nazwaposta);	
		if ( nazwaposta == '') {
			jdkf.infoWin('Uwaga!','Nazwa tematu nie może być pusta!');
			return false;
		}
		
		$.ajax({
			url:'index.php',
			method:'post',
			data:({
				's':'ax',
				'op':id_dzial!=''?'edit_subject':'add_subject',
				'title':nazwaposta,
				'id':id,
				'description':trescposta,
				'id_dzial':id_dzial,
				'czy_mail':czy_mail
			}),
			success:function(msg) {
				if (msg!='') {
					var re = $.parseJSON(msg);
					if (re.result=='error') {
						jdfk.infoWin('Błąd!',re.content);
						result_response=false;
					} else {
							$('#main-content').html(re.content);		
						result_response=true;
					}
				}
			}
		});
		return result_response;
		
  },
  
	edit_post: function(id) {
		var idname='#jdkf_dodaj_post';
    if ($(idname).length ) {
		$(idname).slideToggle("slow");
		$(idname+' form').submit(function(){ jdkf.add_post(id,''); return false; });
		} else {
			$(idname).remove();
		}
	},
	show_move_post: function(id, id_temat, id_forum) {	
		var idname='#jdkf_przenies_post_'+id;
		if (!$(idname).length) {
			var afterblock = '#post_'+id;
			$('#jdkf_przenies_post').clone().insertAfter(afterblock).attr('id','jdkf_przenies_post_'+id).slideDown();
			$(idname+' form').submit(function(){ jdkf.move_post_post(id, id_temat); return false; });
			
		} else {
			$(idname).slideUp(function(){$(idname).remove()})
		}
	},
	move_post_post: function(id, id_temat){
	 var result_response = false;
   var id_dzial = $('#jdkf_przenies_post_'+id+' select[name="nazwaTematu"]').val();
   if(id_dzial==0){
   jdkf.infoWin('Uwaga!','Wybierz dział wątku a nie wątek główny!');
	 return false;
   }   
   $.ajax({
			url:'index.php',
			method:'post',
			data:({
				's':'ax',
				'op':'move_post_post',
				'id_temat_tomove':id_dzial,
				'id_post':id
			}),
			success:function(msg) {
				if (msg=='ok') {
				 $('#post_'+id).fadeOut('slow');
         $('#jdkf_przenies_post_'+id).remove();	
				}
				else{
         alert('wystąpił nieoczekiwany błąd.');
        }
			}
		});		
  },
	move_subject: function(id, id_dzial) {
		var idname='#jdkf_przenies_post_'+id;
		if (!$(idname).length) {
			var afterblock = '#jdkf_subject_menu_'+id;
			$('#jdkf_przenies_post').clone().insertAfter(afterblock).attr('id','jdkf_przenies_post_'+id).slideDown();
			$(idname+' form').submit(function(){ jdkf.move_post(id); return false; });
			
		} else {
			$(idname).slideUp(function(){$(idname).remove()})
		}
	},
	getSubjectContent: function(id){
	 var idname='#jdkf_edytuj_post_'+id;
	 $.ajax({
   url:'index.php',
   method:'post',
   async:false,
   data:({
   's':'ax',
   'op':'getsubjectcontent',
   'id_subject':id
   }),
   success: function(msg){
       var re = $.parseJSON(msg);
       $(idname+' textarea[name="trescTematu"]').val(re.content);
       return re.content;
   }
   }); 
  },
  
	getPostContent: function(id){
	 var idname='#jdkf_edytuj_post_'+id;
        $(idname+' textarea[name="trescOdp"]').val($('#post_content_'+id).html());
  },	
  
  edit_subject: function(id, id_dzial) {
		var idname='#jdkf_edytuj_post_'+id;
		if (!$(idname).length) {
			var afterblock = '#jdkf_edit_subject_'+id;
			var clon = $('#jdkf_dodaj_post').clone().insertAfter(afterblock).attr('id','jdkf_tr_form_'+id).hide().html();
			clon = '<tr id="jdkf_edytuj_post_'+id+'"><td colspan="4">'+clon+'</td></tr>';
			$(afterblock).after(clon).slideDown();
      		$(idname+' form').submit(function(){ jdkf.add_post(id, id_dzial); return false; });
			$(idname+' input[name="nazwaTematu"]').val($(afterblock+' td.post h2 a').html());
			$(idname+' legend').html('Edytuj Temat');
			$(idname+' input[name="submitForm"]').val('Zapisz zmiany');
			$(idname+' textarea[name="trescTematu"]').attr('id',"trescTematu_"+id);
			jdkf.getSubjectContent(id);	
			$(idname+' input[name="nazwaTematu"]').val($(afterblock+' td.post h2 a').html());
			var inst_bb = $(idname);
			$('#trescTematu_'+id).bbcode();
			// editor(
			// 		  {
			// bold:$('.bold', inst_bb),italic:$('.italic', inst_bb),underline:$('.underline', inst_bb),link:$('.link', inst_bb),quote:$('.quote', inst_bb),code:$('.code',inst_bb),image:$('.image',inst_bb),
			// usize:$('.usize', inst_bb),dsize:$('.dsize', inst_bb),nlist:$('.nlist', inst_bb),blist:$('.blist',inst_bb),litem:$('.item',inst_bb),
			// back:$('.back', inst_bb),forward:$('.forward', inst_bb),back_disable:'btn back_disable',forward_disable:'btn forward_disable',
			// exit_warning:true,preview:$('.preview', inst_bb)
			// 		   });
		} else {
			$(idname).slideUp(function(){$(idname).remove()})
		}
	},
	
	zapisz_post: function(id){
	 var idname='#jdkf_edytuj_post_'+id;
	 var tresc = $(idname+' textarea[name="trescOdp"]').val();
	 $.ajax({
   url:'index.php',
   method:'post',
   async:false,
   data:({
   's':'ax',
   'op':'zapiszpost',
   'id':id,
   'tresc':tresc
   }),
   success: function(msg){
       var re = $.parseJSON(msg);       
       $('#post_content_'+id).html(tresc);
       $('#jdkf_edytuj_post_'+id).remove();
       return false;
   }
   }); 
  },	
  getPostContent2: function(id){
	 var idname='#jdkf_edytuj_post_'+id;
        
    $.ajax({
   url:'index.php',
   method:'post',
   async:false,
   data:({
   's':'ax',
   'op':'get_post',
   'id_post':id
   }),
   success: function(msg){
       $(idname+' textarea[name="trescOdp"]').val(msg);
   }
   });    
  },
	edit_post2: function(id) {
	 
		var idname='#jdkf_edytuj_post_'+id;
		if (!$(idname).length) {
			var afterblock = '#post_'+id;
			var clon = $('#jdkf_dodaj_post').clone().insertAfter(afterblock).attr('id','jdkf_tr_form_'+id).hide().html();
			clon = '<tr id="jdkf_edytuj_post_'+id+'"><td colspan="4">'+clon+'</td></tr>';
			$(afterblock).after(clon).slideDown();
      $(idname+' form').submit(function(){ jdkf.zapisz_post(id); location.replace( location.href ); });
			$(idname+' input[name="nazwaTematu"]').val($(afterblock+' td.post h2 a').html());
			$(idname+' input[name="action"]').val('edytujPost');
			$(idname+' legend').html('Edytuj Post');
			$(idname+' input[id="nazwaGrupy"]').val('Zapisz zmiany');
			$(idname+' textarea[name="trescOdp"]').attr('id',"trescTematu_"+id);
			jdkf.getPostContent2(id);	
			$(idname+' input[name="nazwaTematu"]').val($(afterblock+' td.post h2 a').html());
			var inst_bb = $(idname);
			$('#trescTematu_'+id).bbcode();
			// editor(
			// 		  {
			// bold:$('.bold', inst_bb),italic:$('.italic', inst_bb),underline:$('.underline', inst_bb),link:$('.link', inst_bb),quote:$('.quote', inst_bb),code:$('.code',inst_bb),image:$('.image',inst_bb),
			// usize:$('.usize', inst_bb),dsize:$('.dsize', inst_bb),nlist:$('.nlist', inst_bb),blist:$('.blist',inst_bb),litem:$('.item',inst_bb),
			// back:$('.back', inst_bb),forward:$('.forward', inst_bb),back_disable:'btn back_disable',forward_disable:'btn forward_disable',
			// exit_warning:true,preview:$('.preview', inst_bb)
			// 		   });
		} else {
			$(idname).slideUp(function(){$(idname).remove()})
		}
	},
  move_post: function(id){
	 var result_response = false;
   var id_dzial = $('#jdkf_przenies_post_'+id+' select[name="nazwaTematu"]').val();
   if(id_dzial==0){
   jdkf.infoWin('Uwaga!','Wybierz dział wątku a nie wątek główny!');
	 return false;
   }
   $.ajax({
			url:'index.php',
			method:'post',
			data:({
				's':'ax',
				'op':'move_post',
				'id_dzialu':id_dzial,
				'id_post':id,
				'id':getQueryParams('id')
			}),
			success:function(msg) {
				if (msg!='') {
					var re = $.parseJSON(msg);
					if (re.result=='error') {
						jdfk.infoWin('Błąd!',re.content);
						result_response=false;
					} else {
							$('#main-content').html(re.content);		
						result_response=true;
					}
				}
			}
		});
		//return true;
   //alert(id_dzial);
  },
	edit_dzial: function(id) {
		var idname='#jdkf_edytuj_dzial_'+id;
		if (!$(idname).length) {
			var afterblock = id==0?'#right_links':'#jdkf_dzial_title_'+id;
			$('#jdkf_edytuj_dzial').clone().insertAfter(afterblock).attr('id','jdkf_edytuj_dzial_'+id).slideDown();
			$(idname+' form').submit(function(){ jdkf.add_dzial(id); return false; });
			if (id==0) {
				$(idname+' legend').html('Dodaj Kategorię');
				$(idname+' input[name="submitForm"]').val('Dodaj');
				$(idname+' input[name="nazwaKategorii"]').val('');
			} else {
				$(idname+' input[name="nazwaKategorii"]').val($('#jdkf_dzial_title_'+id+' h2').html());
			}
			
		} else {
			$(idname).slideUp(function(){$(idname).remove()})
		}
	},
	
	add_dzial: function(id) {
		var nazwadzialu =$('#jdkf_edytuj_dzial_'+id+' input[name="nazwaKategorii"]').val();
		
		var result_response=false;
		
		if ( nazwadzialu == '') {
			jdkf.infoWin('Uwaga!','Nazwa kategorii nie może być pusta!');
			return false;
		}
		
		$.ajax({
			url:'index.php',
			method:'post',
			data:({
				's':'ax',
				'op':id!=''&&id!=0?'edit_dzial':'add_dzial',
				title:nazwadzialu,
				'id':id
			}),
			success:function(msg) {
				if (msg!='') {
					var re = $.parseJSON(msg);
					if (re.result=='error') {
						jdfk.infoWin('Błąd!',re.content);
						result_response=false;
					} else {
						if (id!='') {
							$('#jdkf_dzial_title_'+id+' h2').html(nazwadzialu);
							$('#jdkf_edytuj_dzial_'+id).slideUp(function(){$('#jdkf_edytuj_dzial_'+id).remove()})
						} else {
							$('#main-content').html(re.content);
						}
						result_response=true;
					}
				}
			}
		});
		return result_response;
		
	},
	
	del_dzial: function() {
	 	
	},
	delete_post: function(id){
   if (confirm('Jesteś pewien że chcesz usunąć ten post?')) {      
      $.ajax({
				url:'index.php',
				method:'post',
				data:({
					's':'ax',
					'op':'delete_post',
					'id_post':id					
				}),
				success:function(msg) {
					if (msg!='') {						
						if (msg=='error') {
							jdfk.infoWin('Błąd!','Błąd');
						} else {
						 $('#post_'+id).fadeOut('slow');	
						}
					}
				}
			});   
    }
  },
	del_subject: function(id){
	 //alert(getQueryParams('id'));
	 //alert('sd');
   if (confirm('Jesteś pewien?')) {
   
			$.ajax({
				url:'index.php',
				method:'post',
				data:({
					's':'ax',
					'op':'delete_subject',
					'id_post':id,
					'id':getQueryParams('id')
				}),
				success:function(msg) {
					if (msg!='') {
						re = $.parseJSON(msg);
						if (re.result=='error') {
							jdfk.infoWin('Błąd!',re.content);
						} else {
							$('#main-content').html(re.content);
						}
					}
				}
			});
		}
		return false;
  },
	public_topic: function(id, iddzial, pub){
  $.ajax({
			url:'index.php',
			method:'post',
			data:({
				's':'ax',
				'op':pub=='on'?'public_on':'public_off',
				'id':id,
				'id_dzial':iddzial
			}),
			success:function(msg) {
				if (msg!='') {
					var re = $.parseJSON(msg);
					if (re.result=='error') {
						jdfk.infoWin('Błąd!',re.content);
						result_response=false;
					} else {
							$('#main-content').html(re.content);
						result_response=true;
					}
				}
			}
		});
		return result_response;
  },
  open_topic: function(id, iddzial, pub){
	var result_response;
  $.ajax({
			url:'index.php',
			method:'post',
			data:({
				's':'ax',
				'op':pub=='on'?'open':'close',
				'id':id,
				'id_dzial':iddzial
			}),
			success:function(msg) {
				if (msg!='') {
					var re = $.parseJSON(msg);
					if (re.result=='error') {
						jdfk.infoWin('Błąd!',re.content);
						result_response=false;
					} else {
							$('#main-content').html(re.content);
						result_response=true;
					}
				}
			}
		});
		return result_response;
  },
  glued_subject: function(id, iddzial, glued){
	var result_response;
  $.ajax({
			url:'index.php',
			method:'post',
			data:({
				's':'ax',
				'op':'glued',
				'id':id,
				'id_dzial':iddzial,
				'glued':glued
			}),
			success:function(msg) {
				if (msg!='') {
					var re = $.parseJSON(msg);
					if (re.result=='error') {
						jdfk.infoWin('Błąd!',re.content);
						result_response=false;
					} else {
							$('#main-content').html(re.content);
						result_response=true;
					}
				}
			}
		});
		return result_response;
  },
	ax_login: function () {
		
		if ( $('#dialog_login input[name="email"]').val()!='' && $('#dialog_login input[name="pass"]').val()!='') {

		$.ajax({
			   
			   type:'POST',
			   url:'../index.php',
			   data: ({
					  s:'ax_login',
					  email: $('#dialog_login input[name="email"]').val(),
					  pass: $('#dialog_login input[name="pass"]').val()
				}),
			   success: function (msg){
					var resp = msg.split('|');
          	
					if (resp[0]=='ok') {
					    $.ajax({
                type:'POST',
			          url:'index.php',
			            data: ({
					         s:'ax',
					         op:'lastloginupdate',
			         	})
              });
							var rl = location.href;
						   if ( rl.indexOf('logout')==-1 ) {
							
								if ( $('#nastrgl').length && $('#nastrgl').val()=='n' ) {
									location.replace( location.href );
								} else {
									
									location.replace( location.href );
								}
							
						   }
						   else {

								location.replace( location.href );
						   
						   }
					   } else {
						   $('p#dialog_login_info').html(resp[1]).show('normal');
						   $('#dialog_login input').val('');
					   }
					return false;

				}
			   });
		} else {
			$('p#dialog_login_info').html('Wypełnij poprawnie formularz logowania!').show('normal');
		}
		return false;
	},
	ax_userdata: function(){
	 var idname='#dialog_userdata';
   var show_email = $(idname+' input[name="show_email"]').is(':checked')?'y':'n';
   var follow_with_my_answer = $(idname+' input[name="follow_with_my_answer"]').is(':checked')?'y':'n';
   $.ajax({
			   
			   type:'POST',
			   url:'index.php',
			   data: ({
					  s:'ax',
					  op:'userdata',
					  show_email: show_email,
					  follow_with_my_answer: follow_with_my_answer
				}),
			   success: function (msg){
					 $('#dialog_userdata').dialog("close");
				 }
			   });
   
  }
	
}
$(document).ready(function(){
          
          jdkf.ktonaforum();
           
          $('.info_tytul').aToolTip({  
           clickIt: false,  
           tipContent: 'Forum otwarte'  
          });
          $('.info_tytulpublic').aToolTip({  
           clickIt: false,  
           tipContent: 'Forum tylko dla zalogowanych'  
          });
          $('.info_tytulpublicclosed').aToolTip({  
           clickIt: false,  
           tipContent: 'Forum tylko dla zalogowanych lecz zamknięte'  
          });
          $('.info_tytulclosed').aToolTip({  
           clickIt: false,  
           tipContent: 'Forum zamknięte'  
          });   		
				  var turl = location.href;
				  var sel;
				  
				  if ($('#dialog_userdata').length) {
	
					$('#dialog_userdata').dialog({
											  resizable: false,
											  autoOpen: false,
											  width: 300,
											  modal:true,
											  buttons: {
												"Zapisz zmiany": function() {
													jdkf.ax_userdata();
												}, 
												"Anuluj": function() { 
													$(this).dialog("close"); 
												} 
											  }
					});

					$('#userdata_btn').click(function(){
								$('#dialog_userdata').dialog('open');
								return false;
					});
				  
				  }
				  
				  if ($('#dialog_login').length) {
	
					$('#dialog_login').dialog({
											  resizable: false,
											  autoOpen: false,
											  width: 300,
											  modal:true,
											  buttons: {
												"Zaloguj": function() {
													jdkf.ax_login();
												}, 
												"Anuluj": function() { 
													$(this).dialog("close"); 
												} 
											  }
					});

				  if ($('#dialog_loginreq').length) {
				  
				  $('#dialog_loginreq').dialog({
											resizable: false,
											autoOpen: false,
											width: 300,
											modal:true,
											buttons: {
											"Anuluj": function() { 
											$(this).dialog("close"); 
											},
											"Zaloguj": function() {
												$(this).dialog("close");
												$('#dialog_login').dialog('open');
											} 
											}
											});
				  }
				  
					$('#login_btn').click(function(){
								$('#dialog_login').dialog('open');
								$('#dialog_login input[name="email"]').focus();
								return false;
					});
				  
				  }
					$('.cytuj_btn').click( function(e) {
						var idrow=$(e.target).parents('tr').attr('id').split('_')[1];
						$.ajax({
			       url:'index.php',
			       method:'post',
			       data:({
				      's':'ax',
				      'op':'trimcontent',
				      'id':idrow
			       }),
			       success:function(msg) {
			        var re = $.parseJSON(msg);
					//if (re.result=='error') {
				      if (re.content!='') {
               msg = re.content.replace(/(\[\/?quote\])/gi,'');
					     $('#trescTematu1').val('[attribution]Użytkownik '+re.user+' napisał:[attribution][quote]'+msg+'[/quote]');
			         }
		           }
            
            }); 
            $(document).scrollTo('#trescTematu1', 800);
						return false;
					});
				 
});

function getQueryParams(param) {
   var qs = document.location.search;
    qs = qs.split("+").join(" ");
    var tokens='';                                         
    while (tokens = /[?&]?([^=]+)=([^&]*)/g.exec(qs)) {
       if(decodeURIComponent(tokens[1])==param) return decodeURIComponent(tokens[2]);
    }

    return getQueryParams(param);
}

