// #################################################################################
// #    File Name   : jpread.js
// #    Project     : JPREAD
// #    System      : On-Line Japanese Reading Material
// #    Purpose     : Generate Dynamic Table of Contents
// #    Function    : JPREAD Control
// #    Medel       : his programe is based on the Document Object Model (DOM)
// #    Language    : JavaScript (Client Side Scripting. ver: 5.x)
// #    Include     : jpreadtoc.js
// #    Date Issued : 2002/03/27(Wed)-16:34:21
// #    Base URL    : http://www.all.co.nz/
// #    Location    : js/
// #    Usage       :
// #    Browsers    : IE5.x and above
// #    Requirement : <BODY ID='oBody'>
// #    Restriction : None
// #    Author      : Hiroto Sekine (Able LL Systems Dpt. CHC, NZL)
// #    Copyright   : (C) 2002 Southern Cross Virtual Co., Ltd. All Rights Reserved.
// #    Contact     : info@all.co.nz
// #    Tab Stop    : 4 (Suitable TAB stop size to view this Source Code)
// # ===============================================================================
// #    ** Revision **
// # Date   Description                                             Sign      Mark
// # ------+-------------------------------------------------------+---------+------
// #
// #################################################################################
@set @DEBUG = 0 // Program Debug Flag: ON(=1)/OFF(=0)
// ###########################################################################
// #                            << NOTICE >>                                 #
// # THIS PROGRAM CODE BELONGS TO SOUTHERN CROSS VIRTUAL CO., LTD. IT IS     #
// # CONSIDERED A TRADE SECRET AND IS NOT TO BE DIVULUGED OR USED BY PARTIES #
// # WHO HAVE NOT RECEIVED WRITTEN AUTHORIZATION FROM THE OWNER.             #
// # ----------------------------------------------------------------------- #
// #                            << 通  知 >>                                 #
// # 本プログラムはSOUTHERN CROSS VIRTUAL CO., LTD.の財産です。本プログラム  #
// # はトレード・シークレットとみなされ、当該権利者の書面による許可なくして、#
// # 漏洩または使用を禁じます。                                              #
// ###########################################################################

var F = document.all;
var DOCURL = document.URL;
var saveStyle;
var saveFgColor;
var saveBgColor;
var saveBC;
var saveFC;

var DCP         = '{89820200-ECBD-11CF-8B85-00AA005B4383}';
var CID         = 'componentid';
var tVer        = 5;
var OLIST1      = "oTOC1";  // OL Tag 1
var OLIST2      = "oTOC2";  // OL Tag 2
var OLIST3      = "oTOC3";  // OL Tag 3
var OLIST4      = "oTOC4";  // OL Tag 4

var BOOK_TITLE  = "Self-Teaching";
var REPEAT      =  7;       // Once a week study
var COPERIOD    = 14;       // cookie expire period:days
var NEXT_PAGE   =  1;       // Move to Next Page
var PREV_PAGE   = -1;       // Move to Previous Page
var KEEP_PAGE   =  0;       // Keep Current Page (reload)
var HOME_PAGE   =  9;       // Move to Home Page
var HOME_URL    = "index.htm";  // Relative URL Address

var UPDATE_PIC  = "updated.gif";
var NEW_PIC     = "new2.gif";
var CONST_PIC   = "i13.gif";
var UPDATE_STR  = " Updated";
var NEW_STR     = " Released";
var CONST_STR   = " Construction";
var MAX_EXPIRY  = "90";

var LESSON_PREFIX   = "Japanese Lesson ";
var APPENDIX_PREFIX = "Appendix ";
var GRAMMAR_PREFIX  = "Grammar ";
var GENERAL_PREFIX  = "General ";
var giWidth = 0;    // Window Width size for "showCaps"

