/* ==============================================================

	SystemHouseFukuchiyama 
	http://www.shfweb.com

*/

YAHOO.namespace("shf");


/* ===================================================================================================================================================
    評価の送信用ダイアログ

*/
function critical_dialog_init() {

    // Define various event handlers for Dialog
    var handleSubmit = function() {
        this.submit();
    };
    var handleCancel = function() {
        this.cancel();
    };

    var handleSuccess = function(o) {
        // Connect to our data source and load the data
        var frmobj = document.getElementById('frmcritical');
        YAHOO.util.Connect.setForm(frmobj); 
        YAHOO.shf.conn = YAHOO.util.Connect.asyncRequest("GET", "idea.ajax.php?type=10", messageshowcallback);
    };

    // Instantiate the Dialog
    YAHOO.shf.crtdialog = new YAHOO.widget.Dialog("dialog_crt", { 
                                                        width : "42em",
                                                        fixedcenter : true,
                                                        zindex:6, 
                                                        modal:true, 
                                                        visible : false, 
                                                        buttons : [ { text:"追加", handler:handleSubmit, isDefault:true },
                                                                { text:"キャンセル", handler:handleCancel } ]
                                                       } );

    // Validate the entries in the form to require that both first and last name are entered
    YAHOO.shf.crtdialog.validate = function() {
        var data = this.getData();
        if (data.Review == "") {
            alert("評価を選択してください");
            return false;
        } else {
            YAHOO.shf.loading.show();
            return true;
        }
    };

    // Wire up the success and failure handlers
    YAHOO.shf.crtdialog.callback = { success: handleSuccess };

    // Render the Dialog
    YAHOO.shf.crtdialog.render();

    YAHOO.util.Event.addListener("critical", "click", YAHOO.shf.crtdialog.show, YAHOO.shf.crtdialog, true);
}

/* ===================================================================================================================================================
    評価の変更送信用ダイアログ

*/
function critical_dialog_change_init() {

    var ajxtype = 11;

    // Define various event handlers for Dialog
    var handleDelete = function() {
        ajxtype = 12;
        this.submit();
    };
    var handleChange = function() {
        ajxtype = 11;
        this.submit();
    };
    var handleCancel = function() {
        this.cancel();
    };

    var handleSuccess = function(o) {
        // Connect to our data source and load the data
        var frmobj = document.getElementById('frmcritical');
        YAHOO.util.Connect.setForm(frmobj); 
//        YAHOO.util.Connect.setHeader("Content-Type","text/html; charset=EUC-JP");
        YAHOO.shf.conn = YAHOO.util.Connect.asyncRequest("GET", "idea.ajax.php?type="+ajxtype, messageshowcallback);
    };

    // Instantiate the Dialog
    YAHOO.shf.crtdialog = new YAHOO.widget.Dialog("dialog_crt", { 
                                                        width : "42em",
                                                        fixedcenter : true,
                                                        zindex:6, 
                                                        modal:true, 
                                                        visible : false, 
                                                        buttons : [ { text:"削除", handler:handleDelete },
                                                                    { text:"変更", handler:handleChange, isDefault:true },
                                                                    { text:"キャンセル", handler:handleCancel } ]
                                                       } );

    // Validate the entries in the form to require that both first and last name are entered
    YAHOO.shf.crtdialog.validate = function() {
        var data = this.getData();
        if (data.Review == "") {
            alert("評価を選択してください");
            return false;
        } else {
            YAHOO.shf.loading.show();
            return true;
        }
    };

    // Wire up the success and failure handlers
    YAHOO.shf.crtdialog.callback = { success: handleSuccess };

    // Render the Dialog
    YAHOO.shf.crtdialog.render();

    YAHOO.util.Event.addListener("critical", "click", YAHOO.shf.crtdialog.show, YAHOO.shf.crtdialog, true);
}

/* ===================================================================================================================================================
    評価の送信用ダイアログ（非ログイン時）

*/
function critical_dialog_login_init() {

    // Define various event handlers for Dialog
    var handleSubmit = function() {
        this.submit();
    };
    var handleCancel = function() {
        this.cancel();
    };

    var handleSuccess = function(o) {
//        document.getElementById("frmcritical").action = "./login.php";
        document.getElementById("frmcritical").submit();
    };

    // Instantiate the Dialog
    YAHOO.shf.crtdialog = new YAHOO.widget.Dialog("dialog_crt", { 
                                                        width : "42em",
                                                        fixedcenter : true,
                                                        zindex:6, 
                                                        modal:true, 
                                                        visible : false, 
                                                        buttons : [ { text:"ログイン", handler:handleSubmit, isDefault:true },
                                                                  { text:"キャンセル", handler:handleCancel } ]
                                                       } );

    // Validate the entries in the form to require that both first and last name are entered
    // Wire up the success and failure handlers
    YAHOO.shf.crtdialog.callback = { success: handleSuccess };

    // Render the Dialog
    YAHOO.shf.crtdialog.render();

    YAHOO.util.Event.addListener("critical", "click", YAHOO.shf.crtdialog.show, YAHOO.shf.crtdialog, true);
}

