var Registration = {
		checkBeforeSubmit: function() {
			
		},

		showProfile: function(id,title) {
			var params = {
					action: 'Plugins/Registration/index.php?view=client&form=profile&userId='+id,
					content: 'html',
					width: 600,
					height: 400,
					title: title
			};
			var light = new CalcunLightbox(params);
			light.show();
			$('.closeLightbox').live('click',function() {
				light.close();
			})	
		}
};

$(document).ready(function(){
	$('#forgot-password-link').click(function() {
		var params = {
			action: 'Plugins/Registration/index.php?view=client&form=forgotPassword',
			content: 'html',
			width: 440,
			height: 120,
			title: 'Elfelejtett jelszó',
			callback: function() {
				$('#forgotPassForm').validate();
			}
		};
		var light = new CalcunLightbox(params);
		light.show();
		$('.closeLightbox').live('click',function() {
			light.close();
		})
		return false;
	});
	
	$('form span.hint').css('display','none');
	var thisForm = $('.userDetails');
	$('input,textarea',thisForm).live('focus',function(){
		var thisInput = this;
		var hint = $(thisInput).nextAll('span.hint_'+$(thisInput).attr('name')).html();
		if(hint) {
			$('#reg_tooltip').text(hint);
		} else {
			$('#reg_tooltip').empty();
		}
	});
	$('input,textarea',thisForm).live('blur',function(){
		$('#hintBox').empty();
	});
	$('a.showProfile').die('click');
	$('a.showProfile').live('click',function() {
		var tempId = $(this).attr('id');
		var id = $(this).attr('id').split('-');
		id = tempId.replace(new RegExp("^"+id[0]+"\-", "i"),'');
		//id = id[id.length-1];
		var title = $(this).attr('title');
		Registration.showProfile(id,title);
		return false
	});
	$('.showMyProfile').die('click').live('click', function() {
		var id = $('form.userDetails input[name=userId]').val();
		var title = 'Profilom megtekintése';
		var params = {
				action: 'Plugins/Registration/index.php?view=client&form=profile&profile=full&userId='+id,
				content: 'html',
				width: 600,
				height: 500,
				title: title
		};
		var light = new CalcunLightbox(params);
		light.show();
		$('.closeLightbox').die('click').live('click',function() {
			light.close();
		});
		return false;
	});
	
	$('.deleteMyAccount')
		.css('color', 'red')
		.die('click').live('click', function() {
			jcConfirm('suretoDeleteAccount', 'Confirm', function(r){
				if(r) {
					$.ajax({ url: '/Plugins/Registration/index.php',
						data: {
						view: 'setting',
						action: 'requestDelete',
						method: 'ajax'
					}, 
					success: function(data) {
						if(data == 'ok') {
							jcInfo('deleteAccountRequestSent', 'Info', function() {
	
							});
						} 
					}});
				}
			});
			return false;
	});
	
	
	$('#registerForm').submit(function(){
		if (!$('#registerForm input[name=acceptRules]').is(':checked')) {
			jcInfo('mustAcceptRules', 'alert');
			return false;
		}
		return true;	
	});
});