function GetScriptEngineInfo(){
    var s = '';
    s += ScriptEngine() + ': ';
    s += ScriptEngineMajorVersion() + '.';
    s += ScriptEngineMinorVersion() + '.';
    s += ScriptEngineBuildVersion();
    return(s);
}
function ReDirect(sURL){
    location.href = sURL;
}
function initStatus(){
    var x, strMsg;

    with(oBody){
        var bMSvmAvailable = isComponentInstalled( DCP, CID );
        var sMSvmVersion   = getComponentVersion( DCP, CID );

        if (connectionType != "offline"){
            x = F["CBTN"];
            if (x != null){
                with(x){
                    title   = "Back to Able Home";
                    value   = "Able Home";
                }
            }
            x = F["SCLS"];
            if (x != null){
                x.innerHTML = "<input type='button' value='Able Home' style='color:red;' />: Back to Able Home page.(Top page only)";
            }
            x = F["WBTN"];  // download all source files
            if (x != null){
                x.style.display = "";
            }
            x = F["HDWN"];
            if (x != null){
                x.style.display = "";
            }
        }
    }
    if (sMSvmVersion != ''){
        sMSvmVersion = 'IE' + ' Version ' + sMSvmVersion;
    }
    var sNeg = (bMSvmAvailable) ? '' : 'NOT ';
    if (!bMSvmAvailable) sMSvmVersion = 'IE6.x Browser';
    var sIEver = sMSvmVersion + ' is ' + sNeg + 'installed.';
    if (!bMSvmAvailable){
        window.alert(sIEver);
        with(oBody){
            addComponentRequest( DCP, CID );
            doComponentRequest();
        }
    } else {
        sIEver = 'IE: ' + oBody.getComponentVersion( DCP, CID );
    }
    var sMver = GetScriptEngineInfo();
    if (sMver.substr(9, 1) < tVer){
        strMsg  = 'Your current Script Engine is "' + sMver + '".\n';
        strMsg += 'This HTML requires "JScript Version ' + tVer + '" or above.\n';
        strMsg += 'Please contact with this page author.';
        window.alert(strMsg);
    }
    if (! window.print){
        x = F[ 'PRN' ];
        if (x != null) x.disabled = true;
    }
    with(oBody.currentStyle){
        saveBgColor = backgroundColor;
        saveFgColor = color;
    }
    with(oBody){
        giWidth = width;
        if ((width < 800) || (height < 600)){
            strMsg  = 'Your current screen resolution is ' + width + ' * ' + height + '.\n';
            strMsg += 'We recommend 800 * 600 and above resolution for the best view.';
            window.alert(strMsg);
        }
        if (colorDepth < 16){
            strMsg  = 'Your current screen color is ' + Math.pow(2, colorDepth) + ' colors.\n';
            strMsg += 'We recommend 65536 and above colors for the best view.';
            window.alert(strMsg);
        }
        strMsg = 'Screen: ' + width + '*' + height + ', Color: ' + colorDepth + ', ' + sMver + ', ' + sIEver;
        window.status = strMsg;
    }
    CreateSelOptions(DOCURL);
    repLastModifiedDate();
    fnUpdateProductInfo("THEVER","MDATE2");
//    initTitles( "DEF", "DEF" );   move to HTML source code in <BODY> tag
}
function CreateSelOptions(base){
    var oSelTag = F[ "SelJump" ];
    if (oSelTag == null) return;
    var urlStr, TheList, oHeadTitle, i, headStr, sp;
    var oTocList;
    var iTocLen;
    var idx = 1;
    var ln = 0;
    var Pre_Fix = "";
    var homeFlag = (DOCURL.lastIndexOf(HOME_URL) != -1) ? true : false;
    if (homeFlag){
        oTocList = oListTOC[1].List;
        iTocLen  = oListTOC[1].Len;
        ln = 1;
    } else {
        sp = base.lastIndexOf("/"); // find last path delimiter ("/")
        sp ++;
        for (i=0; i<oListLen; i++){
            if (base.indexOf(oListTOC[i].List[0].URL.substr(0, 5), sp) != -1){
                oTocList = oListTOC[i].List;
                iTocLen  = oListTOC[i].Len;
                ln = i;
                break;
            }
        }
    }

    oOpt = document.createElement( "OPTION" );
    oOpt.innerText = "Select a title Where to Go..";
    oOpt.value = "0";   // dummy
    oSelTag.appendChild( oOpt );

    for (var i=0; i<iTocLen; i++){
        if (!oTocList[i].Cnd) continue;
        TheList = oTocList[i];
        urlStr = TheList.UrlBody();
        if ((DOCURL.lastIndexOf(urlStr) != -1) && !homeFlag){
            oHeadTitle = F[ "STUDENT" ];
            if (oHeadTitle){
                headStr = "";
                switch(ln){
                    case 0:
                        Pre_Fix = GENERAL_PREFIX;
                        headStr = Pre_Fix + "(" + idx + ")" + TheList.Cap;
                        break;

                    case 1:
                        Pre_Fix = LESSON_PREFIX;
                        headStr = Pre_Fix + "(" + idx + ") - " + TheList.Cap;
                        break;

                    case 2:
                        Pre_Fix = GRAMMAR_PREFIX;
                        var RN = new makeRomanNum();
                        headStr = Pre_Fix + RN[idx-1] + " for L" + TheList.Cap;
                        break;

                    case 3:
                        Pre_Fix = APPENDIX_PREFIX;
                        headStr = Pre_Fix + String.fromCharCode(idx+64) + ": " + TheList.Cap;
                        break;
                }
//                oHeadTitle.innerText = headStr;   // Mod by SKN23 2005/01/03(Mon)-12:28:45
                oHeadTitle.innerHTML = headStr;
            }
            continue;   // skip current page
        }
        oOpt = document.createElement( "OPTION" );
        if (ln == 1){
        oOpt.innerText = "(" + itoStr(2, (i+1)) +")" + TheList.SelOpt() + ((TheList.Cap.length > CAPS_LEN) ? "・・" : "");
        } else {
        oOpt.innerText = TheList.SelOpt() + ((TheList.Cap.length > CAPS_LEN) ? "・・" : "");
        }
        oOpt.value     = TheList.URL;
        oSelTag.appendChild( oOpt );
        idx ++;
    }
    if (homeFlag){
        var x;
        x = F[ "IMG_NEW" ]; if (x != null && x.src != NEW_PIC   ) x.src = NEW_PIC;
        x = F[ "IMG_UPD" ]; if (x != null && x.src != UPDATE_PIC) x.src = UPDATE_PIC;
        x = F[ "IMG_CON" ]; if (x != null && x.src != CONST_PIC ) x.src = CONST_PIC;
    }
}
function toggle(){
    var x = F[ 'SCORE' ];
    var y = F[ 'VIEW' ];
    if ((x != null) && (y != null)){
        with(x.style){
            display = (display == 'none') ? '' : 'none';
            y.value = (display == 'none') ? 'View Score' : 'Hide Score';
        }
        window.scrollBy(0, 290);
    }
}
function beforePrint(){
    var x = F[ 'BTN' ];
    var y = F[ 'SCORE' ];
    if ((x != null) && (y != null)){
        x.style.display = 'none';
        with(y.style){
            saveStyle = display;
            if (display == 'none') display = '';
        }
    } else if (x != null){
        x.style.display = 'none';
    }
    with(oBody.currentStyle){
        saveBC = backgroundColor;
        saveFC = color;
    }
    with(oBody.style){
        backgroundColor = 'white';
        color = 'black';
    }
    var section, ans;
    ans = window.confirm('Click [OK] to print entire page. Click [CANCEL] to select print section.');
    if (!ans){
        var coll = F.tags( 'legend' );
        for (var i=0; i<coll.length; i++){
            x = F[ 'LEG' + i.toString() ];
            if (x != null){
                y = F[ 'FLD' + i.toString() ];
                section = x.innerText;
                ans = window.confirm('Click [OK] to print ' + section + '. Click [CANCEL] to skip.');
                if (!ans && (y != null)) y.style.display = 'none';
            }
        }
        ans = window.confirm('Click [OK] to print Footer Section. Click [CANCEL] to skip.');
        if (!ans){
            x = F[ 'FOOT' ];
            if (x != null) x.style.display = 'none';
        }
    }
    hideText();
}
function afterPrint(){
    var x = F[ 'BTN' ];
    var y = F[ 'SCORE' ];
    if ((x != null) && (y != null)){
        x.style.display = '';
        y.style.display = saveStyle;
    } else if (x != null){
        x.style.display = '';
    }
    with(oBody.style){
        backgroundColor = saveBC;
        color = saveFC;
    }
    var coll = F.tags( 'legend' );
    for (var i=0; i<coll.length; i++){
        x = F[ 'LEG' + i.toString() ];
        if (x != null){
            y = F[ 'FLD' + i.toString() ];
            if ((y != null) && (y.style.display == 'none')) y.style.display = '';
        }
    }
    x = F[ 'FOOT' ];
    if ((x != null) && (x.style.display == 'none')) x.style.display = '';
    hideColor(saveBC);
}
function swap(){
    with(oBody.currentStyle){
        var temp1 = backgroundColor;
        var temp2 = color;
    }
    with(oBody.runtimeStyle){
        backgroundColor = temp2;
        color           = temp1;
    }
    hideColor(temp2);
}
function rubySwitch(flag){
    var i, coll, len;
    coll = F.tags( 'RT' );
    len = coll.length;
    if (len > 0){
        for (i=0; i<len; i++){
            with(coll.item(i).runtimeStyle){
                display = (display == 'none') ? '' : 'none';
            }
        }
        if (flag){
            var e = event.srcElement;
            with(e){
                if (value == 'Ruby On'){
                    value = 'Ruby Off';
                    title = 'Hide Kanji Ruby';
                } else {
                    value = 'Ruby On';
                    title = 'Show Kanji Ruby';
                }
            }
        }
    } else {
        var x;
        x = F[ 'RBTN'    ]; if (x) x.style.display = 'none';
        x = F[ 'RubyOn'  ]; if (x) x.style.display = 'none';
        x = F[ 'RubyOff' ]; if (x) x.style.display = 'none';
    }
}
function reset(){
    var e = event.srcElement;
    if (e.value == 'W/B'){
        var fgColor = 'black';
        var bgColor = 'white';
        e.value = 'Resume';
        e.title = 'Resume orginal color';
    } else {
        var fgColor = saveFgColor;
        var bgColor = saveBgColor;
        e.value = 'W/B';
        e.title = 'Reset screen color';
    }
    with(oBody.runtimeStyle){
        backgroundColor = bgColor;
        color = fgColor;
    }
    hideColor(bgColor);
}
function showCaps(){
    var bwLanguage = window.navigator.browserLanguage;
    var sTabSize = (giWidth < 1024) ? '\t\t= ' : '\t= ';
    var sTempStr;
    with(oBody){
    sTempStr = 'width\t\t= ' + width + '\n' +
        'height\t\t= ' + height   + '\n' +
        'availWidth' + sTabSize + availWidth + '\n' +
        'availHeight\t= ' + availHeight    + '\n' +
        'bufferDepth\t= ' + bufferDepth + '\n' +
        'colorDepth' + sTabSize + colorDepth + '\n' +
        'connectionType\t= ' + connectionType + '\n' +
        'cookieEnabled\t= ' + cookieEnabled     + '\n' +
        'cpuClass\t\t= ' + cpuClass + '\n' +
        'platform\t\t= ' + platform + '\n' +
        'javaEnabled\t= ' + javaEnabled + '\n' +
        'systemLanguage\t= ' + systemLanguage + '\n' +
        'userLanguage\t= ' + userLanguage + '\n' +
        'browserLanguage\t= ' + bwLanguage ;
    }
    window.alert(sTempStr);
}
function chgBtnCaps( caps ){
    var x = F[ "INF9" ];
    var strMsg = "";
    strMsg += "下記の「" + caps + "」ボタンにマウス・カーソルを重ねる"
    if (x != null) x.innerText = strMsg;
}
function itoStr(w, n){
    var i;
    var r = n.toString();
    var d = w - r.length;
    for (i=0; i<d; i++){
        r = "0" + r;
    }
    return(r);
}
function getFirstDueDate(){
    var d = new Date();
    var StudentName, ToDay, cStudentDate;
    var cStudentName = getCookieValue( coSTUDENT_NAME );
    if (cStudentName != null){
        StudentName = getStudentName(cStudentName, 1);
        ToDay = getStudentStartDate(StudentName);
        cStudentDate = getCookieValue( coSTUDENT_DATE );
        if (ToDay < cStudentDate){
            ToDay = (cStudentDate != null) ? cStudentDate : getToday();
        }
    } else {
        StudentName = window.prompt("Please specify your name:", "Guest Student");
        var coExpire = new Date(d.getTime() + (1000 * 60 * 60 * 24 * COPERIOD));
        setCookieValue( coSTUDENT_NAME, StudentName, coExpire );
        ToDay = getToday();
    }
    return(ToDay);
}
function getTargetURL(base, dir){
    // base: Current URL: string (format: qyymmdd)
    // dir: Direction(1:Next, 0:Current, -1;Previous, 9: Home
    var urlStr, i, k, LinkTo, sp;
    var oTocList;
    var iTocLen;

    if (dir == HOME_PAGE){
        location.href = HOME_URL;
        return;
    }
    var homeFlag = (DOCURL.lastIndexOf(HOME_URL) != -1) ? true : false;
    if (homeFlag){
        oTocList = oListTOC[1].List;
        iTocLen  = oListTOC[1].Len;
    } else {
        sp = base.lastIndexOf("/"); // find last path delimiter ("/")
        sp ++;
        for (i=0; i<oListLen; i++){
            if (base.indexOf(oListTOC[i].List[0].URL.substr(0, 5), sp) != -1){
                oTocList = oListTOC[i].List;
                iTocLen  = oListTOC[i].Len;
                break;
            }
        }
    }

    if (base.lastIndexOf(HOME_URL) != -1){
        for (i=0; i<iTocLen; i++){
            if (!oTocList[i].Cnd) continue;
            location.href = oTocList[i].URL;
            return;
        }
        return;
    }
    for (i=0; i<iTocLen; i++){
        urlStr = oTocList[i].UrlBody();     // extract "qyymmdd"
        if (base.lastIndexOf(urlStr) != -1){    // matched
            if ((dir == PREV_PAGE) && (i > 0)){
                k = 1;
                LinkTo = oTocList[i-k].URL;
                while(!oTocList[i-k].Cnd){
                    if (i == k){
                        LinkTo = HOME_URL;
                        break;
                    }
                    k++;
                    LinkTo = oTocList[i-k].URL;
                }
                location.href = LinkTo;
            } else if ((dir == NEXT_PAGE) && (i < (iTocLen-1))){
                k = 1;
                LinkTo = oTocList[i+k].URL;
                while(!oTocList[i+k].Cnd){
                    if ((i+k) == (iTocLen-1)){
                        LinkTo = HOME_URL;
                        break;
                    }
                    k++;
                    LinkTo = oTocList[i+k].URL;
                }
                location.href = LinkTo;
            } else if (dir == KEEP_PAGE){
                location.href = oTocList[i].URL;
            } else {    // default: Home Pge
                location.href = HOME_URL;
            }
            return;
        }
    }
    location.href = HOME_URL;
}
function setItemCaps(){
    var e = event.srcElement;
    gsCapStr = e.innerText;
}
function createTocTables(){	// Modified: 2006/09/20(Wed)-01:34:22 because Added OTOC0 in jpreadtoc.js
    createTocTable(0, oListTOC[0].ID, false);   // General Information
    createTocTable(1, oListTOC[1].ID, true );   // Main Lesson Contents
    createTocTable(2, oListTOC[2].ID, false);   // Grammar Contents
    createTocTable(3, oListTOC[3].ID, false);   // Appendices Contents
    createTocTable(5, oListTOC[5].ID, false);   // Key Lesson Indexes

    var iTocLen  = oListTOC[1].Len;

//  initSchedule(Date, Day, Student, SP, EP, Mode(1,2, 8 or 9), NameType)
//  Default Parm("", 7, "", 1, iTocLen, 1, 1)
    initSchedule("", 7, "", 1, iTocLen, 1, 1);
    imgDateCheck();
}
function createTocTable(nt, ids, fSpan){
    var oOL = F[ ids ];
    if (oOL == null) return;
    var oList, oHref, oImg, oCell;
    if (fSpan) var oSpan;
    var StatImg, StatStr, CapStr;
    var idx = 1;
    var oTocList = oListTOC[nt].List;
    var iTocLen  = oListTOC[nt].Len;

    if (ids == OLIST2){ // Main Lesson Contents
        var dueDate = getFirstDueDate();
        LessonMax = iTocLen + 1;
        @if ( @DEBUG == 1 )
        alert("LessonMax has modified as: " + (LessonMax-1) + "\nFirst Due Date is " + dueDate);
        @end
    }

    for (var i=0; i<iTocLen; i++){
        oCell = oTocList[i];
        if (! oCell.Cnd) continue;

        with(document){
            oList = createElement( "LI"   );
            if (fSpan){
            oSpan = createElement( "SPAN" );
            }
            oHref = createElement( "A"    );
            oImg  = createElement( "IMG"  );
        }
        if (fSpan){
            with(oSpan){
                id        = "L" + itoStr(2, idx);
                innerHTML = "[Due By " + dueDate.substr(2, 8) + "]: Lesson " + itoStr(2, i+1) + " ";
//                          "[Due By " + strDueDD[i].substr(2,8) + "]: Lesson " + itoStr(2, i) + " ";
            }
        }
        if (ids == OLIST3){
            var RN = new makeRomanNum();
            CapStr = GRAMMAR_PREFIX + RN[i] + " for Lesson " + oCell.Cap;
        } else {
            CapStr = oCell.Cap;
        }
        with(oHref){
            href      = oCell.URL;
            innerHTML = CapStr;
//            id = "LX" + iToStr(3, i+1);   // 001 - 999
            onclick   = setItemCaps;
        }
        switch(oCell.Mods()){
            case "R":
                StatImg = NEW_PIC;
                StatStr = NEW_STR;
                break;

            case "U":
                StatImg = UPDATE_PIC;
                StatStr = UPDATE_STR;
                break;

            case "N":
                StatImg = CONST_PIC;
                StatStr = CONST_STR;
                break;
        }
        with(oImg){
            style.display = "none"; // default
            className  = "14";
            id     = oCell.UrlBody();
            border = "0";
            src    = StatImg;
            title  = oCell.DT() + StatStr;
        }

        with(oList){            // LI   tag
            if (fSpan){
            appendChild(oSpan); // SPAN tag
            }
            appendChild(oHref); // A    tag
            appendChild(oImg);  // IMG  tag
        }

        oOL.appendChild(oList); // LI tag

        if (ids == OLIST2) dueDate = getDueDate(dueDate, REPEAT);   // get next due date
        if (fSpan) idx ++;
    }   // for end

//  var oP = document.createElement( "P" );
//  with(oP){
//      style.textAlign = "center";
//      innerHTML = "−出典：<a href='http://www.tv-asahi.co.jp/davinci/' target='_blank'>Predictions</a> of <a href='navigatorhr.htm' target='_blank'>Da Vinci</a> (TV. Asahi : Japan)−";
//  }
//  oOL.appendChild(oP);    // P tag
}
// ******************************************************************
// *    Global Variables Definition
// ******************************************************************

