<mt:setvarblock name="page_title"><__trans phrase="Manage [_1] Address Book" params="<mt:if name="blog_id"><mt:if name="is_blog"><__trans phrase="Blog"><mt:else><__trans phrase="Website"></mt:if><mt:else><__trans phrase="Global"></mt:if>"></mt:setvarblock>
<mt:setvarblock name="system_msg">
    <mt:if name="error">
        <mtapp:statusmsg
            id="generic-error"
            class="error">
            <mt:var name="error">
        </mtapp:statusmsg>
    </mt:if>
    <mt:if name="saved">
        <mtapp:statusmsg
            id="saved"
            class="success">
            <__trans phrase="You have added [_1] to your address book." params="<strong><$mt:var name="saved" escape="html"$></strong>">
        </mtapp:statusmsg>
    </mt:if>
    <mt:if name="saved_deleted">
        <mtapp:statusmsg
            id="saved-deleted"
            class="success">
            <__trans phrase="You have successfully deleted the selected contacts from your address book.">
        </mtapp:statusmsg>
    </mt:if>
</mt:setvarblock>
<mt:setvarblock name="related_content">
    <mt:if name="notification_count">
        <mtapp:widget
            id="useful-links"
            label="<__trans phrase="Useful links">">
            <ul>
                <li><a href="<MT_ACTION mode="export_notification" <mt:if name="blog_id">blog_id="<mt:var name="blog_id">"</mt:if> magic_token="<mt:var name="magic_token">" return_args="<mt:var name="return_args">">" class="icon-left icon-download"><__trans phrase="Download Address Book (CSV)"></a></li>
            </ul>
        </mtapp:widget>
    </mt:if>
    <$mtapp:PageActions$>
</mt:setvarblock>
<mt:setvarblock name="html_body_footer">
    <$mt:include name="include/display_options.tmpl"$>
</mt:setvarblock>
<mt:setvarblock name="html_head" append="1">
    <script type="text/javascript" src="<mt:var name="static_uri">js/tc/client.js"></script>

    <script type="text/javascript">
    /* <![CDATA[ */
    var current_edit = 0;
    var old_note_email = '';
    var old_note_url = '';
    function highlight_note(id) {
        if (current_edit) return;
        jQuery('#note-link-' + id).css({
            'backgroundColor': '#FFC',
            'borderColor': '#FFC'
        });
    }

    function unhighlight_note(id) {
        jQuery('#note-link-' + id).css({
            'backgroundColor': 'transparent',
            'borderColor': '#3F658C'
        });
    }

    function edit_note(id) {
        if (current_edit) return;
        var note_links = new Array();
        note_links.push(getByID('note-email-link-' + id));
        note_links.push(getByID('note-url-link-' + id));
        var note_fields = new Array();
        note_fields.push(getByID('note-email-field-' + id));
        note_fields.push(getByID('note-url-field-' + id));
        var note_email = getByID('note-email-' + id);
        var note_url = getByID('note-url-' + id);
        if (!note_links.length || !note_fields.length || !note_email) return;
        current_edit = id;
        old_note_email = note_email.value;
        old_note_url = note_url.value;
        for (i=0;i<2;++i) {
            note_links[i].style.display = 'none';
            note_fields[i].style.display = 'inline';
        }
        note_email.focus();
        note_email.select();
        unhighlight_note(id);
        return false;
    }

    function cancel_edit(id) {
        var note_links = new Array();
        note_links.push(getByID('note-email-link-' + id));
        note_links.push(getByID('note-url-link-' + id));
        var note_fields = new Array();
        note_fields.push(getByID('note-email-field-' + id));
        note_fields.push(getByID('note-url-field-' + id));
        var note_email = getByID('note-email-' + id);
        var note_url = getByID('note-url-' + id);
        if (!note_links.length || !note_fields.length || !note_email) return;
        note_email.value = old_note_email;
        old_note_email = '';
        note_url.value = old_note_url;
        old_note_url = '';
        current_edit = 0;
        for (i=0;i<2;++i) {
            note_links[i].style.display = 'inline';
            note_fields[i].style.display = 'none';
        }
        return false;
    }

    function submit_edit(id) {
        if ((0 != current_edit) && (id != current_edit))
            id = current_edit;
        // if old email matches new email, ignore submission (same as cancel)
        // if new email is already in our noteList array, warn user
        // if not in noteList and not in range of noteList notes, check with server.
        var note_form = getByID('create-inline-notification-form');
        var note_email = getByID('note-email-' + id);
        var note_url = getByID('note-url-' + id);
        if (!note_form || !note_email || !note_url) return false;
        var new_note_email = note_email.value;
        var new_note_url = note_url.value;
        if ((old_note_email == new_note_email) && (old_note_url == new_note_url)) {
            cancel_edit(id);
            return false;
        }
        return submit_edit_form(id);
    }

    function submit_edit_form(id) {
        var note_form = getByID('create-inline-notification-form');
        var note_email = getByID('note-email-' + id);
        var note_url = getByID('note-url-' + id);
        if (!note_form || !note_email) return false;
        note_form['id'].value = id;
        note_form['email'].value = note_email.value;
        note_form['url'].value = note_url.value;
        note_form.submit();
        return false;
    }

    function setCreateMode () {
        jQuery('#email').val('').focus();
        jQuery('#url').val('');
        jQuery('#create-inline-notification').show();
        jQuery('#create-contact').hide();
        jQuery('#saved-msg').hide();
        jQuery('#saved-deleted-msg').hide();
    }

    function cancelCreateMode () {
    	jQuery('#create-inline-notification').hide();
        jQuery('#create-contact').show();
    }
    </script>
