/*####################################################################################
 * カレンダー画面から日付選択用のコンポーネント
######################################################################################
# 休日付きカレンダー(Version:はやて1.0.0)
# param theYear :"1980-2099"の数値
# param theMonth:"1-12"の数値
# param theDay  :"1-31"の数値
# param callbackScript :コールバックファンクション名
Version 1.1.0：年のスクロール追加操作及びタイトル行の表示
Version 1.1.1：メソッドの完全内部化
Version 1.1.2：海の日および敬老の日の対応
Version 2.0.0: 神戸市交通局向けカスタマイズ
               イントラと違う部分　1.選択範囲が　先月〜来月
                                   2.「カレンダーを隠す」リンクがある(子WindowClose)
Version 3.0.9:駅すぱあとにアクセスし非同期で該当する１年分の祝日を取得し、
              描画クラスの祝日データを書き換える
#####################################################################################*/
function Calendar(){
    if(typeof(util)=="undefined") util=new ExpUtil();
	var url=this.getExpwwwUrl();
	if(url.search(/\?/)<0) url+="?";else 
	if(url.substr(url.length-1,1)!="&") url+="&";
	this.URL=url+"val_callbackfuncname=setHoliday";
    this.expData = arguments[2];
    this.NOT_ERROR=false;
    this.dynamicLoading=false;
    this.className="Calendar";

    //-- 自身のインスタンスをグローバル化 --//
    Calendar.prototype.self=this;

    //-------------------------------------------------------//
    // 結果記録用変数
    //-------------------------------------------------------//
    this.theDate    = null;         // 日付オブジェクト
    this.intputObe  = null;         // 日付入力用inputTag
    this.lenguage   = 0;            // 言語コード(0：日本語、以外は英語)
    this.specCol    = "#FF0000";    // 休日の文字色
//    this.special    = new Array(3,21, 9,23, 1,1, 2,11, 4,29, 5,3, 5,4, 5,5, 11,3, 11,23, 12,23);
    this.special    = new Array(1,1);
    this.weekColor  = new Array(this.specCol,"#000000","#000000","#000000","#000000","#000000","#0000FF");
    this.year;                      // 表示中の年
    this.month;                     // 表示中の月
    this.weekDay;                   // 曜日＊メンバーズ変数の整理が必要になっている。
    this.date;                      // 選択中OR設定された日
    this.thisYear;                  // 処理対象の年
    this.thisMonth;                 // 処理対象の月
    this.fullDate;                  // フォーマットされた結果日付文字列
    this.format=".";                // フォーマット時使用するセパレータ
    this.IS_CHANGE_MONTH=true;      // 月変更フラグ？？
    this.fontSize="15px";
    this.wrtMonth= new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
    this.RESULT=false;

    //-------------------------------------------------------//
    // パラメータの確認
    this.init(arguments);

    //-------------------------------------------------------//
    // --- キャンパス作成 --- //
    //-------------------------------------------------------//
    this.win = new InnerWin("日付選択");
    this.win.setContent(this);
    this.win.appendChild(this.createHeadView());
    this.win.setHeight(320);
    this.win.setBgcolor("#efeff7");

    // --- 本日設定ボタン作成 --- //
    var a=document.createElement("A");
    a.href="#";
        var img=document.createElement("IMG");
        img.src="./img/app/btnCtrCalToday.gif";
        img.style.cssText="border:0;height:35px";
        a.appendChild(img);
        a.onclick=Calendar.setToday;
        a.onmouseover=Calendar.onmouseover;
        a.onmouseout = Calendar.onmouseout;
    this.win.appendChild(a);

/*
    // --- キャンセルボタン作成 --- //
    a=document.createElement("A");
    a.href="#";
    img=document.createElement("IMG");
    img.src="./img/app/btnCtrCalCancel.gif";
    img.style.cssText="border:0;height:35px";
    a.appendChild(img);
    a.onclick=Calendar.cancel;
    a.onmouseover=Calendar.onmouseover;
    a.onmouseout = Calendar.onmouseout;
    this.win.appendChild(a);
*/
    a.appendChild(document.createElement("BR"));
    a.appendChild(document.createElement("BR"));

    var close_link=document.createElement("A");
    close_link.appendChild(document.createTextNode("カレンダーを隠す"));
    close_link.href="javascript:InnerWin.close()";
    this.win.appendChild(close_link);

    this.lineList=new Array(5);
    // --- 日付表示行作成 --- //
    for(var i = 0;i < 6;i++) {
        this.table.appendChild(this.lineList[i]=this.createLine(i));
    }
    // --- 日付データ表示作成 --- //
//    this.writeContes();
    // --- 処理登録 --- //
    this.setHeight = function(height) {
        this.win.setHeight(height);
    }
    this.setWidth = function(width) {
        this.win.setWidth(width);
    }
    this.setLeft = function(left) {
        this.win.setLeft(left);
    }
    this.setTop = function(top) {
        this.win.setTop(top);
    }
    this.setPoint = function(left,top) {
        this.win.setPoint(left, top);
    }

    this.loadingYear=arguments[0].substring(0,4);
    this.dynamicLoad(this.loadingYear);						// 祝日セット

    if(Calendar.prototype.self){
        // 表示されている場合は閉じる
        if(Calendar.prototype.self.IS_OPENING){
//            Calendar.prototype.self.close(true);
            if (typeof(this.expData) != "undefined") {
                this.expData.fireCancelSearchType(this.expData.getSearchType());
            }
            InnerWin.close();
        }else{
            Calendar.prototype.self.init(arguments);
            Calendar.prototype.self.open();
//            Calendar.prototype.self.writeContes();
        }
////////        return;
    }
}

