﻿// JavaScript Document
/*

for right column

*/
var mytime = new Date();
function IncludeFilesRight(elements,FileNames) {
    new Ajax.Request(FileNames + "?uid=" + mytime.getTime() , {
    method: 'get', onComplete: displayData });
    function displayData(responseHttpObj){
		var text = responseHttpObj.responseText;
		parseTextRight(elements,text);
    }
}


function parseTextRight(elements,text){
	var m = 3;
	var CR = String.fromCharCode(13); // 改行コード (CR)
	var LF = String.fromCharCode(10); // 改行コード (CR)
	lineData = text.split(LF);
	var bodyobj = '';
	var l = 0;
	for ( i=0; i<lineData.length; i++){
		if( l < m ){
			values = lineData[i].split(",");
			if(values.length > 1){
				var iconnum = values[0]
				var datedata = values[1];
				var bodydata = values[2];
				var linkdata = values[3];
				var targetdata = values[4];
				var dtvalue = datedata;
				if(iconnum == 1){
					icondata = ' <img src="/sils/jp/common/images/ico_news_01.gif" alt="一般の方へ" width="62" height="19" />';
				}else if(iconnum == 2){
					icondata = ' <img src="/sils/jp/common/images/ico_news_02.gif" alt="在学生の方へ" width="62" height="19" />';
				}else if(iconnum == 3){
					icondata = ' <img src="/sils/jp/common/images/ico_news_03.gif" alt="受験生の方へ" width="62" height="19" />';
				}else if(iconnum == 4){
					icondata = ' <img src="/sils/jp/common/images/ico_news_03.gif" alt="卒業生の方へ" width="62" height="19" />';
				}else{
					icondata = ' <img src="/sils/jp/common/images/spacer.gif" alt="" width="62" height="14" />';
		
				}
				var row = '<dl class="index-col-list-r clearfix">';
				row += '<dt>' + datedata + icondata + '</dt>';
				if(linkdata != ''){
					row += '<dd><a href="' + linkdata + '" target="' + targetdata + '">' + bodydata + '</a></dd>';
				}else{
					row += '<dd>' + bodydata + '</dd>';
				}
				row += '</dl>';
				
				bodyobj += row;
				l++;
			}
		}
	}
	$(elements).innerHTML = bodyobj;
	
}
/*

for index

*/
function IncludeFilesMulti(elements,FileNames) {
	len = FileNames.length;
	for( i = 0 ; i < len ; i++ ){
		new Ajax.Request(FileNames[i] + "?uid=" + mytime.getTime() , {
		method: 'get', onComplete: function (responseHttpObj){
			var text = responseHttpObj.responseText;
			parseTextMulti(elements,text);
			
		}
		});
		
	}
	
}
var maxlength = 6;
var data = "";
var len = 0;
var count = 0;
function parseTextMulti(elements,text){
	var CR = String.fromCharCode(13); // 改行コード (CR)
	var LF = String.fromCharCode(10); // 改行コード (CR)
	count++;
	data += text + LF;
	if(count == len ){
	lineData = data.split(LF);
	var bodyobj = '';
	var obj = new Array();
	for (var i=0; i<lineData.length; i++){
		values = lineData[i].split(",");
		
		if(values != ""){
			var arr = {
				iconnum:values[0] ,
				datedata:values[1],
				bodydata:values[2],
				linkdata:values[3],
				targetdata:values[4]
			};
		
			obj.push(arr);
		}
	}
	
	obj = asort(obj , "datedata");
	obj.reverse();
	for (var i=0; i<obj.length; i++){
		if(i < maxlength){
		var arr = obj[i];
		
		var dtvalue = arr["datedata"];
		if(arr["iconnum"] == 1){
			arr["iconnum"] = ' <img src="/sils/jp/common/images/ico_news_01.gif" alt="一般の方へ" width="62" height="19" />';
		}else if(arr["iconnum"] == 2){
			arr["iconnum"] = ' <img src="/sils/jp/common/images/ico_news_02.gif" alt="在学生の方へ" width="62" height="19" />';
		}else if(arr["iconnum"] == 3){
			arr["iconnum"] = ' <img src="/sils/jp/common/images/ico_news_03.gif" alt="受験生の方へ" width="62" height="19" />';
		}else if(arr["iconnum"] == 4){
			arr["iconnum"] = ' <img src="/sils/jp/common/images/ico_news_04.gif" alt="卒業生の方へ" width="62" height="19" />';
		}else{
			arr["iconnum"] = ' <img src="/sils/jp/common/images/spacer.gif" alt="" width="62" height="14" />';
	
		}
		var row = '<dl class="index-col-list clearfix">';
		row += '<dt>' + arr["datedata"] + arr["iconnum"] + '</dt>';
		if(arr["linkdata"] != ''){
			row += '<dd><a href="' + arr["linkdata"] + '" target="' + arr["targetdata"] + '">' + arr["bodydata"] + '</a></dd>';
		}else{
			row += '<dd>' + arr["bodydata"] + '</dd>';
		}
		row += '</dl>';
		
		bodyobj += row;
		}
	}
	$(elements).innerHTML = bodyobj;
	
	}
}
function asort( assoc , key ){
  assoc.sort ( function (b1, b2) { return b1[key] > b2[key] ? 1 : -1; } );
  return assoc;
}
/*


for index

*/
function IncludeFilesNews(elements,FileNames) {
	len = FileNames.length;
	for( i = 0 ; i < len ; i++ ){
		new Ajax.Request(FileNames[i] + "?uid=" + mytime.getTime()  , {
		method: 'get', onComplete: function (responseHttpObj){
			var text = responseHttpObj.responseText;
			parseTextNews(elements,text);
			
		}
		});
		
	}
	
}
var data = "";
var len;
var count = 0;
function parseTextNews(elements,text){
	var CR = String.fromCharCode(13); // 改行コード (CR)
	var LF = String.fromCharCode(10); // 改行コード (CR)
	count++;
	data += text + LF;
	if(count == len ){
	lineData = data.split(LF);
	var bodyobj = '';
	var obj = new Array();
	for (var i=0; i<lineData.length; i++){
		values = lineData[i].split(",");
		
		if(values != ""){
			var arr = {
				iconnum:values[0] ,
				datedata:values[1],
				bodydata:values[2],
				linkdata:values[3],
				targetdata:values[4]
			};
		
			obj.push(arr);
		}
	}
	
	obj = asort(obj , "datedata");
	obj.reverse();
	for (var i=0; i<obj.length; i++){
		var arr = obj[i];
		
		var dtvalue = arr["datedata"];
		if(arr["iconnum"] == 1){
			arr["iconnum"] = ' <img src="/sils/jp/common/images/ico_news_01.gif" alt="一般の方へ" width="62" height="19" />';
		}else if(arr["iconnum"] == 2){
			arr["iconnum"] = ' <img src="/sils/jp/common/images/ico_news_02.gif" alt="在学生の方へ" width="62" height="19" />';
		}else if(arr["iconnum"] == 3){
			arr["iconnum"] = ' <img src="/sils/jp/common/images/ico_news_03.gif" alt="受験生の方へ" width="62" height="19" />';
		}else if(arr["iconnum"] == 4){
			arr["iconnum"] = ' <img src="/sils/jp/common/images/ico_news_04.gif" alt="卒業生の方へ" width="62" height="19" />';
		}else{
			arr["iconnum"] = ' <img src="/sils/jp/common/images/spacer.gif" alt="" width="62" height="14" />';
	
		}
		var row = '<dl class="index-col-list clearfix">';
		row += '<dt>' + arr["iconnum"] + arr["datedata"] + '</dt>';
		if(arr["linkdata"] != ''){
			row += '<dd><a href="' + arr["linkdata"] + '" target="' + arr["targetdata"] + '">' + arr["bodydata"] + '</a></dd>';
		}else{
			row += '<dd>' + arr["bodydata"] + '</dd>';
		}
		row += '</dl>';
		
		bodyobj += row;
		}
	}
	$(elements).innerHTML = bodyobj;
	
}
function asort( assoc , key ){
  assoc.sort ( function (b1, b2) { return b1[key] > b2[key] ? 1 : -1; } );
  return assoc;
}
/*

for normal style

*/
function IncludeFiles(elements,FileNames) {
    new Ajax.Request(FileNames + "?uid=" + mytime.getTime() , {
    method: 'get', onComplete: displayData });
    function displayData(responseHttpObj){
		var text = responseHttpObj.responseText;
		parseText(elements,text);
    }
}

