<inp2:m_DefineElement name="password_fields">
	<inp2:m_RenderElement design="form_row" prefix="u" field="Password" title="la_fld_Password">
		<td class="control-cell">
			<input type="password" name="<inp2:{$prefix}_InputName field='$field'/>" id="<inp2:{$prefix}_InputName field='$field'/>" value="<inp2:{$prefix}_Field name='{$field}_plain'/>" tabindex="<inp2:m_get param='tab_index'/>"/>
			<input type="button" class="button" id="generate_password" value="<inp2:m_Phrase name='la_btn_Generate' no_editing='1'/>"/>

			<script type="text/javascript">
				$(document).ready(
					function() {
						<inp2:m_ifnot check="{$prefix}_Field" name="{$field}_plain">
							$('#' + jq('<inp2:{$prefix}_InputName field="$field"/>')).val('');
						</inp2:m_ifnot>
					}
				);
			</script>
		</td>
	</inp2:m_RenderElement>

	<inp2:m_RenderElement design="form_row" prefix="u" field="VerifyPassword" title="la_fld_VerifyPassword">
		<td class="control-cell">
			<input type="password" name="<inp2:{$prefix}_InputName field='$field'/>" id="<inp2:{$prefix}_InputName field='$field'/>" value="<inp2:{$prefix}_Field name='{$field}_plain'/>" tabindex="<inp2:m_get param='tab_index'/>"/>

			<span<inp2:m_ifnot check="{$prefix}_Field" name="Password_plain"> style="display: none"</inp2:m_ifnot> id="email_password">
				<input type="hidden" id="<inp2:{$prefix}_InputName field='EmailPassword'/>" name="<inp2:{$prefix}_InputName field='EmailPassword'/>" value="<inp2:{$prefix}_Field field='EmailPassword' db='db'/>">
				<input tabindex="<inp2:m_get param='tab_index'/>" type="checkbox" id="_cb_<inp2:{$prefix}_InputName field='EmailPassword'/>" name="_cb_<inp2:{$prefix}_InputName field='EmailPassword'/>" <inp2:{$prefix}_Field field="EmailPassword" checked="checked" db="db"/> onchange="update_checkbox(this, document.getElementById('<inp2:{$prefix}_InputName field='EmailPassword'/>'));"/>
				<label for="_cb_<inp2:{$prefix}_InputName field='EmailPassword'/>"><inp2:m_Phrase name="la_fld_EmailPassword"/></label>
			</span>

			<script type="text/javascript">
				$(document).ready(
					function() {
						<inp2:m_ifnot check="{$prefix}_Field" name="{$field}_plain">
							$('#' + jq('<inp2:{$prefix}_InputName field="$field"/>')).val('');
						</inp2:m_ifnot>
					}
				);
			</script>
		</td>
	</inp2:m_RenderElement>
</inp2:m_DefineElement>

<inp2:m_DefineElement name="password_fields_js">
	var $field_mask = '<inp2:u_InputName name="#FIELD_NAME#" js_escape="1"/>';
	var $email_phrase = '<inp2:m_Phrase name="la_fld_EmailPassword" js_escape="1"/>';

	$( get_control($field_mask, 'Password') ).change(
		function ($e) {
			var $password = $(this).val();

			if ($password) {
				$('label', '#email_password').html( $email_phrase.replace('{password}', $password) );
				$('#email_password').show();
			}
		}
	);

	$('#generate_password').click(
		function ($e) {
			$.get(
				'<inp2:m_Link template="dummy" events[u]="OnGeneratePassword" no_amp="1" js_escape="1"/>',
				function ($password) {
					$( get_control($field_mask, 'Password') ).val($password).change();
					$( get_control($field_mask, 'VerifyPassword') ).val($password);
				}
			)
		}
	);

	$('label', '#email_password').html( $email_phrase.replace('{password}', '<inp2:u_Field name="Password_plain"/>') );
</inp2:m_DefineElement>