Array.prototype.in_array = function ( obj ) {
	var len = this.length;
	for ( var x = 0 ; x <= len ; x++ ) {
		if ( this[x] == obj ) return true;
	}
	return false;
};

String.prototype.addParam = function(param, val) {

	if (!this.getParam(param, false))
	{
		var tmp = this.trim('/'), hash = '';
		var iHash = (tmp.indexOf('?') != -1 ? tmp.indexOf('?') : (tmp.indexOf('#') != -1 ? tmp.indexOf('#') : false));
		if (iHash)
		{
			hash = tmp.substring(iHash);
			tmp = tmp.substring(0, iHash);
		}
		
		return tmp.concat('/'+ param +'/'+ val + hash);
	}
	else
	{
		var tmp = this.trim('/'), startPos = endPos = 0;
		var target = param + '/', r = '';
		startPos = (this.lastIndexOf(target) + target.length);
		endPos = this.indexOf('/', startPos );

		return tmp.substring(0, startPos) + val + ( endPos>0 ? tmp.substring(endPos) : '' );
	}

	return this;
};

String.prototype.getParam = function(param, defaultValue) {
    var v = this.split('/');
    if(param != '')
    {
        for(var i=0; i < v.length; i++)
        {
            if(v[i] == param) { return (v[i+1]); }
        }
    }
    return defaultValue;
};

jQuery.fn.positionRelativeTo = function (relativeTo, position, offset) {
  var relativeOffset = relativeTo.offset(), posX = 0, posY = 0, offsetRight, offsetBottom, tmp;

  if (position) {
    if (position.left !== undefined) {
      posX = Number(position.left);
    }
    else if (position.right !== undefined) {
      posX = relativeTo.outerWidth() - Number(position.right);
    }
    if (position.top !== undefined) {
      posY = Number(position.top);
    }
    else if (position.bottom !== undefined) {
      posY = relativeTo.outerHeight() - Number(position.bottom);
    }

    if (isNaN(posX)) {
      posX = 0;
    }
    if (isNaN(posY)) {
      posY = 0;
    }
  }

  if (offset) {
    if (offset.left !== undefined) {
      tmp = Number(offset.left);
      if (!isNaN(tmp)) {
        posX += tmp;
      }
    }
    else if (offset.right !== undefined) {
      offsetRight = Number(offset.right);
      if (isNaN(offsetRight)) {
        offsetRight = 0;
      }
    }
    if (offset.top !== undefined) {
      tmp = Number(offset.top);
      if (!isNaN(tmp)) {
        posY += tmp;
      }
    }
    else if (offset.bottom !== undefined) {
      offsetBottom = Number(offset.bottom);
      if (isNaN(offsetBottom)) {
        offsetBottom = 0;
      }
    }
  }

  this.each(function () {
    var $this, parentOffset, left, top;

    $this = jQuery(this);
    parentOffset = $this.offsetParent().offset();

    left = relativeOffset.left - parentOffset.left + posX;
    top  = relativeOffset.top  - parentOffset.top  + posY;

    if (offsetRight !== undefined) {
      left -= $this.outerWidth() + offsetRight;
    }
    if (offsetBottom !== undefined) {
      top -= $this.outerHeight() + offsetBottom;
    }

    $this.css({
      left : left + 'px',
      top  : top  + 'px'
    });
  });
};

if (typeof Flattr == 'undefined') {
	Flattr = {
		ajax: function(url, options) {
				
			var token = this.getCookie("f_rt");
			if (!token) {
				return false;
			}
			
			if (!options) { options = {};}

			if (typeof options === 'function' ) {
				var callback = options;
				options = {};
				options.success = callback;
			}
			
			if (typeof url === "string") {
				options.url = url;
			}
			
			options.beforeSend = function(xhr) {
				xhr.setRequestHeader("X-REQUEST-TOKEN", token);
			};

			$.ajax(options);
			return true;
		},
		
		ajaxRemove: function(elm, url, errorHandler) {

			var options = {
				success: function(response) {
					elm.trigger( { type: 'ajaxremove' } );
					elm.remove();
				}
			};
			
			if (errorHandler) {
				if (typeof errorHandler === 'function') {
					options.error = errorHandler;
				} else {
					options.error = function() {
						Flattr.Dialog.show({ text: errorHandler });
					};
				}
			}
			
			Flattr.ajax(url, options);
		},
		
		ajaxReplace: function(id, url) {
			Flattr.ajax(url, function(response) {
				$('#'+ id).replaceWith(response);
				$("body").trigger({
					type: "ajaxreplace",
					elementId: id
				});
			});
		},
		
		bind: function(func, scope) {

			return function() {
				return func.apply(scope, arguments);
			};
		},
		
		getCookie: function(name) {
			var c_start, c_end;
			
			if (document.cookie.length>0) {

				c_start = document.cookie.indexOf(name + '=');
				if (c_start != -1) {
					c_start += name.length + 1;
					
					c_end = document.cookie.indexOf(';', c_start);
					if (c_end==-1) {
						c_end = document.cookie.length;
					}
					
			    	return unescape(document.cookie.substring(c_start, c_end));
				}
			}
			
			return '';
		}
	};
}

