/* ==============================================================

	SystemHouseFukuchiyama 
	http://www.shfweb.com

*/

YAHOO.namespace("shf");


/* ===================================================================================================================================================
    評価の送信用ダイアログ

*/
function donation_init() {

    // Define various event handlers for Dialog
    var handleSubmit = function() {
        this.submit();
    };
    var handleCancel = function() {
        this.cancel();
    };
    var handleSuccess = function(o) {
        var frmobj = document.getElementById('frmdonation');
        YAHOO.util.Connect.setForm(frmobj); 
        YAHOO.shf.conn = YAHOO.util.Connect.asyncRequest("GET", "userinfo.ajax.php?type=10", messageshowcallback);
    };

    // Instantiate the Dialog
    YAHOO.shf.dialog = new YAHOO.widget.Dialog("dialog_dnt", { 
                                                            width : "30em",
                                                            fixedcenter : true,
                                                            visible : false, 
                                                            constraintoviewport : true,
                                                            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.dialog.validate = function() {

        var data = this.getData();

        //リクエスト日のチェック
        day = data.requestdate;
        if (!isDate(day)) {
            alert("リクエスト日を入力してください");
            return false;
        }

        //ポイント
        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 ((!point) || isNaN(point)) {
            alert("ポイントを入力してください");
            return false;
        }

        YAHOO.shf.loading.show();
        return true;
    };

    // Wire up the success and failure handlers
    YAHOO.shf.dialog.callback = { success: handleSuccess };

    // Render the Dialog
    YAHOO.shf.dialog.render();

    YAHOO.util.Event.addListener("donation", "click", YAHOO.shf.dialog.show, YAHOO.shf.dialog, true);
}

/* ===================================================================================================================================================
    評価を削除するための処理

*/
function donation_delete(delid) {
    YAHOO.shf.loading.show();

//    var frmobj = document.getElementById('frmdonation-del');
//    YAHOO.util.Connect.setForm(frmobj);
    YAHOO.shf.conn = YAHOO.util.Connect.asyncRequest("GET", "userinfo.ajax.php?type=11&id="+delid, messageshowcallback);
}

function mySelectHandler(type,args,obj) {
    var selected = args[0];
    var selDate = this.toDate(selected[0]);
    caledit = YAHOO.util.Dom.get("caledit");
    if (caledit != null) {
        caledit.value = selDate.getFullYear() + "/" + (selDate.getMonth() + 1) + "/" + selDate.getDate();
    }
};

function calendar_init() {
    var cal1 = new YAHOO.widget.Calendar("cal1","cal1Container");

    cal1.selectEvent.subscribe(mySelectHandler, cal1, true);

    cal1.render();
}


function userinfo_init() {
    donation_init();
    calendar_init();

//    YAHOO.util.Event.addListener("donation-del", "click", donation_delete);
//    YAHOO.util.Event.addListener("donation-del", "click", YAHOO.shf.loading.show, YAHOO.shf.loading, true);
}

