<div id="primary_header">
    <h1><?php print $this->translate('Password Settings')?></h1>
    <!--<div id="back_button" name="save">
        <a href="#">
            <span class="stronglastword"><?php echo $this->translate('Save Settings') ?></span>
        </a>
    </div>-->
</div>

<div id="primary_content">
    <div id="primary_content_inner">
        <div id="Flash" class="flash_notice"></div>

        <form id="settingsForm" method="post" action="<?php echo $this->moduleBaseUrl ?>/security/passwordsave">

            <input type="hidden" name="save" value="1" />

            <table class="settings password_policies_toggle">
                <tr>
                    <td class="label"><label for="use_password_policy"><?php echo $this->translate('Use Password Policy')?></label></td>
                    <td>
                        <input type="hidden" name="fields[use_password_policy]" value="0">
                        <input type="checkbox" name="fields[use_password_policy]" id="use_password_policy" value="1" <?php echo $this->password['use_password_policy']=='1'?' checked':'' ?> />
                        <small><?php echo $this->translate('Use a password policy.')?></small>
                    </td>
                </tr>
            </table>
            <div class='divider'></div>
            <table class="settings">
                <tr>
                    <td class="label"><?php print $this->translate('Minimum Characters')?></td>
                    <td>
                        <input type="text" class="small" name="fields[min_length]" id="min_length" value="<?php echo $this->password['min_length'] ?>" />
                        <small><?php print $this->translate('Specify a minimum number of characters permitted in a password.')?></small>
                    </td>
                </tr>
                <tr>
                    <td class="label"><?php print $this->translate('Minimum Lowercase Characters')?></td>
                    <td>
                        <input type="text" class="small" name="fields[min_lowercase_chars]" id="min_lowercase_chars" value="<?php echo $this->password['min_lowercase_chars'] ?>" />
                        <small><?php print $this->translate('Specify a minimum number of lowercase characters permitted.')?></small>
                    </td>
                </tr>
                <tr>
                    <td class="label"><?php print $this->translate('Minimum Uppercase Characters')?></td>
                    <td>
                        <input type="text" class="small" name="fields[min_uppercase_chars]" id="min_uppercase_chars" value="<?php echo $this->password['min_uppercase_chars'] ?>" />
                        <small><?php print $this->translate('Specify a minimum number of uppercase characters permitted.')?></small>
                    </td>
                </tr>
                </table>
            <div class='divider'></div>
            <table class="settings">
                <tr>
                    <td class="label"><label for="disallow_numeric_chars"><?php echo $this->translate('Disallow Numeric Characters')?></label></td>
                    <td>
                        <input type="hidden" name="fields[disallow_numeric_chars]" value="0">
                        <input type="checkbox" name="fields[disallow_numeric_chars]" id="disallow_numeric_chars" value="1" <?php echo $this->password['disallow_numeric_chars']=='1'?' checked':'' ?> />
                        <small><?php echo $this->translate('Disallow numeric characters in password.')?></small>
                    </td>
                </tr>
                <tr>
                    <td class="label"><?php print $this->translate('Minimum Numeric Characters')?></td>
                    <td>
                        <input type="text" class="small" name="fields[min_numeric_chars]" id="min_numeric_chars" value="<?php echo $this->password['min_numeric_chars'] ?>" />
                        <small><?php print $this->translate('Specify a minimum number of numeric characters permitted.')?></small>
                    </td>
                </tr>
                <tr>
                    <td class="label"><label for="disallow_numeric_first"><?php echo $this->translate('Disallow Numeric Character First')?></label></td>
                    <td>
                        <input type="hidden" name="fields[disallow_numeric_first]" value="0">
                        <input type="checkbox" name="fields[disallow_numeric_first]" id="disallow_numeric_first" value="1" <?php echo $this->password['disallow_numeric_first']=='1'?' checked':'' ?> />
                        <small><?php echo $this->translate('Disallow a numeric character to be the first character in the password.')?></small>
                    </td>
                </tr>
                <tr>
                    <td class="label"><label for="disallow_numeric_last"><?php echo $this->translate('Disallow Numeric Character Last')?></label></td>
                    <td>
                        <input type="hidden" name="fields[disallow_numeric_last]" value="0">
                        <input type="checkbox" name="fields[disallow_numeric_last]" id="disallow_numeric_last" value="1" <?php echo $this->password['disallow_numeric_last']=='1'?' checked':'' ?> />
                        <small><?php echo $this->translate('Disallow a numeric character to be the last character in the password.')?></small>
                    </td>
                </tr>
            </table>
            <div class='divider'></div>
            <table class="settings">
                <tr>
                    <td class="label"><label for="disallow_nonalphanumeric_chars"><?php echo $this->translate('Disallow Non-Alphanumeric Characters')?></label></td>
                    <td>
                        <input type="hidden" name="fields[disallow_nonalphanumeric_chars]" value="0">
                        <input type="checkbox" name="fields[disallow_nonalphanumeric_chars]" id="disallow_nonalphanumeric_chars" value="1" <?php echo $this->password['disallow_nonalphanumeric_chars']=='1'?' checked':'' ?> />
                        <small><?php echo $this->translate('Disallow alphanumeric characters in password.')?></small>
                    </td>
                </tr>
                <tr>
                    <td class="label"><?php print $this->translate('Minimum Non-Alphanumeric Characters')?></td>
                    <td>
                        <input type="text" class="small" name="fields[min_nonalphanumeric_chars]" id="min_nonalphanumeric_chars" value="<?php echo $this->password['min_nonalphanumeric_chars'] ?>" />
                        <small><?php print $this->translate('Specify a minimum number of non-alphanumeric characters permitted.')?></small>
                    </td>
                </tr>
                <tr>
                    <td class="label"><label for="disallow_nonalphanumeric_first"><?php echo $this->translate('Disallow Non-Alphanumeric Character First')?></label></td>
                    <td>
                        <input type="hidden" name="fields[disallow_nonalphanumeric_first]" value="0">
                        <input type="checkbox" name="fields[disallow_nonalphanumeric_first]" id="disallow_nonalphanumeric_first" value="1" <?php echo $this->password['disallow_nonalphanumeric_first']=='1'?' checked':'' ?> />
                        <small><?php echo $this->translate('Disallow a non-alphanumeric character to be the first character in the password.')?></small>
                    </td>
                </tr>
                <tr>
                    <td class="label"><label for="disallow_nonalphanumeric_last"><?php echo $this->translate('Disallow Non-Alphanumeric Character Last')?></label></td>
                    <td>
                        <input type="hidden" name="fields[disallow_nonalphanumeric_last]" value="0">
                        <input type="checkbox" name="fields[disallow_nonalphanumeric_last]" id="disallow_nonalphanumeric_last" value="1" <?php echo $this->password['disallow_nonalphanumeric_last']=='1'?' checked':'' ?> />
                        <small><?php echo $this->translate('Disallow a non-alphanumeric character to be the last character in the password.')?></small>
                    </td>
                </tr>
            </table>
            <div class='divider'></div>
            <table class="settings">
                <tr>
                    <td class="label"><label for="three_type_chars"><?php echo $this->translate('Enable Three-of-Char-Types Checking')?></label></td>
                    <td>
                        <input type="hidden" name="fields[three_type_chars]" value="0">
                        <input type="checkbox" name="fields[three_type_chars]" id="three_type_chars" value="1" <?php echo $this->password['three_type_chars']=='1'?' checked':'' ?> />
                        <small><?php echo $this->translate('Enable checking that password must contain at least three of: at least one uppercase letter, at least one lowercase letter, at least one number, at least one symbol.')?></small>
                    </td>
                </tr>
            </table>
            <div class='divider'></div>

    </div>
    </form>
    <div id="back_button">
        <a href="#">
            <span class="stronglastword"><?php echo $this->translate('Save Settings') ?></span>
        </a>
    </div>