function parseText(elements,text){
	var CR = String.fromCharCode(13); // 改行コード (CR)
	var LF = String.fromCharCode(10); // 改行コード (CR)
	lineData = text.split(LF);
	var bodyobj = '';
	for (var i=0; i<lineData.length; i++){
		values = lineData[i].split(",");
		var iconnum = values[0]
		var datedata = values[1];
		var bodydata = values[2];
		var linkdata = values[3];
		var targetdata = values[4];
		var dtvalue = datedata;
		if(iconnum == 1){
			icondata = ' <img src="/sils/jp/common/images/ico_news_01.gif" alt="一般の方へ" width="62" height="19" />';
		}else if(iconnum == 2){
			icondata = ' <img src="/sils/jp/common/images/ico_news_02.gif" alt="在学生の方へ" width="62" height="19" />';
		}else if(iconnum == 3){
			icondata = ' <img src="/sils/jp/common/images/ico_news_03.gif" alt="受験生の方へ" width="62" height="19" />';
		}else if(iconnum == 4){
			icondata = ' <img src="/sils/jp/common/images/ico_news_04.gif" alt="卒業生の方へ" width="62" height="19" />';
		}else{
			icondata = ' <img src="/sils/jp/common/images/spacer.gif" alt="" width="62" height="14" />';

		}
		var row = '<dl class="index-col-list clearfix">';
		row += '<dt>' + datedata + icondata + '</dt>';
		if(linkdata != ''){
			row += '<dd><a href="' + linkdata + '" target="' + targetdata + '">' + bodydata + '</a></dd>';
		}else{
			row += '<dd>' + bodydata + '</dd>';
		}
		row += '</dl>';
		
		bodyobj += row;
	}
		$(elements).innerHTML = bodyobj;
	
}
/*

for archive

*/
function monthArchives(elements,FileNames) {
    new Ajax.Request(FileNames + "?uid=" + mytime.getTime() , {
    method: 'get', onComplete: displayData });
    function displayData(responseHttpObj){
		var text = responseHttpObj.responseText;
		parseTextMonthArchives(elements,text);
    }
}