/* ===================================================================================================================================================
    評価の送信用ダイアログ（自分が投稿したアイデアの時）

*/
function critical_dialog_self_init() {

    // Define various event handlers for Dialog
    var handleCancel = function() {
        this.cancel();
    };

    // Instantiate the Dialog
    YAHOO.shf.crtdialog = new YAHOO.widget.Dialog("dialog_crt", { 
                                                        width : "42em",
                                                        fixedcenter : true,
                                                        zindex:6, 
                                                        modal:true, 
                                                        visible : false, 
                                                        buttons : [ { text:"ＯＫ", handler:handleCancel } ]
                                                       } );

    // Render the Dialog
    YAHOO.shf.crtdialog.render();

    YAHOO.util.Event.addListener("critical", "click", YAHOO.shf.crtdialog.show, YAHOO.shf.crtdialog, true);
}




/* ===================================================================================================================================================
    寄付ポイントの送信用ダイアログ

	$point_max    アイデアに対してベットできる最大ポイント
    $point_have   ユーザーが保持しているポイント

*/
function donation_dialog_init() {

    // Define various event handlers for Dialog
    var handleSubmit = function() {
        this.submit();
    };
    var handleCancel = function() {
        this.cancel();
    };
    var handleSuccess = function(o) {
        var point = document.getElementById("point").value;

        // Connect to our data source and load the data
        var frmobj = document.getElementById('frmdonation');
        YAHOO.util.Connect.setForm(frmobj);
        YAHOO.shf.conn = YAHOO.util.Connect.asyncRequest("GET", "idea.ajax.php?type=20", messageshowcallback);
    };

    // Instantiate the Dialog
    YAHOO.shf.dntdialog = new YAHOO.widget.Dialog("dialog_dnt", { 
                                                        width : "30em",
                                                        fixedcenter : true,
                                                        zindex:6, 
                                                        modal:true, 
                                                        visible : false, 
                                                        buttons : [ { text:"ＯＫ", handler:handleSubmit, isDefault:true },
                                                                { text:"キャンセル", handler:handleCancel } ]
                                                       } );

    // Validate the entries in the form to require that both first and last name are entered
    YAHOO.shf.dntdialog.validate = function() {
        var data = this.getData();
        point = data.point;

        han = "0123456789.,-+";
        zen = "０１２３４５６７８９．，−＋";
        str = "";
        for (i=0; i<point.length; i++)
        {
            c = point.charAt(i);
            n = zen.indexOf(c,0);
            if (n >= 0) c = han.charAt(n);
            str += c;
        }
        point = str;

        if (isNaN(point)) {
            alert("ポイントを入力してください");
            return false;
        }

        if (point == 0) {
            alert("0以上の数値を入力してください");
            return false;
        }

        if (point > $point_have) {
            alert("自分が保持しているポイントより大きな値が入力されています。");
            return false;
        }

/*
        if (point > $point_max) {
            point = $point_max;
            document.getElementById("point").value = $point_max;
            if (point == 0) {
                alert("既に開発着手までのポイントを超えているため、ベットできません。");
                return false;
            }
        }
*/

        YAHOO.shf.loading.show();
        return true;
    };

    // Wire up the success and failure handlers
    YAHOO.shf.dntdialog.callback = { success: handleSuccess };

    // Render the Dialog
    YAHOO.shf.dntdialog.render();

    YAHOO.util.Event.addListener("donation", "click", YAHOO.shf.dntdialog.show, YAHOO.shf.dntdialog, true);
}


/* ===================================================================================================================================================
    寄付ポイントの送信用ダイアログ（非ログイン）

*/
function donation_dialog_login_init() {

    // Define various event handlers for Dialog
    var handleSubmit = function() {
        this.submit();
    };
    var handleCancel = function() {
        this.cancel();
    };
    var handleSuccess = function(o) {
//        document.getElementById("frmdonation").action = "./login.php";
        document.getElementById("frmdonation").submit();
    };

    // Instantiate the Dialog
    var dialog = new YAHOO.widget.Dialog("dialog_dnt", { 
                                                        width : "30em",
                                                        fixedcenter : true,
                                                        zindex:6, 
                                                        modal:true, 
                                                        visible : false, 
                                                        buttons : [ { text:"ログイン", handler:handleSubmit, isDefault:true },
                                                                { text:"キャンセル", handler:handleCancel } ]
                                                       } );

    // Wire up the success and failure handlers
    dialog.callback = { success: handleSuccess };

    // Render the Dialog
    dialog.render();

    YAHOO.util.Event.addListener("donation", "click", dialog.show, dialog, true);
}


