<?php if (!defined('IN_CONTEXT')) die('access violation error!'); ?>
<script type="text/javascript" language="javascript">
<!--
function on_buynow_success(response) {
    var o_result = _eval_json(response);
    if (!o_result) {
        return on_failure(response);
    }
    
    var stat = document.getElementById("buynow_stat");
    if (o_result.result == "ERROR") {
        document.forms["prepayform"].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_buynow_failure(response) {
    document.forms["prepayform"].reset();
    
    document.getElementById("buynow_stat").innerHTML = "<?php _e('Request failed!'); ?>";
    return false;
}
//-->
</script>


<div class="art_list">
	<div class="art_list_title"><?php _e('Confirm Order Payment'); ?></div>
	<span id="buynow_stat" class="status" style="display:none;"></span>
	
<?php
$prepay_form = new Form('index.php?_m=mod_order', 'prepayform', 'check_prepay_info');
$prepay_form->p_open('mod_order', 'buynow', '_ajax');
?>
	 <?php echo Html::input('hidden', 'o_id', $curr_order->id); ?>
	 	<div class="order_1"><?php _e('Total Payment'); ?></div><div class="order_2">￥<?php echo $curr_order->total_amount; ?></div><div class="blankbar1"></div>
	 	<div class="order_1"><?php _e('Account Balance'); ?></div><div class="order_2">￥<?php echo $curr_userext->balance; ?></div><div class="blankbar1"></div>
		<?php echo Html::input('submit', 'submit', __('Confirm & Pay Now'), 'class="submit_order orange"'); ?>
</div>



<?php
$prepay_form->close();
$running_msg = __('Sending payment information...');
$custom_js = <<<JS
$("#buynow_stat").css({"display":"block"});
$("#buynow_stat").html("$running_msg");
_ajax_submit(thisForm, on_buynow_success, on_buynow_failure);
return false;

JS;
$prepay_form->addCustValidationJs($custom_js);
$prepay_form->writeValidateJs();
?>
</div>