var CURRENT_DTIME_PTN = "MM/DD/YYYY hh:mm:ss";
var STANDARD_DATE_ID  = "MDATE";
var ThisVersion       = "3.50"; // 2004/03/11(Thu)-12:00:21
var CPATN   = null; // Current Patern Format String
var NPATN   = null; // New Pattern Format String
var iCurLen = 0;    // Current Pattern Format String Length
var iNewLen = 0;    // New Pattern Format String Length

if (typeof(F) == "undefined"){
    var F = document.all;
}

// ******************************************************************
// *    Data Format Constructor
// ******************************************************************

function fmPack( pos, chr, len ){
    this.Pos    = pos;  // Start Offset: based 0;-1:No data
    this.Chr    = chr;  // Format Qualifier; Default: ""
    this.Len    = len;  // Symbol Length; Default: 0 length
}
function makePatnArray( n ){
    // n: Pattern String Length (max)
    for (var i=0; i<n; i++){
        this[i] = new fmPack( -1, "", 0 );
    }
    this.length = n;
}

function getQualifyLen( cSYM ){
    for (i=0; i<iCurLen; i++){
        if (cSYM == CPATN[i].Chr) return(CPATN[i].Len);
        if (CPATN[i].Chr == "") break;
    }
    return(-1);
}