if (typeof Flattr != 'undefined') {
	Flattr.Dialog = {
		show: function(options) {

			if (!options.buttons) {
				options.buttons = {
					"Ok": function() {
						$(this).dialog("close");
					}
				};
			}
		
			var $dialog = $('<div></div>')
			.html(options.text)
			.dialog({
				autoOpen: false,
				modal: true,
				title: options.title,
				buttons: options.buttons
			});

			$dialog.dialog('open');

		}
	};
}

if (typeof Flattr != 'undefined') {
	Flattr.Form = {
		addRequestToken: function(formName) {
			
			var f_rt = Flattr.getCookie('f_rt');
			$("#" + formName).append( '<input type="hidden" name="f_rt" value="'+ f_rt  +'" />' );
			
		}	
	};
}

if (typeof Flattr != 'undefined') {
	Flattr.Subscribe = {

		closeOverlay: function() {
			$('#subscribeOverlay').hide();
		},
	
		openOverlay: function(thingId) {
			
			var elm = $('#subscribeOverlay');

			if ( !elm.length ) {
				elm = $('<div id="subscribeOverlay"><div id="subscribeClose"><img src="/_img/close.png" /></div><div id="subscribeArrow">&nbsp;</div><div id="subscribeContent"></div></div>');
				elm.find('#subscribeClose img').click(Flattr.Subscribe.closeOverlay);
				elm.hide();
				
				$('body').prepend(elm);
				elm.wrap($('<div></div>').css({'margin': '0 auto', 'position':'relative'}).width($('.wide').outerWidth()));
			}

			Flattr.ajax('/subscription/add/id/'+ thingId, {
				success: function(response) {
					elm.find('#subscribeContent').html(response.content);
					elm.find('.subscribeMonth > a').click(function(){
						
						var options = { 
							'type': 'post',
							'data': { 'requestKey': response.requestKey },
							'complete': function(xhr, textStatus) {
								if (textStatus == 'success') {

									Flattr.Subscribe.closeOverlay();
									$("#flattr-"+ thingId +" a.flattr-ed").replaceWith('<span class="flattr"><span class="flattr-subscribed">&nbsp;</span></span>');
								} else {
									// show dialog
									Flattr.Subscribe.closeOverlay();
									
									if (xhr.responseText) {
										var dialogOptions = jQuery.parseJSON(xhr.responseText);
									} else {
										var dialogOptions = { 'title': 'Subscription error', 'text': 'Failed to add subscription. Please try again later.' };
									}
									Flattr.Dialog.show( dialogOptions );
								}
							}
						};
						Flattr.ajax(this.href, options);
						
						return false;
					});
					
					var foo = $("#flattr-"+ thingId +" a.flattr-ed > span");
					elm.show().positionRelativeTo(foo, { 'top': (foo.outerHeight() / 2), 'right': 0 }, { 'top': 0 - (elm.outerHeight() / 2) - 7 } );
					
				}
			});

		}
	};
}

