//ファイルを読み込んだ際に関数を読み込む
function prepareOnloadFunction(func){
	var oldonload = window.onload;
	if(typeof window.onload != 'function'){
		window.onload = func;
		}else{
		window.onload = function(){
			oldonload();
			func();
			}
		}
	}
//クラス属性を作成・追加する
function addClass(element,value){
	if(!element.className){
		element.className = value;
		}else{
		newClassName = element.className;
		newClassName += " ";
		newClassName += value;
		element.className = newClassName;
		}
	}
//次のノードが要素ノードか調べる
function getNextElement(node){
	if(node.nodeType == 1){
		return node;
		}
	if(node.nextSibling){
		return getNextElement(node.nextSibling);
		}
	return null;
	}
//新規ウィンドウを立ち上げる
function  newWin(winURL){
	window.open(winURL,"","");
	}
//コンテンツ領域
function prepareOutLinks1(){
	if(!document.getElementById) return;
	if(!document.getElementsByTagName) return;
	var side1 = document.getElementById("side1");
	var links = side1.getElementsByTagName("a");
	for(var i=0; i<links.length; i++){
		if(links[i].className.indexOf("newWin") == -1) continue;
		if(links[i].className.indexOf("newWin") != -1){
			var advertisement = links[i].parentNode;
			if(advertisement.className.indexOf("advertisement") != -1) continue;
			if(advertisement.className.indexOf("advertisement") == -1){
				var newWinImg = document.createElement("img");
				newWinImg.setAttribute("alt","新規ウィンドウ");
				newWinImg.setAttribute("src","/images/icon_newWin.gif");
				newWinImg.setAttribute("width","12");
				newWinImg.setAttribute("height","12");
				links[i].appendChild(newWinImg);
				links[i].onmouseover = function(){
					this.lastChild.setAttribute("src","/images/icon_newWin_over.gif");
					}
				links[i].onmouseout = function(){
					this.lastChild.setAttribute("src","/images/icon_newWin.gif");
					}
				}
			links[i].onclick = function(){
				newWin(this.getAttribute("href"));
				return false;
				}
			}
		}
	}
prepareOnloadFunction(prepareOutLinks1);

//フッター領域
function prepareOutLinks2(){
	if(!document.getElementById) return;
	if(!document.getElementsByTagName) return;
	var footer = document.getElementById("footer");
	var links = footer.getElementsByTagName("a");
	for(var i=0; i<links.length; i++){
		if(links[i].className.indexOf("newWin") == -1) continue;
		if(links[i].className.indexOf("newWin") != -1){
			var imgLength = links[i].getElementsByTagName("img");
			if(imgLength.length != 0){
				links[i].onclick = function(){
					newWin(this.getAttribute("href"));
					return false;
					}
				}
			if(imgLength.length == 0){
				var newWinImg = document.createElement("img");
				newWinImg.setAttribute("alt","新規ウィンドウ");
				newWinImg.setAttribute("src","/images/icon_newWinFooter.gif");
				newWinImg.setAttribute("width","12");
				newWinImg.setAttribute("height","10");
				links[i].appendChild(newWinImg);
				links[i].onmouseover = function(){
					this.lastChild.setAttribute("src","/images/icon_newWinFooter_over.gif");
					}
				links[i].onmouseout = function(){
					this.lastChild.setAttribute("src","/images/icon_newWinFooter.gif");
					}
				links[i].onclick = function(){
					newWin(this.getAttribute("href"));
					return false;
					}
				}
			}
		}
	}
prepareOnloadFunction(prepareOutLinks2);
//アフィリエイト領域
function prepareOutLinks3(){
	if(!document.getElementById) return;
	if(!document.getElementsByTagName) return;
	if(!document.getElementById("advertisement1")) return;
	var advertisement1 = document.getElementById("advertisement1");
	var links = advertisement1.getElementsByTagName("a");
	for(var i=0; i<links.length; i++){
		if(links[i].className.indexOf("newWin") == -1) continue;
		if(links[i].className.indexOf("newWin") != -1){
			links[i].onclick = function(){
				newWin(this.getAttribute("href"));
				return false;
				}
			}
		}
	}
