/*********************************************************/
/**   汎用スクリプト                                    **/
/**                                                     **/
/**          Copyright (C) 2005 KASHU SYSTEM DESIGN     **/
/**                                                     **/
/*********************************************************/


var menuTimer = 0;

// 画像を表示
function ChangeImage(tId, tPict)
{
    var dc, img;

    dc = document;
    if(dc.images){
        img = null;
        if(dc.layers) {
            img = findElement(tId, 0);
        } else {
            img = dc.images[tId];
        }
        if(img){
            img.src = tPict;
        }
    }
}

// レイヤーの消去タイマーをセット
function SetLayerClearTimer() {
    menuTimer = setTimeout("HideAllLayer()",1000);
}
            
            
// レイヤーの消去タイマーをリセット
function ResetLayerClearTimer() {
    clearTimeout(menuTimer);
}

// レイヤーを取得
function GetLayer(tLayer) 
{ 
    if(typeof tLayer != "string"){
        return(null);
    }
    return(document.getElementById(tLayer).style);
} 

// 一つのレイヤーを隠す
function HideLayer(tLayer)
{
    var lyr = GetLayer(tLayer); 
    if(lyr) { 
        lyr.visibility = "hidden";
    } 
} 

// 一つのレイヤーを表示
function ShowLayer(tParent, tLayer)
{
    var lyr = GetLayer(tLayer); 
    if(lyr) { 
        lyr.left = GetOffsetLeft(tParent);
        lyr.top = GetOffsetTop(tParent) + tParent.offsetHeight + 2;
        lyr.visibility = "visible";
    } 
} 

// 親のLeftの座標を取得
function GetOffsetLeft(tParent)
{
    var x;

    x = tParent.offsetLeft;
    if(tParent.offsetParent != null){
        // 更に親の座標を取得
        x += GetOffsetLeft(tParent.offsetParent);
    }

  return(x);
}

// 親のTop座標を取得
function GetOffsetTop(tParent)
{
    var y;

    y = tParent.offsetTop;
    if(tParent.offsetParent != null){
        // 更に親の座標を取得
        y += GetOffsetTop(tParent.offsetParent);
    }

  return(y);
}


// サブメニューをポップアップ
function PopupSubMenu(tEvent, tMenuId)
{
    var button;

    if(navigator.userAgent.indexOf("MSIE") >= 0){
        button = window.event.srcElement;
    } else {
        button = tEvent.currentTarget;
    }

    // すべてのレイヤーを隠す
    HideAllLayer();

    // サブメニューのレイヤーを表示
    ShowLayer(button, tMenuId);

}

// すべてのレイヤーを隠す
function HideAllLayer() { 
    HideLayer("SUBM_HOME"); 
    HideLayer("SUBM_PRODUCTS"); 
    HideLayer("SUBM_LICENCE"); 
    HideLayer("SUBM_ABOUTUS"); 
}

// ポップメニューを作成
// 各ファイルに書くのが面倒なのでここに書く
// どうせJavaScriptが使用出来ないとポップメニューは表示されない
function MakeSubMenu(menuId, tCurrent)
{
    var tBuff = "";
    var tUrl = new Array();
    var tName = new Array();
    var cnt;
    var obj = document.getElementById(menuId);


    // HOME
    cnt = 0;

    tUrl[cnt] = "homes/index.html";
    tName[cnt] = "過去のNEWS";
    cnt++;
    tUrl[cnt] = "homes/sitemap.html";
    tName[cnt] = "サイトマップ";
    cnt++;

    tBuff += "<div id='SUBM_HOME' class='MENU'>";
    tBuff += MakeSubMenuEx(tCurrent, cnt, tUrl, tName);
    tBuff += "</div>";

    // ダウンロード
    cnt = 0;

    tUrl[cnt] = "products/minmas.html";
    tName[cnt] = "しゃべって答えるみんなの１００マス計算トレーニング";
    cnt++;
    tUrl[cnt] = "products/ktaiprn.html";
    tName[cnt] = "ケータイへ印刷";
    cnt++;
    // tUrl[cnt] = "products/freeware.html";
    // tName[cnt] = "フリーウェア";
    // cnt++;
    // 2006.07.20 コメントアウト kawamoto del start
    // tUrl[cnt] = "products/faq.html";
    // tName[cnt] = "よくある質問";
    // cnt++;
    // 2006.07.20 コメントアウト kawamoto del end

    tBuff += "<div id='SUBM_PRODUCTS' class='MENU'>";
    tBuff += MakeSubMenuEx(tCurrent, cnt, tUrl, tName);
    tBuff += "</div>";

    // ライセンス取得
    cnt = 0;

    tUrl[cnt] = "licence/licflow.html";
    tName[cnt] = "ライセンスキー取得の流れ";
    cnt++;

    tUrl[cnt] = "licence/payment.html";
    tName[cnt] = "お支払方法";
    cnt++;

    tUrl[cnt] = "licence/licence.cgi?new";
    tName[cnt] = "ライセンスキー取得";
    cnt++;

    tBuff += "<div id='SUBM_LICENCE' class='MENU'>";
    tBuff += MakeSubMenuEx(tCurrent, cnt, tUrl, tName);
    tBuff += "</div>";

    // 会社案内
    cnt = 0;

    //2006.08.31 コメントアウト saitou del start
    //tUrl[cnt] = "aboutus/substance.html";
    //tName[cnt] = "会社概要";
    //cnt++;
    // 2006.07.20 コメントアウト kawamoto del start
    // tUrl[cnt] = "aboutus/information.html";
    // tName[cnt] = "事業案内";
    // cnt++;
    // 2006.07.20 コメントアウト kawamoto del end
    tUrl[cnt] = "aboutus/employment.html";
    //tName[cnt] = "採用情報";
    //cnt++;
    // 2006.08.31 コメントアウト saitou del end
    tUrl[cnt] = "aboutus/map.html";
    tName[cnt] = "交通・アクセス";
    cnt++;
    tUrl[cnt] = "aboutus/reference.html";
    tName[cnt] = "お問い合わせ";
    cnt++;

    tBuff += "<div id='SUBM_ABOUTUS' class='MENU'>";
    tBuff += MakeSubMenuEx(tCurrent, cnt, tUrl, tName);
    tBuff += "</div>";


    if(typeof(obj.innerHTML)!="undefined"){
        obj.innerHTML = tBuff;
    }
}

function MakeSubMenuEx(tCurrent, cnt, tUrl, tName)
{
    var tBuff = "";
    var i;

    for(i = 0; i < cnt; i++){
        tBuff += "<a href = " + tCurrent + tUrl[i] + " onmouseover = ResetLayerClearTimer(); onfocus = ResetLayerClearTimer(); onmouseout = SetLayerClearTimer(); class='MENUITEM'>"+ tName[i] +"</a>";
    }

    return(tBuff);
}

