﻿function JsBrowsVersion()
{
	if(navigator.userAgent.indexOf("Opera") != -1)
	{ 
		return 1; //あなたのブラウザは Opera です
	}
	else if(navigator.userAgent.indexOf("MSIE") != -1)
	{
		return 0; //あなたのブラウザは Internet Explorer です
	}
	else if(navigator.userAgent.indexOf("Firefox") != -1)
	{
		return 2; //あなたのブラウザは Firefox です
	}
	else if(navigator.userAgent.indexOf("Netscape") != -1)
	{
		return 3; //あなたのブラウザは Netscape です
	}
	else if(navigator.userAgent.indexOf("Safari") != -1)
	{
		return 4; //あなたのブラウザは Safari です
	}
	else
	{
		return 5; //判別できませんでした。
	}
}

function JSBrowsIE_Version()
{
	var myAgent = myAgent = navigator.userAgent; 
	var myTop = myAgent.indexOf("MSIE",0);
	var myLast = myAgent.indexOf(";", myTop);
	var myVer = myAgent.substring(myTop+5, myLast);    // IEのバージョン切り取り
	return myVer;
}

function jsOpenWindow(url, target)
{
	window.open(url, target);
}

//ﾌｫﾛｰｱｯﾌﾟ説明を表示する
function jsPopupWindow(windowurl, width, height)
{   
	var win_data = "toolbar=0,location=1,directories=0,status=1,menubar=0,scrollbars=yes,resizable=1,width="+width+",height="+height+",left=10,top=10";
	nw = window.open(windowurl,'ViewFollowUpInfo', win_data);
	nw.focus();
}

//リピーター用の下部open用
function jsRepeaterOnchange(rowName, chkName)
{
	var objRow = document.getElementById(rowName);
	var objChk = document.getElementById(chkName);
	if(null==objRow || null==objChk) return;
	
	objRow.style.backgroundColor = "#FFFFC0";
	objChk.checked = true;
}

//指定Objにフォーカスをセットする
function SetForcus(objname)
{
	var obj = document.getElementById(objname);
	if(null == obj) return;
	
	obj.focus();
}

//指定Objに未定999/99セット
function set9999(objname)
{
	var obj = document.getElementById(objname);
	if(null == obj) return;
	
	obj.value = "9999/99";		
}

//カンマを付ける
function number_format(str)
{
	var num = new String(str).replace(/,/g, "");
	while(num != (num = num.replace(/^(-?\d+)(\d{3})/, "$1,$2")));
	return num;
}

//￥付きカンマを付ける(0なら空白をかえす)
function number_format_ZerotoEmpty(str)
{
	if('' == str || '0' == str) return '';
	
	var num = new String(str).replace(/,/g, "");
	while(num != (num = num.replace(/^(-?\d+)(\d{3})/, "$1,$2")));
	return "￥" + num;
}

//空白なら0を返す
function parseInt_NullToZero(str)
{
	if('' == str) return 0;
	return parseInt(str);
}

//数値のみかチェックする
function validater_numeric(value)
{
	return !(value.match(/[\D]/g));
}

//クリップボードへ値を送る
function SendClickBoard(str)
{
	alert('以下内容をクリップボードへコピーしました。\r\n貼り付けてご利用できます。\r\n\r\n'+str);
	clipboardData.setData("Text", str);
}

//LeftTrim
function LTrim( value )
{
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

//RightTrim
function RTrim( value )
{
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

//Trim(両側)
function trim( value )
{
	return LTrim(RTrim(value));
}

//Urlエンコーダ
function encodeURL(str)
{
  var character = '';
  var unicode   = '';
  var string    = '';
  var i         = 0;

  for (i = 0; i < str.length; i++) {
    character = str.charAt(i);
    unicode   = str.charCodeAt(i);

    if (character == ' ') {
      string += '+';
    } else {
      if (unicode == 0x2a || unicode == 0x2d || unicode == 0x2e || unicode == 0x5f || ((unicode >= 0x30) && (unicode <= 0x39)) || ((unicode >= 0x41) && (unicode <= 0x5a)) || ((unicode >= 0x61) && (unicode <= 0x7a))) {
        string = string + character;
      } else {
        if ((unicode >= 0x0) && (unicode <= 0x7f)) {
          character   = '0' + unicode.toString(16);
          string += '%' + character.substr(character.length - 2);
        } else if (unicode > 0x1fffff) {
          string += '%' + (oxf0 + ((unicode & 0x1c0000) >> 18)).toString(16);
          string += '%' + (0x80 + ((unicode & 0x3f000) >> 12)).toString(16);
          string += '%' + (0x80 + ((unicode & 0xfc0) >> 6)).toString(16);
          string += '%' + (0x80 + (unicode & 0x3f)).toString(16);
        } else if (unicode > 0x7ff) {
          string += '%' + (0xe0 + ((unicode & 0xf000) >> 12)).toString(16);
          string += '%' + (0x80 + ((unicode & 0xfc0) >> 6)).toString(16);
          string += '%' + (0x80 + (unicode & 0x3f)).toString(16);
        } else {
          string += '%' + (0xc0 + ((unicode & 0x7c0) >> 6)).toString(16);
          string += '%' + (0x80 + (unicode & 0x3f)).toString(16);
        }
      }
    }
  }

  return string;
}


function js_download_confirm()
{
	return confirm('個人情報・機密情報を含む可能性のあるファイルをダウンロードします。\r\n個人情報保護法・機密保持契約に従い、本ファイルが漏洩することのないよう対策を講じてください。\r\nまた使用後は速やかに本ファイルを削除してください。\r\n\r\n以上にご了承いただける場合は、OK ボタンをクリックしてください。');
}


/* Cookie */
function getCookie(key,  tmp1, tmp2, xx1, xx2, xx3)
{
    tmp1 = " " + document.cookie + ";";
    xx1 = xx2 = 0;
    len = tmp1.length;
    while (xx1 < len)
    {
        xx2 = tmp1.indexOf(";", xx1);
        tmp2 = tmp1.substring(xx1 + 1, xx2);
        xx3 = tmp2.indexOf("=");
        if (tmp2.substring(0, xx3) == key)
        {
            return(unescape(tmp2.substring(xx3 + 1, xx2 - xx1 - 1)));
        }
        xx1 = xx2 + 1;
    }
    return("");
}
/* Cookie */
function setCookie(key, val, tmp)
{
    tmp = key + "=" + escape(val) + "; ";
    tmp += "expires=Tue, 31-Dec-2030 23:59:59; path=/;";
    document.cookie = tmp;
}
/* Cookie */
function clearCookie(key) 
{
    document.cookie = key + "=" + "xx; expires=Tue, 1-Jan-1980 00:00:00;";
}



/*改行コードを消す*/
function jsCutReturnCode(objname)
{
	var obj = document.getElementById(objname);
	if(null == obj) return;
	
	var newLen = '';
	var nowStr = obj.value;
	for(var i=0; i < nowStr.length; i++)
	{
		text = escape(nowStr.substring(i, i+1));
		if(text != "%0D" && text != "%0A")
		{
			newLen += nowStr.substring(i, i+1);
		}
	}
	obj.value = newLen;
}
