/**
 * コメント制御用スクリプト
 * Extに依存
 */
function setCommentForm(vid)
{
    if(isLogin==false){
        Ext.MessageBox.show({
            title: "コメントの登録にはログインが必要です",
            msg: "コメントを登録できるのはClipCastのメンバーだけです。ログインを行うかメンバー登録を行ってください。",
            icon: Ext.MessageBox.ERROR,
            buttons: Ext.MessageBox.OK,
            width: 320
        });
        return;
    }

    //VIDEOIDがなければ終了
    if(!vid) return;

    //Form Panelを作成
    var form = new Ext.FormPanel({
        url: baseUrl+'/index.php/pc/comment_process',
        method: 'POST',
        defaultType: 'hidden',
        bodyStyle: 'padding: .3em',
        border: false,
        layout: 'fit',
        items:[
        {
            name: 'id',
            value: vid
        },
        {
            name: 'target_action',
            value: 'add'
        },
        {
            name: 'ret_type',
            value: 'ajax'
        },
        {
            xtype: 'textarea',
            fieldLabel: '登録するコメント',
            name: 'sc_comment',
            allowBlank: false,
            height: 100,
            width:400 
        }
        /*
        {
            xtype: 'checkbox',
            fieldLabel: 'メール送信(オプション)',
            name: 'track_comment',
            checked: true,
            boxLabel: 'このビデオにコメントが登録されたらメールで通知'
        }
        */
        ],
        buttons:[
        {
            text: 'キャンセル',
            handler: function()
            {
                win.close();
            }
        },
        {
            text: 'コメントを登録',
            handler: function()
            {
                if(form.getForm().isValid()==false) return;
                form.getForm().submit({ 
                    success: function()
                    {
                        reloadComment(vid);
                        win.close();
                    },
                    failure: function()
                    {
                        Ext.MessageBox.show({
                            title: "コメントの登録に失敗しました",
                            msg: "コメントの登録が完了しませんでした。<br />申し訳ありませんが、もう一度時間を空けてからご登録ください。",
                            icon: Ext.MessageBox.ERROR,
                            buttons: Ext.MessageBox.OK,
                            width: 320
                        });
                    },
                    waitTitle: 'コメントを登録しています',
                    waitMsg: '少々お待ちください'
                });
            }
        }
        ]
    });

    var win = new Ext.Window({
        title: 'ビデオにコメントを登録',
        autoShow: true,
        items:[form],
        resizable: false,
        modal: true,
        width: 420
    });
    win.show();

}



function reloadComment(vid)
{
    new Ajax.Updater(
        'commentPart',
        baseUrl+'/index.php/pc/video_comment',
        {
            parameters: 'id='+vid
        }
    );
}