function getQualifyPos( cSYM ){
    for (i=0; i<iCurLen; i++){
        if (cSYM == CPATN[i].Chr) return(CPATN[i].Pos);
        if (CPATN[i].Chr == "") break;
    }
    return(-1);
}
function getQualifyChr( cSYM ){
    for (i=0; i<iCurLen; i++){
        if (cSYM == CPATN[i].Chr) return(i);
        if (CPATN[i].Chr == "") break;
    }
    return(-1);
}
if (typeof(makeDayOfWeek2) == "undefined"){
    function wdPack2(jday, eday){
        this.Jday = jday;   // JP
        this.Eday = eday;   // EN
    }
    function makeDayOfWeek2(){
        var i = 0;
        this[i++] = new wdPack2( "日", "Sun" ) ; // 0
        this[i++] = new wdPack2( "月", "Mon" ) ; // 1
        this[i++] = new wdPack2( "火", "Tue" ) ; // 2
        this[i++] = new wdPack2( "水", "Wed" ) ; // 3
        this[i++] = new wdPack2( "木", "Thu" ) ; // 4
        this[i++] = new wdPack2( "金", "Fri" ) ; // 5
        this[i++] = new wdPack2( "土", "Sat" ) ; // 6
        this.length = i;
    }
}

function fnFormatData( sNewPatn, sCurPatn, sData ){

    // sNewPatn: New output data format (string)    eg. "YYYY/MM/DD(ddd)-hh:mm:ss"
    // sCurPatn: Current input data format (string) eg. "MM/DD/YYYY hh:mm:ss"
    // sDate: Input raw data (string)               eg. 02/26/2003-10:08:30 ---> 2003/02/26(ddd)-10:08:30
    // sDate is expected as single byte data

    /* *---------------------------------------------------------------
    << Pre-Defined Symbols as place holder >>
        Y: Year  Symbol (eg. YYYY stands for 2003, YY is 03)
        M: Month Symbol (eg. MM stands for 10, 02,... so on)
        D: Day   Symbol (eg. DD stands for 06, 28,... so on)
        h: Hour  Symbol (eg. hh stands for 10, 05,... so on)
        m: Min.  Symbol (eg. mm stands for 01, 20,... so on)
        s: Sec.  Symbol (eg. ss stands for 10, 59,... so on)
    ----------------------------------------------------------------* */
    var i, j, k;    // General use purpose
    var aChr;       // Current character
    var pChr;       // Previous character
    var sYEAR;
    var s1 = "";
    var s2 = "";
    var s3 = "";
    var s  = "";

    iNewLen = sNewPatn.length;
    iCurLen = sCurPatn.length;
    CPATN   = new makePatnArray(iCurLen);
    NPATN   = new makePatnArray(iNewLen);

    for (pChr = null, i=0, j=0, k=0; i<iCurLen; i++){
        aChr = sCurPatn.substr(i,1);
        if (aChr == pChr){
            CPATN[k].Len ++;
            continue;
        }
        CPATN[j].Pos = i;
        CPATN[j].Chr = aChr;
        CPATN[j].Len ++;    // 1
        k = j++;
        pChr = aChr;
    }

    for (i=0; i<iCurLen; i++){
        if (CPATN[i].Pos == -1) break;
        s1 += CPATN[i].Chr + " ";
        s2 += CPATN[i].Pos + " ";
        s3 += CPATN[i].Len + " ";
    }

    for (pChr = null, i=0, j=0, k=0; i<iNewLen; i++){
        aChr = sNewPatn.substr(i,1);
        if (aChr == pChr){
            NPATN[k].Len ++;
            continue;
        }
        NPATN[j].Pos = i;
        NPATN[j].Chr = aChr;
        NPATN[j].Len ++;    // 1
        k = j++;
        pChr = aChr;
    }

    s1 = "";
    s2 = "";
    s3 = "";
    for (i=0; i<iNewLen; i++){
        if (NPATN[i].Pos == -1) break;
        s1 += NPATN[i].Chr + " ";
        s2 += NPATN[i].Pos + " ";
        s3 += NPATN[i].Len + " ";
    }

    for (i=0; i<iNewLen; i++){
        if ((nc = NPATN[i].Chr) == "") break;
        cp = getQualifyChr(nc);
        if ((cp != -1) && (CPATN[cp].Len == NPATN[i].Len)){ // nc is found in sData
            s += sData.substr(CPATN[cp].Pos, CPATN[cp].Len);
        } else if ((cp != -1) && ((CPATN[cp].Chr == 'Y') && (CPATN[cp].Len != NPATN[i].Len))){
            if (NPATN[i].Len == 4){
                sYEAR = sData.substr(CPATN[cp].Pos, CPATN[cp].Len);
                if (sYEAR > "50"){
                    sYEAR = "19" + sYEAR;   // 19XX
                } else {
                    sYEAR = "20" + sYEAR;   // 20XX
                }
            } else {
                sYEAR = sData.substr(CPATN[cp].Pos+(CPATN[cp].Len-NPATN[i].Len), NPATN[i].Len);
            }
            s += sYEAR;
        } else if (cp == -1){
            if (NPATN[i].Len == 1){ // should be a delimiter such as "/"
                s += ((nc == 'S') ? ' ' : nc);
            } else if ((nc == "d") && (NPATN[i].Len >= 3)){ // ddd ===> day of week
                var d = new Date();
                pY = getQualifyPos('Y'); lY = getQualifyLen('Y');
                pM = getQualifyPos('M'); lM = getQualifyLen('M');
                pD = getQualifyPos('D'); lD = getQualifyLen('D');
                sYEAR = (pY >= 0) ? sData.substr(pY, lY) : d.getFullYear();
                if (sYEAR.length == 2){
                    if (sYEAR > 50){
                        sYEAR = "19" + sYEAR;   // 19XX
                    } else {
                        sYEAR = "20" + sYEAR;   // 20XX
                    }
                }
                var iYEAR  = eval(sYEAR);
                var iMONTH = eval(sData.substr(pM, lM));
                var iDAY   = eval(sData.substr(pD, lD));
                d = new Date(iYEAR, iMONTH-1, iDAY);
                day = d.getDay();
                var DaysOfWeek = new makeDayOfWeek2();
                s += DaysOfWeek[day].Eday;
                DaysOfWeek = null;
            } else {
                s += sNewPatn.substr(NPATN[i].Pos, NPATN[i].Pos);   // copy from NewPatn
            }
        }
    }
    return s;
}
function fnUpdateVersion( sID ){
    var oConectType = F.oBody.connectionType;
    var pType = (oConectType != "offline") ? "w" : "c";
    var coll = F.tags("SPAN");
    for (var i=0; i<coll.length; i++){
        if (coll[i].className == sID) coll[i].innerText = ThisVersion + pType;
    }
    var x = F["HCOUNT"];
    if (x != null){
        x.style.display = ((pType != "w") ? "" : "none");
    }
    @if (@DEBUG == 1) alert("Connection Type= " + oConectType); @end
}

