var tabstate = 'newsrelease';

function topNewsTab(tabid,tabno) {
	if(document.getElementById('top-news-contents')){
		if(tabno == 1){
			if(tabid == 'newsrelease'){
				if(document.getElementById('tab-newsrelease')) document.getElementById('tab-newsrelease').style.backgroundPosition = 'left top';
				if(document.getElementById('tab-koushin')) document.getElementById('tab-koushin').style.backgroundPosition = 'left -60px';
				if(document.getElementById('top-newsrelease')) document.getElementById('top-newsrelease').style.display = 'block';
				if(document.getElementById('top-koushin')) document.getElementById('top-koushin').style.display = 'none';
			} else if(tabid == 'koushin'){
				if(document.getElementById('tab-newsrelease')) document.getElementById('tab-newsrelease').style.backgroundPosition = 'left -60px';
				if(document.getElementById('tab-koushin')) document.getElementById('tab-koushin').style.backgroundPosition = 'left top';
				if(document.getElementById('top-newsrelease')) document.getElementById('top-newsrelease').style.display = 'none';
				if(document.getElementById('top-koushin')) document.getElementById('top-koushin').style.display = 'block';
			}

			tabstate = tabid;

		} else if(tabno == 2){
			if( tabstate != tabid ){
				if(tabid == 'newsrelease'){
					if(document.getElementById('tab-newsrelease')) document.getElementById('tab-newsrelease').style.backgroundPosition = 'left -30px';
				} else if(tabid == 'koushin'){
					if(document.getElementById('tab-koushin')) document.getElementById('tab-koushin').style.backgroundPosition = 'left -30px';
				}
			}
		} else if(tabno == 3){
			if( tabstate != tabid ){
				if(tabid == 'newsrelease'){
					if(document.getElementById('tab-newsrelease')) document.getElementById('tab-newsrelease').style.backgroundPosition = 'left -60px';
				} else if(tabid == 'koushin'){
					if(document.getElementById('tab-koushin')) document.getElementById('tab-koushin').style.backgroundPosition = 'left -60px';
				}
			}
		}
	}
}


function rollover() {
	if(document.getElementsByTagName) {
	var images = document.getElementsByTagName("img");
		for(var i=0; i < images.length; i++) {
			if(images[i].getAttribute("src").match("_off.")) {
				images[i].onmouseover = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));
				}
				images[i].onmouseout = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));
				}
			}
		}
	}
}

function blendoff(idname) {document.getElementById(idname).style.display = 'none';}
function blendon(idname) {document.getElementById(idname).style.display = 'block';}

if(window.addEventListener) {
	window.addEventListener("load", rollover, false);
}
else if(window.attachEvent) {
	window.attachEvent("onload", rollover);
}

(function() {

function $(id) {
	return document.getElementById(id);
}

function setStyleDisplay(id, status) {
	$(id).style.display = status;
}

function goTop(a, t) {
	a = a || 0.1;
	t = t || 16;

	var x1 = 0;
	var y1 = 0;
	var x2 = 0;
	var y2 = 0;
	var x3 = 0;
	var y3 = 0;

	if (document.documentElement) {
		x1 = document.documentElement.scrollLeft || 0;
		y1 = document.documentElement.scrollTop || 0;
	}
	if (document.body) {
		x2 = document.body.scrollLeft || 0;
		y2 = document.body.scrollTop || 0;
	}
	var x3 = window.scrollX || 0;
	var y3 = window.scrollY || 0;

	var x = Math.max(x1, Math.max(x2, x3));
	var y = Math.max(y1, Math.max(y2, y3));

	var speed = 1 + a;
	window.scrollTo(Math.floor(x / speed), Math.floor(y / speed));
	if(x > 0 || y > 0) {
		var f = "MGJS.goTop(" + a + ", " + t + ")";
		window.setTimeout(f, t);
	}
}

window['MGJS'] = {};
window['MGJS']['$'] = $;
window['MGJS']['setStyleDisplay'] = setStyleDisplay;
window['MGJS']['goTop'] = goTop;

})();

function doPopup() {
	if (!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName("a");
		for (var i=0; i < links.length; i++) {
			if (links[i].className.match("popup")){links[i].onclick = function(){window.open(this.href);return false;}}
		}
}
window.onload = doPopup;


// thank you for  [ zaru blog ]
// http://zaru.tofu-kun.org/
// http://blog.tofu-kun.org/070627210315.php

//文字数の設定
var stopCount = 50;

function strLength(strSrc){
	len = 0;
	strSrc = escape(strSrc);
	for(i = 0; i < strSrc.length; i++, len++){
		if(strSrc.charAt(i) == "%"){
			if(strSrc.charAt(++i) == "u"){
				i += 3;
				len++;
			}
			i++;
		}
	}
	return len;
}
function showLength( str,name ) {
	var strCount = Math.ceil(strLength(str).toString() / 2);
	if(strCount > stopCount){
		document.getElementById(name + "Inner").innerHTML = '<em style="color:#ff0000;">' + strCount + ' / 50 Over!</em>';
	}else if(strCount == stopCount){
		document.getElementById(name + "Inner").innerHTML = '<em style="color:#ff0000;">' + strCount + ' / 50</em>';
	}else{
		document.getElementById(name + "Inner").innerHTML = strCount + " / 50";
	}
}

window.onload = function(){
	var text2Check = document.getElementById("text2");
	if(text2Check){
		text2Check.onkeyup = function(){
			showLength(document.getElementById("text2").value,document.getElementById("text2").id);
		}
	}
}


/*
      max_width  = 100 ;
      max_height =  50 ;

      function keep_max() {
        for (i in document.images) {
          if (document.images[i].className != 'gazou_type') continue ; // gazou_type は適当に変更してください
          if (document.images[i].width > document.images[i].height &amp; document.images[i].width > max_width) {
            document.images[i].width = max_width ;
          }
          else {
            if (document.images[i].height > max_height) { document.images[i].height = max_height ; }
          }
        }
      }
*/




