//Rollover
(function(onLoad){
	try {
		window.addEventListener('load', onLoad, false);
	}catch (e){
		window.attachEvent('onload', onLoad);
	}
})(function(){
	var tags = ["img","input"];
	for( var i=0, len=tags.length; i<len; i++ ) {
		var over = function() { this.src = this.src.replace('_off.', '_on.'); };
		var out = function() { this.src = this.src.replace('_on.', '_off.'); };
		var el = document.getElementsByTagName(tags[i]);
		var pre = new Array();
		for (var j=0, len2=el.length; j<len2; j++) {
			var attr = el[j].getAttribute('src');
			if (!el[j].src.match(/_off\./)&&attr) continue;
			pre[j] = new Image();
			pre[j].src = el[j].src.replace('_off.', '_on.');
			el[j].onmouseover = over;
			el[j].onmouseout = out;
		}
	}
});

//PopUp
window.onload = function (){
	var node_a = document.getElementsByTagName('a');
	for (var i in node_a) {
		var rel = node_a[i].rel;
		var className = node_a[i].className;
		if(className == 'medicine'){
			node_a[i].onclick = function() {
				return winOpen(this.href, "popup[740,700]")
			};
		}else if(className == 'medicine_photo'){
			node_a[i].onclick = function() {
				return winOpen(this.href, "popup[700,700]")
			};
		}else if(rel != 0){
			node_a[i].onclick = function() {
				if(this.rel.match(/^popup(?:\[(\d+?),(\d+?)\])?$/)){
					return winOpen(this.href, this.rel)
				}
				return true;
			}
		}
	}
};
function winOpen(url, rel) {
	rel = rel.replace(/popup\[|\]/g,"");
	var split = rel.split(',') ;
	window.open(url,'','width='+ split[0] +',height='+ split[1] +',toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1');
	return false;
};
function winOpen_levo(url, rel) {
	rel = rel.replace(/popup\[|\]/g,"");
	var split = rel.split(',') ;
	window.open(url,'','width='+ split[0] +',height='+ split[1] +',toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=0');
	return false;
};

//Copyright
function year(){
	var data = new Date();
	var now_year = data.getFullYear();
	document.write(now_year);
};

//ChgPWin
function ChgPWin(src){
	if(opener.closed == false){
		window.opener.location.href=src;
		window.opener.focus();
	}else{
		window.open(src,'_blank');
	}
}

//FontSizeChanger
var TextSizeController = {
	tsUnit:"%",
	normalSize:80,
	unitSize:10,
	cookieName:"tsc",
	cookieExpDay:365,
	cookieOffMsg:"Cookieを有効にして下さい。",
	cookiePath:"/",
	bodyObj:function(){
		return document.getElementsByTagName('body')[0];
	},
	getCookie:function(){
		var cd = document.cookie.split("; ");
		for(var i=0;i<cd.length;i++){
			if(cd[i].indexOf(this.cookieName + "=")>=0){
				var latestSetting = cd[i].split("=")[1];
				return latestSetting;
			}
		}
		return false;
	},
	writeCookie:function(value){
		var ce = new Date();
		ce.setTime(ce.getTime() + (this.cookieExpDay*24*60*60*1000));
		document.cookie = this.cookieName + "=" + value + "; expires=" + ce.toGMTString() + "; path=" + this.cookiePath;
	},
	checkCookie:function(){
		if(!navigator.cookieEnabled){
			alert(this.cookieOffMsg);
			return false;
		}
		return true;
	},
	sizeControl:function(key){
		this.checkCookie();
		var latestSize = parseInt(this.bodyObj().style.fontSize);
		(key=="+")?latestSize+=this.unitSize:latestSize-=this.unitSize;
		this.bodyObj().style.fontSize = latestSize + this.tsUnit;
		this.writeCookie(latestSize);
		return false;
	},
	sizeReset:function(){
		this.checkCookie();
		this.bodyObj().style.fontSize = this.normalSize + this.tsUnit;
		this.writeCookie(this.normalSize);
	},
	init:function(){
		var bodyStyle = this.bodyObj().style;
		if(this.getCookie()){
			bodyStyle.fontSize = this.getCookie() + this.tsUnit;
		}
		else{
			bodyStyle.fontSize = this.normalSize + this.tsUnit;
		}
	}
};
function setEventTSC(){
	var anchorObj = document.getElementsByTagName('a');
	for(var i=0;i<anchorObj.length;i++){
		if(anchorObj[i].className.match("tsPlus")){
			anchorObj[i].onclick = function(){
				TextSizeController.sizeControl('+');
				return false;
			};
		}else if(anchorObj[i].className.match("tsMinus")){
			anchorObj[i].onclick = function(){
				TextSizeController.sizeControl('-');
				return false;
			};
		}else if(anchorObj[i].className.match("tsReset")){
			anchorObj[i].onclick = function(){
				TextSizeController.sizeReset();
				return false;
			};
		}
	}
	TextSizeController.init();
}
if(window.addEventListener){
	window.addEventListener("load",setEventTSC,false);
}else if(window.attachEvent){
	window.attachEvent("onload",setEventTSC);
}
