﻿/*zmiana rozmiaru czcionki*/
$(document).ready(function()
{
	$("img.duzyR").click(function()
	{
		$('p, div.opis-margines, div.line, span, a, li,  h3, div.czas, .center-hor, .docs-border, .aktualnosci-margines, .aktualnosci-margines ul, .aktualnosci-blok div, .mapa-serwisu div, td h2.tytul, .ankieta-odpowiedz, .szukaj-margines, .reg5 .aktualnosci-blok,.jq-chat-text ').each(function(index)
		{
			$(this).addClass("duzy-tekst");
			$(this).removeClass("maly-tekst")
		});

		$('ul.poziom1 li, h2, h4 a, .reg3 .aktualnosci-blok span, .reg3 .aktualnosci-blok a.czytaj, .box_grad a, span.info3, .center, .center  a, .float-right span, .float-right span a, ul.poziom1 li a,ul.poziom1 li a span, span.pusty, .newsBar a, .newsBar a span, .newsBar span, .menu-boczne .aktualnosci-blok p,  .menu-boczne .aktualnosci-blok span,  .menu-boczne .aktualnosci-blok a, .reg3 .box_br div, a.link-wstecz ').each(function(index)
		{
			$(this).removeClass("duzy-tekst")
		});

	});

	$("img.standR").click(function()
	{
		$('p, div.opis-margines, div.line, span, a, li,  h3, div.czas, .center-hor, .docs-border, .aktualnosci-margines, .aktualnosci-margines ul, .aktualnosci-blok div, .mapa-serwisu div, td h2.tytul, .ankieta-odpowiedz, .szukaj-margines, .reg5 .aktualnosci-blok,.jq-chat-text ').each(function(index)
		{
			$(this).removeClass("duzy-tekst");
			$(this).removeClass("maly-tekst")
		});
	});

	$("img.malyR").click(function()
	{
		$('p, div.opis-margines, div.line, span, a, li,  h3, div.czas, .center-hor, .docs-border, .aktualnosci-margines, .aktualnosci-margines ul, .aktualnosci-blok div, .mapa-serwisu div, td h2.tytul, .ankieta-odpowiedz, .szukaj-margines, .reg5 .aktualnosci-blok,.jq-chat-text ').each(function(index)
		{
			$(this).removeClass("duzy-tekst");
			$(this).addClass("maly-tekst")
		});

		$('ul.poziom1 li, h2, h4 a, .reg3 .aktualnosci-blok span, .reg3 .aktualnosci-blok a.czytaj, .box_grad a, span.info3, .center, .center  a, .float-right span, .float-right span a, ul.poziom1 li a,ul.poziom1 li a span, span.pusty, .newsBar a, .newsBar a span, .newsBar span, .menu-boczne .aktualnosci-blok p,  .menu-boczne .aktualnosci-blok span,  .menu-boczne .aktualnosci-blok a, .reg3 .box_br div, a.link-wstecz ').each(function(index)
		{
			$(this).removeClass("maly-tekst")
		});

	});
});

// *** TO BE CUSTOMISED ***

var style_cookie_name = "style";
var style_cookie_duration = 30;

// *** END OF CUSTOMISABLE SECTION ***

