<!--
var popupSpec;
var subcatMask0, subcatMask1, subcatMask2, subcatMask3;
var subcatMask4, subcatMask5, subcatMask6;
var category, subcategory, useCookie;

function doTagProMap(){
        initPopupSpec();

	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="760" height="450">');
	document.write('<param name="movie" value="map.swf">');
	document.write('<param name="quality" value="high">');
        // wmode が window でないと、日本語入力がその場変換にならない。
	document.write('<param name="wmode" value="window">');
        document.write('<param name="FlashVars" ' +
                       'value="popupSpec=' + popupSpec + '">');
	document.write('<embed src="map.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="760" height="450" wmode="window" FlashVars="popupSpec=' + popupSpec + '">');
	document.write('</embed></object>');
}

function doTagJrMap(){
        initCategory();

	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="760" height="480">');
	document.write('<param name="movie" value="images/img.swf">');
	document.write('<param name="quality" value="high">');
        document.write('<param name="FlashVars" ' +
                       'value="category=' + category +
                       '&subcatMask0=' + subcatMask0 +
                       '&subcatMask1=' + subcatMask1 +
                       '&subcatMask2=' + subcatMask2 + 
                       '&subcatMask3=' + subcatMask3 + 
                       '&subcatMask4=' + subcatMask4 + 
                       '&subcatMask5=' + subcatMask5 + 
                       '&subcatMask6=' + subcatMask6 + '">');
//	document.write('<embed src="images/img.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="760" height="480">');
	document.write('<embed src="images/img.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="760" height="480" FlashVars="category=' + category + '&subcatMask0=' + subcatMask0 + '&subcatMask1=' + subcatMask1 + '&subcatMask2=' + subcatMask2 + '&subcatMask3=' + subcatMask3 + '&subcatMask4=' + subcatMask4 + '&subcatMask5=' + subcatMask5 + '&subcatMask6=' + subcatMask6 + '">');
	document.write('</embed></object>');
}

function getCookie(key) {
    if ( document.cookie == key || document.cookie.indexOf(key + ';') >= 0 ) {
        return null;
    }
    if ( (index1 = document.cookie.indexOf(key + '=')) < 0 ) {
        return null;
    }
    if ( (index2 = document.cookie.indexOf(';', index1)) < 0 ) {
        index2 = document.cookie.length;
    }
    return document.cookie.substring(index1 + key.length + 1, index2);
}
function putCookie(key, value) {
    // 不自然に見えるが、これで既存のものに追加される。
    document.cookie = key + '=' + value;
}
function getCookieLastPopup() {
    return getCookie('lastPopup');
}
function putCookieLastPopup(value) {
    putCookie('lastPopup', value);
}
function getCookieReload() {
    return getCookie('reload');
}
function putCookieReload(value) {
    putCookie('reload', value);
}
function openFromFlash(newURL) {
    // Flash から呼び出された状態でページを開くと、
    // Firefox と IE で動作が異なる (Firefox 2, IE6, IE7 でテスト済み)。
    // Firefox では、現在の履歴の中で JavaScript が実行されるのに対して、
    // IE では、次の履歴として実行される。
    // ただし、javascript:void(location.href=xxxx) のように、直接、
    // 新しい URL が書かれている場合には、IE も Firefox も、新しいページを
    // 次の履歴にロードする。
    //
    // location.replace()
    //    Firefox:  履歴の現在位置を上書き、かつ、以降の履歴が残る
    //    IE     :  次の履歴にロード
    //
    // location.href=
    //    Firefox:  次の履歴にロード
    //    IE     :  次の履歴は現在の履歴と同じURL になり、
    //              次の次の履歴に新しいページをロード
    //
    if ( navigator.appName.indexOf('Netscape') >= 0 ) {
        // Firefox
        location.href = newURL;
    }
    else {
        // IE
        //location.replace() を使いたいところだが、将来仕様変更があった
        //場合に Flash の状態が保持されなくなる恐れがあるため、余分な
        //履歴が残るのは気になるが、安全策として location.href を使うこ
        //とにする (回避策を模索したが、見つけられなかった)。
        //location.replace(newURL);
        location.href = newURL;
    }
}

