<?php
if (!defined('IN_CONTEXT')) die('access violation error!');
?>
<script type="text/javascript" language="javascript">
<!--
function on_success(response) {
    var o_result = _eval_json(response);
    if (!o_result) {
        return on_failure(response);
    }
    
    var stat = document.getElementById("adminqqfrm_stat");
    if (o_result.result == "ERROR") {
        document.forms["qqform"].reset();
        
        stat.innerHTML = o_result.errmsg;
        return false;
    } else if (o_result.result == "OK") {
	    stat.innerHTML = "<?php _e('OK, redirecting...'); ?>";
	    window.location.href = o_result.forward;
    } else {
        return on_failure(response);
    }
}

function on_failure(response) {
    document.forms["qqform"].reset();
    
    document.getElementById("adminqqfrm_stat").innerHTML = "<?php _e('Request failed!'); ?>";
    return false;
}
//-->
</script>
<div class="content_title">
	<h3><?php _e($content_title); ?></h3>
</div>
<div class="space"></div>
<div class="content_toolbar">
	<a href="<?php echo Html::uriquery('mod_qq', 'admin_list'); ?>" title=""><?php _e('Back'); ?></a>
</div>
<div class="space"></div>
<div class="status_bar">
	<span id="adminqqfrm_stat" class="status" style="display:none;"></span>
</div>
<div class="space"></div>
<?php
$qq_form = new Form('index.php', 'qqform', 'check_qq_info');
$qq_form->p_open('mod_qq', $next_action, '_ajax');
?>
<table id="qqform_table" class="form_table" cellspacing="1">
    <tfoot>
        <tr>
            <td colspan="2">
            <?php
            echo Html::input('reset', 'reset', __('Reset'));
            echo Html::input('button', 'cancel', __('Cancel'), 'onclick="window.history.go(-1);"');
            echo Html::input('submit', 'submit', __('Save'));
            echo Html::input('hidden', 'qq[id]', $curr_qq->id);
            ?>
            </td>
        </tr>
    </tfoot>
    <tbody>
	     <tr>
            <td class="label"><?php _e('Category'); ?></td>
            <td class="entry">
            <?php
            echo Html::select('qq[category]', 
                $select_categories, 
                $curr_qq->category);
            ?>
            </td>
        </tr>
        <tr>
            <td class="label"><?php _e('Account'); ?></td>
            <td class="entry">
            <?php
            echo Html::input('text', 'qq[account]', $curr_qq->account, 
                '', $qq_form, 'RequiredTextbox', 
                __('Please input account!'));
            ?>
            </td>
        </tr>
        <tr>
            <td class="label"></td>
            <td class="entry">
            <?php
            echo Html::input('checkbox', 'qq[published]', '1', 
                Toolkit::switchText($curr_qq->published, 
                    array('0' => '', '1' => 'checked="checked"')));
            ?>
            &nbsp;<?php _e('Publish'); ?>
            </td>
        </tr>
    </tbody>
</table>
<?php
$qq_form->close();
$running_msg = __('Saving QQ account...');
$custom_js = <<<JS
$("#adminqqfrm_stat").css({"display":"block"});
$("#adminqqfrm_stat").html("$running_msg");
_ajax_submit(thisForm, on_success, on_failure);
return false;

JS;
$qq_form->addCustValidationJs($custom_js);
$qq_form->writeValidateJs();
?>
