
function insertPage(){
	// dateTime のページを追加する
	var yymmdd = document.getElementById("addAnyPage").value;
	var hour = document.getElementById("_hour").value;
	if (hour < 10) hour = "0" + hour;
	var min = document.getElementById("_min").value;
	if (min < 10) min = "0" + min;
	var dateTime = yymmdd + " " + hour + ":" + min + ":00";
    
    //alert("insertPage->"+dateTime); return; //##

    closeFloatPanel();
    addPage(dateTime);
}

function openAddPagePanel(datetime){
    // ページ追加パネルを開く
    var w = 350;
	var x = 10;
	var y = 40;

    // アクティブなページの位置にパネルを表示
    var elm = document.getElementById(currentDate() + ".page");
    if (elm){
        var pos = getPosition(elm); // dom.js
        y = pos.y + 70;
        x = pos.x + 10;
    }
    
    var panel = new FloatPanel("_floatPanel", x, y, w, "ページ追加");
    var base = panel.contents;
    base.parentNode.style.backgroundColor = "#ffe";
    var elm = newDIV(base, "");
    elm.style.borderRadius = "10px";

	// 年月日
    var div = newDIV(elm, "");
    div.style.paddingTop = "5px";
    div.style.paddingRight = "10px";
    div.style.textAlign = "right";
	var yy = datetime.substr(0, 4) * 1;
	var mm = datetime.substr(5, 2) * 1;
	var dd = datetime.substr(8, 2) * 1;
	var label = nengou(yy); // 西暦に相当する年号
    newDatePopUp(div, "addAnyPage", label, yy, mm, dd, false);
    
    var sp = newSPAN(div, "");
    sp.style.paddingLeft = "10px";
	// 時
	var anArray = makeArray(0, 24);
	var hour = datetime.substr(11, 2);
    var pu = newPopupMenu(sp, "_hour", anArray, hour);
	var tx = newTEXT(sp, ":");
	// 分
	var anArray = makeArray(0, 60);
	var min = datetime.substr(14, 2);
    var pu = newPopupMenu(sp, "_min", anArray, min);
    
    // FOOTER
    var div = newDIV(elm, "/clearfix");
    div.style.paddingTop = "5px";
    var dv = newDIV(div, "/right-side");
    dv.style.paddingRight = "5px";
    dv.style.paddingBottom = "10px";
    dv.style.width = "100%";
    var sp = newSPAN(dv, "");
    sp.innerHTML = " のページをカルテに ";
    sp.style.fontSize = "10pt";
    sp.style.position = "relative";
    sp.style.paddingRight = "5px";
    sp.style.top = "5px";
	var bt = newDIV(dv, "/fixButton");
    bt.innerHTML = "挿入";
	bt.setAttribute("onclick", "insertPage()");
}

function makeDateTimePopup(elm, datetime){
    // 年月日自分パップアップ・メニューを生成
    setAddWithReservedDate(elm);
    
    var div = elmFor("datePopArea");
    div.innerHTML = "";
    
    // 年月日ポップアップ・メニュー
    var date = (elm.checked) ? datetime : todayAndTime();
	var yy = date.substr(0, 4) * 1;
	var mm = date.substr(5, 2) * 1;
	var dd = date.substr(8, 2) * 1;
	var label = nengou(yy); // 西暦に相当する年号
    var sp = newSPAN(div, "");
    newDatePopUp(sp, "addAnyPage", label, yy, mm, dd, false);
    
    // 時分ポップアップ・メニュー
    var sp = newSPAN(div, "");
    sp.style.paddingLeft = "10px";
	// 時
	var anArray = makeArray(0, 24);
	var hour = date.substr(11, 2);
    var pu = newPopupMenu(sp, "_hour", anArray, hour);
	var tx = newTEXT(sp, ":");
	// 分
	var anArray = makeArray(0, 60);
	var min = date.substr(14, 2);
    var pu = newPopupMenu(sp, "_min", anArray, min);
}

function closeAddReservedPagePanel(){
    closeFloatPanel();
    setIsReserved(false);
    setAddPageDateTime(null);
    
    get_pages(owner(), patientId(), openPages);
}
function openAddReservedPagePanel(patientId, datetime){
    // 予約ページ追加パネルを開く
    var w = 350;
	var x = 10;
	var y = 200;
    
    // アクティブなページの位置にパネルを表示
    var elm = document.getElementById(currentDate() + ".page");
    if (elm){
        var pos = getPosition(elm); // dom.js
        y = pos.y + 80;
        x = pos.x + 10;
    }
    
    var panel = new FloatPanel("_floatPanel", x, y, w, "ページ追加");
    if (!panel) return;
    var base = panel.contents;
    base.parentNode.style.backgroundColor = "#ffe";
    var elm = newDIV(base, "");
    elm.style.borderRadius = "10px";
    
    // チェック・ボックス
    var div = newDIV(elm, "");
    div.style.fontSize = "10pt";
    div.style.paddingRight = "9px";
    div.style.textAlign = "right";
    var cb = newCHECKBOX(div, "", "予約日時でページ追加", addWithReservedDate());
    cb.setAttribute("onchange", "makeDateTimePopup(this,'" + datetime + "')");
    
	// 年月日
    var div = newDIV(elm, "datePopArea");
    div.style.paddingTop = "5px";
    div.style.paddingRight = "10px";
    div.style.textAlign = "right";
    makeDateTimePopup(cb, datetime);

    // FOOTER
    var div = newDIV(elm, "/clearfix");
    div.style.paddingTop = "5px";
    var dv = newDIV(div, "/right-side");
    dv.style.paddingRight = "5px";
    dv.style.paddingBottom = "10px";
    dv.style.width = "100%";
    var sp = newSPAN(dv, "");
    sp.innerHTML = " のページをカルテに挿入 ";
    sp.style.fontSize = "10pt";
    sp.style.position = "relative";
    sp.style.paddingRight = "5px";
    sp.style.top = "5px";
    
	var bt = newDIV(dv, "/whiteButton");
    bt.innerHTML = "しない";
	bt.setAttribute("onclick", "closeAddReservedPagePanel()");
    
	var bt = newDIV(dv, "/fixButton");
    bt.innerHTML = "する";
	bt.setAttribute("onclick", "insertPage()");

    _debug("== openAddReservedPagePanel end"); //##
}