Calendar.prototype.getExpwwwUrl = function() {
    return expwwwURL;
}

Calendar.prototype.dynamicLoad = function(year) {
    util.dynamicLoad(this.URL + '&val_holidayyear=' + year);
}

function setHoliday(holidayList){
    Calendar.prototype.self.setHoliday(holidayList);
}
Calendar.prototype.setHoliday=function(holidayList){
	// 正常処理の確認
	if(holidayList.status!=0){
		alert("駅名取得時に下記のエラー発生しています。\n" + holidayList.errMsg);
		return;
	}
	// 各種結果の取得
	var holiday = holidayList.holiday;
	this.special = holiday;
	if (!this.dynamicLoading) {
        this.dynamicLoading = true;
	    Calendar.prototype.self.open();
	}
}
Calendar.prototype.setMoveAble = function(moveAble) {
    this.win.setMoveAble(moveAble);
}

Calendar.prototype.init = function(arguments) {
    this.NOT_ERROR=this.checkParams(arguments[0]);
    if (!this.NOT_ERROR) {
        this.theDate = new Date();
        this.year =this.theDate.getFullYear();
        this.month=this.theDate.getMonth()+1;
        this.date =this.theDate.getDate();
        this.NOT_ERROR=true;
//        status="gave [Calendar()] a bade paramater!";
    }
    this.thisYear  = this.year;
    this.thisMonth = this.month;
    
    // 2.ｺｰﾙﾊﾞｯｸ関数名の取得・確認
    if (!this.NOT_ERROR || arguments[1]==null || arguments[1].length==0){
        this.NOT_ERROR=false;
//        status="gave [Calendar] a bade paramater! call back script was not input";
        return;
    }

    Calendar.script=arguments[1];
    this.theDate=(this.theDate==null)? new Date(this.year, this.month, this.date) : this.theDate;
    // 3.表示言語の取得・表示文字を設定
    this.lenguage=(arguments.length>2&&typeof(arguments[2])=="number")?arguments[2]:0;
    this.separator=(this.lenguage==0)?new Array("年","月") : new Array("/","");
    this.weekStr  =(this.lenguage==0)?new Array("日","月","火","水","木","金","土") : new Array("SU","MO","TU","WE","TH","FR","SR");

    // 4.休日リストの取得・確認
    if (arguments.length==4 && typeof(arguments[3])=="object" && arguments[3].length>=0){
        this.special = arguments[3];
        this.IS_SPECIAL_CHANGED=true;
    }else{
        if (arguments[4]=="ADD" && typeof(arguments[3])=="object" && arguments[3].length>0){
            this.special=this.special.concat(arguments[3]);
        }
    }
}

Calendar.prototype.open = function() {
    if (this.dynamicLoading) {
        this.IS_OPENING=true;
        this.win.open(this);
        this.writeContes();
        // 非表示にされた月切替えボタンの復旧
        if(this.monthElement){
            if(this.canBackMonth() && this.canGoMonth()){
                this.monthElement.style.display="";
                this.monthElement=null;
            }
        }
    }
}

