/**
 * JavaScript 東方研究会用
 *
 * @author ATS
 * @version 1.0
 */

var pgcnt = 1;

// ページジャンプ
function pageJump(lst, pg) {
    var elm = document.getElementById(lst);
    var stw = (elm.currentStyle || document.defaultView.getComputedStyle(elm, '')).width;
    maxpg = parseInt(stw) / 932;

    if (pg >= 1 && pg <= maxpg) {
        document.getElementById('footerleft').style.backgroundImage='url(img/nvlof.gif)';
        document.getElementById('footerright').style.backgroundImage='url(img/nvrof.gif)';
        document.getElementById('pgprev').style.backgroundImage='url(img/prevcr.gif)';
        document.getElementById('pgnext').style.backgroundImage='url(img/nextcr.gif)';
        if (pg == 1) {
            document.getElementById('footerleft').style.backgroundImage='none';
            document.getElementById('footerleft').style.cursor='auto';
            document.getElementById('pgprev').style.backgroundImage='none';
            document.getElementById('pgprev').style.cursor='auto';
        }
        if (pg == maxpg) {
            document.getElementById('footerright').style.backgroundImage='none';
            document.getElementById('footerright').style.cursor='auto';
            document.getElementById('pgnext').style.backgroundImage='none';
            document.getElementById('pgnext').style.cursor='auto';
        }

        var chi ="";
        for (i = 1; i <= maxpg; i++) {
            chi = "chi" + i;
            document.getElementById(chi).style.backgroundImage='url(img/pj2.gif)';
        }
        chi = "chi" + pg;
        document.getElementById(chi).style.backgroundImage='url(img/pj1.gif)';

        if (pg != pgcnt) {
            pgcnt = pg;
            var increment = 932;
            var fx = new Fx.Style(lst, 'margin-left', {
                duration: 1500,
                //transition: Fx.Transitions.Back.easeInOut,
                transition: Fx.Transitions.Quad.easeInOut,
                //transition: Fx.Transitions.Back.easeOut,
                wait: true
            });
            var totIncrement = increment*(pgcnt-1)*(-1);
            fx.stop();
            fx.start(totIncrement);
        }
    }
}

// ページ進む
function pageNext(lst) {
    var elm = document.getElementById(lst);
    var stw = (elm.currentStyle || document.defaultView.getComputedStyle(elm, '')).width;
    maxpg = parseInt(stw) / 932;

    if (pgcnt < maxpg) {
        pgcnt++;

        if (pgcnt == maxpg) {
            document.getElementById('footerright').style.backgroundImage='none';
            document.getElementById('footerright').style.cursor='auto';
            document.getElementById('pgnext').style.backgroundImage='none';
            document.getElementById('pgnext').style.cursor='auto';
        } else {
            document.getElementById('footerright').style.backgroundImage='url(img/nvrof.gif)';
            document.getElementById('footerleft').style.backgroundImage='url(img/nvlof.gif)';
            document.getElementById('pgnext').style.backgroundImage='url(img/nextcr.gif)';
            document.getElementById('pgprev').style.backgroundImage='url(img/prevcr.gif)';
        }

        var chi ="";
        for (i = 1; i <= maxpg; i++) {
            chi = "chi" + i;
            document.getElementById(chi).style.backgroundImage='url(img/pj2.gif)';
        }
        chi = "chi" + pgcnt;
        document.getElementById(chi).style.backgroundImage='url(img/pj1.gif)';

        var increment = 932;
        var fx = new Fx.Style(lst, 'margin-left', {
            duration: 1500,
            //transition: Fx.Transitions.Back.easeInOut,
            //transition: Fx.Transitions.Back.easeOut,
            //transition: Fx.Transitions.Expo.easeInOut,
            //transition: Fx.Transitions.Sine.easeInOut,
            transition: Fx.Transitions.Quad.easeInOut,
            wait: true
        });
        var totIncrement = increment*(pgcnt-1)*(-1);
        fx.stop();
        fx.start(totIncrement);
    }
}