function switch_style(css_title) {
	// You may use this script on your site free of charge provided
	// you do not remote this notice or the URL below. Script from
	// http://www.thesitewizard.com/javascripts/change-style-sheets.shtml
	var i, link_tag;
	for (i = 0, link_tag = document.getElementsByTagName("link");i < link_tag.length; i++)
	 {
			link_tag[i].media = 'screen';
			if (link_tag[i].title == css_title)
			{
				link_tag[i].disabled = false;
			}
			else
			{
				link_tag[i].disabled = true;
			}
		}

		//ukrywam na przemian przyciski do wersji dla niewidzacych i do wersji normalnej
		var przyciskToHide, przyciskToShow, przyciskToHide2, przyciskToShow2;
		if (css_title == "normal") {
			przyciskToHide = document.getElementById("normal");
			przyciskToShow = document.getElementById("niewidzacy");
		//	przyciskToShow2 = document.getElementById("niewidzacy2");
		}
		else {
			przyciskToHide = document.getElementById("niewidzacy");
		//	przyciskToHide2 = document.getElementById("niewidzacy2");
			przyciskToShow = document.getElementById("normal");
		}
		if (przyciskToHide != null)
		{
			przyciskToHide.style.visibility = 'hidden';
		}
		if (przyciskToShow != null)
		{
			przyciskToShow.style.visibility = 'visible';
		}
		set_cookie(style_cookie_name, css_title,
      style_cookie_duration);
	}
}


$(document).ready(function() {

	set_style_from_cookie();
});

function set_style_from_cookie() {
	var css_title = Edito.Cookie.getCookie(style_cookie_name);
	if (css_title && css_title.length)
	{
		switch_style(css_title);
	}
	else
	{
		switch_style('normal');
	}
}
function set_cookie(cookie_name, cookie_value,
    lifespan_in_days, valid_domain) {
	// http://www.thesitewizard.com/javascripts/cookies.shtml
	var domain_string = valid_domain ?
                       ("; domain=" + valid_domain) : '';
	document.cookie = cookie_name +
                       "=" + encodeURIComponent(cookie_value) +
                       "; max-age=" + 60 * 60 *
                       24 * lifespan_in_days +
                       "; path=/" + domain_string;
}
function get_cookie(cookie_name) {
	// http://www.thesitewizard.com/javascripts/cookies.shtml
	var cookie_string = document.cookie;
	if (cookie_string.length != 0) {
		var cookie_value = cookie_string.match(
                        '(^|;)[\s]*' +
                        cookie_name +
                        '=([^;]*)');
		return decodeURIComponent(cookie_value[2]);
	}
	return '';
}

var base = '';

/* Przegladarka zdjec */
$(document).ready(function()
{
	base = $('script[src*=default.js]').attr('src').replace('Scripts/default.js', '');
	var settings = {
		imageLoading:	base + 'Images/lightbox/lightbox-ico-loading.gif',
		imageBtnPrev:	base + 'Images/lightbox/lightbox-btn-prev.gif',
		imageBtnNext:	base + 'Images/lightbox/lightbox-btn-next.gif',
		imageBtnClose:	base + 'Images/lightbox/lightbox-btn-close.gif',
		imageBlank:		base + 'Images/lightbox/lightbox-blank.gif'
	};
	$('a[rel*=lightbox]').lightBox(settings);
	$('a[class*=lightbox]').lightBox(settings);
});


/* Sterowanie szerokoscia kolumn */
$(document).ready(function()
{
	var width = 0;
	var reg3 = $('.lewa-strona');
	var reg6 = $('.regprawy');
	
	if(reg3.length == 0)
	{
		width = 963;
	}
	else if (reg6.length == 0) {
		width = 704;
		$('.reg5').width(width);
	}
	
	if(width > 0)
	{
		$('.prawa-strona').width(width);
	}
});


/* Ankieta */
$(document).ready(function()
{
	$('div.poll').each(function()
	{
		var poll = $(this);
		var key = poll.attr('rel');
		
		if(Edito.Cookie.GetValue('Edito.Polls', key) != null)
			poll.find('.chart').css('display', 'block');
		else
			poll.find('.question').css('display', 'block');
	});
});