function parseTextMonthArchives(elements,text){
	var CR = String.fromCharCode(13); // 改行コード (CR)
	var LF = String.fromCharCode(10); // 改行コード (CR)
	lineData = text.split(LF);

	var monArray = new Array();
	var monList = new Array();
	var bodyobj = ""
	for (var i=0; i<lineData.length; i++){
		values = lineData[i].split(",");
		var val = { 'date':values[1] , 'body':values[2] };
		if( values[0] in monArray){
			monArray[values[0]].push(val);
		}else{
			monArray[values[0]] = new Array();
			monArray[values[0]].push(val);
			
			monList.push(values[0]);
		}
	}

	var selector = '';
	selector += '<strong>Past News</strong>';
	selector += '<select onchange="jumpArchive(this)">';
	selector += '<option value="0">-----</option>';
	for (var i=0; i<monList.length; i++){
		var selectorrow = '';
		selectorrow += '<option value="' + monList[i] + '">' + monList[i] + '</option>';
		
		selector += selectorrow;
	}
	selector += '</select>';
	$('as').innerHTML = selector;


	var archivetext = '';
	for (var i=0; i<monList.length; i++){
		var mobj = monArray[monList[i]];
		var htmltext = '<div class="archive-row"><h4 class="contents-subtitle"><a name="' + monList[i] + '">' + monList[i] + '</a></h4>';
		htmltext += '<div class="archive-area">';
			for (var m=0; m<mobj.length; m++){
				htmltext += '<dl class="archive-list clearfix" style="clear:both; width:100%;">';
				htmltext += '<dt>' + mobj[m].date + '</dt>';
				htmltext += '<dd>' + mobj[m].body + '</dd>';
				htmltext += '</dl>';
				//alert(mobj[m].date);
			}
		htmltext += '</div>';

		archivetext += htmltext;
	}
		$(elements).innerHTML = archivetext;
	
}
/*

for archive

*/
function newsArchives(elements,FileNames) {
    new Ajax.Request(FileNames + "?uid=" + mytime.getTime() , {
    method: 'get', onComplete: displayData });
    function displayData(responseHttpObj){
		var text = responseHttpObj.responseText;
		parseTextNewsArchives(elements,text);
    }
}

function parseTextNewsArchives(elements,text){
	var CR = String.fromCharCode(13); // 改行コード (CR)
	var LF = String.fromCharCode(10); // 改行コード (CR)
	lineData = text.split(LF);

	var archivetext = '';
	for (var i=0; i<lineData.length; i++){
		values = lineData[i].split(",");
		var iconnum = values[0];
		var datedata = values[1];
		var bodydata = values[2];
		var linkdata = values[3];
		var targetdata = values[4];
		if(iconnum == 1){
			var icondata = ' <img src="/sils/jp/common/images/ico_news_01.gif" alt="一般の方へ" width="62" height="19" />';
		}else if(iconnum == 2){
			var icondata = ' <img src="/sils/jp/common/images/ico_news_02.gif" alt="在学生の方へ" width="62" height="19" />';
		}else if(iconnum == 3){
			var icondata = ' <img src="/sils/jp/common/images/ico_news_03.gif" alt="受験生の方へ" width="62" height="19" />';
		}else if(iconnum == 4){
			var icondata = ' <img src="/sils/jp/common/images/ico_news_04.gif" alt="卒業生の方へ" width="62" height="19" />';
		}else{
			var icondata = '';
		}
		if(values.length > 1){
			var htmltext = '<dl class="newsrow-inner clearfix">';
			htmltext += '<dt>' + icondata  + datedata + '</dt>';
			if(linkdata != ''){
				htmltext += '<dd><a href="' + linkdata + '" target="' + targetdata + '">' + bodydata + '</a></dd></dl>';
			}else{
				htmltext += '<dd>' + bodydata + '</dd></dl>';
			}
			archivetext += htmltext;
		}
	}


		$(elements).innerHTML = archivetext;
		
	
}