function initPopupSpec() {
    cookie = getCookieLastPopup();

    // cookie が使用可能かどうかテスト
    putCookieLastPopup('1_1');
    if ( getCookieLastPopup() == '1_1' ) {
        useCookie = true;
        putCookieLastPopup(cookie);
        popupSpec = cookie;

        if ( location.search.indexOf('?p=_') < 0 ) {
            putCookieLastPopup('');
            popupSpec = '';
        }
        else if ( (techID = getCookieReload()) != null && techID != '' ) {
            putCookieReload('');
            // location.href= は、Firefox では location.replace() と
            // 同様に動作するので使えない。
            //location.href = getURLPro(popupSpec, techID);
            window.open(getURLPro(popupSpec, techID), '_self');
        }
    }
    else {
        useCookie = false;
        initReloadPro();
    }
}
function openDetail(popupSpec, techID) {
    if ( useCookie ) {
        if ( location.search.indexOf('?p=_') < 0 ) {
            putCookieLastPopup(popupSpec);
            putCookieReload(techID);
            openFromFlash((location.href.lastIndexOf('?') >= 0 ?
                           location.href.substring
                               (0, location.href.lastIndexOf('?')) :
                           location.href) +
                          '?p=_');
        }
        else {
            // すでに URL に ?p=_ が付いている場合、リロード不要
            putCookieLastPopup(popupSpec);
            openFromFlash(getURLPro(popupSpec, techID));
        }
    }
    else {
        if ( location.search.length >= 4 &&
             location.search.
             substring(0, 3 + popupSpec.length) == '?p=' + popupSpec) {
            openFromFlash(getURLPro(popupSpec, techID));
        }
        else {
            reloadPage1Pro(popupSpec, techID);
        }
    }
}
function getURLPro(popupSpec, techID) {
    return (location.href.indexOf("/pro/english/") >= 0 ? 
            "../../cgi-bin/detail_pro_en.php" :
            "../cgi-bin/detail_pro.php") +
           "?id=" + techID + "&p=" + (useCookie ? "_" : popupSpec);
}
function resetLastPopupPro() {
    putCookieLastPopup('');
}

function initCategory() {
    cookie = getCookieLastPopup();

    // cookie が使用可能かどうかテスト
    putCookieLastPopup('-1');
    if ( getCookieLastPopup() == '-1' ) {
        useCookie = true;
        putCookieLastPopup(cookie);
        category = cookie;

        if ( (index = location.search.indexOf('?c=')) < 0 ) {
            putCookieLastPopup('');
            category = '';
        }
        else if ( (subcategory = getCookieReload()) != null &&
                  subcategory != '' ) {
            putCookieReload('');
            // location.href= は、Firefox では location.replace() と
            // 同様に動作するので使えない。
            //location.href = getURLJr(category, subcategory);
            window.open(getURLJr(category, subcategory), '_self');
        }
        else {
            // クッキーは上書きされるので、URL に指定があるときには
            // URL を優先する。
            spec = location.search.substring(index + 3, index + 4);
            if ( spec != '_' ) {
                category = spec;
            }
        }
    }
    else {
        useCookie = false;
        initReloadJr();
    }
}
function loadPage(category, subcategory) {
    if ( useCookie ) {
        if ( location.search.indexOf('?c=_') < 0 ) {
            putCookieLastPopup(category);
            putCookieReload(subcategory);
            openFromFlash((location.href.lastIndexOf('?') >= 0 ?
                           location.href.substring
                               (0, location.href.lastIndexOf('?')) :
                           location.href) +
                          '?c=_');
        }
        else {
            // すでに URL に ?c=_ が付いている場合、リロード不要
            putCookieLastPopup(category);
            openFromFlash(getURLJr(category, subcategory));
        }
    }
    else {
        if ( location.search.length >= 4 &&
             location.search.substring(0, 4) == '?c=' + category ) {
            // すでに URL に ?c=X が付いている場合、リロード不要
            // location.href= は、Firefox では location.replace() と
            // 同様に動作するので使えない。
            //location.href = getURLJr(category, subcategory);
            openFromFlash(getURLJr(category, subcategory));
        }
        else {
            reloadPage1Jr(category, subcategory);
        }
    }
}
function getURLJr(category, subcategory) {
    return (location.href.indexOf("/junior/english/") >= 0 ? 
            "../../cgi-bin/search_result_jr_en.php" :
            "../cgi-bin/search_result_jr.php") +
           "?main_category=" + category +
           "&sub_category=" + (subcategory < 0 ? "" : subcategory) +
           "&c=" + (useCookie ? "_" : category);
}
function resetLastPopupJr() {
    putCookieLastPopup('');
}

