//Open blank window
window.onload = function() {
	
	//class blankで新しいウィンドウ
	var node_a = document.getElementsByTagName('a');
	for (var i in node_a) {
		if (node_a[i].className == 'blank') {
			node_a[i].onclick = function() {
			window.open(this.href, '', '');
			return false;
			};
		};
	};
	
	//ページスクロール
	tinyScrolling.init();
};



//ページスクロール

/* Tiny Scrolling - a smooth navigation between internal links and their destinations
by Marco Rosella - http://www.centralscrutinizer.it/en/design/js-php/tiny-scrolling
based on the works by Travis Beckham and Brian McAllister.
                v0.3 - March 27, 2006
*/

var tinyScrolling = {
	speed : 25,      //set here the scroll speed: when this value increase, the speed decrease. 
	maxStep: 150,	 //set here the "uniform motion" step for long distances
	brakeK: 3,		 //set here the coefficient of slowing down
	hash:null,		
	currentBlock:null,
	requestedY:0,
	init: function() {
			var lnks = document.getElementsByTagName('a');   
			for(var i = 0, lnk; lnk = lnks[i]; i++) {   
				if ((lnk.href && lnk.href.indexOf('#') != -1) &&  ( (lnk.pathname == location.pathname) ||
				('/'+lnk.pathname == location.pathname) ) && (lnk.search == location.search)) {  
				lnk.onclick = tinyScrolling.initScroll;   		
				}   
			}
	},
	getElementYpos: function(el){
			var y = 0;
			while(el.offsetParent){  
				y += el.offsetTop    
				el = el.offsetParent;
			}	return y;
	},		
	getScrollTop: function(){
			if(document.all) return (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
			else return window.pageYOffset;   
	},	
	getWindowHeight: function(){
			if (window.innerHeight)	return window.innerHeight;
			if(document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight;
	},
	getDocumentHeight: function(){
			if (document.height) return document.height;
			if(document.body.offsetHeight) return document.body.offsetHeight;
	},
	initScroll: function(e){
			var targ;  
			if (!e) var e = window.event;
			if (e.target) targ = e.target;
			else if (e.srcElement) targ = e.srcElement;   
			tinyScrolling.hash = targ.href.substr(targ.href.indexOf('#')+1,targ.href.length); 
			tinyScrolling.currentBlock = document.getElementById(tinyScrolling.hash);   
			if(!tinyScrolling.currentBlock) return;
			tinyScrolling.requestedY = tinyScrolling.getElementYpos(tinyScrolling.currentBlock); 
			tinyScrolling.scroll();  
			return false;
	},
	scroll: function(){
			var top  = tinyScrolling.getScrollTop();
			if(tinyScrolling.requestedY > top) {  	
				var endDistance = Math.round((tinyScrolling.getDocumentHeight() - (top + tinyScrolling.getWindowHeight())) / tinyScrolling.brakeK);
				endDistance = Math.min(Math.round((tinyScrolling.requestedY-top)/ tinyScrolling.brakeK), endDistance);
				var offset = Math.max(2, Math.min(endDistance, tinyScrolling.maxStep));
			} else { var offset = - Math.min(Math.abs(Math.round((tinyScrolling.requestedY-top)/ tinyScrolling.brakeK)), tinyScrolling.maxStep);
			} window.scrollTo(0, top + offset);  
			if(Math.abs(top-tinyScrolling.requestedY) <= 1 || tinyScrolling.getScrollTop() == top) {
				window.scrollTo(0, tinyScrolling.requestedY);
				if(!document.all || window.opera) location.hash = tinyScrolling.hash;
				tinyScrolling.hash = null;
			} else 	setTimeout(tinyScrolling.scroll,tinyScrolling.speed);
	}		
}

//表示・非表示切り替え
function showop(){
	document.getElementById('display').style.display = "block";
    document.getElementById('nonDisplay').style.display = "none";    
}
function hideop(){
    document.getElementById('display').style.display = "none";
    document.getElementById('nonDisplay').style.display = "block";
}

//タグ一覧切り替え
function tagshowop(){
	document.getElementById('tagDisplay').style.display = "none";
    document.getElementById('tagNonDisplay').style.display = "inline";
	document.getElementById('display').style.display = "block";
}
function taghideop(){
    document.getElementById('tagDisplay').style.display = "inline";
    document.getElementById('tagNonDisplay').style.display = "none";
	document.getElementById('display').style.display = "none";
}


//クリックでtrの背景を変更
function ChgTR(e){
	var el = e.target || e.srcElement;
	if(el.type != 'checkbox'){ return false; }
	var tr = el;
	while(tr){
	if(tr.tagName == 'TR'){
		tr.style.backgroundColor = el.checked ? "#F0F8FF" : "#FFFFFF"; break;
		}
	tr = tr.parentNode;
	}
}

//すべてのチェックボックスを選択
// 全て選択押下処理
function fnc_all_click(objAll){

	// 全ての要素に対して
	for(var i=0;i<document.formCheck.length;i++){
		//チェックボックスであれば
		if(document.formCheck[i].type=="checkbox"){
			document.formCheck[i].checked = objAll.checked;
		}
	}
}

// 全て選択以外の押下処理
function fnc_mbr_click(objMbr){

	// チェックボックスのチェックが外れたら『全て選択』のチェックを外す
	if(objMbr.checked == false){
		document.formCheck.allcheck.checked = false;
		return;
	}
	for(var i=0;i<document.formCheck.length;i++){
		//チェックボックスであれば
		if(document.formCheck[i].type=="checkbox"){
			// 『全て選択』以外全てチェックされていたら
			// 『全て選択』をチェックする
			if(document.formCheck[i].checked==false
			                 &&
			   document.formCheck[i].name!="allcheck"){
				return;
			}
		}
	}

	document.formCheck.allcheck.checked = true;

}

function __confirm(str){
 return window.confirm(str);
}

var __cookie = {
  get:function(n,m){
  	token = document.cookie.split('; ');
	for (i=0; i<token.length; i++){
		m_token = token[i].split('=');
		if(m_token[0] == n){
			return m_token[1];
		}
	}
	return false;
  },
  set:function(n,v,e,p){
	token = document.cookie.split('; ');
	if(token.length < 40){
	  	document.cookie=n+'='+encodeURIComponent(v)+'; path='+p+'; expires='+e
	}
  },
  remove:function(n,p){
  	document.cookie=n+'=0; path='+p+'; expires=Sun, 19-Aug-2007 00:00:00 GMT'
  }
}

function disableOtherGroup(obj){
	chkboxList = document.getElementsByClassName(obj.className);
	for(i=0; i<chkboxList.length; i++){
		if(obj.name != chkboxList[i].name){
			chkboxList[i].disabled = obj.checked;
		}
	}
}

function changeAc(obj){


	if(obj.value == 'cur'){
		document.getElementById('search_box').action=document.getElementById('cur_tag_path').value;
	}else if(obj.value == 'new'){
		document.getElementById('search_box').action = document.getElementById('new_tag_path').value;
	}else if(obj.value == 'cur_f'){
		document.getElementById('search_box_f').action=document.getElementById('cur_tag_path').value;
	}else if(obj.value == 'new_f'){
		document.getElementById('search_box_f').action=document.getElementById('new_tag_path').value;
	}
	
}


if (typeof document.getElementsByClassName != "function") {

	document.getElementsByClassName = function(className){
		var names=className.split(/\s+/),
		all=this.getElementsByTagName("*"),
		memo={},
		ret=[];
		for(var i=0,l=all.length,elem,iname,flag;i<l;i++) {
			elem=all[i];
			iname=elem.className;
			if (!(iname in memo)) {
				memo[iname] = " " + iname.toLowerCase() + " ";
			}
			for (var j=0,jname;j<names.length;j++) {
				jname=names[j];
				if (!(jname in memo)) {
					memo[jname] = " " + jname.toLowerCase() + " ";
				}
				if (flag = memo[iname].indexOf(memo[jname]) != -1) {
					continue;
				}
				else {
					break;
				}
			}
			if(flag)ret[ret.length]=elem;
		}
		return ret;
	}

}


// 1クリックアクション回避

function showSWF( pass, width, height, id){
	var show = ""
	show+="<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'"
	show+=" codebase='https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0'"
	show+=" width=" + width
	show+=" height=" + height
	show+=" title=" + id
	show+=" align='middle'>\n"
	show+="<param name='allowScriptAccess' value='sameDomain' />\n"
	show+="<param name='movie' value=" + pass + " />\n"
	show+="<param name='quality' value='high' />\n"
	show+="<param name='scale' value='noscale' />\n"
	show+="<param name='bgcolor' value='#ffffff' />\n"
	show+="<embed src=" + pass
	show+=" quality='high' scale='noscale' salign='t' bgcolor='#ffffff'"
	show+=" width=" + width + " height=" + height
	show+=" name=" + id + " align='middle' allowScriptAccess='sameDomain'"
	show+=" type='application/x-shockwave-flash' pluginspage='https://www.macromedia.com/go/getflashplayer' />\n"
	show+="<noembed></noembed>\n"
	show+="</object>";
	document.write(show);
}

// サブウィンドウ表示

function subwindow(url){
	window.open(url, "window_name", "width=700,height=600,scrollbars=yes");
}