</div>

<script type="text/javascript">
    $( function()
    {
        if($("#use_password_policy", "#password").attr('checked') == false)
        {
            $('#settingsForm', '#password').find('.settings:not(.password_policies_toggle),.divider').css('opacity', 0.4)
            $('#settingsForm', '#password').find('.settings:not(.password_policies_toggle),.divider').css('cursor', 'not-allowed')
        }

        if($('#disallow_nonalphanumeric_chars', '#password').attr('checked') == true)
        {
            $('#min_nonalphanumeric_chars').val(0)
            $('#min_nonalphanumeric_chars').css('opacity', 0.4)
            $('#min_nonalphanumeric_chars').css('cursor', 'not-allowed')
            disableItem($('#disallow_nonalphanumeric_first'), true)
            $('#disallow_nonalphanumeric_first').css('opacity', 0.4)
            disableItem($('#disallow_nonalphanumeric_last'), true)
            $('#disallow_nonalphanumeric_last').css('opacity', 0.4)
        }

        if($('#disallow_numeric_chars', '#password').attr('checked') == true)
        {
            $('#min_numeric_chars').val(0)
            $('#min_numeric_chars').css('opacity', 0.4)
            $('#min_numeric_chars').css('cursor', 'not-allowed')
            disableItem($('#disallow_numeric_first'), true)
            $('#disallow_numeric_first').css('opacity', 0.4)
            disableItem($('#disallow_numeric_last'), true)
            $('#disallow_numeric_last').css('opacity', 0.4)
        }

        $('.iphoneStyle', '#password').each( function() { $(this).iphoneStyle() });
        $('.stronglastword', '#password').each( function() { $(this).stronglastword() });
        $('#use_password_policy', '#password').bind('change', function()
        {

            if($("#use_password_policy", "#password").attr('checked') == true)
            {
                //$('#settingsForm', '#password').find('.settings:not(.password_policies_toggle),.divider').show();
                $('#settingsForm', '#password').find('.settings:not(.password_policies_toggle),.divider').css('opacity', 1)
                $('#settingsForm', '#password').find('.settings:not(.password_policies_toggle),.divider').css('cursor', 'pointer');
            }
            else
            {
                //$('#settingsForm', '#password').find('.settings:not(.password_policies_toggle),.divider').hide();
                $('#settingsForm', '#password').find('.settings:not(.password_policies_toggle),.divider').css('opacity', 0.4)
                $('#settingsForm', '#password').find('.settings:not(.password_policies_toggle),.divider').css('cursor', 'not-allowed')
            }
        });
        $('#disallow_nonalphanumeric_chars', '#password').unbind().bind('change', function()
        {
            if($('#disallow_nonalphanumeric_chars', '#password').attr('checked') == true)
            {
                $('#min_nonalphanumeric_chars').val(0)
                $('#min_nonalphanumeric_chars').css('opacity', 0.4)
                $('#min_nonalphanumeric_chars').css('cursor', 'not-allowed')
                disableItem($('#disallow_nonalphanumeric_first'), true)
                $('#disallow_nonalphanumeric_first').parent().addClass('iPhoneCheckDisabled');
                disableItem($('#disallow_nonalphanumeric_last'), true)
                $('#disallow_nonalphanumeric_last').parent().addClass('iPhoneCheckDisabled');
            }
            else
            {
                $('#min_nonalphanumeric_chars').val(<?php echo $this->password['min_nonalphanumeric_chars'] ?>)
                $('#min_nonalphanumeric_chars').css('opacity', 1);
                $('#min_nonalphanumeric_chars').css('cursor', 'pointer');
                enableItem($('#disallow_nonalphanumeric_first'), false)
                $('#disallow_nonalphanumeric_first').parent().removeClass('iPhoneCheckDisabled');
                enableItem($('#disallow_nonalphanumeric_last'), false)
                $('#disallow_nonalphanumeric_last').parent().removeClass('iPhoneCheckDisabled');
            }
        });
        $('#disallow_numeric_chars', '#password').unbind().bind('change', function()
        {
            if($('#disallow_numeric_chars', '#password').attr('checked') == true)
            {
                $('#min_numeric_chars').val(0)
                $('#min_numeric_chars').css('opacity', 0.4)
                $('#min_numeric_chars').css('cursor', 'not-allowed')
                disableItem($('#disallow_numeric_first'), true)
                $('#disallow_numeric_first').parent().addClass('iPhoneCheckDisabled');
                disableItem($('#disallow_numeric_last'), true)
                $('#disallow_numeric_last').parent().addClass('iPhoneCheckDisabled');
            }
            else
            {
                $('#min_numeric_chars').val(<?php echo $this->password['min_numeric_chars'] ?>)
                $('#min_numeric_chars').css('opacity', 1)
                $('#min_numeric_chars').css('cursor', 'pointer')
                enableItem($('#disallow_numeric_first'), false)
                $('#disallow_numeric_first').parent().removeClass('iPhoneCheckDisabled');
                enableItem($('#disallow_numeric_last'), false)
                $('#disallow_numeric_last').parent().removeClass('iPhoneCheckDisabled');
            }
        });

        $('#back_button a', '#password').bind("click", function()
        {

            return $('#settingsForm', '#password').submit()

        })

        // bind to the form's submit event and cancel legacy submit
        $('#settingsForm', '#password').submit(function()
        {

            $.php($("#settingsForm", '#password').attr("action"),$("#settingsForm", '#password').serializeArray());
            return false;

        });

        $('#settingsForm :checkbox').iphoneStyle();

    });
</script>