/* Ocena */
$(document).ready(function()
{
	var getRating = function(sender, e)
	{
		if(typeof(sender.position) == 'undefined')
			sender.position = $(sender).offset();
		
		var rating = 1 + parseInt((e.pageX - sender.position.left) / 12);
		
		return rating;
	}
	
	var setRating = function(sender, rating)
	{
		$(sender).find('span').width(Math.round(rating * 12));
	}
	
	$('span.rating').each(function()
	{
		var stars = $(this);
		var current = $(this).find('span').attr('rel').replace(',', '.');
		
		setRating(this, current);
		
		if($(this).attr('rel'))
		{
			stars.mousemove(function(e)
			{
				var rating = getRating(this, e);
				setRating(this, rating);
			});
			
			stars.mouseleave(function(e)
			{
				setRating(this, current);
			});
			
			stars.click(function(e)
			{
				var rating = getRating(this, e);
				var link = $(this).attr('rel') + '/' + rating;
				
				$.ajax({
					type: 'POST',
					data: '{}',
					url: link,
					contentType: 'application/json; charset=utf-8',
					dataType: 'json',
					success: function(data, status)
					{
						if (data.d.Status == true)
						{
							current = data.d.Rating;
							setRating(stars.get(0), current);
							stars.find('span').attr('rel', current);
						}
						
						$('<div class="rating-message"></div>')
							.html(data.d.Message)
							.hide()
							.insertAfter(stars)
							.fadeIn('slow')
							.animate({opacity: 1.0}, 3000)
							.fadeOut('slow');
					}
				});
				
				$(this)
					.css('cursor', 'default')
					.trigger('mouseout', e)
					.unbind('mousemove')
					.unbind('click');
			});
		}
		else
		{
			$(this).css('cursor', 'default');
		}
	});
});


/* W przypadku nacisniecia klawisza enter wywoluje akcje podpieta pod dany przycisk */
function Exec(e, xpath)
{
	e = e || window.event;
	
	if (e.keyCode == 13)
	{
		var button = $(xpath).get(0);
		
		if (button != null)
		{
			if (button.href != null && button.href != "")
			{
				location.href = button.href;
			}
			else
			{
				button.click();
			}
        }
        
        return false;
	}
}


var EditoCalendar = new Object();

/* wywolanie kalendarza */
EditoCalendar.showCalendar = function(obj, field, btn)
{
    Calendar.setup({
        inputField : field,
        ifFormat : "%Y-%m-%d",
        button : btn,
        singleClick : true,
        align : "Lt"
    });
    obj.onclick();
    return false;
}

/*
Wywolanie AJAX-owe do Edito

$.ajax({
	type: 'POST',
	data: '{file: "plik.pdf", name: "Nazwa pliku alózc"}',
	url: 'API/Cms.Accounts.LoginView/Test',
	contentType: 'application/json; charset=utf-8',
	dataType: 'json',
	success: function(data, status)
	{
		alert(data.d);
	},
	error: function(request, status, error)
	{
		alert(status + ', ' + error);
	}
});
*/

/* Ajax Indicator */
jQuery.fn.extend({
	showAjaxIndicator: function() {
		var div = $('<div class="jq-ajax-indicator"></div>');
		this.before(div);

		div.css('width', this.get(0).offsetWidth + 'px');
		div.css('height', this.get(0).offsetHeight + 'px');
		div.css('top', this.get(0).offsetTop + 'px');
		div.css('left', this.get(0).offsetLeft + 'px');
	},

	hideAjaxIndicator: function() {
		$(this).prev('div.jq-ajax-indicator').remove();
	}
});

