//共通して使うJavascript

//▼▼▼▼▼　　及川さん（ドリームウィーバー？）作成　　▼▼▼▼▼
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//▲▲▲▲▲　　及川さん（ドリームウィーバー？）作成　　▲▲▲▲▲


//▼▼▼▼▼　　石田設定　　▼▼▼▼▼

function jump_page(linkLoc) {
 if(linkLoc !="") { window.location.href=linkLoc;}
}

function open_page(url){ 
	window.open(url); 
} 

function window_popup(url,width,height,scroll){
	window.open(url, "popup", "width="+width+",height="+height+",scrollbars="+scroll);
}


function not_yet() {
 alert('未実装です');
}

function insertValue(target, ins_text) {
    var objTarget = eval('document.' + target);

        //IE support
        if (document.selection) {
            objTarget.focus();
            sel = document.selection.createRange();
            sel.text = ins_text;
        }
		
}

// ヘルプの表示
//  使用例：<SPAN onMouseOver="popUp('てすと')" onMouseOut="hidePop()">ヘルプ</SPAN>
//  ※ページのどこかに、以下のタグを置いてください
//  <SPAN id="tips" STYLE="visibility: hidden; position: absolute;"></SPAN>
function popUp(msg) {
  tips.innerHTML = '<table bgcolor="#444411" cellspacing=1 cellpadding=2><tr><td bgcolor="#ffffdd" style="font-size:12px;">'+msg+'</td></tr></table>' ;
  // ヘルプの位置を調整
  tips.style.left = event.x + 10; // 表示するx座標（適度に調整してください）
  tips.style.top = event.y + 10 + document.body.scrollTop; // 表示するy座標（適度に調整してください） 
  tips.style.visibility = "visible";
}

function popUp_img(msg, max_w, max_h) {
  tips.innerHTML = '<table bgcolor="#444411" cellspacing=1 cellpadding=2><tr><td bgcolor="#ffffdd" style="font-size:12px;"><img id="popup_img" src="'+msg+'" ></td></tr></table>' ;
  // ヘルプの位置を調整
  tips.style.left = event.x + 10; // 表示するx座標（適度に調整してください）
  tips.style.top = event.y + 10 + document.body.scrollTop; // 表示するy座標（適度に調整してください）
  
  imgResize('popup_img', max_w, max_h);
  
  tips.style.visibility = "visible";
}

// ヘルプの非表示
function hidePop() {
  tips.style.visibility = "hidden";
}

//画像のリサイズ
function imgResize(img_name, winWidth, winHeight){

	// 変数の定義
	imgWidth = document.getElementById(img_name).width; // 画像の幅
	imgHeight = document.getElementById(img_name).height; // 画像の高さ
	
	widthRate = imgWidth / winWidth; // 画像サイズと画像表示領域のサイズの比率 (幅)
	heightRate = imgHeight / winHeight; // 画像サイズと画像表示領域のサイズの比率 (高さ)
	
	if (widthRate >= 1 && heightRate >= 1){
		// 画像のwidth、height共に画面に収まらない場合
		if (widthRate > heightRate){
			// 画像のwidthの比率の方が大きい場合
			// widthに合わせてリサイズ
			document.getElementById(img_name).style.width = winWidth;
			document.getElementById(img_name).style.height = Math.floor(imgHeight / widthRate);
		} else {
			// 画像のheightの比率の方が大きい場合
			// heightに合わせてリサイズ
			document.getElementById(img_name).style.width = Math.floor(imgWidth / heightRate);
			document.getElementById(img_name).style.height = winHeight;
		}
	} else if (widthRate >= 1 && heightRate < 1){
		// 画像のwidthのみ画面に収まらない場合
		document.getElementById(img_name).style.width = winWidth;
		document.getElementById(img_name).style.height = Math.floor(imgHeight / widthRate);
	} else if (widthRate < 1 && heightRate >= 1){
		// 画像のheightのみ画面に収まらない場合
		document.getElementById(img_name).style.width = Math.floor(imgWidth / heightRate);
		document.getElementById(img_name).style.height = winHeight;
	} else {
		// 画像のwidht、heightともに画面に収まる場合
		// なにもしないぜ
	}
}


//CSVダウンロード用
function dl_submit(self,flg){
	window.location.target = 'dl';
	window.location.href = self+'?act=download&flg='+flg;
}
