
var _tags;
function setTagArray(array){
    _tags = array;
}
function tagArray(){
    // tag: section.fieldName の配列を返す
    return _tags;
}

/////////////////////////
///// カルテからの継承値 ///

function noa(){
    // NOA を返す
    return (window.opener) ? window.opener : null;
}

function patientId(){
    return (noa()) ? noa().patientId() : "";
}

function patientKanjiName(){
    return (noa()) ? noa().patientKanjiName() : "";
}

function currentDate(){
    return (noa()) ? noa().currentDate() : "";
}

function owner(){
    return (noa()) ? noa().owner() : "";
}

///// カルテからの継承値 ///
/////////////////////////


///////////////////////////
/// Ajax による処理 /////////

function gotTagArray(){
    var array = ["NameSection.patientKanjiName","AddressSection.address"];
    setTagArray(array);
    showBody();
}
function getTagArray(){
    // 一括入力で使うタグの配列をサーバへリクエスト
    gotTagArray();
}

/// Ajax による処理 /////////
///////////////////////////

function showBody(){
    // 入力部分を生成
    var elm = document.getElementById("bodyArea");
    elm.innerHTML = "";
    var tbl = newTABLE(elm, "simpleTable");

    var tags = tagArray();
    for (num in tags){
        var tag = tags[num];
		var cell = noa().cellForTag(tag);
        var tr = newTR(tbl, "", "");
        var td = newTD(tr, "", cell.label);
        var td = newTD(tr, "", "");
        var fd = newFIELD(td, tag, "", 100, noa().valueForTag(tag));
    }
}

function help(){
	var win = window.open("./help.html","Help"
						  ,"width=450,height=700,scrollbars=yes,resizable=yes");
	win.focus();
}

function initBatchInput(){
    // 初期化
    var elm = document.getElementById("base");
    elm.innerHTML = "";
    var div = newDIV(elm, ""); // control area
    var table = newTABLE(div, "baseTable");
    
    ///// HEADER ////////////////////////
    var tr = newTR(table, "", "");
    var td = newTD(tr, "titleBar", "");
    var tbl = newTABLE(td, "simpleTable");
    // TITLE
    var tr = newTR(tbl, "", "");
    var td = newTD(tr, "", "一括入力");
    td.style.width = "80px";
    var patientInfo = "";
    if (patientId())
        patientInfo = patientId()+" : "+patientKanjiName()+"　"+currentDate();
    var td = newTD(tr, "", patientInfo);
    // HELP
    var td = newTD(tr, "", "");
    td.style.width = "20px";
    td.style.textAlign = "right";
    var im = newIMAGE(td, "", "./Help.png", "?");
    im.style.height = "18px";
    im.style.verticalAlign = "top";
    im.setAttribute("onclick", "help()");
    
    ///// BODY //////////////////////////
    var tr = newTR(table, "bodyArea", "");
    
    ///// FOOTER ////////////////////////
    var tr = newTR(table, "", "");
    var td = newTD(tr, "titleBar", "");
    var tbl = newTABLE(td, "simpleTable");
    // VERSION
    var tr = newTR(tbl, "", "");
    var td = newTD(tr, "", version());
    // PREFERENCE
    var td = newTD(tr, "", "");
    td.style.width = "20px";
    var im = newIMAGE(td, "", "./hammer.png", "P");
    im.style.height = "15px";
    im.style.verticalAlign = "top";
    im.setAttribute("onclick", "openPreference()");
    
    getTagArray();
}

function version(){
    return "Ver.1106807";
}