Calendar.prototype.close = function() {
    this.IS_OPENING=false;
//    this.expData.fireCancelSearchType(this.expData.getSearchType());
    this.win.close();
}
/***********************************************************
 * 子ウィンド閉じる場合はコンテナのInnerWinからコールバック
 * されるメソッドでリタン値はTRUEの場合はが面の閉じる処理が
 * スキップされ、その対応は必要に応じて講じるべきです。
 ************************************************************/
Calendar.prototype.fireClose = function(is_cancel,key){
    this.IS_OPENING=false;
    if (typeof(is_cancel) == "undefined") {
        if(Calendar.script && typeof(Calendar.script) == "function") {
            Calendar.script();
        }
    }
    if (typeof(this.expData) != "undefined" && typeof(key) != "undefined") {
        this.expData.fireCancelSearchType(this.expData.getSearchType());
    }
    return false;
}

Calendar.prototype.setFontSize = function(fontSize){
    this.fontSize=fontSize;
}

/**********************************************
 * クラス初期化パラメータの確認
 * 初期化対象メンバー変数：
 * 1.theDate    ：日付オブジェクト
 * 2.year        ：日付の年部(数値)
 * 3.month        ：日付の月部(数値)
 * 4.date        ：日付の日部(数値)
 **********************************************/
Calendar.prototype.checkParams = function(){
    if(arguments.length==0) {
        return false;
    }
    if (typeof(arguments[0])=="object") {
        if(arguments[0].getDate == new Date().getDate){
            this.theDate = arguments[0];
            this.year  = this.theDate.getFullYear();
            this.month = this.theDate.getMonth()+1;
            this.date  = this.theDate.getDate();
            return true;
        } else {
            if(arguments[0].tagName=="INPUT"&&arguments[0].type=="TEXT"){
                this.intputObe = arguments[0];
               arguments[0] = arguments[0].value;
            }else{
                this.ErrMsg="最初のパラメータには「Calendar」の対応できないObjectが渡されています。";
                return false;
            }
        }
    }
   
    arguments[0]= arguments[0]+"";
    while(arguments[0].indexOf(" ",0) > -1) {
        arguments[0]=arguments[0].replace(/ /, "");
    }
    var params;
    if(arguments[0].length < 6) {
        this.ErrMsg="最初のパラメータには「Calendar」の対応できない桁数の日付が渡されています。";
        return false;
    }

    if(arguments[0].indexOf(".", 0) > 1 || arguments[0].indexOf("/", 0) > 1 || arguments[0].indexOf("年", 0) > 1){
        if(!this.initDate(arguments[0])) {
            return false;
        }
    } else if(arguments[0].length == 6) {    //YYYYMD
        this.year = arguments[0].substring(0,4);
        this.month= arguments[0].substring(4,5);
        this.date = arguments[0].substring(5,6);
    } else if(arguments[0].length == 7){    // YYYYMMD
        this.year = arguments[0].substring(0,4);
        this.month= arguments[0].substring(4,6);
        this.date = arguments[0].substring(6,7);
    } else if(arguments[0].length == 8){    // YYYYMMDD
        this.year = arguments[0].substring(0,4);
        this.month= arguments[0].substring(4,6);
        this.date = arguments[0].substring(6,8);
    }
    if(this.year == null || this.month == null || this.date == null) {
        return false;
    }
    if(!isFinite(this.year) || !isFinite(this.month) || !isFinite(this.date)) {
        return false;
    }
    
    this.year = eval(this.year);
    this.month= eval(this.month);
    this.date = eval(this.date);

    if((this.year+"").length != 4 || (this.month <= 0 && this.month > 12) || (this.date <= 0 && this.date > 31) ) {
        return false;
    }
    var d = new Date(this.year, this.month-1, this.date);
    if(this.year != d.getFullYear() || this.month != d.getMonth() + 1 || this.date != d.getDate()) {
        return false;
    }
    return true;
}

/**********************************************
 * 初期化パラメータフォーマットされた日付を解析
 **********************************************/