/*
 * URL による Flash の状態の保存（cookie が使えないとき）
 */
function initReloadPro() {
    popupSpec = "";
    index1 = location.search.indexOf('?p=')
    index2 = location.search.indexOf('&t=')
    index3 = location.search.indexOf('&h=')
    if ( index1 == 0 && index2 < 0 ) {
        popupSpec = location.search.substring(3, location.search.length);
    }
    else if ( index1 == 0 && index2 > 0 && index3 > 0 ) { 
        popupSpec = location.search.substring(3, index2);
        techID = location.search.substring(index2 + 3, index3);
        if ( location.search.substring(index3 + 3, index3 + 4) == '_' ) {
            reloadPage2Pro(popupSpec, techID);
            return;
        }
        else {
            historyLength = parseInt(location.search.substring
                                     (index3 + 3, location.search.length));
            if ( history.length == historyLength ) {
                reloadPage3Pro(popupSpec, techID);
                return;
            }
        }
    }
}
function reloadPage1Pro(popupSpec, techID) {
    openFromFlash((location.href.lastIndexOf('?') >= 0 ?
                   location.href.substring(0, location.href.lastIndexOf('?')) :
                   location.href) +
                  '?p=' + popupSpec + '&t=' + techID + '&h=_');
}
function reloadPage2Pro(popupSpec, techID) {
    location.replace((location.href.lastIndexOf('?') >= 0 ?
                      location.href.substring
                          (0, location.href.lastIndexOf('?')) :
                      location.href) +
                     '?p=' + popupSpec + '&t=' + techID +
                     '&h=' + history.length);
}
function reloadPage3Pro(popupSpec, techID) {
     // location.href= は、Firefox では location.replace() と
     // 同様に動作するので使えない。
     //location.href = getURLPro(popupSpec, techID);
     window.open(getURLPro(popupSpec, techID), '_self');
}

function initReloadJr() {
    category = -1;
    if ( location.search.length == 4 &&
         location.search.substring(0, 3) == '?c=' ) {
        category = parseInt(location.search.substring(3, 4));
    }
    else if ( location.search.length >= 8 &&
              location.search.substring(0, 3) == '?c=' &&
              location.search.substring(4, 7) == '&s=' &&
              location.search.substring(8, 11) == '&h=' ) {
        category = parseInt(location.search.substring(3, 4));
        subcategory = location.search.substring(7, 8);
        if ( subcategory == '_' ) {
            subcategory = -1;
        }
        else {
            subcategory = parseInt(subcategory);
        }
        if ( location.search.substring(11, 12) == '_' ) {
            reloadPage2Jr(category, subcategory);
            return;
        }
        else {
            historyLength = parseInt(location.search.substring
                                     (11, location.search.length));
            if ( history.length == historyLength ) {
                reloadPage3Jr(category, subcategory);
                return;
            }
        }
    }
}
function reloadPage1Jr(category, subcategory) {
    openFromFlash((location.href.lastIndexOf('?') >= 0 ?
                   location.href.substring(0, location.href.lastIndexOf('?')) :
                   location.href) +
                  '?c=' + category +
                  '&s=' + (subcategory < 0 ? '_' : subcategory) +
                  '&h=_');
}
function reloadPage2Jr(category, subcategory) {
    location.replace((location.href.lastIndexOf('?') >= 0 ?
                      location.href.substring
                          (0, location.href.lastIndexOf('?')) :
                      location.href) +
                     '?c=' + category + 
                     '&s=' + (subcategory < 0 ? '_' : subcategory) +
                     '&h=' + history.length);
}
function reloadPage3Jr(category, subcategory) {
     // location.href= は、Firefox では location.replace() と
     // 同様に動作するので使えない。
     //location.href = getURLJr(category, subcategory);
     window.open(getURLJr(category, subcategory), '_self');
}

-->