</mt:setvarblock>
<mt:setvarblock name="action_buttons">
<button
    onclick="doRemoveItems(getByID('<$mt:var name="object_type"$>-listing-form'), '<__trans phrase="contact" escape="js">', '<__trans phrase="contacts" escape="js">'); return false;"
    accesskey="x"
    title="<__trans phrase="Delete selected [_1] (x)" params="<$mt:var name="object_label_plural"$>">"
    ><__trans phrase="Delete"></button>
</mt:setvarblock>
<mt:setvarblock name="content_header">
    <ul class="action-link-list">
        <li id="create-contact"><a href="javascript:void(0)" onclick="setCreateMode()" class="icon-left icon-create"><__trans phrase="Create Contact"></a></li>
    </ul>
</mt:setvarblock>
<mt:include name="include/header.tmpl">

<div class="create-inline" id="create-inline-notification">
<form method="post" action="<mt:var name="script_url">" id="create-inline-notification-form">
<input type="hidden" name="blog_id" value="<mt:var name="blog_id">" />
<input type="hidden" name="__mode" value="save" />
<input type="hidden" name="_type" value="notification" />
<input type="hidden" name="return_args" value="<mt:var name="return_args" escape="html">" />
<input type="hidden" name="magic_token" value="<mt:var name="magic_token">" />
<input type="hidden" name="id" value="" />
<mtapp:setting
    id="email"
    label="<__trans phrase="Email">"
    label_class="inline"
    hint=""
    show_hint="0">
    <input type="text" name="email" id="email" value="<mt:var name="email" escape="html">" />
</mtapp:setting>
<mtapp:setting
    id="website"
    label="<__trans phrase="Website URL">"
    label_class="inline"
    hint=""
    show_hint="0">
    <input type="text" name="url" id="url" value="<mt:var name="url" escape="html">">
</mtapp:setting>
    <span class="buttons">
        <button
            type="submit"
            class="small-button"
            ><__trans phrase="Add Contact"></button>
        <button
            type="button"
            class="small-button mt-cancel-action"
            ><__trans phrase="Cancel"></button> 
    </span>
</form>
</div>
<mt:include name="include/notification_table.tmpl">
<mt:setvarblock name="jq_js_include" append="1">
    jQuery.mtCheckbox();

    jQuery('button.mt-do-action').click(function() {
        jQuery('#create-inline-notification-form').submit();
    });
    jQuery('button.mt-cancel-action').click(function() {
        cancelCreateMode();
        return false;
    });
</mt:setvarblock>
<mt:include name="include/footer.tmpl">