prepareOnloadFunction(prepareOutLinks3);
function prepareOutLinks4(){
	if(!document.getElementById) return;
	if(!document.getElementById("adMT01")) return;	
	var adMT01 = document.getElementById("adMT01");
	var links = adMT01.getElementsByTagName("a")[0];
	links.onclick = function(){
		newWin(this.getAttribute("href"));
		return false;
		}
	}
prepareOnloadFunction(prepareOutLinks4);

//最新情報
function TK1975_2008lastnData(nameOfClass,x,obj){
	var elements = document.getElementsByTagName("*");
	for(var i=0; i<elements.length; i++){
		if(elements[i].className.indexOf(nameOfClass) == -1) continue;
		if(elements[i].className.indexOf(nameOfClass) != -1) {
			var count1 = elements[i].childNodes.length;
			var displayArea = elements[i].getElementsByTagName(obj);
			var count = new Array();
			var number = 0;
			for(var j=0; j<displayArea.length; j++){
				var count2 = displayArea[j].parentNode.childNodes.length;
				if(count1 != count2) continue;
				if(count1 == count2){
					displayArea[j].style.display = "none";
					count[number] = displayArea[j];
					number = number+1;
					}
				}
			if(x > count.length){
				for(var k= 0; k<count.length; k++){
					count[k].style.display = "block";
					if(obj == "dd" && k != 0){
						count[k].getElementsByTagName("span")[0].style.display = "none";
						}
					}
				}else{
				for(var k= 0; k<x; k++){
					count[k].style.display = "block";
					if(obj == "dd" && k != 0){
						count[k].getElementsByTagName("span")[0].style.display = "none";
						}
					}
				}
			}
		}
	}
function TK1975_lastn(){
	if(!document.getElementById) return;
	if(!document.getElementsByTagName) return;
	var secondaryDls = document.getElementById("secondary").getElementsByTagName("dl");
	for(var i=0; i<secondaryDls.length; i++){
		if(secondaryDls[i].className.indexOf("lastn5") == -1) continue;
		if(secondaryDls[i].className.indexOf("lastn5") != -1) {		
			addClass(secondaryDls[i],"news");
			}		
		}
	TK1975_2008lastnData("news",5,"dt");
	TK1975_2008lastnData("news",5,"dd");
	}
prepareOnloadFunction(TK1975_lastn);
//検索窓にフォーカス
function searchArea(){
	if(!document.getElementById) return;
	if(!document.getElementsByTagName) return;
	var inputArea = document.getElementById("search");
	var url = location.href;
	if(url.indexOf("search-result.org") == -1){
		inputArea.focus();
		}
	}
//prepareOnloadFunction(searchArea);

//時分秒を秒へ
function tk1975_displayTimeS(totalHMS,splitString){
	var time = totalHMS.split(splitString);
	var hour = parseInt(time[0])*60*60;
	var minute = parseInt(time[1])*60;
	var second = parseInt(time[2]);
	var timeS = hour + minute + second;
	return timeS;
	}
//秒を時分秒へ
function tk1975_displayTimeHMS(totalSecond,splitString){
	var totalMinute = Math.floor(totalSecond/60);
	var hour = Math.floor(totalMinute/60);
	var second = totalSecond - totalMinute*60;
	var minute = totalMinute - hour*60;
	if(minute < 10){
		minute = "0" + minute;
		}
	if(hour < 10){
		hour = "0" + hour;
		}
	if(second < 10){
		second = "0" + second;
		}
	if(splitString == null){
		var timeHMS = hour+"時間"+minute+"分"+second+"秒";
		}else{
		var timeHMS = hour+splitString+minute+splitString+second;
		}
	return timeHMS;
	}