Calendar.prototype.initDate = function(date) {
    var params=date.split(".");
    if (params.length==3) {    // YYYY.#9.#9
        this.year = params[0];
        this.month= params[1];
        this.date = params[2];
        this.format=".";
    } else {
        params=date.split("/");
        if (params.length == 3) {    // YYYY/#9/#9
            this.year = params[0];
            this.month= params[1];
            this.date = params[2];
            this.format="/";
        } else {    // YYYY年#9月#9日
            params = date.split("年");
            if(params.length!=2) return false;
            this.year = params[0];
            params = params[1].split("月");
            if(params.length!=2) return false;
            this.month= params[0];
            this.date = params[1].split("日")[0];
            this.format="年";
        }
    }
    return true;
}

/*####################################################################################
# 「画面表示関連の処理」
# createHeadView    ：カレンダー上部２行固定部分の作成
# createLine        ：カレンダーの日付表示行を作成
# writeContes        ：カレンダー上日付データ表示
# 
#####################################################################################*/

/**********************************************
 * カレンダー上部２行固定部分の作成
 **********************************************/
Calendar.prototype.createHeadView=function(){
    var Table, table, Tbody, tbody, tr, td, a, img;
    Table=document.createElement("TABLE");
    Table.style.cssText="FONT-SIZE:"+this.fontSize+";table-layout:fixed;margin:8px 4px 0px 4px;"; 
    table=Table;
    table.cellSpacing="1";
    table.cellPadding="0";
    table.align="center";
    table.border="0";
    table.style.backgroundColor="#000000";
    table.appendChild(Tbody=tbody=document.createElement("TBODY"));
    tbody.appendChild(tr=document.createElement("TR"));
    tr.align="center"; tr.valign="middle";
    tr.appendChild(td=document.createElement("TD"));
    td.colSpan="7";
    td.appendChild(table=document.createElement("TABLE"));
    table.style.backgroundColor="white";
    table.style.width="100%";
    table.appendChild(tbody=document.createElement("TBODY"));
    tbody.appendChild(tr=document.createElement("TR"));

    // --- 表示月ダウンボタン --- //
    tr.appendChild(td=document.createElement("TH")); 
    td.bgColor="white";
    td.width="20%";
    a=document.createElement("A");
    a.href="#";
    img=document.createElement("IMG");
    img.src="./img/app/btnCtrCalDec.gif";
    img.width= img.height="18";
    img.style.border=0;
    a.appendChild(img);
    a.onmouseover=Calendar.onmouseover;
    a.onmouseout=Calendar.onmouseout;
    a.onclick=Calendar.decMonth;
    if(!this.canBackMonth()) {
        a.style.display="none";
        this.monthElement = a;
    }
    td.appendChild(a);
    // --- 年月表示 --- //
    tr.appendChild(td=document.createElement("TH")); td.bgColor="white";
    td.style.cssText="FONT-SIZE:"+this.fontSize+"; width:60%"; 
    this.yyyymmView=td;
    td.appendChild(document.createTextNode(this.year + this.separator[0] + this.month + this.separator[1]));
    td.noWrap=true;
    // --- 表示月アップボタン --- //
    tr.appendChild(td=document.createElement("TH"));
    td.bgColor="white";
    td.width="20%";
    a=document.createElement("A");
    a.href="#";
    img=document.createElement("IMG");
    img.src="./img/app/btnCtrCalAdd.gif";
    img.width= img.height="18";
    img.style.border=0;
    a.appendChild(img);
    a.onmouseover=Calendar.onmouseover;
    a.onmouseout=Calendar.onmouseout;
    a.onclick=Calendar.addMonth;
    if(!this.canGoMonth()) {
        a.style.display="none";
        this.monthElement = a;
    }
    td.appendChild(a);
    Tbody.appendChild(tr=document.createElement("TR"));
    tr.align="center"; tr.valign="middle";
    tr.style.cssText="FONT-SIZE:"+this.fontSize+";";
    tr.style.backgroundColor="white";
    var thList=new Array("日","月","火","水","木","金","土");
    for(var i = 0;i < thList.length;i++){
        tr.appendChild(td=document.createElement("TH"));
        td.style.width="35px";
        td.appendChild(document.createTextNode(thList[i]));
        if(i==0) {
            td.style.color="#FF0000";
        } else {
            if(i==6) {
                td.style.color="#0000FF";
            }
        }
    }
    this.table=Tbody;
    return Table;
}

/**********************************************
 * カレンダーの日付表示行を作成
 **********************************************/
