/**
 * change fieldset link process callback
 */
function jcf_ajax_change_fieldset()
{
    $f_id = $_POST['fieldset_id'];
    $fieldset = jcf_fieldsets_get($f_id);
    ob_start();
    ?>
		<div class="jcf_edit_fieldset">
			<h3 class="header"><?php 
    echo __('Edit Fieldset:', JCF_TEXTDOMAIN) . ' ' . $fieldset['title'];
    ?>
</h3>
			<div class="jcf_inner_content">
				<form action="#" method="post" id="jcform_edit_fieldset">
					<fieldset>
						<input type="hidden" name="fieldset_id" value="<?php 
    echo $fieldset['id'];
    ?>
" />
						
						<p><label for="jcf_edit_fieldset_title"><?php 
    _e('Title:', JCF_TEXTDOMAIN);
    ?>
</label> <input class="widefat" id="jcf_edit_fieldset_title" type="text" value="<?php 
    echo esc_attr($fieldset['title']);
    ?>
" /></p>
						
						<div class="field-control-actions">
							<div class="alignleft">
								<a href="#remove" class="field-control-remove"><?php 
    _e('Delete', JCF_TEXTDOMAIN);
    ?>
</a> |
								<a href="#close" class="field-control-close"><?php 
    _e('Close', JCF_TEXTDOMAIN);
    ?>
</a>
							</div>
							<div class="alignright">
								<?php 
    echo print_loader_img();
    ?>
								<input type="submit" value="<?php 
    _e('Save', JCF_TEXTDOMAIN);
    ?>
" class="button-primary" name="savefield">
							</div>
							<br class="clear"/>
						</div>
					</fieldset>
				</form>
			</div>
		</div>
		<?php 
    $html = ob_get_clean();
    jcf_ajax_reposnse($html, 'html');
}
    echo $field['id_base'];
    ?>
"><?php 
    echo $field['title'];
    ?>
</option>
							<?php 
}
?>
						</select>
						<input type="submit" name="add_field" value="<?php 
_e('Add', JCF_TEXTDOMAIN);
?>
" />
						<?php 
echo print_loader_img();
?>
					</fieldset>
				</form>
			</div>
		</th>
	</tr></tfoot>
	<tbody id="the-collection-list-<?php 
echo $collection_id;
?>
" class="ui-sortable">
		<?php 
