rl_myprofile = {
		
		init : function ()
		{
			$('a.edit').each( function () {
				var id = $(this).attr('id');
				if (id.substring(0,4) != 'form' || $(this).hasClass('upload'))
					return;
				$(this).click( function (ev) {
					ev.preventDefault();
					var idform = /_([a-z]+)_/.exec( $(this).attr('id') )[1];
					$(this).hide();
					var content = $('#form_'+idform+'_holder').html();
					$('#form_'+idform+'_holder').load( baseurl+'myprofile/__ajaxform/form__'+idform+'/', function () { rl_myprofile.initForm( idform, $(this), content ) }  );
				} );
			} );
		},
		
		
		initForm : function ( idform, formholder, content )
		{
			var form = formholder.find('form').eq(0);
			formholder.append( '<div class="btnbar"><a href="#" class="btn_submit">submit</a><a href="#" class="btn_cancel">cancel</a></div>' );
			formholder.find('a.btn_cancel').click( function (ev) { ev.preventDefault(); $('#form_'+idform+'_holder').empty().append(content).parent().find('a.edit').show(); } );
			formholder.find('a.btn_submit').click( function (ev) { ev.preventDefault(); form.ajaxSubmit( 
				{
					success:function (content) {
						$('#form_'+idform+'_holder').empty().append(content);
						if ($('#form_'+idform+'_holder').find('form').length > 0)
						{
							// form was sent back
							rl_myprofile.initForm( idform, formholder, content );
						} else {
							$('#form_'+idform+'_holder').parent().find('a.edit').show();
						}
					}
				} );
			} );
		}
		
};

$(document).ready( function () { rl_myprofile.init(); } );