/* 
Komentarze */
$(document).ready(function() {
	var ajaxurl = $('#jq-comments-url').val();
	var token = $('#jq-comments-token').val();

	var getComments = function(token, pageIndex) {
		$.ajax({
			type: 'POST',
			data: '{token: "' + token + '", pageIndex: "' + pageIndex + '"}',
			url: ajaxurl,
			contentType: 'application/json; charset=utf-8',
			dataType: 'json',
			success: function(data, status) {
				$('#jq-comments').hideAjaxIndicator();
				$('#jq-comments').html(data.d.Content);
			}
		});
	}

	$('#jq-comments a[href^=#comments-page]').live('click', function() {
		$('#jq-comments').showAjaxIndicator();
		var pageIndex = $(this).attr('href').replace('#comments-page', '');
		getComments(token, pageIndex);
	});

	if (location.hash.length > 0) {
		var pageIndex = parseInt(location.hash.replace('#comments-page', ''));
		if (!isNaN(pageIndex) && location.hash == '#comments-page' + pageIndex) {
			$('#jq-comments').showAjaxIndicator();
			getComments(token, pageIndex);
		}
	}

	$('form[name=frmAddComment]').ajaxForm({
		beforeSubmit: function(arr, form, options) {
			form.find('.komunikat').remove();
			form.find('span.error').remove();
		},
		success: function(data, status) {
			// Odswiezenie listy komentarzy
			if ($(data).find('Status').text() == 'true') {
				$('[name=comment]').val('');
				$('[name=nick]').val('');

				var pageIndex = parseInt(location.hash.replace('#comments-page', ''));
				if (isNaN(pageIndex) || location.hash != '#comments-page' + pageIndex) {
					pageIndex = 1;
				}

				$('#jq-comments').showAjaxIndicator();
				getComments(token, pageIndex);
			}
			// Pokazanie walidatorow
			else {
				$(data).find('Errors CommentError').each(function() {
					var key = $(this).find('Key').text();
					var value = $(this).find('Value').text();
					var control = $('[name=' + key + ']');

					// Pokazanie walidatora
					control.after('<span class="error" rel="Error.' + key + '">' + value + '</span>');

					// Skrocenie tekstu jesli rozmiar zostal przekroczony
					if (control.val().length > control.attr('maxlength')) {
						control.val(control.val().substring(0, control.attr('maxlength')));
					}
				});
			}

			// Pokazanie komunikatu
			var content = $(data).find('Content').text();
			if (content.length > 0) {
				$('#jq-add-comment').prepend($(data).find('Content').text());
				$('#jq-add-comment')
					.find('.komunikat')
					.animate({ opacity: 1.0 }, 3000)
					.fadeOut('slow');
			}
		}
	});
});

/* Dodawanie komentarzy */
/*$(document).ready(function()
{
	$('form[name=frmAddComment]').ajaxForm({
		success: BlogComments.ajaxResponse
	});
});*/

var BlogComments =
{
	ajaxResponse : function(responseText, statusText)
	{
		if (responseText != undefined)
		{
			var result = eval('(' + responseText + ')').d;
			
			if(result.Status)
				BlogComments.addComment(result.Content);
			else
				BlogComments.displayErrors(result.Errors);
		}
	},
	
	addComment : function(content)
	{
		$("form[name=frmAddComment]").get(0).reset();
		$(".jq-comments").prepend(content);
	},
	
	hideErrors : function()
	{
		$("form[name=frmAddComment] span[rel^=Error]").addClass('hide');
		$("form[name=frmAddComment] .error").not('span').removeClass('error');
	},
	
	displayErrors : function(errors)
	{
		BlogComments.hideErrors();
		
		if(errors != null)
		{
			for (var i = 0; i < errors.length; i++)
			{
				$("form[name=frmAddComment] span[rel=Error." + errors[i] + "]").removeClass('hide');
				$("form[name=frmAddComment] [name=" + errors[i] + "]").addClass('error');
			}
		}
	}
}

/* Autocomplete - Tagi */
$(document).ready(function()
{
	var url = base.replace('Themes/Default/', '') + "API/pl/Cms.Tags/Autocomplete/1/pl";
	$('input[rel=tags]').autocomplete(url, {
		multiple: true, 
		mustMatch: false, 
		autoFill: true
	});
});


/* FCKeditor */
$(document).ready(function()
{
	var basepath = base.replace('Themes/Default/', '') + 'Shared/FCKeditor/';
	
	$('textarea[rel=fckeditor]').fck({
		'path': basepath, 
		'toolbar': 'Basic',
		'height': '300px',
		'config': {
			'CustomConfigurationsPath': base + 'Scripts/fckcustom.js'
		}
	});
});