if (!empty($collection['fields']) && is_array($collection['fields'])) {
    ?>
			<?php 
    foreach ($collection['fields'] as $field_id => $field) {
    /**
     *	function to show add/edit form to edit field settings
     *	call $this->form inside
     */
    public function do_form()
    {
        ob_start();
        $op = $this->id_base == $this->id ? __('Add', JCF_TEXTDOMAIN) : __('Edit', JCF_TEXTDOMAIN);
        ?>
		<div class="jcf_edit_field">
			<h3 class="header"><?php 
        echo $op . ' ' . $this->title;
        ?>
</h3>
			<div class="jcf_inner_content">
				<form action="#" method="post" id="<?php 
        echo $this->is_collection_field() ? 'jcform_edit_collection_field' : 'jcform_edit_field';
        ?>
">
					<fieldset>
						<input type="hidden" name="field_id" value="<?php 
        echo $this->id;
        ?>
" />
						<input type="hidden" name="field_number" value="<?php 
        echo $this->number;
        ?>
" />
						<input type="hidden" name="field_id_base" value="<?php 
        echo $this->id_base;
        ?>
" />
						<input type="hidden" name="fieldset_id" value="<?php 
        echo $this->fieldset_id;
        ?>
" />
						<?php 
        if ($this->is_collection_field()) {
            ?>
							<input type="hidden" name="collection_id" value="<?php 
            echo $this->collection_id;
            ?>
" />
						<?php 
        }
        $this->form($this->instance);
        // need to add slug field too
        $slug = esc_attr($this->slug);
        ?>
						<p>
							<label for="<?php 
        echo $this->get_field_id('slug');
        ?>
"><?php 
        _e('Slug:', JCF_TEXTDOMAIN);
        ?>
</label>
							<input class="widefat" id="<?php 
        echo $this->get_field_id('slug');
        ?>
" name="<?php 
        echo $this->get_field_name('slug');
        ?>
" type="text" value="<?php 
        echo $slug;
        ?>
" />
							<br/><small><?php 
        _e('Machine name, will be used for postmeta field name. (should start from underscore)', JCF_TEXTDOMAIN);
        ?>
</small>
						</p>
						<?php 
        // enabled field
        if ($this->is_new) {
            $this->instance['enabled'] = 1;
        }
        ?>
						<p>
							<label for="<?php 
        echo $this->get_field_id('enabled');
        ?>
">
								<input class="checkbox" type="checkbox" 
										id="<?php 
        echo $this->get_field_id('enabled');
        ?>
"
										name="<?php 
        echo $this->get_field_name('enabled');
        ?>
"
										value="1" <?php 
        checked(true, @$this->instance['enabled']);
        ?>
 />
								<?php 
        _e('Enabled', JCF_TEXTDOMAIN);
        ?>
</label>
						</p>
						<?php 
        if ($this->is_collection_field()) {
            ?>
							<?php 
            if ($this->id_base == 'inputtext') {
                ?>
								<p>
									<label for="<?php 
                echo $this->get_field_id('group_title');
                ?>
">
										<input class="checkbox" type="checkbox" 
											id="<?php 
                echo $this->get_field_id('group_title');
                ?>
"
											name="<?php 
                echo $this->get_field_name('group_title');
                ?>
"
											value="1" <?php 
                checked(true, @$this->instance['group_title']);
                ?>
 />
										<?php 
                _e('Use this field as collection item title?', JCF_TEXTDOMAIN);
                ?>
									</label>
								</p>
						
							<?php 
            }
            ?>
							<p>
								<label for="<?php 
            echo $this->get_field_id('field_width');
            ?>
"><?php 
            _e('Select Field Width', JCF_TEXTDOMAIN);
            ?>
</label>
								<select class="widefat" 
										id="<?php 
            echo $this->get_field_id('field_width');
            ?>
"
										name="<?php 
            echo $this->get_field_name('field_width');
            ?>
">
									<?php 
            foreach (Just_Field_Collection::$field_width as $key => $width) {
                ?>
										<option value="<?php 
                echo $key;
                ?>
"<?php 
                echo @$this->instance['field_width'] == $key ? ' selected' : '';
                ?>
>
											<?php 
                echo $width;
                ?>
</option>
									<?php 
            }
            ?>
								</select> 
									
							</p>
						<?php 
        }
        ?>
						<div class="field-control-actions">
							<div class="alignleft">
								<?php 
        if ($op != __('Add', JCF_TEXTDOMAIN)) {
            ?>
								<a href="#remove" class="field-control-remove"><?php 
            _e('Delete', JCF_TEXTDOMAIN);
            ?>
</a> |
								<?php 
        }
        ?>
								<a href="#close" class="field-control-close"><?php 
        _e('Close', JCF_TEXTDOMAIN);
        ?>
</a>
							</div>
							<div class="alignright">
								<?php 
        echo print_loader_img();
        ?>
								<input type="submit" value="<?php 
        _e('Save', JCF_TEXTDOMAIN);
        ?>
" class="button-primary" name="savefield">
							</div>
							<br class="clear"/>
						</div>
					</fieldset>
				</form>
			</div>
		</div>
		<?php 
        $html = ob_get_clean();
        return $html;
    }
    /**
     *	function to show add/edit form to edit field settings
     *	call $this->form inside
     */
    function do_form()
    {
        ob_start();
        $op = $this->id_base == $this->id ? __('Add', JCF_TEXTDOMAIN) : __('Edit', JCF_TEXTDOMAIN);
        ?>
		<div class="jcf_edit_field">
			<h3 class="header"><?php 
        echo $op . ' ' . $this->title;
        ?>
</h3>
			<div class="jcf_inner_content">
				<form action="#" method="post" id="jcform_edit_field">
					<fieldset>
						<input type="hidden" name="field_id" value="<?php 
        echo $this->id;
        ?>
" />
						<input type="hidden" name="field_number" value="<?php 
        echo $this->number;
        ?>
" />
						<input type="hidden" name="field_id_base" value="<?php 
        echo $this->id_base;
        ?>
" />
						<input type="hidden" name="fieldset_id" value="<?php 
        echo $this->fieldset_id;
        ?>
" />
						<?php 
        $this->form($this->instance);
        // need to add slug field too
        $slug = esc_attr($this->slug);
        ?>
						<p>
							<label for="<?php 
        echo $this->get_field_id('slug');
        ?>
"><?php 
        _e('Slug:', JCF_TEXTDOMAIN);
        ?>
</label>
							<input class="widefat" id="<?php 
        echo $this->get_field_id('slug');
        ?>
" name="<?php 
        echo $this->get_field_name('slug');
        ?>
" type="text" value="<?php 
        echo $slug;
        ?>
" />
							<br/><small><?php 
        _e('Machine name, will be used for postmeta field name.', JCF_TEXTDOMAIN);
        ?>
</small>
						</p>
						<?php 
        // enabled field
        if ($this->is_new) {
            $this->instance['enabled'] = 1;
        }
        ?>
						<p>
							<label for="<?php 
        echo $this->get_field_id('enabled');
        ?>
">
								<input class="checkbox" type="checkbox" 
										id="<?php 
        echo $this->get_field_id('enabled');
        ?>
"
										name="<?php 
        echo $this->get_field_name('enabled');
        ?>
"
										value="1" <?php 
        checked(true, @$this->instance['enabled']);
        ?>
 />
								<?php 
        _e('Enabled', JCF_TEXTDOMAIN);
        ?>
</label>
						</p>
						
						<div class="field-control-actions">
							<div class="alignleft">
								<?php 
        if ($op != __('Add', JCF_TEXTDOMAIN)) {
            ?>
								<a href="#remove" class="field-control-remove"><?php 
            _e('Delete', JCF_TEXTDOMAIN);
            ?>
</a> |
								<?php 
        }
        ?>
								<a href="#close" class="field-control-close"><?php 
        _e('Close', JCF_TEXTDOMAIN);
        ?>
</a>
							</div>
							<div class="alignright">
								<?php 
        echo print_loader_img();
        ?>
								<input type="submit" value="<?php 
        _e('Save', JCF_TEXTDOMAIN);
        ?>
" class="button-primary" name="savefield">
							</div>
							<br class="clear"/>
						</div>
					</fieldset>
				</form>
			</div>
		</div>
		<?php 
        $html = ob_get_clean();
        return $html;
    }