Calendar.prototype.createLine = function(no) {
    var tr, td;
    tr=document.createElement("TR");
    tr.align="center"; tr.valign="middle";
    tr.style.display="none";
    for (var i = 0;i < 7;i++) {
        tr.appendChild(td=document.createElement("TD"));
        td.style.backgroundColor="white";
        td.appendChild(document.createElement("BR"));
    }
    return tr;
}

/**********************************************
 * カレンダー上日付データ表示
 **********************************************/
Calendar.prototype.writeContes = function(){
    // --- 日付行を非表示に --- //
    for(var i = 0;i < this.lineList.length;i++) {
        this.lineList[i].style.display="none";
    }
    this.IS_CHANGE_MONTH=true;
    var date_W=this.theDate.getDate();
    this.theDate = new Date(this.year, this.month-1, 1);
    this.year    = this.theDate.getFullYear()
    this.month   = this.theDate.getMonth()+1;

    if(this.thisMonth==null) {
        this.thisMonth=this.month;
    }
    if(this.thisYear==null) {
        this.thisYear=this.year;
    }
    var count = this.theDate.getDay();
    
    if(((this.year % 4==0) && (this.year % 100!=0)) || (this.year % 400==0)) {
        this.wrtMonth[2]=29;
    } else {
        this.wrtMonth[2]=28;
    }
    var nisuu=this.wrtMonth[this.month];
    var wkCnt = ((count+nisuu) % 7>0) ? Math.floor((count+nisuu) / 7) + 1 : Math.floor((count+nisuu) / 7);
/*    
    if(!this.IS_SPECIAL_CHANGE && this.month == 3){
        this.special[1] = Math.floor(20.8431 + 0.242194 * (this.year - 1980) - Math.floor((this.year - 1980) / 4));
    }else{
        this.special[3] = Math.floor(23.2488 + 0.242194 * (this.year - 1980) - Math.floor((this.year - 1980) / 4));
    }
*/
    var day, color, bgColor,wrt, textNode;
    var monthTable = new Array(32);
    for (var i = 0;i < this.special.length / 2;i++) {
        if(this.special[i * 2] == (this.month)) {
            monthTable[this.special[i * 2 + 1]] = this.specCol;
        }
    }

    for(var i=0;i<wkCnt;i++){
        var tr=this.lineList[i];
            tr.style.display="";
        var td=tr.firstChild;
        for(var j=0;j<7;j++){
            if(td.firstChild) td.removeChild(td.firstChild);
            day=i*7+j-count+1;
            if(day < 1 || day > nisuu){
                td.style.backgroundColor="#D3D3D3";
                td.appendChild(document.createElement("BR"));
                td.style.cursor="default";
                td.onClick = "";
                td=td.nextSibling;
                if(!td) {
                    continue;
                }
            } else {
                bgColor = (eval(this.year) == eval(this.thisYear) && eval(this.month) == eval(this.thisMonth) && eval(this.date) == eval(day))? "yellow" : "white";
                color=this.weekColor[j];

                if(monthTable[day] != null || (monthTable[day-1] != null && j == 1)) {
                    color=this.specCol;
                }

//                if (j==1 && (((day > 7  && day < 15) && (this.month == 1 || this.month == 10)) || ((day > 15 && day < 22) && (this.month == 9 || this.month == 7)))) {
//                    color=this.specCol;
//                }

                td.style.backgroundColor=bgColor;
                td.style.color=color;
                td.style.cursor="pointer";
                util.addEvent(td, this, "selected","onclick" );
                td.appendChild(document.createTextNode(day));
                td=td.nextSibling;
            }
        }
    }
    this.yyyymmView.innerHTML=this.year + this.separator[0] + this.month + this.separator[1];
    this.IS_CHANGE_MONTH=false;
}

/***********************************************
 * クロージャ対応用処理
 ***********************************************/
Calendar.getImgName=function(element){
    var imageSrcString;
    var imageSrcPath;
    var imageName;
    imageSrcString = element.src;
    imageSrcPath   = imageSrcString.substring(0,(imageSrcString.lastIndexOf("/")));
    imageName      = imageSrcString.substring(imageSrcString.lastIndexOf("/"),imageSrcString.length).replace(/Over/i, "").replace(/.gif/i, "");
    return imageSrcPath + imageName;
//    return src.replace(/Over/i, "").replace(/.gif/i, "");
}