if (typeof Flattr != 'undefined') {
	Flattr.UserHelper = {
		activeStep: false,
		isLoaded: false,

		getActiveStep: function() {
			if (!this.activeStep) {
				this.setActiveStep();
			}

			return this.activeStep;
		},
		
		highlight: function() {
			var hl = $('#userHelperHL_'+ this.getActiveStep());
			if (hl.length)
			{
				hl.addClass('userNotice');
			}
		},
		
		next: function() {
			if (this.isLoaded)
			{
				$('.activestep .description').hide('slow'); 
	
				var img = $('.activestep img.checkbox_unchecked_image');
				img.attr("src", "/_img/checkbox-checked-21x21.png");
	
				this.unHighlight();
				$('.activestep').removeClass("activestep").addClass("stepdone");
				
				var nextList = $('.notdonestep');
				this.setActiveStep(nextList.first());
				
				$('.activestep .description').show('slow');
				
				this.highlight();
			}
		},

		setActiveStep: function(obj) {
			if (obj) {
				obj.addClass('activestep');
			} else {
				obj = $('.activestep');
			}

			this.activeStep = obj.attr('id');
			if(this.activeStep)
			{
				this.activeStep.replace('userHelper_', '');
			}
			else
			{
				this.activeStep = false;
			}
		},
		
		setup: function() {
			if ($('#userHelper').length)
			{
				this.isLoaded = true;
				$('.notdonestep .description').hide();
				this.highlight();
			}
		},
		
		unHighlight: function() {
			var hl = $('#userHelperHL_'+ this.getActiveStep());
			if (hl.length)
			{
				hl.removeClass('userNotice');
			}
		}
	};
}

Flattr.Class = {
	create: function(source) {

		var c = function(){
			this.__construct.apply(this, arguments);
		};
		if (!c.prototype.__construct) {
			c.prototype.__construct = function(){};
		}
		
		this.addProperties(c, source);
	    c.prototype.constructor = c;
	    
		return c;
	},
	
	addProperties: function(destination, source) {

	    var properties = [];
	    for (var property in source) {
	    	properties.push(property);
	    }

		for (var i = 0, length = properties.length; i < length; i++) {
			var property = properties[i], value = source[property];
			destination.prototype[property] = value;
		}

	}
};

Flattr.Dashboard = Flattr.Class.create({

	__construct: function(options) {
	
		this.options = {
			totalMeans: 0,
			availableMeans: 0,
			reservedMeans: 0,
			monthly: 2,
			timeActive: 1
		};
		
		this.init( options );
	},

	init: function( options ) {
		
		$.extend(this.options, options);
		this.updateMonthly( this.options.monthly );

		$('#user-notifications .close-button').click(function(event) {
			var li = $(this).parent(),
				url,
				params;

			if (li.hasClass('handmade')) {
				url = '/usernotifications/remove',
				params = {
					id: li.find('.id').text()
				};
			} else if (li.hasClass('tutorial')) {
				url = '/usernotifications/settutorialflag',
				params = {
					flag: li.find('.flag').text()
				};
			}

			li.remove();
			$('#user-notifications li:last-child').css({
				borderBottom: 'none'
			});

			$.post(url, params, function(data) {
			});
		});
	},

	niceAmount: function( amount ) {
		amount = Number( amount );
		amount = amount.toFixed(2);
		var niceAmount = String(amount);
		return niceAmount.replace('.', ',');
	},

	reduceMonthly: function( monthly ) {

		var timeActive = this.options.timeActive;
		monthly = monthly * timeActive;

		var percentActive = ((1 - timeActive) * 100);
		percentActive = percentActive.toFixed(2);
		$('#extraInfo').html( this.options.text.recentlyActivated.replace('%s', percentActive) );

		return monthly;
	},

	reload: function() {
		var that = this;
		Flattr.ajax('/dashboard/options/', {
			success: function(response) {
				options = jQuery.parseJSON( response );
				that.init( options );
			}
		});
		
	},
	
	updateClickValue: function( monthly ) {

		var clicks = $('#clicks').html();

		if (clicks > 0) {

			var clickValue = ( monthly / clicks );
			clickValue = ( Math.round(clickValue * 100) / 100 );

		} else {
			clickValue = 0;
		}

		$('#clickValueMonth').html( '&euro;' + this.niceAmount(monthly) );
		$('#currentClickValue').html( '&euro;' + this.niceAmount(clickValue) );
	},

	updateMonthly: function( newMonthly, onlyUpdateLabel ) {

		$('#monLabel').html('&euro;' + newMonthly); // slider orange box
	    if (onlyUpdateLabel)
		{
			return;
		}
		
		newMonthly = Number(newMonthly);
		var actualMonthly = newMonthly;
		
		if ( this.options.timeActive < 1 ) {
			actualMonthly = this.reduceMonthly( actualMonthly );
		}

		if ( actualMonthly > this.options.availableMeans ) {
			actualMonthly = Number(this.options.availableMeans);
		}

		this.newMonthly = newMonthly;
		this.actualMonthly = Number(actualMonthly);
		
		this.reservedMeans = (Number(this.options.reservedMeans) + this.actualMonthly);
		this.availableMeans = (Number(this.options.totalMeans) - this.reservedMeans);

		this.updateDashboard();

		this.options.monthly = newMonthly;
	},

	updateDashboard: function() {

		if ( this.newMonthly > this.options.availableMeans ) {
			$('#tooHigh').html( this.options.text.notEnoughMeans.replace('%s', '&euro;' + this.niceAmount(this.actualMonthly) ) );
		} else if ( this.newMonthly != this.options.monthly ) {
			$('#tooHigh').html( this.options.text.changedMonthly.replace('%s', '&euro;' + this.niceAmount(this.actualMonthly) ) );
		}

		$('#availableMeans').html( '&euro;' + this.niceAmount(this.availableMeans) );
		$('#upcomingMonth').html( '&euro;-' + this.niceAmount(this.actualMonthly) );
		$('#reservedMeans').html( '&euro;' + this.niceAmount(this.reservedMeans) );
		this.updateClickValue( this.actualMonthly );

	}
	
});