function fnUpdateMdate2( sID ){
    @if (@DEBUG == 1) alert("fnUpdateMdate2 >> IN: SID=" + sID); @end
    var coll = F.tags("SPAN");
    for (var i=0; i<coll.length; i++){
        if (coll[i].className == sID && coll[i].innerText.substr(0,2) == "YY"){  // (oID.innerText.substr(0,2) == "YY") is emergency to avoid twice call
            with(coll[i]){
                style.display = "";
                //                       New Ptn    Current Pattern    Current Data(Date)
                innerText = fnFormatData(innerText, CURRENT_DTIME_PTN, document.lastModified);
                @if (@DEBUG == 1) alert("fnUpdateMdate2 >> New Date=" + innerText); @end
            }
        }
    }
    @if (@DEBUG == 1) alert("fnUpdateMdate2 >> OUT"); @end
}

function fnUpdateProductInfo( sID1, sID2 ){
    // sID1: Version SPAN-Tag ClassName
    // sID2: Update Date SPAN-Tag ClassName
    fnUpdateVersion( sID1 );
    fnUpdateMdate2( sID2 );
}

function fnUpdateMdate( sID ){
    var oID = F[ sID ];
    if ((oID != null) && (oID.innerText.substr(0,2) == "YY")){  // (oID.innerText.substr(0,2) == "YY") is emergency to avoid twice call
        with(oID){
            style.display = "";
            //                       New Ptn     Current Pattern       Current Data(Date)
            innerText = fnFormatData(innerText, "MM/DD/YYYY hh:mm:ss", document.lastModified);
        }
    }
}

