/************************************************
  
Site Name: 
Description: common script
Version: 
Author: 
Last Modified :

************************************************/

// ポップアップ表示メソッド

function popup_open(winnam, width, height) {
    var w, h
    if (width != null && width != "" && width != undefined)
    { w = "width=" + width + "px," }
    if (height != null && height != "" && height != undefined)
    { h = "height=" + height + "px," }
    var objWindow = window.open(winnam, "popup3", w + h + "toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, close=yes");
    objWindow.focus();

    return false;
}


// ポップアップ表示メソッド(メニューバー、ツールバーの表示)

function popup_open2(winnam, width, height) {
    var w, h
    if (width != null && width != "" && width != undefined)
    { w = "width=" + width + "px," }
    if (height != null && height != "" && height != undefined)
    { h = "height=" + height + "px," }
    var objWindow = window.open(winnam, "popup3", w + h + "toolbar=yes, location=no, directories=no, status=yes, menubar=yes, scrollbars=yes, resizable=yes, close=yes");
    objWindow.focus();

    return false;
}

// ポップアップ表示メソッド(バー等を全て表示)

function popup_open3(winnam, width, height) {
    var w, h
    if (width != null && width != "" && width != undefined)
    { w = "width=" + width + "px," }
    if (height != null && height != "" && height != undefined)
    { h = "height=" + height + "px," }
    var objWindow = window.open(winnam, "popup3", w + h + "toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, close=yes");
    objWindow.focus();

    return false;
}

// ポップアップ表示メソッド

function popup_close() {
    window.opener = window;
    var win = window.open(location.href, "_self");
    win.close();
}

// 検索アシスタント用メソッド

function insertBusStop(stationNm,DepTextBox,ArvTextBox,DepRdoBtn,ArvRdoBtn) {

    if (DepRdoBtn.checked) {
        DepRdoBtn.checked = false;
        ArvRdoBtn.checked = true;
        ArvTextBox.focus();
        ArvTextBox.style.background = 'lemonchiffon';
        DepTextBox.style.background = 'white';
        DepTextBox.style.color = '#000000';
        DepTextBox.value = stationNm;
    } else {
        DepRdoBtn.checked = true;
        ArvRdoBtn.checked = false;
        DepTextBox.focus();
        DepTextBox.style.background = 'lemonchiffon';
        ArvTextBox.style.background = 'white';
        ArvTextBox.style.color = '#000000';
        ArvTextBox.value = stationNm;
    }
     return false;
}

// ＪＲ岐阜、名鉄岐阜挿入メソッド

function insert_value(cntrlNm, val) {
    cntrlNm.value = val;
    cntrlNm.style.color = "#000000";
    return false;
}

// 逆区間ボタンクリックメソッド

function change_value(cntrlNmDep, cntrlNmArv) {
    var tmp;
    tmp = cntrlNmDep.value;
    cntrlNmDep.value = cntrlNmArv.value;
    cntrlNmArv.value = tmp;


    tmp = cntrlNmDep.style.color;
    cntrlNmDep.style.color = cntrlNmArv.style.color;
    cntrlNmArv.style.color = tmp;
    
    return false;
}

// Query String から 配列を返す

function getParameter(str) {
    var dec = decodeURIComponent;
    var par = new Array, itm;
    if (typeof (str) == 'undefined') return par;
    if (str.indexOf('?', 0) > -1) str = str.split('?')[1];
    str = str.split('&');
    for (var i = 0; str.length > i; i++) {
        itm = str[i].split("=");
        if (itm[0] != '') {
            par[itm[0]] = typeof (itm[1]) == 'undefined' ? true : dec(itm[1]);
        }
    }
    return par;
}

// 配列 から Query Stringを返す

function setParameter(par) {
    var enc = encodeURIComponent;
    var str = '', amp = '';
    if (!par) return '';
    for (var i in par) {
        str = str + amp + i + "=" + enc(par[i]);
        amp = '&'
    }
    return str;
}

// JavaScriptでページ遷移を行う

function movePage(pageName) {
    var query = makeQuery("", "");
    location.href = pageName + '?' + query;
    return false;
}

// JavaScriptでページ切替を行う

function changePage(topTypeId) {
    var query = makeQuery(topTypeId,"");
    location.href = 'Frm_0000.aspx?' + query;
    return false;
}

// JavaScriptでサイドバーのページ切替を行う

function changePageTo(pageName) {
    var query = makeQuery("", pageName);
    location.href = 'Frm_0400.aspx?' + query;
    return false;
}

// テキストボックスにある入力を促すメッセージを消す

function focusText(txt, document, rdoBtn) {
    var hdn = document.getElementById('Hdn_SuggestDefaultValue');
    whiteTextBox(document);
    txt.style.background = 'lemonchiffon';
    rdoBtn.checked = true;
    if (txt.value == hdn.value || txt.value == "") {
        txt.value = "";
        txt.style.color = "#000000";
    }
    return false;
}

// テキストボックスに入力を促すメッセージを表示する

function blurText(txt, document, rdoBtn) {
    var hdn = document.getElementById('Hdn_SuggestDefaultValue');
    whiteTextBox(document);
    if (rdoBtn.checked) {
        txt.style.background = 'lemonchiffon';
    } else {
        txt.style.background = 'white';
    }
    if (txt.value == "" || txt.value == hdn.value) {
        txt.style.color = "#AAAAAA";
        txt.value = hdn.value;
    }
    else {
        txt.style.color = "#000000";
    }
    return false;
}

// テキストボックスの初期表示を設定します

function loadText(txt, hdn) {
    if (txt.value == "" || txt.value == hdn.value) {
       // if (!txt.hasFocus()) {
            txt.value = hdn.value;
        //}
        txt.style.color = "#AAAAAA";
    }
    else {
        txt.style.color = "#000000";
    }
    return false;
}



//テキストボックスを白くする

function whiteTextBox(document) {

    var elements = document.getElementsByTagName('input');

    var i;
    for (i = 0; i < elements.length; i++) {
        if (elements[i].style.background != "") {
            elements[i].style.background = 'white';
        }
    }
    return false;
}