Flattr.Splash = Flattr.Class.create({

	__construct: function(containerId, options) {

		this.heart = false;
		this.options = {
			interval: 7000,
			disableClick: false
		};
		$.extend(this.options, options);

		this.container = $('#'+containerId);
		if (!this.container) {
			return false;
		}

		if (this.container.children().length <= 1) { return; }
		
		this.container.hover(
			Flattr.bind(function() {
				this.stop();
				
				if (!this.options.disableClick) {
					this.container.css('cursor', 'pointer');
				}
			}, this),
			Flattr.bind(this.start, this)
		);

		if (!this.options.disableClick) {
			this.container.click(
				Flattr.bind(function(){
					this.stop();
					this.run();
				}, this)
			);
		}

		this.heartbeat();
	},

	heartbeat: function() {
		this.run();
		this.start();
	},

	run: function() {

		var p = this.container;
		if (!p.data('csi')) {
			var e = p.children(":first");
			p.data('csi', e);
			e.show();
		} else {
			var e = p.data('csi');
			var n = e.next();

			if (!n.length) {
				n = p.children(":first");
			}
			p.data('csi', n);

			n.css('z-index', 1);
			e.css('z-index', 0);
			
			e.fadeOut(1200);
			n.fadeIn(1200);
		}
	},

	start: function() {
		this.heart = setTimeout(Flattr.bind(this.heartbeat, this), this.options.interval);
	},

	stop: function() {
		clearTimeout(this.heart);
		this.heart = false;
	}

});

/** TABS **/

function initTabs()
{
	var hash = window.location.hash;
	if (hash.length > 4 && hash.substring(1, 5) == 'tab_')
	{
		hash = hash.substring(1);
		var tabLink = $('a[name="'+ hash +'"]');
		if (tabLink.length > 0)
		{
			tab(hash, tabLink.attr('href'));
		}
	}
}

function initTabForm(tabId)
{
	var form;	
	if ( (form = $('#'+tabId.substring(4)+'Frm')) == null ) {
		return;
	}

    form.submit(function() {
        
		var token = Flattr.getCookie("f_rt"); //$.cookie("f_rt"); /** @todo use flattr.getcookie instead */
		if (token) {

			$.ajax({
				url:  form.attr('action'),
				type: 'post',
				data: form.serialize(),
				beforeSend: function(xhr) {
					xhr.setRequestHeader("X-REQUEST-TOKEN", token);
				},
				success: function(response) {
					$('#'+tabId).html(response);
					initTabForm(tabId);
				},
				error: function(xhr, textStatus, errorThrown) {
					alert(xhr.responseText);
				}
			});
		}
		else {
			alert('No token?');
		}

        return false;
    });

    $('#'+tabId.substring(4)+'Frm a').click(function(i){
    	Flattr.ajax($(this).attr('href'), function(response) {
			$('#'+tabId).html(response);
			initTabForm(tabId);
    	});
    	
    	return false;
    });
}

