var CalenderFileName ='homepage/js/yasumi.txt';	//カレンダー用テキストファイル

//btowといっしょに呼び出す場合には重複するので不要
//function createHttpRequest(){// XMLファイルを開くための関数
//	if(window.ActiveXObject){
//		try{
//			return new ActiveXobject("Msxml2.XMLHTTP")
//		}catch(e){
//			try{
//				return new ActiveXObject("Microsoft.XMLHTTP")
//			}catch(e2){
//				return null;
//			}
//		}
//	}else if(window.XMLHttpRequest){
//		return new XMLHttpRequest();
//	}else{
//		return null;
//	}
//}

//"以下カレンダー
function carender(){
 var myDate=new Date();
 var y=myDate.getFullYear();
 var m=myDate.getMonth()+1;
 var d = myDate.getDate();
 //以下monthの処理、当月と翌月を２ケタ表示に修正する
 if(m==12){
  var nm=1;
  var ny=y+1;
 }else{
  var nm=m+1;
  var ny=y;
 }
 m='0'+m;
 nm='0'+nm;
 var lng=m.length;
 m=m.substr(lng-2,2);
 var nlng=nm.length;
 nm=nm.substr(nlng-2,2);
 var kc='01'+y+m;//01YYYYMM(今月)の文字列作成
 var kcn='01'+ny+nm;//01YYYYMM(来月)の文字列作成
 var mc='02'+y+m;//02YYYYMM(今月)の文字列作成
 var mcn='02'+ny+nm;//02YYYYMM(今月)の文字列作成
 var diva = document.createElement('div');
 var divb = document.createElement('div');
 var httpobj = createHttpRequest(); //検索対象のファイルを開く
 httpobj.open("GET",CalenderFileName,true);
 httpobj.onreadystatechange = function(){
 if (httpobj.readyState==4){
	if(httpobj.status == 200||httpobj.status == 0){
		var csvdoc = httpobj.responseText;
		var lines = csvdoc.split('\n');
		for (var j = 0; j < lines.length; j++) {//以下条件分岐で、カレンダーテキストより該当行を取得
			if(lines[j].indexOf(kc)>=0){var kou_c=lines[j];}
			if(lines[j].indexOf(kcn)>=0){var kou_cn=lines[j];}
			if(lines[j].indexOf(mc)>=0){var min_c=lines[j];}
			if(lines[j].indexOf(mcn)>=0){var min_cn=lines[j];}
		}
		 diva.innerHTML='<h3 class="dark">野田市立興風図書館</h3>';
		if(kou_c){
			putCarend(diva,kou_c,d);
		}else{
			diva.innerHTML+='データがありません。<br><a href="OPP0100">お知らせ</a>よりご確認ください。<br>';
		}
		if(kou_cn){
			putCarend(diva,kou_cn,0);
		}
		divb.innerHTML='<h3 class="dark">他の野田市立図書館</h3>';
		if(min_c){
			putCarend(divb,min_c,d);
		}else{
			diva.innerHTML+='データがありません。<br><a href="OPP0100">お知らせ</a>よりご確認ください。<br>';
		}
		if(min_cn){
			putCarend(divb,min_cn,0);
		}
		var d = document.getElementById('calenda');
		d.innerHTML='<div style="padding-left:1em;"><span style="background-color:#f99;">日付</span>は休館日です。　<b>(日付)</b>は今日の日付です。</div>';
		d.appendChild(diva);
		d.appendChild(divb);
		if(navigator.appName == "Microsoft Internet Explorer"){
			diva.style.styleFloat='left';
			divb.style.styleFloat='left';
		}else{
			diva.style.cssFloat='left';
			divb.style.cssFloat='left';
		}
		diva.style.width='48%';
		divb.style.width='48%';
		diva.style.margin='0.2em';
		divb.style.margin='0.2em';
	}
 }
 }
 httpobj.send(null);
}
function putCarend(div,kou_c,da){//挿入div,開館カレンダー行,今日の日付(太字にするため）,を取得
 var w ='';
 for(var i=8;i<kou_c.length;i++){
 	if(da==(i-7)){
 		if(kou_c.charAt(i)=='o'){
 			w = w+'<td>(<b>'+(i-7)+'</b>)</td>';
 		}else if(kou_c.charAt(i)=='x'){
 			w = w+'<td style="background-color:#f99;">(<b>'+(i-7)+'</b>)</td>';
 		}
 	}else{
 		if(kou_c.charAt(i)=='o'){
 			w = w+'<td>'+(i-7)+'</td>';
 		}else if(kou_c.charAt(i)=='x'){
 			w = w+'<td style="background-color:#f99;">'+(i-7)+'</td>';
 		}
 	}
 	
 	if(kou_c.charAt(6)=='0'){//月が１ケタの時はif内、２桁のelseを行う
 		var d = new Date(kou_c.substr(2,4),kou_c.substr(7,1)-1,(i-7)).getDay();
 	}else{
 		var d = new Date(kou_c.substr(2,4),kou_c.substr(6,2)-1,(i-7)).getDay();
 	}
 	
 	if(d==6){
 		w=w+'</tr>';
 		if(i+1 != kou_c.length)w=w+'<tr align="center">';
 	}
 	if(i==8){
 		for(var k=0;k<d;k++){
 			w='<td> </td>'+w;
 		}
 	}
 }
 var w ='<tr align="center">'+w; 
 div.innerHTML +='<div style="text-align:center;">'+kou_c.substr(2,4)+'年'+kou_c.substr(6,2)+'月の休館日</div>';
 div.innerHTML +='<table border="1" width="100%"><tr style="background-color:#ccc;"><th style="color:#f66;">日</th><th>月</th><th>火</th><th>水</th><th>木</th><th>金</th><th style="color:#66f;">土</th></tr>' + w +'</table>';
}
//以下ログイン表示
function looksLogin(){
	var looksLoginObj = createHttpRequest(); //検索対象のファイルを開く
	looksLoginObj.open('GET','OPP0100',true);
	looksLoginObj.onreadystatechange = function(){
		if (looksLoginObj.readyState==4){
			var t = looksLoginObj.responseText;
			var d = document.getElementById('lookslogin');
			if(d&&t){
				d.innerHTML='<h2 style="text-align:left;">ログイン</h2>';
				d.style.fontSize='100%';
				if(t.indexOf("現在ログイン中です")>=0){
					d.innerHTML +='<div class="normalanc"><span style="color:#f00;">現在ログイン中。</span><br>ログアウトは<a href="OPP1000">利用状況</a>から</div>';
				}else{
					d.innerHTML +='<iframe src="https://www.library-noda.jp/login2.html" id= "loginframe" frameborder="0" scrolling="no" style="width:100%;" name="loginframe"><a href="login.html">標準ログイン</a>をご利用下さい。</iframe>';
				}
			}
		}
	}
	
    looksLoginObj.send(null);
}


