$(function(){
    hb_ostatus_bind();
});
function hb_init_ostatus()
{
    $('#os-order-id').val('');
    $('#os-msg').val('');
    $('#os-order-id').val('');
    $('.os-form .os-msg').hide(); 
    $('.os-form .os-response').hide().html(''); 
    $('.os-form .os-msg-response').hide().html('');
    $('.os-form .os-wait').hide().html('');
    $('.os-form .os-init').show(); 
    $('.os-form .os-msg-input').show(); 
    $('.os-form').center();
    $('.os-form').jqmShow();
    return false;
}

function hb_ostatus_bind()
{
    $("#home_check_status").click(hb_init_ostatus);
    $('#os-snd-status').click(handle_ostatus_status);
    $('#os-snd-msg').click(handle_ostatus_msg);
    $('.os-form').jqm({modal:true,overlay:0});
}

function handle_ostatus_status(e)
{
    var order_id = $('#os-order-id').val();
    $('#os-msg').val('');
    $('.os-form .os-msg').hide();
    $('.os-form .os-response').html('checking ...'); 
    $('.os-form .os-response').show();
    $.post('/ajax/statuscheck', 
    {'order_id':order_id}, 
    function(data) { 
        if( data.success ) { 
            $('.os-form .os-msg').show();
            $('#os-msg-order-id').val(order_id);
        }
        $('.os-form .os-response').html(data.msg);
    }, 'json');
    return false;
}

function handle_ostatus_msg(e)
{
    var msg = $('#os-msg').val(); 
    var order_id = $('#os-msg-order-id').val();
    var data = {'msg':msg,'order_id':order_id};
    os_show_wait();
    $.post('/ajax/statuscheck/message', data, 
    function(resp) { 
        os_hide_wait();
        $('.os-form .os-msg-response').html(resp.msg).show();
        if(resp.success) { 
            $('.os-form .os-msg-input').hide();
        }
    }, 'json');
    return false;
}

function os_show_wait()
{
    $('.os-form .os-wait').show();
}
function os_hide_wait()
{
    $('.os-form .os-wait').hide();
}