/* FCKeditor */
$(document).ready(function()
{
	var basepath = base.replace('Themes/Default/', '') + 'Shared/FCKeditor/';
	
	$('textarea[rel=fckbbcode]').fck({
		'path': basepath, 
		'toolbar': 'Basic',
		'height': '300px',
		'config': {
			'CustomConfigurationsPath': base + 'Scripts/fckbbcode.js'
		}
	});
});

/* Dynamic Form */
$(document).ready(function()
{
	var panels = $('.df-main');
	
	panels.hide().eq(0).show();
	
	panels.each(function(i)
	{
		if ($(this).find('span.error').length > 0)
		{
			panels.hide().eq(i).show();
			return false;
		}
	})
	
	panels.find('.df-button-prev').click(function()
	{
		panels.filter(':visible').hide().prev().show();
	});
	
	panels.find('.df-button-next').click(function()
	{
		panels.filter(':visible').hide().next().show();
	});
});

/* Chat */
var Chat =
{
	options: {},
	timeout: 10000,
	timer: null,
	lastupdate: 0,

	init: function(options) {
		this.options = options;
		this.updateTimer();
		this.getMessages();
	},

	updateTimer: function() {
		var now = new Date();
		var end = Date.parse(Chat.options.End) + now.getTimezoneOffset() * 60 * 1000;
		var timeleft = end - now.getTime();

		if (timeleft > 0) {
			$('.jq-chat-timer').html(Chat.formatTimer(timeleft));
			setTimeout(Chat.updateTimer, 1000);
		}
	},

	formatTimer: function(timeleft) {
		var seconds = parseInt(timeleft / 1000);
		var hours = parseInt(seconds / 3600);
		seconds = seconds - hours * 3600;
		var minutes = parseInt(seconds / 60);
		seconds = seconds - minutes * 60;

		return hours + ":" + Chat.zeroPad(minutes) + ":" + Chat.zeroPad(seconds);
	},

	addMessage: function(message) {
		if (message == undefined)
			message = $('.jq-chat-input').val();

		if (message.length > 0) {
			$('.jq-chat-input').val('');
			$('.jq-chat-input').attr('disabled', 'disabled');
			$('.jq-chat-button').attr('disabled', 'disabled');

			message = message.replace(/\\/g, '\\\\').replace(/"/g, '\\"');

			$.ajax({
				type: 'POST',
				data: '{pageId: "' + Chat.options.PageId + '", message: "' + message + '"}',
				url: Chat.options.AddMessage,
				contentType: 'application/json; charset=utf-8',
				dataType: 'json',
				success: function(data, status) {
					$('.jq-chat-button').removeAttr("disabled");
					$('.jq-chat-input').removeAttr("disabled");
					$('.jq-chat-input').get(0).focus();

					if (Chat.timer != null)
						clearTimeout(Chat.timer);

					Chat.timer = Chat.getMessages();
				}
			});
		}

		return false;
	},

	getMessages: function() {
		$.ajax({
			type: 'GET',
			url: Chat.options.GetMessages + '/' + Chat.options.PageId + '/' + Chat.lastupdate,
			contentType: 'text/xml; charset=utf-8',
			dataType: 'xml',
			success: function(data, status) {
				Chat.viewMessages(data);
				Chat.timer = setTimeout(Chat.getMessages, Chat.timeout);
			}
		});
	},

	viewMessages: function(xml) {
		Chat.lastupdate = parseInt($(xml).find('messages').attr('date'));

		var entries = $(xml).find('entry');
		var moderator = $(xml).find('messages').attr('moderator') == 'true';

		var wnd = $('.jq-chat-wnd').get(0);
		var scrollHeight = wnd.scrollHeight;

		for (var i = 0; i < entries.length; i++) {
			Chat.showEntry(wnd, entries[i], moderator);
		}

		if (wnd.scrollTop >= scrollHeight - wnd.offsetHeight) {
			wnd.scrollTop = wnd.scrollHeight;
		}
	},

	showEntry: function(wnd, entry, moderator) {
		Chat.lastupdate = parseInt($(entry).find('date').text());

		if ($(entry).find('priv').length > 0) {
			var command = $(entry).find('text').text();

			if ($(entry).find('priv').text() == Chat.options.Token) {
				if (command == 'kick' || command == 'ban') {
					Chat.reload();
					return;
				}

				// Wyswietlenie komunikatu
				$(entry).find('priv').text('system');
			}
			if ($(entry).find('priv').text() == 'moderator') {
				// Dodanie moderatora na liste uzytkownikow
				if (command == 'enter') {
					this.showModerator(entry, moderator);
					return;
				}
			}
			if ($(entry).find('priv').text() == 'highlight') {
				// Wyswietlenie komunikatu od moderatora
				this.showMessage(wnd, entry, moderator);
			}
			if ($(entry).find('priv').text() == 'system') {
				// Dodanie uzytkownika na liste uzytkownikow
				if (command == 'enter') {
					this.showUser(entry, moderator);
					return;
				}
				// Usuniecie moderatora lub uzytkownika z listy
				if (command == 'leave') {
					this.removeUser(entry);
					return;
				}

				// Wyswietlenie komunikatu od uzytkownika
				this.showMessage(wnd, entry, moderator);
			}
		}
		else {
			this.showMessage(wnd, entry, moderator);
		}
	},

	showMessage: function(wnd, entry, moderator) {
		var row = $('.jq-chat-tpl').clone();

		if ($(entry).find('priv').length > 0 && $(entry).find('priv').text() == 'system') {
			// Komunikaty systemowe
			var cssclass = 'chat-row-system';
			row.find('.jq-chat-nick').parent().hide();
		}
		else if ($(entry).find('priv').length > 0 && $(entry).find('priv').text() == 'highlight') {
			// Wiadomosci od moderatora
			var cssclass = 'chat-row-highlight';
		}
		else if (moderator == true && $(entry).find('publish').text() == 'false') {
			// Wiadomosci nieopublikowane w widoku moderatora
			var cssclass = 'chat-row-publish';
		}
		else {
			// Wiadomosci opublikowane
			var cssclass = '';
		}

		row.removeClass('jq-chat-tpl').addClass(cssclass);
		row.find('.jq-chat-date').html(Chat.formatTime(new Date(Chat.lastupdate)));
		row.find('.jq-chat-nick').html($(entry).find('nick').text());
		row.find('.jq-chat-text').html($(entry).find('text').text());

		if (moderator == true && $(entry).find('publish').text() == 'false') {
			Chat.addIcons(row, entry);
		}
		else {
			Chat.removeIcons(row);

			if ($(entry).find('priv').length == 0)
				Chat.changeStatus(wnd, entry);
		}

		$(wnd).append(row);
	},

	showModerator: function(entry, moderator) {
		var wnd = $('.jq-chat-moderators').get(0);
		var row = $('.jq-chat-user-tpl').clone();
		var cssclass = 'chat-row-moderator';

		row.removeClass('jq-chat-user-tpl')
		   .attr('rel', $(entry).find('userid').text())
		   .addClass(cssclass);
		row.find('.jq-chat-user')
		   .html($(entry).find('nick').text())

		if (moderator == true)
			Chat.addIcons(row, entry);
		else
			Chat.removeIcons(row);

		$(wnd).append(row);

		var rows = $(wnd).find('>div').get();

		rows.sort(function(a, b) {
			var keyA = $(a).find('.jq-chat-user').text().toUpperCase();
			var keyB = $(b).find('.jq-chat-user').text().toUpperCase();
			if (keyA < keyB) return -1;
			if (keyA > keyB) return 1;
			return 0;
		});

		$(rows).each(function(index, row) {
			$(wnd).append(row);
		});
	},

	showUser: function(entry, moderator) {
		var wnd = $('.jq-chat-users').get(0);
		var row = $('.jq-chat-user-tpl').clone();
		var cssclass = 'chat-row-even';

		row.removeClass('jq-chat-user-tpl')
		   .attr('rel', $(entry).find('userid').text())
		   .addClass(cssclass);
		row.find('.jq-chat-user')
		   .html($(entry).find('nick').text())

		if (moderator == true)
			Chat.addIcons(row, entry);
		else
			Chat.removeIcons(row);

		$(wnd).append(row);

		var rows = $(wnd).find('>div').get();

		rows.sort(function(a, b) {
			var keyA = $(a).find('.jq-chat-user').text().toUpperCase();
			var keyB = $(b).find('.jq-chat-user').text().toUpperCase();
			if (keyA < keyB) return -1;
			if (keyA > keyB) return 1;
			return 0;
		});

		$(rows).each(function(index, row) {
			$(wnd).append(row);
		});
	},

	removeUser: function(entry) {
		var id = $(entry).find('userid').text();

		var wnd = $('.jq-chat-users').get(0);
		$(wnd).find('[rel=' + id + ']').remove();

		var wnd = $('.jq-chat-moderators').get(0);
		$(wnd).find('[rel=' + id + ']').remove();
	},

	addIcons: function(row, entry) {
		row.find('.jq-chat-kick')
			.click(function() {
				Chat.addMessage('kick -a ' + $(entry).find('userid').text());

				var btn = this;
				$(btn).removeClass('jq-chat-kick').addClass('jq-chat-kick-off');
				setTimeout(function() {
					$(btn).removeClass('jq-chat-kick-off').addClass('jq-chat-kick');
				}, 5000);
			});

		row.find('.jq-chat-ban')
			.click(function() {
				$(this).removeClass('jq-chat-ban').addClass('jq-chat-ban-off').unbind('click');
				Chat.addMessage('ban -a ' + $(entry).find('userid').text());
			});

		row.find('.jq-chat-publish')
			.click(function() {
				$(this).removeClass('jq-chat-publish-off').addClass('jq-chat-publish').unbind('click');
				Chat.addMessage('publish -a ' + $(entry).find('msgid').text());
			})
			.each(function(i) {
				if ($(entry).find('publish').text() == 'false')
					$(this).removeClass('jq-chat-publish').addClass('jq-chat-publish-off').attr('rel', $(entry).find('msgid').text());
				else
					$(this).unbind('click');
			});
	},

	removeIcons: function(row) {
		row.find('.jq-chat-kick').remove();
		row.find('.jq-chat-ban').remove();
		row.find('.jq-chat-publish').remove();
	},

	changeStatus: function(wnd, entry) {
		$(wnd).find('.jq-chat-publish-off[rel=' + $(entry).find('msgid').text() + ']')
			  .removeClass('jq-chat-publish-off')
			  .addClass('jq-chat-publish')
			  .unbind('click');
	},

	logout: function() {
		$.ajax({
			type: 'POST',
			data: '{pageId: "' + Chat.options.PageId + '"}',
			url: Chat.options.Logout,
			contentType: 'application/json; charset=utf-8',
			dataType: 'json',
			success: function(data, status) {
				Chat.reload();
			}
		});
	},

	reload: function() {
		location.reload(true);
	},

	formatTime: function(date) {
		var now = new Date();
		date.setMinutes(date.getMinutes() + date.getTimezoneOffset());

		var sec = date.getSeconds();
		var min = date.getMinutes();
		var hour = date.getHours();

		return hour + ':' + Chat.zeroPad(min) + ':' + Chat.zeroPad(sec);
	},

	zeroPad: function(number) {
		return number > 9 ? number : '0' + number;
	}
}