function repLastModifiedDate(){
    var oModDate = F[ "MDATE" ];
    if (oModDate == null) return;
    if ((oModDate != null) && (oModDate.innerText.substr(0,2) == "YY")){  // (oID.innerText.substr(0,2) == "YY") is emergency to avoid twice call
        fnUpdateMdate( "MDATE" );
        return;
    }

    var n;
    if (DOCURL.lastIndexOf( B_CORE0 ) != -1){
        n = 0;
    } else if (DOCURL.lastIndexOf( B_CORE3 ) != -1){
        n = 3;
    } else if (DOCURL.lastIndexOf( B_CORE2 ) != -1){
        n = 2;
    } else if (DOCURL.lastIndexOf( B_CORE1 ) != -1){
        n = 1;
    } else {
        n = 1;
    }

    var oTocList = oListTOC[n].List;
    var iTocLen  = oListTOC[n].Len;
    var urlStr;
    var homeFlag = (DOCURL.lastIndexOf(HOME_URL) != -1) ? true : false;
    var curModifiedDate = oModDate.innerText.substr(0, 10); // yyyy/mm/dd
    var curModifiedTime = oModDate.innerText.substr(16, 8); // hh:mm:ss

    for (var i=0; i<iTocLen; i++){
        urlStr = (homeFlag) ? HOME_URL : oTocList[i].UrlBody(); // extract "qyymmdd"
        if (DOCURL.lastIndexOf(urlStr) != -1){      // matched
            @if ( @DEBUG == 1 )
            window.alert("Current Page is " + urlStr);
            @end
            if (( curModifiedDate <  oTocList[i].Date()) ||
                ((curModifiedDate == oTocList[i].Date()) &&
                 (curModifiedTime <= oTocList[i].Time()))){
                oModDate.innerText = oTocList[i].DT();
                curModifiedDate    = oTocList[i].Date();    // yyyy/mm/dd
                curModifiedTime    = oTocList[i].Time();    // hh:mm:ss
                @if ( @DEBUG == 1 )
                window.status = "Replaced Last Modified Date As: " + oModDate.innerText;
                @end
            }
            if (!homeFlag) return;
        }
    }
}
function fnStripBrackets( aStr ){
    var s = 0;
    var p = aStr.indexOf( "(", s );
    if (p == -1) return aStr;
    var r = aStr.length;
    var q = aStr.indexOf( ")", s );
    var sRet = "";
    do {
        sRet += aStr.substr( s, (p-s) );
        s = q + 1;
        p = aStr.indexOf( "(", s );
        q = aStr.indexOf( ")", s );
    } while( (p != -1) && (q != -1) );
    sRet += aStr.substr( s, (r-s) );
    return sRet;
}
var CUSTOM_TAG = "DEF"; // Defined in <HTML> tag above
function initTitles( sTag, sClass ){
    // arg1: HTML TAG element name (eg."SPAN")
    // arg2: Element Class name (eg. "DEF")
    var oColl = document.body.getElementsByTagName( sTag );
    var iCollLen = oColl.length;
    if (sTag == CUSTOM_TAG){
        for (var i=0; i<iCollLen; i++){
            oColl[i].title = "Click to view extended descripton for " + fnStripBrackets(oColl[i].innerText) + ".";
        }
    } else {
        for (var i=0; i<iCollLen; i++){
            if (oColl[i].className == sClass){
                oColl[i].title = "Click to view extended descripton for " + fnStripBrackets(oColl[i].innerText) + ".";
            }
        }
    }
}
var CUSTOM_TAG2 = "DEF2"; // Defined in <HTML> tag above
function initTitles2( sTag, sClass ){
    // arg1: HTML TAG element name (eg."SPAN")
    // arg2: Element Class name (eg. "DEF")
    var oColl = document.body.getElementsByTagName( sTag );
    var iCollLen = oColl.length;
    if (sTag == CUSTOM_TAG2){
        for (var i=0; i<iCollLen; i++){
            oColl[i].title = "Click to view extended descripton for " + fnStripBrackets(oColl[i].innerText) + ".";
        }
    } else {
        for (var i=0; i<iCollLen; i++){
            if (oColl[i].className == sClass){
                oColl[i].title = "Click to view extended descripton for " + fnStripBrackets(oColl[i].innerText) + ".";
            }
        }
    }
}
function fnSetReading(){
    // Purpose: provide Hiragana reading for the word
    // This function can be used in the following case only.
    // <Ruby><MY:DEF TipID='M05' onmousedown='fnSetReading();'>****</MY:DEF><RP>...
    var oObj = event.srcElement;
    var oOrg = oObj;
    if (oObj.parentElement.tagName == "RUBY"){
        oObj = oObj.parentElement;
    } else if (oObj.children.length > 0 && oObj.children(0).tagName == "RUBY"){
        oObj = oObj.children(0);
    } else if (oObj.children.length == 0){
        oOrg.addMessage = "";
        return;
    } else {
        do {
            oObj = oObj.parentElement;
        } while(oObj.tagName != "RUBY");
    }
    var i = 0;
    while(oObj.children(i).tagName != "RT") i++;
    oOrg.addMessage = oObj.children(i).innerHTML;   // Mod by SKN23 on 2005/01/30(Sun)-22:05:34
}
function fnSetFromNotes(){
    // Purpose: provide Hiragana reading for the word
    // This function can be used in the following case only.
    // <Ruby><MY:DEF TipID='M05' onmousedown='fnSetFromNotes();'>****</MY:DEF><RP>...
    // <span><ruby><rb>腫瘍</rb><rp>(</rp><rt>しゅよう</rt><rp>)</rp></ruby><span id="M01">...</span></span>
    var oObj = event.srcElement;
    var oOrg = oObj;
    var TargetID = F[ oObj.TipID ];
    if (TargetID != null){
        if (TargetID.parentElement.tagName == "SPAN"){
            oObj = TargetID.parentElement;
            var oObjP = oObj;
            var ChildLen = oObjP.children.length;
            var k = 0;
            do {
                oObj = oObjP.children(k);
            }while (++k < ChildLen && oObj.tagName != "RUBY");
            if (oObj.tagName == "RUBY"){
                oObjP = oObj;
                ChildLen = oObjP.children.length;
                k = 0;
                do {
                    oObj = oObjP.children(k);
                }while (++k < ChildLen && oObj.tagName != "RT");
                oOrg.addMessage = (oObj.tagName == "RT") ? oObj.innerHTML : "- Not Defined -<RT>";
            } else {
                oOrg.addMessage = "- Not Defined -<RUBY>";
            }
        } else {
            oOrg.addMessage = "- Not Defined -<SPAN>";
        }
    } else {
        oOrg.addMessage = "- Not Defined -<TipID>";
    }
}

