page_onload(function(){
Lecture("now","1");
});
function Lecture(mode,page){
Loading();
if(typeof(LecData)=="undefined"){
LecData=TSVtoArray(ajax.get("data/lecture.tsv"));
}
var Limit=3;
var Data=new Array();
var MonthArray=new Array();
var temp_now=DateFormat();
if(mode=="now"){
for(var i=0;i<LecData.length;i++){
var temp_date=DateFormat(LecData[i][0]);
if(DateCompareAB(temp_date,temp_now)=="a"){
MonthArray.push(temp_date.y+"-"+temp_date.m);
Data.push(LecData[i]);
}
}
}else{
for(var i=0;i<LecData.length;i++){
var temp_date=DateFormat(LecData[i][0]);
if(DateCompareAB(temp_date,temp_now)=="b"){
MonthArray.push(temp_date.y+"-"+temp_date.m);
Data.push(LecData[i]);
}
}
Data.reverse();
}
var MonthCnt=ArrayUnique(MonthArray);
var PageCnt=Math.ceil(MonthCnt/Limit);
if(mode=="now"){
var mode_html= '<div class="mode"><a href="javascript:Lecture(\'past\',1)">▲ 以前の講演会</a></div>';
}else{
var mode_html= '<div class="mode"><a href="javascript:Lecture(\'now\',1)">▲ 今後の講演会</a></div>';
}
if(Data.length>0){
if(mode=="past"&&PageCnt>1){
$("page").style.display="block";
if(page!=1){
var page_html='ページ <a href="javascript:Lecture(\''+mode+'\','+(page-1)+')"><img src="images/icon_left.gif" alt="前のページ" width="14" height="14" /></a>［&nbsp;';
}else{
var page_html='ページ <img src="images/d.gif" alt="" width="14" height="14" />［&nbsp;';
}
for(i=1;i<=PageCnt;i++){
if(i==page){
page_html+='<a href="javascript:Lecture(\''+mode+'\','+i+')"><em>'+i+'</em></a>&nbsp;';
}else{
page_html+='<a href="javascript:Lecture(\''+mode+'\','+i+')">'+i+'</a>&nbsp;';
}
}
if(page<PageCnt){
page_html+='] <a href="javascript:Lecture(\''+mode+'\','+(page+1)+')"><img src="images/icon_right.gif" alt="次のページ" width="14" height="14" /></a></div>';
}else{
page_html+='］<img src="images/d.gif" alt="" width="14" height="14" /></div>';
}
}else{
var page_html="";
$("page").style.display="none";
}
var icon = '<img src="images/icon_pdf_s.gif" height="17" width="17" />';
var table_html="";
var table_head_html  = '<table cellspacing="0" cellpadding="0"><colgroup><col width="65" /><col width="70" /><col width="35" /><col width="580" /></colgroup><thead><tr><td>開催日</td><td>開催地</td><td>詳細</td><td>講演会名</td></tr></thead><tbody>';
var table_foot_html =  '</tbody></table>';
var mc=1;
var mc_flag=0;
var pc_s=page*Limit-2;
if(mode=="past"){
var pc_e=page*Limit;
}else{
var pc_e=1000;
}
var first_cnt=0;
for(var i=0;i<Data.length;i++){
var p_date=DateFormat(Data[i][0]);
if(Data[i+1]){
var n=DateFormat(Data[i+1][0]);
if(p_date.y+"-"+p_date.m != n.y+"-"+n.m){
mc_flag=1;
}
}else{
mc_flag=1;
}
if(mc>=pc_s&&mc<=pc_e){
if(first_cnt==0){
table_html+='<h2> 【 '+p_date.y+'年 '+p_date.m+'月 】</h2>';
table_html+=table_head_html;
first_cnt++;
}
table_html+='<tr><td>'+p_date.m+'月'+p_date.d+'日</td><td>'+Data[i][1]+'</td><td><a href="'+Data[i][3]+'">'+icon+'</a></td><td>'+Data[i][2]+'</td></tr>';
}
if(mc_flag==1){
if(mc>=pc_s&&mc<pc_e){
if(i==Data.length-1){
table_html+=table_foot_html;
}else{
table_html+=table_foot_html;
table_html+='<h2> 【 '+n.y+'年 '+n.m+'月 】</h2>';
table_html+=table_head_html;
}
}else if(mc==pc_e){
table_html+=table_foot_html;
break;
}
mc++;
mc_flag=0;
}
}
$("page").innerHTML = page_html;
$("mode").innerHTML = mode_html;
$("res").innerHTML = table_html;
OpenNew();
}else{
$("page").innerHTML = "";
$("mode").innerHTML = mode_html;
$("res").innerHTML = '<div id="loading">データがありません。</div>';
}
function ArrayUnique(a){
var _a=new Array();
for(var i=0;i<a.length;i++){
if(_a.length>0){
var f=0;
for(var j=0;j<_a.length;j++){
if(a[i]==_a[j]) f++;
}
if(f==0) _a.push(a[i]);
}else{
_a.push(a[i]);
}
}
return _a.length;
}
function DateFormat(_d){
if(_d){
var _a=_d.split("/");
return {y:parseInt(_a[0]),m:parseInt(_a[1]),d:parseInt(_a[2])};
}else{
var _d=new Date();
return {y:parseInt(_d.getFullYear()),m:parseInt(_d.getMonth()+1),d:parseInt(_d.getDate())};
}
}
function DateCompareAB(a,b){
if(a.y>b.y){
return "a";
}else if(a.y==b.y){
if(a.m>b.m){
return "a";
}else if(a.m==b.m){
if(a.d>=b.d){
return "a";
}else{
return "b";
}
}else{
return "b";
}
}else{
return "b";
}
}
function Loading(){
$("res").innerHTML = '<div id="loading">データ読み込み中.....</div>';
}
}