Calendar.onmouseover = function(event){
    var element=(document.all)? window.event.srcElement : event.target;
    var imgName = Calendar.getImgName(element);
    element.src=imgName+"Over.gif";
}

Calendar.onmouseout = function(event){
    var element=(document.all)? window.event.srcElement : event.target;
    var imgName = Calendar.getImgName(element);
    element.src=imgName+".gif";
}

Calendar.addMonth=function(event){
    Calendar.prototype.self.changeMonth(1, event);
    if (this.dynamicLoading) {
        this.writeContes();
    }
}

Calendar.decMonth=function(event){
    Calendar.prototype.self.changeMonth(-1, event);
    if (this.dynamicLoading) {
        this.writeContes();
    }
}

//例外？//
Calendar.cancel = function(){
    this.IS_OPENING=false;
    InnerWin.close();
}
/**********************************************
 * 本日設定表示
 **********************************************/
Calendar.setToday = function(){Calendar.prototype.self.setToday();}
Calendar.prototype.setToday = function(){
    this.theDate = new Date();
    this.year =this.theDate.getFullYear();
    this.month=this.theDate.getMonth()+1;
    this.date =this.theDate.getDate();
    this.RESULT=true;
    this.weekDay=this.weekStr[new Date(this.year, this.month-1, this.date).getDay()];
    var format = new Array(this.format, this.format, "");
    
    if(format[0] == "年" && format[1] != "月") {
        format = new Array("年","月","日");
    }
    
    this.fullDate=this.year + format[0] + ((this.month<10)? ("0"+this.month+"") : this.month) + format[1] +  ((this.date<10)? ("0"+this.date+"") : this.date) + format[2];
    this.IS_CHANGE_MONTH=false;
    if(Calendar.script && typeof(Calendar.script)=="function") {
        Calendar.script(Calendar.prototype.self);
        //new Function("hander", this.script+"(hander);")(this);
    }
    if (typeof(this.expData) != "undefined") {
        this.expData.fireCancelSearchType(this.expData.getSearchType());
    }
    this.close();
}
/*####################################################################################
# 「画面操作関連の処理」
# changeYear        ：表示対象年の変更+-1
# changeMonth        ：表示対象月の変更+-1
# 
#####################################################################################*/

/**********************************************
 * 表示対象年の変更+-1
 **********************************************/
Calendar.prototype.changeYear = function(){
    this.year=this.year+arguments[0];
    this.writeContes();
//    this.yyyymmView.innerHTML=this.year + this.separator[0] + this.month + this.separator[1];
}

/**********************************************
 * 表示対象月の変更+-1
 **********************************************/
Calendar.prototype.changeMonth=function(m, event){
    var month=(m<0)? 1:12; // 基準設定
    if(this.month==month){
        this.month=(month==1)?12:1;
        this.year=this.year+m;
        this.dynamicLoading = false;
        this.dynamicLoad(this.year);
    } else {
        this.month=this.month+m;
    }
    
    if (this.dynamicLoading) {
        this.writeContes();
    }
//    this.yyyymmView.innerHTML=this.year + this.separator[0] + this.month + this.separator[1];

    if(this.monthElement){
        this.monthElement.style.display="";
        this.monthElement=null;
    }

    // --- 表示範囲(3年間)の設定
    event = (document.all)? window.event:event;
    var element=(document.all)? event.srcElement : event.target; // 上の「element」ほんとに参照できる  ??
    if(element.tagName!="A"){
        element=element.parentNode;
    }
    
    if(!this.canBackMonth() || !this.canGoMonth()){
        element.style.display="none";
        this.monthElement=element;
    }
/*
    if(this.month == 12 || this.month == 1){
        var thisYear = new Date().getFullYear(); // 今年
        if(this.month == 12 && this.year>thisYear){
            this.monthElement=element;
            element.style.display="none";
        } else if(this.month == 1 && this.year<thisYear) {
            element.style.display="none";
            this.monthElement=element;
        }
    }
*/
}

Calendar.prototype.canBackMonth=function(){
/* デフォルトでは前年→来年まで表示する　ここからコメント
    if(this.month == 1){
        var thisYear = new Date().getFullYear(); // 今年
        if(this.year < thisYear) {
            return false;
        }
    }
    return true;
   デフォルトでは前年→来年まで表示する　ここまでコメント */
/* 神戸市交通局では前月→来月まで表示する　ここから修正 */
    var today = new Date();
    var thisYearMonth = '' + today.getFullYear() + ('0' + (today.getMonth() + 1)).substr(-2);
    var selectedYearMonth = '' + this.year + ('0' + this.month).substr(-2);

    if(selectedYearMonth >= thisYearMonth){
        return true;
    }else{
        return false;
    }
/* 神戸市交通局では前月→来月まで表示する　ここまで修正 */
}

