function spa_components_smileys_form()
{
    global $spPaths;
    ?>
<script type= "text/javascript">/*<![CDATA[*/
    jQuery(document).ready(function(){
    	spjAjaxForm('sfsmileysform', 'sfreloadsm');

    	jQuery("#sfsmileytable").tableDnD({
    		dragHandle: "dragHandle",
    		onDragClass: "tdDragClass"
    	});

    	jQuery("#sfsmileytable tr").hover(function() {
    		jQuery(this.cells[0]).addClass('showDragHandle');
    	}, function() {
    		jQuery(this.cells[0]).removeClass('showDragHandle');
    	});

    	var button = jQuery('#sf-upload-button'), interval;
    	new AjaxUpload(button,{
    		action: '<?php 
    echo SFUPLOADER;
    ?>
',
    		name: 'uploadfile',
    	    data: {
    		    saveloc : '<?php 
    echo addslashes(SF_STORE_DIR . '/' . $spPaths['smileys'] . '/');
    ?>
'
    	    },
    		onSubmit : function(file, ext){
                /* check for valid extension */
    			if (! (ext && /^(jpg|png|jpeg|gif|JPG|PNG|JPEG|GIF)$/.test(ext))){
    				jQuery('#sf-upload-status').html('<p class="sf-upload-status-text"><?php 
    echo esc_js(spa_text('Only JPG, PNG or GIF files are allowed!'));
    ?>
</p>');
    				return false;
    			}
    			/* change button text, when user selects file */
    			utext = '<?php 
    echo esc_js(spa_text('Uploading'));
    ?>
';
    			button.text(utext);
    			/* If you want to allow uploading only 1 file at time, you can disable upload button */
    			this.disable();
    			/* Uploding -> Uploading. -> Uploading... */
    			interval = window.setInterval(function(){
    				var text = button.text();
    				if (text.length < 13){
    					button.text(text + '.');
    				} else {
    					button.text(utext);
    				}
    			}, 200);
    		},
    		onComplete: function(file, response){
    			jQuery('#sf-upload-status').html('');
    			button.text('<?php 
    echo esc_js(spa_text('Browse'));
    ?>
');
    			window.clearInterval(interval);
    			/* re-enable upload button */
    			this.enable();
    			/* add file to the list */
    			if (response==="success"){
                    var site = "<?php 
    echo SFHOMEURL;
    ?>
index.php?sp_ahah=components&amp;sfnonce=<?php 
    echo wp_create_nonce('forum-ahah');
    ?>
&amp;action=delsmiley&amp;file=" + file;
                    var name = file.replace('.', '_');
    				var count = document.getElementById('smiley-count');
    				var scount = parseInt(count.value) + 1;
    				jQuery('#sfsmileytable').append(
                        '<tr id="smiley' + scount + '">' +
                        '<td class="dragHandle" style="text-align:center;width:2%"><img class="spSmiley" src="<?php 
    echo SFSMILEYS;
    ?>
' + file + '" alt="" /></td>' +
                        '<td class="wp-core-ui">' +
                        '<fieldset class="sffieldset"><legend><strong>' + file + '</strong></legend><input type="hidden" name="smfile[]" value="' + file + '" />' +
                        '<div class="sp-form-row"><div class="wp-core-ui sflabel sp-label-40"><?php 
    echo spa_text('Name');
    ?>
:</div><input type="text" class="wp-core-ui sp-input-60" name="smname[]" value="' + name + '" /><div class="clearboth"></div></div>' +
                        '<input type="hidden" name="smfile[]" value="' + file + '" />' +
                        '<div class="sp-form-row"><div class="wp-core-ui sflabel sp-label-40"><?php 
    echo spa_text('Code');
    ?>
:</div><input type="text" class="wp-core-ui sp-input-60" name="smcode[]" value="' + name + '" /><div class="clearboth"></div></div>' +
                        '<div class="sp-form-row"><input type="checkbox" name="smbreak-' + name + '" id="sf-smbreak-' + name + '" /><label for="sf-smbreak-' + name + '" class="wp-core-ui"><?php 
    echo spa_text('Break Smileys Row in Editor Display');
    ?>
</label><div class="clearboth"></div></div>' +
                        '<div class="sp-form-row"><input type="checkbox" name="sminuse-'+ name + '" id="sf-sminuse-' + name + '" checked="checked" /><label for="sf-sminuse-' + name + '" class="wp-core-ui"><?php 
    echo spa_text('Allow Use of this Smiley');
    ?>
</label><div class="clearboth"></div></div>' +
                        '</fieldset>' +
                        '</td>' +
                        '<td style="text-align: left;vertical-align: middle;margin:0;padding:0 4px 0 0;width:3%"><img src="<?php 
    echo SFCOMMONIMAGES . 'delete.png';
    ?>
" title="<?php 
    echo spa_text('Delete Smiley');
    ?>
" alt="" onclick="spjDelRow(\'' + site + '\', \'smiley' + scount + '\');" /></td>' +
                        '</tr>');
    				jQuery('#smiley-count').val(scount);
    				jQuery('#sf-upload-status').html('<p class="sf-upload-status-success"><?php 
    echo esc_js(spa_text('Smiley uploaded!'));
    ?>
</p>');
                	jQuery('.ui-tooltip').hide();
    			} else if (response==="invalid"){
    				jQuery('#sf-upload-status').html('<p class="sf-upload-status-fail"><?php 
    echo esc_js(spa_text('Sorry, the file has an invalid format!'));
    ?>
</p>');
    			} else if (response==="exists") {
    				jQuery('#sf-upload-status').html('<p class="sf-upload-status-fail"><?php 
    echo esc_js(spa_text('Sorry, the file already exists!'));
    ?>
</p>');
    			} else {
    				jQuery('#sf-upload-status').html('<p class="sf-upload-status-fail"><?php 
    echo esc_js(spa_text('Error uploading file!'));
    ?>
</p>');
    			}
    		}
    	});
    });/*]]>*/
</script>
<?php 
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=components-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=smileys';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfsmileysform" name="sfsmileys" enctype="multipart/form-data">
	<?php 
    echo sp_create_nonce('forum-adminform_smileys');
    spa_paint_options_init();
    #== SMILEYS Tab ============================================================
    spa_paint_open_tab(spa_text('Components') . ' - ' . spa_text('Smileys'), true);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Custom Smiley Upload'), true, 'smiley-upload');
    $loc = SF_STORE_DIR . '/' . $spPaths['smileys'] . '/';
    spa_paint_file(spa_text('Select smiley file to upload'), 'newsmileyfile', false, true, $loc);
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    do_action('sph_components_smileys_right_panel');
    spa_paint_close_container();
    echo '<div class="sfform-panel-spacer"></div>';
    spa_paint_close_tab();
    spa_paint_open_nohead_tab(true);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Custom Smileys'), true, 'custom-smileys');
    echo '<p><b>' . spa_text('To re-order your Smileys drag and drop using the grab handle on the left of each row') . '</b></p>';
    spa_paint_custom_smileys();
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_close_container();
    ?>
	<div class="sfform-submit-bar">
	<input type="submit" class="button-primary" id="updatesmileys" name="saveit" value="<?php 
    spa_etext('Update Smileys Component');
    ?>
" />
	</div>
<?php 
    spa_paint_close_tab();
    ?>
	</form>
<?php 
}
function spa_forums_create_forum_form()
{
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	spjAjaxForm('sfforumnew', 'sfreloadfb');
    });
</script>
<?php 
    global $spPaths, $tab;
    spa_paint_options_init();
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=forums-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=createforum';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfforumnew" name="sfforumnew">
<?php 
    echo sp_create_nonce('forum-adminform_forumnew');
    spa_paint_open_tab(spa_text('Forums') . ' - ' . spa_text('Create New Forum'), true);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Create New Forum'), 'true', 'create-new-forum');
    # check there are groups before proceeding
    if (spdb_count(SFGROUPS) == 0) {
        echo '<br /><div class="sfoptionerror">';
        spa_etext('There are no groups defined');
        echo '<br />' . spa_text('Create new group');
        echo '</div><br />';
        spa_paint_close_fieldset();
        spa_paint_close_panel();
        spa_paint_close_container();
        spa_paint_close_tab();
        echo '</form>';
        return;
    }
    # Select the forum type first
    echo "<div class='sp-form-row'>\n";
    echo "<div class='wp-core-ui sflabel sp-label-40'>" . spa_text('What type of forum are you creating') . ":</div>\n";
    echo "<div class='wp-core-ui sp-radio'>";
    echo '<input type="radio" name="forumtype" id="sfradio1" tabindex="' . $tab . '" value="1" checked="checked" onchange="spjSetForumOptions(\'forum\');" />' . "\n";
    echo '<label for="sfradio1" class="wp-core-ui">' . spa_text('Standard Forum') . '</label><br>' . "\n";
    $tab++;
    # check there are forums before offering subforum creation!
    if (spdb_count(SFFORUMS) != 0) {
        echo '<input type="radio" name="forumtype" id="sfradio2" tabindex="' . $tab . '" value="2" onchange="spjSetForumOptions(\'subforum\');" />' . "\n";
        echo '<label for="sfradio2" class="wp-core-ui">' . spa_text('Sub or child forum') . '</label>' . "\n";
        $tab++;
    }
    echo '</div><div class="clearboth"></div></div>';
    # Now display the two select box options
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=forums&amp;sfnonce=' . wp_create_nonce('forum-ahah');
    $target = 'fseq';
    echo '<div id="groupselect" style="display:block;">';
    echo "<div class='sp-form-row'>\n";
    echo "<div class='wp-core-ui sflabel sp-label-40'>" . spa_text('Select group new forum will belong to') . ":</div>\n";
    echo '<select class="wp-core-ui  sp-input-60" tabindex="' . $tab . '" name="group_id"  onchange="spjSetForumSequence();">';
    echo spa_create_group_select(0, 1);
    echo "</select>\n";
    echo '<div class="clearboth"></div>';
    echo '</div>';
    $tab++;
    echo '</div>';
    echo '<div id="forumselect" style="display:none;">';
    echo "<div class='sp-form-row'>\n";
    echo "<div class='wp-core-ui sflabel sp-label-40'>" . spa_text('Select forum new subforum will belong to') . ":</div>\n";
    echo '<select class="wp-core-ui  sp-input-60" tabindex="' . $tab . '" name="forum_id"  onchange="spjSetForumSequence();">';
    echo sp_render_group_forum_select(false, false, false, true);
    echo "</select>\n";
    echo '<div class="clearboth"></div>';
    echo '</div>';
    $tab++;
    echo '</div>';
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_close_container();
    echo '<div class="sfform-panel-spacer"></div>';
    spa_paint_close_tab();
    echo '<div class="sfform-panel-spacer"></div>';
    echo '<div class="sfhidden" id="block1">';
    spa_paint_open_nohead_tab(false);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Forum Details'), false);
    $target = 'thisforumslug';
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=forums&amp;sfnonce=' . wp_create_nonce('forum-ahah');
    # forum name and slug
    echo "<div class='sp-form-row'>";
    echo "<div class='wp-core-ui sflabel sp-label-40'>" . spa_text('Forum Name') . ':</div>';
    echo '<input type="text" class="wp-core-ui sp-input-60" tabindex="' . $tab . '" name="forum_name" value="" onchange="spjSetForumSlug(this, \'' . $ahahURL . '\', \'' . $target . '\', \'new\');" />';
    echo '<div class="clearboth"></div>';
    echo '</div>';
    $tab++;
    echo "<div class='sp-form-row'>\n";
    echo "<div class='wp-core-ui sflabel sp-label-40'>" . spa_text('Forum slug') . ":</div>";
    echo '<input type="text" class="wp-core-ui sp-input-60" tabindex="' . $tab . '" name="thisforumslug" id="thisforumslug" value="" disabled="disabled" onchange="spjSetForumSlug(this, \'' . $ahahURL . '\', \'' . $target . '\', \'new\');" />';
    echo '<div class="clearboth"></div>';
    echo '</div>';
    $tab++;
    spa_paint_input(spa_text('Description'), 'forum_desc', '', false, true);
    spa_paint_checkbox(spa_text('Locked'), 'forum_status', 0);
    spa_paint_checkbox(spa_text('Disable forum RSS feed so feed will not be generated'), 'forum_private', 0);
    echo '<div class="sfoptionerror spaceabove">';
    echo '<p><b>' . sp_text('Custom Icon Ordering') . '</b></br>';
    echo sp_text('When using custom forum or topic icons and multiple conditions exist, the following precedence is used:') . '</p>';
    echo sp_text('Locked') . '<br />';
    echo sp_text('Pinned') . '<br />';
    echo sp_text('Unread') . '<br />';
    echo sp_text('Custom') . '<br />';
    echo sp_text('Theme Default') . '<br />';
    echo '</div>';
    spa_paint_select_start(spa_text('Custom forum icon'), 'forum_icon', '');
    spa_select_icon_dropdown('forum_icon', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', '', false);
    spa_paint_select_end();
    spa_paint_select_start(spa_text('Custom forum icon when new posts'), 'forum_icon_new', '');
    spa_select_icon_dropdown('forum_icon_new', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', '', false);
    spa_paint_select_end();
    spa_paint_select_start(spa_text('Custom forum icon when locked'), 'forum_icon_locked', '');
    spa_select_icon_dropdown('forum_icon_locked', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', '', false);
    spa_paint_select_end();
    spa_paint_select_start(spa_text('Custom topic icon'), 'topic_icon', '');
    spa_select_icon_dropdown('topic_icon', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', '', false);
    spa_paint_select_end();
    spa_paint_select_start(spa_text('Custom topic icon when new posts'), 'topic_icon_new', '');
    spa_select_icon_dropdown('topic_icon_new', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', '', false);
    spa_paint_select_end();
    spa_paint_select_start(spa_text('Custom topic icon when locked'), 'topic_icon_locked', '');
    spa_select_icon_dropdown('topic_icon_locked', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', '', false);
    spa_paint_select_end();
    spa_paint_select_start(spa_text('Custom topic icon when pinned'), 'topic_icon_pinned', '');
    spa_select_icon_dropdown('topic_icon_pinned', spa_text('Select Custom Icon'), SF_STORE_DIR . '/' . $spPaths['custom-icons'] . '/', '', false);
    spa_paint_select_end();
    spa_paint_input(spa_text('Custom meta keywords (SEO option must be enabled)'), 'forum_keywords', '', false, true);
    spa_paint_wide_textarea('Special forum message to be displayed above forums', 'forum_message', '');
    spa_paint_close_fieldset();
    echo '<div class="sfoptionerror spaceabove">';
    echo sprintf(sp_text('To re-order your Groups, Forums and SubForums use the %s Order Groups and Forums %s option from the Forums Menu'), '<b>', '</b>');
    echo '</div>';
    spa_paint_close_panel();
    spa_paint_tab_right_cell();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Extended Forum Options'), false);
    # As added by plugins
    do_action('sph_forum_create_forum_options');
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Add User Group Permissions'), false);
    echo '<div id="block2" class="sfhidden">';
    echo '<strong>' . spa_text('You can selectively set the permission sets for the forum below. If you want to use the default permissions for the selected group, then do not select anything') . '</strong>';
    # Permissions
    $usergroups = spa_get_usergroups_all();
    $roles = sp_get_all_roles();
    foreach ($usergroups as $usergroup) {
        echo '<input type="hidden" name="usergroup_id[]" value="' . $usergroup->usergroup_id . '" />';
        spa_paint_select_start(sp_filter_title_display($usergroup->usergroup_name), 'role[]', '');
        echo '<option value="-1">' . spa_text('Select permission set') . '</option>';
        foreach ($roles as $role) {
            echo '<option value="' . $role->role_id . '">' . sp_filter_title_display($role->role_name) . '</option>' . "\n";
        }
        spa_paint_select_end();
    }
    echo '</div>';
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_close_container();
    ?>
		<div class="sfform-submit-bar">
            <input type="submit" class="button-primary" id="saveit" name="saveit" value="<?php 
    spa_etext('Create New Forum');
    ?>
" />
		</div>
    	<?php 
    spa_paint_close_tab();
    ?>
        </div>
	</form>
	<div class="sfform-panel-spacer"></div>
<?php 
}
function spa_special_rankings_form($rankings)
{
    global $tab, $spPaths;
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	spjAjaxForm('sfaddspecialrank', 'sfreloadfr');
    });
</script>
<?php 
    spa_paint_options_init();
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=components-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=specialranks&amp;action=newrank';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" name="sfaddspecialrank" id="sfaddspecialrank">
<?php 
    echo sp_create_nonce('special-rank-new');
    spa_paint_open_tab(spa_text('Components') . ' - ' . spa_text('Special Forum Ranks'), true);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Special Forum Ranks'), true, 'special-ranks');
    spa_paint_input(spa_text('New Special Rank Name'), 'specialrank', '', false, true);
    echo '<input type="submit" class="button-primary" id="addspecialrank" name="addspecialrank" value="' . spa_text('Add Special Rank') . '" />';
    spa_paint_close_fieldset();
    do_action('sph_components_add_rank_panel');
    echo '</form>';
    spa_paint_close_panel();
    spa_paint_close_container();
    echo '<div class="sfform-panel-spacer"></div>';
    spa_paint_close_tab();
    # display rankings info
    if ($rankings) {
        spa_paint_open_nohead_tab(true);
        spa_paint_open_panel();
        ?>
		<table class="wp-list-table widefat">
			<tr>
				<th width="50%"><strong><?php 
        spa_etext('Special Rank Name');
        ?>
</strong></th>
				<th width="50%"><strong><?php 
        spa_etext('Special Rank Badge');
        ?>
</strong></th>
			</tr>
		</table>

<?php 
        foreach ($rankings as $rank) {
            ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	spjAjaxForm('sfspecialrankupdate<?php 
            echo $rank['meta_id'];
            ?>
', '');
    });
</script>
<?php 
            $ahahURL = SFHOMEURL . 'index.php?sp_ahah=components-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=specialranks&amp;action=updaterank&amp;id=' . $rank['meta_id'];
            $delsite = SFHOMEURL . 'index.php?sp_ahah=components&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;action=del_specialrank&amp;key=' . $rank['meta_id'];
            ?>
			<form action="<?php 
            echo $ahahURL;
            ?>
" method="post" id="sfspecialrankupdate<?php 
            echo $rank['meta_id'];
            ?>
" name="sfspecialrankupdate<?php 
            echo $rank['meta_id'];
            ?>
">
<?php 
            echo sp_create_nonce('special-rank-update');
            ?>
			<table class="wp-list-table widefat" id="srank<?php 
            echo $rank['meta_id'];
            ?>
">
				<tr>
					<td width="50%" style="overflow:hidden">
						<input type="text" class="wp-core-ui" size="16" tabindex="'.$tab.'" name="<?php 
            echo 'specialrankdesc[' . $rank['meta_id'] . ']';
            ?>
" value="<?php 
            echo $rank['meta_key'];
            ?>
" />
					</td>
					<td width="50%" style="overflow:hidden">
						<?php 
            spa_select_icon_dropdown('specialrankbadge[' . $rank['meta_id'] . ']', spa_text('Select Badge'), SF_STORE_DIR . '/' . $spPaths['ranks'] . '/', $rank['meta_value']['badge'], true, 105);
            ?>
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<div class="sp-half-row-left">
							<input type="submit" class="button-primary" style="vertical-align:top;" id="updatespecialrank.<?php 
            echo $rank['meta_id'];
            ?>
" name="updatespecialrank.<?php 
            echo $rank['meta_id'];
            ?>
" value="<?php 
            spa_etext('Update Rank');
            ?>
" />
							</form>
							<img style="vertical-align:top;" onclick="spjDelRow('<?php 
            echo $delsite;
            ?>
', 'srank<?php 
            echo $rank['meta_id'];
            ?>
');" src="<?php 
            echo SFCOMMONIMAGES;
            ?>
delete.png" title="<?php 
            spa_etext('Delete Special Rank');
            ?>
" alt="" />
<?php 
            $loc = '#sfrankshow-' . $rank['meta_id'];
            $site = SFHOMEURL . 'index.php?sp_ahah=components&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;action=show&amp;key=' . $rank['meta_id'];
            $gif = SFCOMMONIMAGES . 'working.gif';
            $text = esc_js(spa_text('Show/Hide Members'));
            ?>
							<input type="button" id="show<?php 
            echo $rank['meta_id'];
            ?>
" class="button-secondary" value="<?php 
            echo $text;
            ?>
" onclick="spjToggleRow('<?php 
            echo $loc;
            ?>
');spjShowMemberList('<?php 
            echo $site;
            ?>
', '<?php 
            echo $gif;
            ?>
', '<?php 
            echo $rank['meta_id'];
            ?>
');" />

						</div>

						<div class="sp-half-row-right">
<?php 
            $base = SFHOMEURL . 'index.php?sp_ahah=components-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah');
            $target = 'members-' . $rank['meta_id'];
            $image = SFADMINIMAGES;
            ?>
							<input type="button" id="remove<?php 
            echo $rank['meta_id'];
            ?>
" class="button-secondary button-jump-left" value="<?php 
            spa_etext('Remove Members');
            ?>
" onclick="jQuery('<?php 
            echo $loc;
            ?>
').show();spjLoadForm('delmembers', '<?php 
            echo $base;
            ?>
', '<?php 
            echo $target;
            ?>
', '<?php 
            echo $image;
            ?>
', '<?php 
            echo $rank['meta_id'];
            ?>
', 'open'); " />
							<input type="button" id="add<?php 
            echo $rank['meta_id'];
            ?>
" class="button-secondary button-jump-left" value="<?php 
            spa_etext('Add Members');
            ?>
" onclick="jQuery('<?php 
            echo $loc;
            ?>
').show();spjLoadForm('addmembers', '<?php 
            echo $base;
            ?>
', '<?php 
            echo $target;
            ?>
', '<?php 
            echo $image;
            ?>
', '<?php 
            echo $rank['meta_id'];
            ?>
', 'open'); " />

						</div
					</td>
				</tr>

				<tr id="sfrankshow-<?php 
            echo $rank['meta_id'];
            ?>
">
					<td colspan="2">
					<div id="members-<?php 
            echo $rank['meta_id'];
            ?>
"></div>
					</td>
				</tr>

			</table>
<?php 
        }
        spa_paint_close_panel();
        spa_paint_close_container();
        echo '<div class="sfform-panel-spacer"></div>';
        spa_paint_close_tab();
    }
}
function spa_profiles_avatars_form()
{
    global $spPaths;
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	spjAjaxForm('sfavatarsform', 'sfreloadav');

    	jQuery("#sfavataroptions").sortable({
    		placeholder: 'sortable-placeholder',
    		update: function () {
    			jQuery("input#sfavataropts").val(jQuery("#sfavataroptions").sortable('serialize'));
    		}
    	});

    	var button = jQuery('#sf-upload-button'), interval;
    	new AjaxUpload(button,{
    		action: '<?php 
    echo SFUPLOADER;
    ?>
',
    		name: 'uploadfile',
    	    data: {
    		    saveloc : '<?php 
    echo addslashes(SF_STORE_DIR . "/" . $spPaths['avatar-pool'] . '/');
    ?>
'
    	    },
    		onSubmit : function(file, ext){
                /* check for valid extension */
    			if (! (ext && /^(jpg|png|jpeg|gif|JPG|PNG|JPEG|GIF)$/.test(ext))){
    				jQuery('#sf-upload-status').html('<p class="sf-upload-status-fail"><?php 
    echo esc_js(spa_text('Only JPG, PNG or GIF files are allowed!'));
    ?>
</p>');
    				return false;
    			}
    			/* change button text, when user selects file */
    			utext = '<?php 
    echo esc_js(spa_text('Uploading'));
    ?>
';
    			button.text(utext);
    			/* If you want to allow uploading only 1 file at time, you can disable upload button */
    			this.disable();
    			/* Uploding -> Uploading. -> Uploading... */
    			interval = window.setInterval(function(){
    				var text = button.text();
    				if (text.length < 13){
    					button.text(text + '.');
    				} else {
    					button.text(utext);
    				}
    			}, 200);
    		},
    		onComplete: function(file, response){
    			jQuery('#sf-upload-status').html('');
    			button.text('<?php 
    echo esc_js(spa_text('Browse'));
    ?>
');
    			window.clearInterval(interval);
    			/* re-enable upload button */
    			this.enable();
    			/* add file to the list */
    			if (response==="success"){
                    site = "<?php 
    echo SFHOMEURL;
    ?>
index.php?sp_ahah=profiles&amp;sfnonce=<?php 
    echo wp_create_nonce('forum-ahah');
    ?>
&amp;action=delavatar&amp;file=" + file;
    				jQuery('<table style="width:100%"></table>').appendTo('#sf-avatar-pool').html('<tr><td style="width:60%;text-align:center"><img class="sfavatarpool" src="<?php 
    echo SFAVATARPOOLURL;
    ?>
/' + file + '" alt="" /></td><td class="sflabel" style="text-align:center;width:30%">' + file + '</td><td class="sflabel" style="text-align:center;width:9%"><img src="<?php 
    echo SFCOMMONIMAGES;
    ?>
' + 'delete.png' + '" title="<?php 
    echo esc_js(spa_text('Delete Avatar'));
    ?>
" alt="" onclick="spjDelRowReload(\'' + site + '\', \'sfreloadav\');" /></td></tr>');
    				jQuery('#sf-upload-status').html('<p class="sf-upload-status-success"><?php 
    echo esc_js(spa_text('Avatar Uploaded!'));
    ?>
</p>');
    			} else if (response==="invalid"){
    				jQuery('#sf-upload-status').html('<p class="sf-upload-status-fail"><?php 
    echo esc_js(spa_text('Sorry, the file has an invalid format!'));
    ?>
</p>');
    			} else if (response==="exists") {
    				jQuery('#sf-upload-status').html('<p class="sf-upload-status-fail"><?php 
    echo esc_js(spa_text('Sorry, the file already exists!'));
    ?>
</p>');
    			} else {
    				jQuery('#sf-upload-status').html('<p class="sf-upload-status-fail"><?php 
    echo esc_js(spa_text('Error uploading file!!'));
    ?>
</p>');
    			}
    		}
    	});
    });
</script>
<?php 
    $sfoptions = spa_get_avatars_data();
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=profiles-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=avatars';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfavatarsform" name="sfavatars">
	<?php 
    echo sp_create_nonce('forum-adminform_avatars');
    spa_paint_options_init();
    #== PROFILE OPTIONS Tab ============================================================
    spa_paint_open_tab(spa_text('Profiles') . ' - ' . spa_text('Avatars'));
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Avatar Options'), true, 'avatar-options');
    spa_paint_checkbox(spa_text('Display avatars'), 'sfshowavatars', $sfoptions['sfshowavatars']);
    spa_paint_input(spa_text('Maximum avatar display width (pixels)'), 'sfavatarsize', $sfoptions['sfavatarsize'], false, false);
    spa_paint_checkbox(spa_text('Enable avatar uploading'), 'sfavataruploads', $sfoptions['sfavataruploads']);
    spa_paint_input(spa_text('Maximum avatar upload file size (bytes)'), 'sfavatarfilesize', $sfoptions['sfavatarfilesize'], false, false);
    spa_paint_checkbox(spa_text('Auo resize avatar uploads'), 'sfavatarresize', $sfoptions['sfavatarresize']);
    spa_paint_input(spa_text('Uploaded avatar resize quality (if resizing)'), 'sfavatarresizequality', $sfoptions['sfavatarresizequality'], false, false);
    spa_paint_checkbox(spa_text('Enable avatar pool selection'), 'sfavatarpool', $sfoptions['sfavatarpool']);
    spa_paint_checkbox(spa_text('Enable remote avatars'), 'sfavatarremote', $sfoptions['sfavatarremote']);
    $values = array(spa_text('G - Suitable for all'), spa_text('PG- Suitable for 13 and above'), spa_text('R - Suitable for 17 and above'), spa_text('X - Suitable for all adults'));
    spa_paint_radiogroup(spa_text('Gravatar max rating'), 'sfgmaxrating', $values, $sfoptions['sfgmaxrating'], false, true);
    spa_paint_checkbox(spa_text('Replace WP avatar with SP avatar'), 'sfavatarreplace', $sfoptions['sfavatarreplace']);
    echo '<br /><div class="sfoptionerror">';
    spa_etext('Warning: If you want to replace WP avatars with SP avatars, make sure you dont have WP avatars in your avatar priorities (have it below SP Default Avatars) or you will have a circular reference');
    echo '</div><br />';
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    do_action('sph_profiles_avatar_left_panel');
    spa_paint_tab_right_cell();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Avatar Priorities'), true, 'avatar-priorities');
    spa_etext('Select the avatar dislay priority order by dragging and dropping the buttons below.  The top of the list is the highest priority order.  When an avatar is found for the current priority, it is used.  If none is found, the next priority is checked and so on.  An SP Default Avatar will always be found. Any avatar after the SP Default Avatar is essentially ignored');
    echo '<div>';
    echo '<ul id="sfavataroptions" class="menu">';
    $list = array(0 => spa_text('Gravatars'), 1 => spa_text('WP Avatars'), 2 => spa_text('Uploaded Avatar'), 3 => spa_text('SP Default Avatars'), 4 => spa_text('Avatar Pool'), 5 => spa_text('Remote Avatar'));
    if ($sfoptions['sfavatarpriority']) {
        foreach ($sfoptions['sfavatarpriority'] as $priority) {
            echo '<li id="aitem_' . $priority . '" class="menu-item menu-item-depth-0"><span class="item-name">' . $list[$priority] . '</span></li>';
        }
    }
    echo '</ul>';
    echo '<input type="text" class="inline_edit" size="70" id="sfavataropts" name="sfavataropts" />';
    echo '</div>';
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_close_container();
    spa_paint_close_tab();
    spa_paint_open_nohead_tab(false);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Avatar Pool Upload'), true, 'avatar-pool-upload');
    $loc = SF_STORE_DIR . '/' . $spPaths['avatar-pool'] . '/';
    spa_paint_file(spa_text('Select avatar to upload'), 'newavatar', false, true, $loc);
    echo '<table><tr>';
    echo '<td class="sflabel"><small>';
    spa_etext('Please be advised that Admin uploaded avatars for the avatar pool are NOT subject to the user uploaded avatar size limits.  So use caution when picking avatars for your avatar pool');
    echo '</small></td>';
    echo '</tr></table>';
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    spa_paint_tab_right_cell();
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Avatar Pool'), true, 'avatar-pool');
    spa_paint_avatar_pool();
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    do_action('sph_profiles_avatar_right_panel');
    spa_paint_close_container();
    ?>
    	<div class="sfform-submit-bar">
    	   <input type="submit" class="button-primary" id="saveit" name="saveit" value="<?php 
    spa_etext('Update Avatar Options');
    ?>
" />
    	</div>
<?php 
    spa_paint_close_tab();
    ?>
	</form>
<?php 
}