function fnStripHtmlTags( sCaption ){
    // IN : "Non-Smoking <span class='NAME'>Izakaya</span>"
    // OUT: "Non-Smoking Izakaya"
    var sRet = "";
    var p  = 0;
    var q  = 0;
    var l  = sCaption.length;
    var sp = sCaption.indexOf( '<', p );
    var ep = sCaption.indexOf( '>', p );
    while((sp != -1) && (ep != -1)){
        q = sp - p;
        sRet += sCaption.substr( p, q );
        p = ep + 1;
        sp = sCaption.indexOf( '<', p );
        ep = sCaption.indexOf( '>', p );
    }
    sRet += sCaption.substr( p, l-p );
    return sRet;
}
function OnMouse2(base, dir){
    var e = window.event.srcElement;
    var urlStr, LinkCap, k, i, sp;
    var pageTitle = "";
    var oTocList, iTocLen;

    sp = base.lastIndexOf("/"); // find last path delimiter ("/")
    sp ++;
    for (i=0; i<oListLen; i++){
        if (base.indexOf(oListTOC[i].List[0].URL.substr(0, 5), sp) != -1){
            oTocList = oListTOC[i].List;
            iTocLen  = oListTOC[i].Len;
            break;
        }
    }

    if (base.lastIndexOf(HOME_URL) != -1){
        oTocList = oListTOC[1].List;
        iTocLen  = oListTOC[1].Len;
        for (i=0; i<iTocLen; i++){
            if (!oTocList[i].Cnd) continue;
            pageTitle = oTocList[i].Cap;
            break;
        }
    } else {

    for (i=0; i<iTocLen; i++){
        urlStr = oTocList[i].UrlBody();     // extract "qyymmdd"
        if (base.lastIndexOf(urlStr) != -1){    // matched
            if ((dir == PREV_PAGE) && (i > 0)){
                k = 1;
                LinkCap = oTocList[i-k].Cap;
                while(!oTocList[i-k].Cnd){
                    if (i == k){
                        LinkCap = "Home Page of " + BOOK_TITLE;
                        break;
                    }
                    k++;
                    LinkCap = oTocList[i-k].Cap;
                }
                pageTitle = LinkCap;
            } else if ((dir == NEXT_PAGE) && (i < (iTocLen-1))){
                k = 1;
                LinkCap = oTocList[i+k].Cap;
                while(!oTocList[i+k].Cnd){
                    if ((i+k) == (iTocLen-1)){
                        LinkCap = "Home Page of " + BOOK_TITLE;
                        break;
                    }
                    k++;
                    LinkCap = oTocList[i+k].Cap;
                }
                pageTitle = LinkCap;
            } else if (dir == KEEP_PAGE){
                pageTitle = oTocList[i].Cap;
            } else {    // default: Home Pge
                pageTitle = "Home Page of " + BOOK_TITLE;
            }
            break;
        }
    }
    }

    if (dir == HOME_PAGE) pageTitle = "Home Page of " + BOOK_TITLE;
    with(e.style){
        color  = 'lime';
        cursor = 'hand';
    }
    e.title = (pageTitle != "") ? fnStripHtmlTags(pageTitle) : fnStripHtmlTags(e.title);
}
function OnMouse(){
    var e = window.event.srcElement;
    with(e.style){
        color  = 'lime';
        cursor = 'hand';
    }
}
function OutMouse(){
    var e = window.event.srcElement;
    with(e.style){
        color  = '';
        cursor = '';
    }
}
function showHitCounter(sID){
    if (F.oBody.connectionType != "offline"){
        var x = F[ sID ];
        if (x != null){
            with(x.style){
                display = (display == "none") ? "" : "none";
            }
        }
    }
}
function showTran(){
    var x = F[ 'FLD1' ];
    if (x != null){
        with(x.runtimeStyle){
            display = (display == 'none') ? '' : 'none';
        }
    }
    showHitCounter('HCOUNT');
}
function showTran2(sID){
    if (sID != "FLD99"){
        var x = F[ sID ];
        if (x != null){
            with(x.runtimeStyle){
                display = (display == 'none') ? '' : 'none';
            }
        }
    }
    showHitCounter('HCOUNT');
}
function hideColor(targetColor){
    var coll = F.tags( 'SPAN' );
    var clen = coll.length;
    if (clen > 0){
        for (var i=0; i < clen; i++){
            with(coll.item(i)){
                if (className == 'HIDE'){
                    runtimeStyle.color = targetColor;
                }
            }
        }
    }
}
function hideText(){
    var coll = F.tags( 'SPAN' );
    var clen = coll.length;
    var tlen, j;
    if (clen > 0){
        for (var i=0; i<clen; i++){
            with(coll.item(i)){
                if (className == 'HIDE'){
                    tlen = innerText.length;
                    innerText = '   ';
                    for (j=1; j<tlen; j++){
                        innerText += '   ';
                    }
                }
            }
        }
    }
}
function MyErrHandler(msg, url, line){
    var strMsg;
    strMsg  = 'UnAnticipated Error Occurred.';
    strMsg += '\n' + msg;
    strMsg += '\nat Line ' + line;
    strMsg += '\nin the ' + document.title + ' page.';
    window.alert(strMsg);
    return true;
}
window.onerror = MyErrHandler;
// #################################################################################
// #    << End of jpread.js >> (C) 2002 Southern Cross Virtual Co., Ltd. (v1.2)
// #################################################################################