// ページ戻る
function pagePrev(lst) {
    var elm = document.getElementById(lst);
    var stw = (elm.currentStyle || document.defaultView.getComputedStyle(elm, '')).width;
    maxpg = parseInt(stw) / 932;

    if (pgcnt > 1) {
        pgcnt--;
        if (pgcnt == 1) {
            document.getElementById('footerleft').style.backgroundImage='none';
            document.getElementById('footerleft').style.cursor='auto';
            document.getElementById('pgprev').style.backgroundImage='none';
            document.getElementById('pgprev').style.cursor='auto';
        } else {
            document.getElementById('footerleft').style.backgroundImage='url(img/nvlof.gif)';
            document.getElementById('footerright').style.backgroundImage='url(img/nvrof.gif)';
            document.getElementById('pgprev').style.backgroundImage='url(img/prevcr.gif)';
            document.getElementById('pgnext').style.backgroundImage='url(img/nextcr.gif)';
        }

        var chi ="";
        for (i = 1; i <= maxpg; i++) {
            chi = "chi" + i;
            document.getElementById(chi).style.backgroundImage='url(img/pj2.gif)';
        }
        chi = "chi" + pgcnt;
        document.getElementById(chi).style.backgroundImage='url(img/pj1.gif)';

        var increment = 932;
        var fx = new Fx.Style(lst, 'margin-left', {
            duration: 1500,
            //transition: Fx.Transitions.Back.easeInOut,
            //transition: Fx.Transitions.Sine.easeInOut,
            transition: Fx.Transitions.Quad.easeInOut,
            wait: true
        });
        var totIncrement = increment*(pgcnt-1)*(-1);
        fx.stop();
        fx.start(totIncrement);
    }
}

// サブメニューオープン
function subMenuOpen(ss) {
    document.getElementById(ss).style.visibility="visible"
}

// サブメニュークローズ
function subMenuClose(tt) {
    document.getElementById(tt).style.visibility="hidden"
}

// テキストボックスクリア＆入力不可＆画像入れ替え
function selectChange(sel, txt, img, imgl) {
    var lat = imgl.split(",");
    var answer = sel.selectedIndex;

    if(answer != 0) {
        txt.disabled = true;
        img.value = lat[answer-1];
        txt.value = "";
    } else {
        txt.disabled = false;
    }
}

function setDay(year, month, day){

    var years = parseInt(year.options[year.selectedIndex].value);
    var months = parseInt(month.options[month.selectedIndex].value);
    var lastday = monthday(years,months);
    var itemnum = day.length;
    if (lastday - 1 < day.selectedIndex) {
        day.selectedIndex = lastday - 1;
    }
    day.length = lastday;
    for (cnt = itemnum + 1;cnt <= lastday;cnt++) {
        day.options[cnt - 1].text = cnt;
    }
}
function monthday(years,months){
    var lastday = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    if (((years % 4 == 0) && (years % 100 != 0)) || (years % 400 == 0)){
        lastday[1] = 29;
    }
    return lastday[months - 1];
}

// 場所リストの動的変更
function placeListGen(radio, plcno, plcnm) {

    var nosp = plcno.split(",");
    var nmsp = plcnm.split(",");
    radio.options.length = 0;
    radio.options.length = nosp.length + 1;
    radio.options[0].value = "0";
    radio.options[0].text = "";

    var j = 1;
    if(nosp) {
        for (i = 0; i < nosp.length; i++) {
            radio.options[j].value = nosp[i];
            radio.options[j].text = nmsp[i];
            j++;
        }
    }
}

//地域リストの動的変更
function regionalListGen(opn, plcno, plcnm) {
    var nosp = plcno.split(",");
    var nmsp = plcnm.split(",");
    opn.options.length = nosp.length;

    if(nosp) {
        for (i = 0; i < nosp.length; i++) {
            opn.options[i].value = nosp[i];
            opn.options[i].text = nmsp[i];
        }
    }
}

// ポップアップ
var sPop;
function openPop(url){
    sPop = window.open(url,"OpenPop","scrollbars=no,width=920,height=530");
    sPop.focus();
}
function closePop(){
    if (sPop){
        sPop.close();
    }
}