Calendar.prototype.canGoMonth=function(){
/* デフォルトでは前年→来年まで表示する　ここからコメント
    if(this.month == 12){
        var thisYear = new Date().getFullYear(); // 今年
        if(this.year > thisYear){
            return false;
        }
    }
    return true;
   デフォルトでは前年→来年まで表示する　ここまでコメント */
/* 神戸市交通局では前月→来月まで表示する　ここから修正 */
    var today = new Date();
    var thisYearMonth = '' + today.getFullYear() + ('0' + (today.getMonth() + 1)).substr(-2);
    var selectedYearMonth = '' + this.year + ('0' + this.month).substr(-2);

    if(selectedYearMonth <= thisYearMonth){
        return true;
    }else{
        return false;
    }
/* 神戸市交通局では前月→来月まで表示する　ここまで修正 */
}


/**********************************************
 * 選択した日付取得
 **********************************************/
Calendar.prototype.selected = function(event){
    // IE：event.srcElement
    // NN：event.target
    var value = (document.all)? event.srcElement.innerText : event.target.innerHTML;
    if(value=="<B>" || value.length==0) return;
    this.RESULT=true;
    this.date=value;
    this.weekDay=this.weekStr[new Date(this.year, this.month-1, this.date).getDay()];
    var format = new Array(this.format, this.format, "");
    if(format[0]=="年" && format[1]!="月") {
        format = new Array("年","月","日");
    }
    this.fullDate=this.year + format[0] + ((this.month<10)? ("0"+this.month+"") : this.month) + format[1] +  ((this.date<10)? ("0"+this.date+"") : this.date) + format[2];
    this.IS_CHANGE_MONTH=false;
    if(Calendar.script && typeof(Calendar.script)=="function") {
        Calendar.script(Calendar.prototype.self);
    }
    if (typeof(this.expData) != "undefined") {
        this.expData.fireCancelSearchType(this.expData.getSearchType());
    }
//    if (typeof(setTimeSelectBox) == "function") {
//        setTimeSelectBox(false);
//    }
    this.close();
}

/**********************************************
 * 結果を指定された形帰す処理
 **********************************************/
Calendar.prototype.getValue = function(){
    if(!this.RESULT)  return null;
    var format = (arguments.length>0)? arguments[0] : "";
    var length=format.length;
    if(length==0) return this.fullDate;
    var Y="", M="", D="";
    var params = arguments[0].split("年");
    if(params.length==2){
        Y = params[0];
        params = params[1].split("月");
        if(params.length==2){
            M= params[0];
            if(params[1].indexOf("日") >0){
                D = params[1].substring(0,params[1].length-1);
                format = new Array("年","月","日");
            } else {
                format = new Array("年","月");
            }
        }
    }else{
        params = arguments[0].split(".");
        if(params.length==3){
            format = new Array(".",".","");
        } else {
            params = arguments[0].split("/");
            if(params.length==3) format = new Array("/","/","");
        }
        if(params.length==3){
            Y = params[0];
            M = params[1];
            D = params[2];
        }
    }
    if(Y!="9999" || (M!="99"&&M!="#9"&&M!=" 9") || (D!="99"&&D!="#9"&&D!=" 9")) {
        return this.fullDate;
    }
    
    Y = this.year;
    M = (M=="99"&&this.month<10)? "0" + this.month : ((M==" 9"&&this.month<10)? " " + this.month : this.month);
    D = (D=="99"&&this.date<10)? "0" + this.date : ((D==" 9"&&this.date<10)? " " + this.date : this.date);
    this.IS_CHANGE_MONTH=false;
    Calendar.win=null;
    
    if(format.toString()=="年,月") {
        return (Y + format[0] + M + format[1]);
    }
    return (Y + format[0] + M + format[1] + D + format[2]);
}

/**********************************************
 * エラー発生したかを確認する処理
 **********************************************/
Calendar.prototype.getResult = function(){
    return (this.NOT_ERROR && this.RESULT);
}