function tab(tabId, url)
{
	$('.tab_container').hide();
	
	if (!url)
	{
		window.location.hash = '';
		$('#' + tabId).show();
		return;
	}

	var tab = $('#' + tabId);
	if (tab.length != 0)
	{
		if (tab.html() == '')
		{
			var token = Flattr.getCookie("f_rt"); 
			if (token) {
				
				$.ajax({
					url: url,
		    		beforeSend: function(xhr) {
		    			xhr.setRequestHeader("X-REQUEST-TOKEN", token);
		    		},
		    		success: function(response) {
		    			window.location.hash = tabId;
		    			tab.html(response);
		    			initTabForm(tabId);
		    					    			
		    			tab.show();
		    		},
					error: function(xhr, textStatus, errorThrown) {
						alert('An error has occured');
					}
				});

			}
		}
		else
		{
			window.location.hash = tabId;
			tab.show();
		}
	}
}
/**
 * Sets up pagination and appends navigation divs to specified element
 * 
 */
function paginationHandler(totalpages, current, element,hash,callback)
{
	addPagination(totalpages, current,element,hash,callback);
	/*
	* Adds all pagination views
	*/
	function addPagination(totalpages, current, element,hash,callback)
	{
		element.append( ' <div class="paging">  \
			<div class="pages" id="pages">  \
			</div> 				\
			</div> 				\
		');
		for(x = 1;x<=totalpages;x++)
		{
			currentTrue = (x===current) ? true : false;
			addPage(x,currentTrue,hash,element);
		}
		addClickHandler();
	}

	/**
	*Adds click handlers on all pagination tabs
	*/
	function addClickHandler()
	{
		var divs = $(".pages > div");
		divs.click( function() {
			currentValue = $.attr(this,"value")-1;

			divs.removeClass("current");
			//Add current class to div, if match
			divs.filter(function(value) 
			{ 
				if(parseInt(value) === parseInt(currentValue) )
				{
					return true;
				}
				else 
				{
					return false;
				}
			})
			.addClass("current"); 

			callback(currentValue+1); //Alert the callback
			return false; // Return false, avoiding any link-follows
		}
		);
	}

	/*
	* Adds a page to pagination bar
	*/
	function addPage(page,current,hash,element)
	{	
		element = $('.pages', element);
		if(current)
		{
			element.append("<div class='page current' value='"+page+"'> <a href='"+hash+"'>"+page+"</a></div>");
		}
		else
		{
			element.append("<div class='page' value='"+page+"'> <a href='"+hash+"'>"+page+"</a></div>");
		}
	}
}


function getSelected(formId, fieldName, flag)
{
	values = new Array();
	count = 0;

	$("form#" + formId + " INPUT[type='checkbox']").each(
		function()
		{
			if ( $(this).attr('checked') )
			{
				values.push($(this).val());
				count += 1;
			}
		}
	);
	if ( count > 0 )
	{
		return values;
	}
	return false;
}

function checkSelected(formId, fieldName, selectedValues, flag)
{
	values = selectedValues.split(',');
	if ( fieldName == '' )
	{
		$("form#" + formId + " INPUT[type='checkbox']").each(
			function() 
			{
				if ( values.in_array($(this).val()) )
				{
					$(this).attr('checked', flag);
				} 
			}
		);
	}
	else
	{
		$("form#" + formId + " INPUT[@name=" + fieldName + "][type='checkbox']").each(
			function() 
			{
				if ( values.toString().indexOf($(this).val()) !== -1 )
				{
					$(this).attr('checked', flag);
				} 
			}
		);
	}
}

function checkAll(formId, fieldName, flag)
{
	if ( fieldName == '' )
	{
		$("form#" + formId + " INPUT[type='checkbox']").attr('checked', flag);
	}
	else
	{
		$("form#" + formId + " INPUT[@name=" + fieldName + "][type='checkbox']").attr('checked', flag);
	}
}

/* Related to story */ 
function submitComment()
{
	$.ajax({
		url:  '/comment/post',
		type: 'post',
		data: $("#commentStory").serialize(),
		success: function(data) {
			$('#comments-inner').append(data);
			$('#write').removeAttr("disabled");
			$('#comment').val('');
			$('#comments').show();
		},
		error: function(xhr, textStatus, errorThrown) {
			alert(xhr.responseText);
		}
		
	});
}
/* End story */

function setHover(obj, isHover)
{
	if (isHover)
		$(obj).addClass('hover');
	else
		$(obj).removeClass('hover');
}

