//////////////////////////////////////////////////////////////////////////
//
// スクロールしてページトップに戻る
//
//////////////////////////////////////////////////////////////////////////


function backToTop() {
  var x1 = x2 = x3 = 0;
  var y1 = y2 = 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;
  }
  x3 = window.scrollX || 0;
  y3 = window.scrollY || 0;
  var x = Math.max(x1, Math.max(x2, x3));
  var y = Math.max(y1, Math.max(y2, y3));
  window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));
  if (x > 0 || y > 0) {
      window.setTimeout("backToTop()", 25);
  }
}

//////////////////////////////////////////////////////////////////////////
//
// スワップイメージ
//
//////////////////////////////////////////////////////////////////////////
(function(){
	function rollover(){
		var targetClassName = "rollImg";
		var suffix = "_o";

		var overReg = new RegExp("^(.+)(\\.[a-z]+)$");
		var outReg = new RegExp("^(.+)" + suffix + "(\\.[a-z]+)$");

		var preload = new Array();
		var images = document.getElementsByTagName("img");
		var submitBtn = document.getElementsByTagName("input");

		for (var i = 0, il = images.length; i < il; i++) {
			var classStr = images[i].getAttribute("class") || images[i].className;
			var classNames = classStr.split(/\s+/);
			for(var j = 0, cl = classNames.length; j < cl; j++){
				if(classNames[j] == targetClassName){

					//preload
					preload[i] = new Image();
					
					if (images[i].getAttribute("src").indexOf("_o") == -1) {
						preload[i].src = images[i].getAttribute("src").replace(overReg, "$1" + suffix + "$2");
					} else {
						preload[i].src = images[i].getAttribute("src");
					}
					
					//mouseover
					images[i].onmouseover = function() {
						if (this.getAttribute("src").indexOf("_o") == -1) {
							this.src = this.getAttribute("src").replace(overReg, "$1" + suffix + "$2");
						} else {
							this.src = this.getAttribute("src");
						}
					}

					//mouseout
					images[i].onmouseout = function() {
						this.src = this.getAttribute("src").replace(outReg, "$1$2");
					}
				}
			}
		}
		for (var i = 0, il = submitBtn.length; i < il; i++) {
			var classStr = submitBtn[i].getAttribute("class") || submitBtn[i].className;
			var classNames = classStr.split(/\s+/);
			for(var j = 0, cl = classNames.length; j < cl; j++){
				if(classNames[j] == targetClassName){

					//preload
					preload[i] = new Image();

					preload[i] = new Image();
					if (submitBtn[i].getAttribute("src").indexOf("_o") == -1) {
						preload[i].src = submitBtn[i].getAttribute("src").replace(overReg, "$1" + suffix + "$2");
					} else {
						preload[i].src = submitBtn[i].getAttribute("src");
					}
					
					//mouseover
					submitBtn[i].onmouseover = function() {
						if (this.getAttribute("src").indexOf("_o") == -1) {
							this.src = this.getAttribute("src").replace(overReg, "$1" + suffix + "$2");
						} else {
							this.src = this.getAttribute("src");
						}
					}

					//mouseout
					submitBtn[i].onmouseout = function() {
						this.src = this.getAttribute("src").replace(outReg, "$1$2");
					}
				}
			}
		}
	}

	function addEvent(elem,event,func){
		if(elem.addEventListener) {
			elem.addEventListener(event, func, false);
		}else if(elem.attachEvent) {
			elem.attachEvent("on" + event, func);
		}
	}
	addEvent(window,"load",rollover);
})();
//////////////////////////////////////////////////////////////////////////
//
// 
// WEB登録フォーム関連
//
//
//////////////////////////////////////////////////////////////////////////
function medHisChk(){		//医療事務
	if(document.entryForm.his_valid[1].checked == true){
		document.entryForm.his_period_s.readOnly = true;
		document.entryForm.his_period_e.readOnly = true;
		document.entryForm.his_content.readOnly = true;
	}else{
		document.entryForm.his_period_s.readOnly = false;
		document.entryForm.his_period_e.readOnly = false;
		document.entryForm.his_content.readOnly = false;
	}
}
//////////////////////////////////////////////////////////////////////////
//
// 
// PRINT
//
//
//////////////////////////////////////////////////////////////////////////

function print_out() {
   /* print() が使えるブラウザかどうかを判断 */
   if (navigator.userAgent.match(/msie (\d)/i))
      v = (eval(RegExp.$1) >= 5) ? 1 : 0;
   else if (self.innerWidth)
      v = (eval(navigator.appVersion.charAt(0)) >= 4) ? 1 : 0;
   else v = 0;

   /* print() が使えるブラウザなら印刷を実行 */
   if (v) self.print();
   else alert("お使いのブラウザではこの機能は利用できません");
}
