var SendPassword = Class.create();
Object.extend(SendPassword.prototype, {

	initialize: function()
	{
		this.elementId = 'sendToFriend';
		Event.observe(window, 'load', this.onLoad.bind(this));
	},
	
	onLoad: function() 
	{
		$$('a.send-password').each(function(item) {
			item.observe('click', this.showWindow.bindAsEventListener(this))
		}, this);
	},
	
	showWindow: function(e)
	{
		e.stop();
		new Ajax.Request(BASE_URL + '/' + LANGUAGE + '/users/forget-password/type/' + AUTH_TYPE, {
			onSuccess: this.onResponse.bind(this)
		})
	},
		
	onResponse: function(transport)
	{
		$(document.body).insert(transport.responseText);
		$$('#' + this.elementId + ' div.btn-close').each(function(item) { item.observe('click', this.destroy.bind(this));}, this);
		$('btnSend').observe('click', this.submit.bindAsEventListener(this));
	},
	
	submit: function(e)
	{
		e.stop();
		var form = $('form');
		
		var data = form.serialize(true);
		data.url = window.location.href;
		
		new Ajax.Request(form.action, {
			parameters: data,
			onSuccess: function(transport) {
				$('sendToFriendTitle').update(transport.responseText);
			}
		});
		
		form.remove();
		$('sendToFriendTitle').update('Processing...');
	},
	
	destroy: function()
	{
		$(this.elementId).remove();
	}
	
});

new SendPassword();