$(function()
{
	$("#header .tabs li").hover(function() {
		$('ul:first', this).show();
	}, function() {
		$('ul:first', this).hide();
	});
});

Flattr.clickUnclaimed = function( thing_md5 ) {
	var csrf_token = $('#default-csrf-token');
	var data = {url_md5:thing_md5, "csrf_token":csrf_token.val(), "form_id":"default"};
	$.post('/pendingclicks',data,function(data){
		if (data.success == 'true') {

			var button = $('#flattr-dummy-button-'+thing_md5+'');
			button.find('.flattr-link').attr('class', 'flattr-pending');

			var count = button.find('.flattr-count span');
			count.text(parseInt(count.text()) + 1);	

			button.find(".pending-click-link").replaceWith(function() {
				return $('<span />').addClass('flattr').append($(this).contents());
			});
		}
		if (data.dialogContent && data.dialogContent != '') {
			$.facebox(data.dialogContent);
		}

		if (data.csrf_token)
		{
			csrf_token.val(data.csrf_token);
		}
	});
	return false;
}

$(document).ready(function()
{
	var timeoutId = null,
		twitterResponses = {};

	$('.pending-click-link').click(function(){
		Flattr.clickUnclaimed($(this).attr('href'));
		return false;
	});

	$("#footer_locale_switcher select").change(function() {
		var lang_code = $(this).val();
		window.location = "/locales/switch/locale/" + lang_code;
	});

	// SUBMIT TWITTER SIDEBAR
	$("#twitter_auto_suggestion input").hide();
	$('#flattr_twitter').keydown(function(e) {
		if (e.keyCode === 13) { // RETURN
			e.preventDefault();
		}
	}).keyup(function(e) {
		var url = "http://api.twitter.com/1/users/show.json?callback=?",
			$this = $(this),
		    name = $.trim($this.val()),
			params = {
				screen_name: name
			};

		if (!name)
		{
			$("#twitter_auto_suggestion input").attr("disabled", "disabled");
			$("#twitter_auto_suggestion").hide();
			return;
		}

		$("#twitter_auto_suggestion").show();

		if (timeoutId !== null)
		{
			if (timeoutId !== false) {
				clearTimeout(timeoutId);
			}
			$("#twitter_auto_suggestion h2").hide();
			$("#twitter_auto_suggestion input").hide();
			if ($("#twitter_auto_suggestion img").attr("src") !== '/_img/ajax_loader.gif') {
				$("#twitter_auto_suggestion img").attr("src", '/_img/ajax_loader.gif');
			}
			timeoutId = null;
		}

		var onTwitterData = function (data) {
			if ($this.val() !== name) {
				return;
			}
			$("#twitter_auto_suggestion input").removeAttr("disabled").show();
			$("#twitter_auto_suggestion img").attr("src", data.profile_image_url);
			$("#twitter_auto_suggestion h2").text(data.name).show();
			$("#twitter_auto_suggestion").show();
		};

		if (twitterResponses[name]) {
			onTwitterData(twitterResponses[name]);
			timeoutId = false;
		}
		else {
			timeoutId = setTimeout(function() {
				$.getJSON(url, params, function(data) {
					twitterResponses[name] = data;
					onTwitterData(twitterResponses[name]);
				});
			}, 500);
		}
	});
});

function flattrTwitterUser()
{
	var twitterUsr = $('#flattr_twitter').val();
	if(twitterUsr.length < 1)
	{
		alert("Please enter a valid Twitter username");
		return false;
	}
	var form = $('#flattr-twitter-user-form');
	var loader = $('#flattr-twitter-user-form-loader');
	form.hide();
	loader.show();
	
	var csrf_token = form.find('#csrf-token-flattr-twitter-user-form').val();
	var form_id = form.find('input[name=form_id]').val();
	var payload = {"ident": twitterUsr, "type" : "twitter.com", "csrf_token" : csrf_token, "form_id" : form_id};
	$.post("/flattr", payload, function(data) {
		if ( true == data.success )
		{
			window.location = data.redirectTo;
		}
		else
		{
			if (data.dialogContent != '') {
				var err_box = $('#flattr-twitter-user-form-error');
				err_box.html(data.dialogContent);
				err_box.show();
			}
			$('#flattr_twitter').val('');
			form.show();
			loader.hide();
		}
	}, 'json');
	
	return false;
}

