var PasswordWeasel = new Class({
				
	dblclickcatch : false,
				
	initialize : function() {

	},
	
	submit: function() {
		
		if(this.validate()) {
		
			if(!oPasswordWeasel.dblclickcatch) {
				oPasswordWeasel.dblclickcatch = true;
				
				var post = new Hash();
				post.set('password-box-username-email', $('password-box-username-email').get('value'));
				
				$('password-box-submit-button').set('value',oLocalization.ajaxloading);
	
				new Request.JSON({
					method: 'post',
					data: JSON.encode(post),
					url: '/ajax/PasswordWeasel.submit.ajax.php',
					onFailure: function(exc) {
						oPasswordWeasel.error([oLocalization.js_default_ajax_error]);
					},
					onError: function() {
						oPasswordWeasel.error([oLocalization.js_default_ajax_error]);
					},
					onSuccess: function(o) {
						switch(o.success) {
							case(-1):
								oPasswordWeasel.error([oLocalization.js_default_ajax_error]);
								break;
							case(0):
								if($chk(o.errorids)) {
									for(var i=0; i < o.messages.length; i++) {
										if($chk(o.errorids[i])) {
											if(!$(o.errorids[i]).hasClass('error')) {
												$(o.errorids[i]).addClass('error');
												$(o.errorids[i] + '-label').addClass('error');
											}
										}
									}
								}
								oPasswordWeasel.error(o.messages);
								break;
							case(1):
								oPasswordWeasel.success(o.messages);
								break;
						}
					}
				}).send();
				
			}
			
		}
			
	},
	
	validate: function() {
		
		if($chk(this.Feedback)) {
			this.Feedback.hide();
			$(this.Feedback.feedbackboxcontainerid).set('style','padding-top:0px;');
		}
		
		var valid = true;
		var messages = [];
		var c = 0;
		$$('input.password-box-non-empty,textarea.password-box-non-empty').each(function(el) {
			if(el.get('value').trim() == '') {
				if(!el.hasClass('error')) {
					el.addClass('error');
					$(el.id + '-label').addClass('error');
				}
				messages[c] = el.get('errmessage');
				c = c+1;
				valid = false;
			} else {
				if(el.hasClass('error')) {
					el.removeClass('error');
					$(el.id + '-label').removeClass('error');
				}
			}
		});

		if(!valid) {
			this.dblclickcatch = false;	
			this.error(messages);
		}
		
		return valid;
		
	},
	
	success: function(messages) {
		
		new Fx.Tween($('password-form'), {onComplete:function() {$('password-form').tween('height',0)}}).start('opacity',0);
		
		
		this.Feedback = new SuccessBox(messages);
		this.Feedback.setCustomFeedbackboxcontainerId('ajaxfeedbackboxcontainer');
		this.Feedback.show();
		
		var h = ($(this.Feedback.feedbackboxcontainerid).getPosition().y - 56);
		new Fx.Scroll($(document.body)).start(0, h);
		setTimeout("$(oPasswordWeasel.Feedback.feedbackbox.get('id')).highlight('#1f6130')",500);
		
	},
	
	error: function(messages) {	
		
		this.Feedback = new ErrorBox(messages);
		this.Feedback.setCustomFeedbackboxcontainerId('ajaxfeedbackboxcontainer');
		this.Feedback.show();

		var h = ($(this.Feedback.feedbackboxcontainerid).getPosition().y - 56);
		new Fx.Scroll($(document.body)).start(0, h);
		setTimeout("$(oPasswordWeasel.Feedback.feedbackbox.get('id')).highlight('#ad0000')",500);
		
		this.dblclickcatch = false;
		$('password-box-submit-button').set('value',oLocalization.submit);
		
	}

});
