function E(ID){
	if(document.getElementById(ID)){
		return document.getElementById(ID);
	}else{
		return null;
	}
}
//***********************************************************************
// chkSubWin
// 目的 :	サブウィンドウの死活監視。死んでいれば親のフリーズを解除
// 引数 :	なし
// 戻り値 :	なし
//***********************************************************************
function chkSubWin(){
		if(subwin != null && subwin != ""){
			var ret = subwin.closed;
			if(ret == false){
				subwin.focus();
			}else{
			UnFreezeScreen();
			}
		}else{
			//UnFreezeScreen();
		}
}
//***********************************************************************
// openDialog
// 目的 :	ダイアログを開く。
// 引数 :	strURL...URL
//			nWidth...ダイアログの幅
//			nHeight...ダイアログの高さ
// 戻り値 :	true
//***********************************************************************
function openDialog(strURL, nWidth, nHeight) {
	return window.showModalDialog(strURL, window,
			"scroll: 1;help: no;resizable: no; status: no;dialogWidth:" + nWidth + "px;dialogHeight:"+ nHeight +"px;");
}

//***********************************************************************
// openPreviewDialog
// 目的 :	印刷プレビューダイアログを開く。
// 引数 :	url...URL
// 戻り値 :	dialogの戻り値
//***********************************************************************
function openPreviewDialog(url) {
	return openDialog(url, 1020, 739);
	
	// スクリーン全部を使って表示(保留)
//	return window.showModalDialog(url, window,
//			"scroll: 1;help: no;resizable: no; status: no;dialogWidth:" + screen.availWidth + "px;dialogHeight:" + screen.availHeight + "px;dialogTop:0px;dialogLeft:0px");
}

//***********************************************************************
// openWindow
// 目的 :	ウインドウを開く。
// 引数 :	strURL..........URL
//			strWindowName...ウインドウ名
//			nWidth..........ウインドウの幅
//			nHeight.........ウインドウの高さ
// 戻り値 :	ウインドウオープンオブジェクト
//***********************************************************************
function openWindow(strURL, strWindowName, nWidth, nHeight)
{
	var wnd = window.open(strURL, strWindowName, "channelmode=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=1,status=1,titlebar=1,toolbar=0,width=" + nWidth + "px,height=" + nHeight + "px,top=0,left=0");
	wnd.focus();
	return wnd;
}

//***********************************************************************
// openWindowCenter
// 目的 :	ウインドウを画面中央に開く。
// 引数 :	strURL..........URL
//			strWindowName...ウインドウ名
//			nWidth..........ウインドウの幅
//			nHeight.........ウインドウの高さ
// 戻り値 :	ウインドウオープンオブジェクト
//***********************************************************************
function openWindowCenter(strURL, strWindowName, nWidth, nHeight)
{
	var topPos = (screen.height / 2) - (nHeight / 2);
	var leftPos = (screen.width / 2) - (nWidth / 2);

	var wnd = window.open(strURL, strWindowName, "channelmode=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=1,status=0,titlebar=0,toolbar=0,width=" + nWidth + "px,height=" + nHeight + "px,top=" + topPos + ",left=" + leftPos);
	wnd.focus();
	return wnd;
}

//***********************************************************************
// openMaximizeWindow
// 目的 :	最大化ウインドウを開く。
// 引数 :	strURL..........URL
//			strWindowName...ウインドウ名
// 戻り値 :	ウインドウオープンオブジェクト
//***********************************************************************
function openMaximizeWindow(strURL, strWindowName)
{
	var newWindow = openWindow(strURL, strWindowName, 0, 0);
	newWindow.moveTo(0,0);
	newWindow.resizeTo(screen.availWidth,screen.availHeight);
	return newWindow;
}

//***********************************************************************
// openWindowOutOfDisplay
// 目的 :	ウインドウを画面外に開く。
// 引数 :	strURL..........URL
//			strWindowName...ウインドウ名
// 戻り値 :	ウインドウオープンオブジェクト
//***********************************************************************
function openWindowOutOfDisplay(strURL, strWindowName)
{
	var topPos = screen.height * 10;
	var leftPos = screen.width * 10;

	return window.open(strURL, strWindowName, "channelmode=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=0,width=0px,height=0px,top=" + topPos + ",left=" + leftPos);
}

//***********************************************************************
// closeWindow
// 目的 :	ウインドウを閉じる。
// 引数 :	strWindowName...ウインドウ名
// 戻り値 :	なし
//***********************************************************************
function closeWindow(strWindowName)
{
	var targetWindow = openWindowOutOfDisplay("", strWindowName);

	if (targetWindow) {
		targetWindow.close();
	}
}

//***********************************************************************
// openPdfWindow
// 目的 :	ウインドウを画面中央に開く。(PDF用設定)
// 引数 :	strURL..........URL
//			strWindowName...ウインドウ名
//			nWidth..........ウインドウの幅
//			nHeight.........ウインドウの高さ
// 戻り値 :	ウインドウオープンオブジェクト
//***********************************************************************
function openPdfWindow(strURL, strWindowName, nWidth, nHeight)
{
	var topPos = (screen.height / 2) - (nHeight / 2);
	var leftPos = (screen.width / 2) - (nWidth / 2);

	var wnd = window.open(strURL, strWindowName, "channelmode=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=0,toolbar=0,width=" + nWidth + "px,height=" + nHeight + "px,top=" + topPos + ",left=" + leftPos);
	wnd.focus();
	return wnd;
}

//***********************************************************************
// openPdfWindowPortrait
// 目的 :	ウインドウを画面中央に開く。(PDF縦向き用デフォルト設定)
// 引数 :	strURL..........URL
//			strWindowName...ウインドウ名
// 戻り値 :	ウインドウオープンオブジェクト
//***********************************************************************
function openPdfWindowPortrait(strURL, strWindowName)
{
	closeWindow(strWindowName);
	return openPdfWindow(strURL, strWindowName, 610, 841);
}

//***********************************************************************
// openPdfWindowLandscape
// 目的 :	ウインドウを画面中央に開く。(PDF横向き用デフォルト設定)
// 引数 :	strURL..........URL
//			strWindowName...ウインドウ名
// 戻り値 :	ウインドウオープンオブジェクト
//***********************************************************************
function openPdfWindowLandscape(strURL, strWindowName)
{
	closeWindow(strWindowName);
	return openPdfWindow(strURL, strWindowName, 841, 610);
}


//***********************************************************************
// setParentTitle
// 目的 :	最上層のタイトルを変更する
// 引数 :	なし
// 戻り値 :	なし
//***********************************************************************
function setParentTitle()
{
	parent.top.document.title = document.title;
}

//***********************************************************************
// lockObjects
// 目的 :	指定されたObject配列の全ての要素に対して使用を禁止します。
// 引数 :	obj...無効化するObject配列
// 戻り値 :	もともと使用不可だった項目
//***********************************************************************
function lockObjects(obj) {
	var ret = new Array();  //戻り値：もともと使用不可だった項目
	var retCount = 0;

	for (i = 0; i < obj.length; i++) {
		if( (obj[i].readOnly) && (obj[i].readOnly == true) ) {
			// ReadOnlyなオブジェクトは何もしない
		} else if( (obj[i].type) && (obj[i].type == 'hidden') ) {
			// hiddenには何もしない
		} else if(obj[i].href) {
			// リンクオブジェクトはリンク先属性を削除
			//属性値退避
			obj[i].locktmp_href    = obj[i].href;
			obj[i].locktmp_onclick = obj[i].onclick;
			obj[i].locktmp_color   = obj[i].style.color;
			//属性値削除
			obj[i].removeAttribute("href");
			obj[i].onclick = "void();";
			obj[i].removeAttribute("onclick");
			if( ( obj[i].currentStyle ) && ( obj[i].currentStyle.color == "#000000" ) ) {		//IEのみ
				obj[i].style.color = "black";
			}
		} else {
			// それ以外はdisabled指定
			if( obj[i].disabled == true ) {
				ret[retCount++] = obj[i]; //もともと使用不可だった項目
			} else {
				obj[i].disabled = true;
			}
		}
	}
	return ret;
}
//***********************************************************************
// unLockObjects
// 目的 :	lockObjectsによる使用禁止を解除します。
// 引数 :	obj...無効化するObject配列
// 戻り値 :	なし
//***********************************************************************
function unLockObjects(obj) {
	for (i = 0; i < obj.length; i++) {
		if( (obj[i].readOnly) && (obj[i].readOnly == true) ) {
			// ReadOnlyなオブジェクトは何もしない
		} else if( (obj[i].type) && (obj[i].type == 'hidden') ) {
			// hiddenには何もしない
		} else if(obj[i].locktmp_href) {
			// リンクオブジェクトはリンク先属性を復帰
			//属性値復帰
			obj[i].href        = obj[i].locktmp_href;
			obj[i].onclick     = obj[i].locktmp_onclick;
			obj[i].style.color = obj[i].locktmp_color;
			//退避領域クリア
			obj[i].removeAttribute( 'locktmp_href' );
			obj[i].removeAttribute( 'locktmp_onclick' );
			obj[i].removeAttribute( 'locktmp_color' );
		} else {
			// それ以外はdisabled指定を解除
			obj[i].disabled = false;
		}
	}
}

//***********************************************************************
// lockAllControl
// 目的 :	画面のINPUT、A、SELECTタグを全て無効化します。
// 引数 :	jyogaiList 例外的に無効化しない項目 （省略可）
// 戻り値 :	もともと使用不可だった項目
//***********************************************************************
function lockAllControl( jyogaiList ) {
	var inputObj  = document.getElementsByTagName("input");
	var linkObj   = document.getElementsByTagName("a");
	var selectObj = document.getElementsByTagName("select");
	//除外項目を除去
	inputObj  = removeObjects( inputObj,  jyogaiList );
	linkObj   = removeObjects( linkObj,   jyogaiList );
	selectObj = removeObjects( selectObj, jyogaiList );

	//項目を無効化
    var ret = new Array(); //戻り値：元々disabledだった項目
    [].push.apply( ret, lockObjects(inputObj) );
    [].push.apply( ret, lockObjects(linkObj) );
    [].push.apply( ret, lockObjects(selectObj) );

    return ret;
}

//***********************************************************************
// unLockAllControl
// 目的 :	lockObjectsによる画面の使用禁止を解除します。
// 引数 :	jyogaiList 例外的に無効化しない項目 （省略可）
// 戻り値 :	なし
//***********************************************************************
function unLockAllControl( jyogaiList ) {
	var inputObj  = document.getElementsByTagName("input");
	var linkObj   = document.getElementsByTagName("a");
	var selectObj = document.getElementsByTagName("select");
	//除外項目を除去
	inputObj  = removeObjects( inputObj,  jyogaiList );
	linkObj   = removeObjects( linkObj,   jyogaiList );
	selectObj = removeObjects( selectObj, jyogaiList );

	//項目の無効化を解除
	unLockObjects(inputObj);
	unLockObjects(linkObj);
	unLockObjects(selectObj);
}
//***********************************************************************
// objから、removelistに含まれるものを除去して返す
//***********************************************************************
function removeObjects( obj, removelist ) {
	if( (obj == null) || (obj.length <= 0)
		|| (removelist == null) || (removelist.length <= 0) ) {
		return obj;
	}

	var ret = new Array();
	var count = 0;

	for( var i = 0, len_obj = obj.length; i < len_obj; i++ ) {
		var isAdd = true;
		for( var j = 0, len_rmv = removelist.length; j < len_rmv; j++ ) {
			if( removelist[j] == null ) {
				continue;
			}
			if( removelist[j] == obj[i] ) {
				isAdd = false;
				break;
			}
		}
		if( !isAdd ) {
			continue;
		}
		ret[count] = obj[i];
		count++;
	}	return ret;

}

//***********************************************************************
// killAllTrigger
// 目的 :	画面のINPUT(button)、Aタグを全て無効化します。
//			※[注意] このメソッドを呼び出すと、以降その項目のonclickは一切動かなくなります。（submitするまで）
//			※画面submit時のロック用。
//***********************************************************************
function killAllTrigger() {
	var inputObj = document.getElementsByTagName("input");
	var linkObj   = document.getElementsByTagName("a");

    //button, submitだけ抜き出す
    var btnObj = new Array();
    for( var i = 0, imax = inputObj.length; i < imax; i++ ) {
    	var obj = inputObj[i];
    	if( obj.type=='button' ) {
    		//btnObj.push( obj );
    		killTrigger( obj );
    	} else if( obj.type=='submit' ) {
    		killTrigger( obj );
    	} else if( obj.type=='reset' ) {
    		killTrigger( obj );
    	}
    }

	//リンクを無効化
    killTriggers( linkObj );
}
function killTrigger( element ) {
	element.onclick = function() { return false; };
}
function killTriggers( elements ) {
	for( var i = 0, imax = elements.length; i < imax; i++ ) {
		killTrigger( elements[i] );
	}
}
//***********************************************************************
// submitLock
// 目的 :	画面submit時のロック処理
// 			※killAllTrigger()は一度呼んだら後にはひけないので注意
//***********************************************************************
function submitLock() {
	FreezeScreen();
	killAllTrigger();
}

//**********************************************************************
// overrideSubmit
// 目的 :	全てのFormのsubmitメソッドを置き換えます
// 引数 :	なし
// 戻り値 :	なし
//***********************************************************************
function overrideSubmit() {
	
	var forms = document.getElementsByTagName("form");
	
	for (i = 0; i < forms.length; i++) {
		forms[i].superSubmit = forms[i].submit;
		forms[i].submit = function() {
			this.superSubmit();
				lockAllControl();
		}
	}
}

//***********************************************************************
// changeDate
// 目的 :	受付期間を選択してFromを置き換える。不正な値が入力された場合はなにもしない
// 引数 :	frmName フォーム名
//          fromName 受付期間from名
//          fromName 受付期間To名
//          fromName 受付期間名
// 戻り値 :	なし
//***********************************************************************
function changeDate(frmName,fromName,toName,selectName){
  var to = document.getElementById(frmName + ":" + toName).value;
  var period = document.getElementById(frmName + ":" +selectName).value;
  var monthTbl = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  if(to == ""){
    to = new Date();
    }else{
    to = new Date(to);
    }
    if(to=="Invalid Date"){
    	return;
    }
    month = to.getMonth();
    to.setMonth(month - period + 1);
    fromYear = to.getFullYear();
    if(fromYear.length > 4) return;
    fromMonth = to.getMonth();
    if(fromMonth==0){
    	fromMonth = 12;
    	fromYear = fromYear - 1;
    }
    if(fromMonth < 10){
     fromMonth = "0" + fromMonth;
     }
    fromDate = to.getDate();
    if(fromDate < 10) fromDate = "0" + fromDate;
    //うるう年
    if((( fromYear % 4 ) == 0 && (fromYear % 100 ) !=0 ) || (fromYear % 400) ==0 ) monthTbl[1] = 29;
    if(monthTbl[fromMonth-1] < fromDate) {
    fromDate = monthTbl[fromMonth - 1];
    }
    from = fromYear + "/" + fromMonth + "/" + fromDate;
    document.getElementById(frmName + ":" + fromName).value = from;
  }


//***********************************************************************
// setElementClassById
// 目的 :	オブジェクトのクラス要素の追加、変更を行う
// 引数 :	elem エレメントのID
//			value クラス名
// 戻り値 :	なし
//***********************************************************************
function setElementClassById(elem, value) {
   if(document.getElementById) {
         var obj = document.getElementById(elem);
         if(obj) {
            obj.className = value;
         }
   }
}
//***********************************************************************
// encodeURL
// 目的 :	getでダブルバイトが含まれる文字列を送信する際にUTF-8で文字列をエンコードする
// 引数 :	str...エンコードする文字列
// 戻り値 :	UTF-8でエンコードされた文字列
//***********************************************************************
function encodeURL(str){

    var s0, i, s, u;
    s0 = "";                // encoded str
    for (i = 0; i < str.length; i++){   // scan the source
        s = str.charAt(i);
        u = str.charCodeAt(i);          // get unicode of the char
        if (s == " "){s0 += "+";}       // SP should be converted to "+"
        else {
            if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a))){       // check for escape
                s0 = s0 + s;            // don't escape
            }
            else {                  // escape
                if ((u >= 0x0) && (u <= 0x7f)){     // single byte format
                    s = "0"+u.toString(16);
                    s0 += "%"+ s.substr(s.length-2);
                }
                else if (u > 0x1fffff){     // quaternary byte format (extended)
                    s0 += "%" + (oxf0 + ((u & 0x1c0000) >> 18)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
                else if (u > 0x7ff){        // triple byte format
                    s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
                else {                      // double byte format
                    s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
            }
        }
    }
    return s0;
}

//***********************************************************************
// blinkMsg
// 目的 :	一定秒ごとに指定したidのオブジェクトのスタイルを切り替える（点滅させる）
//　　　　　問合せ内容をリーダーに送信するバージョン
// 戻り値 :	なし
//***********************************************************************
blinkFlg=true;
function blinkMsg(id,coler){
	var interval = 500;
	if(!E(id)) return;
	if(blinkFlg){
		E(id).style.color="#C40000";
	}else{
		E(id).style.color="#FCFAE4";
	}
	blinkFlg=!blinkFlg;
setTimeout("blinkMsg('" + id + "')",interval);
}
//***********************************************************************
// blinkMsg2
// 目的 :	一定秒ごとに指定したidのオブジェクトのスタイルを切り替える（点滅させる）
//　　　　　問合せ内容をリーダーに送信しないバージョン
// 戻り値 :	なし
//***********************************************************************
blinkFlg=true;
function blinkMsg2(id,coler){
	var interval = 500;
	if(!E(id)) return;
	if(blinkFlg){
		E(id).style.color="#003366";
	}else{
		E(id).style.color="#FCFAE4";
	}
	blinkFlg=!blinkFlg;
setTimeout("blinkMsg2('" + id + "')",interval);
}
//***********************************************************************
// changeColorByTime
// 目的 :	時間経過により色を変更する
// 戻り値 :	なし
//***********************************************************************
function changeColorByTime(){
	if(!E("field1")) return;
	if(!E("field1")) return;
	if(!E("field1")) return;
	dispTimer();
	setClassByTime();
}

var start = new Date(); 
// 初期化 
var hour = 0; 
var min = 0; 
var sec = 0; 
var now = 0; 
var datet = 0; 

function dispTimer(){
now = new Date(); 
datet = parseInt((now.getTime() - start.getTime()) / 1000); 
hour = parseInt(datet / 3600); 
min = parseInt((datet - hour * 3600) / 60);
sec = datet % 60; 
// 数値が1桁の場合、頭に0を付けて2桁で表示する指定 
if(hour < 10) { hour = "0" + hour; } 
if(min < 10) { min = "0" + min; } 
if(sec < 10) { sec = "0" + sec; } 
// テキストフィールドにデータを渡す処理 
E("field1").value = hour; 
E("field2").value = min; 
E("field3").value = sec; 
setTimeout("dispTimer()", 1000); 
}

function setClassByTime(){
//2分、5分、10分
setTimeout('setElementClassById("text", "attention attention2")',120000);
setTimeout('setElementClassById("text", "attention attention5")',300000);
setTimeout('setElementClassById("text", "attention attention10")',600000);
}
 
//カンマ挿入関数
function insertComma(x) { // 引数の例としては 95839285734.3245
    var s = "" + x; // 確実に文字列型に変換する。例では "95839285734.3245"
    var p = s.indexOf("."); // 小数点の位置を0オリジンで求める。例では 11
    if (p < 0) { // 小数点が見つからなかった時
        p = s.length; // 仮想的な小数点の位置とする
    }
    var r = s.substring(p, s.length); // 小数点の桁と小数点より右側の文字列。例では ".3245"
    for (var i = 0; i < p; i++) { // (10 ^ i) の位について
        var c = s.substring(p - 1 - i, p - 1 - i + 1); // (10 ^ i) の位のひとつの桁の数字。例では "4", "3", "7", "5", "8", "2", "9", "3", "8", "5", "9" の順になる。
        if (c < "0" || c > "9") { // 数字以外のもの(符合など)が見つかった
            r = s.substring(0, p - i) + r; // 残りを全部付加する
            break;
        }
        if (i > 0 && i % 3 == 0) { // 3 桁ごと、ただし初回は除く
            r = "," + r; // カンマを付加する
        }
        r = c + r; // 数字を一桁追加する。
    }
    return r; // 例では "95,839,285,734.3245"
}

 
	//カンマ削除関数
	function delComma(w) {
    	var z = w.replace(/,/g,"");
    	return (z);
	}

	//数値チェック関数
	function checkIsNumber(value){
      return (value.match(/[0-9]+/g) == value);
	}

//***********************************************************************
// messageタグの整形
// 
// 基本形： <span id="aaa"><h:message /></span>
// この場合は aaa のidを渡す。
// ※<h:message>タグのすぐ外側のタグID
// 
// <h:message>タグで、メッセージがある場合のみ改行させたりする
//***********************************************************************
function shapeMessageTag( targetId ) {
    var ihtml = E( targetId ).innerHTML;

    if( ihtml != '' ) {
        var head = '<div style=\'margin-top:3px;margin-bottom:3px;\'>'
                 + '<ul id=\'' + targetId + ':messages\'></ul>'
                 + '<ul id=\'' + targetId + ':messages_global\'>'
                 + '<li>';
        var tail = '</li></ul></div>';

        E( targetId ).innerHTML = head + ihtml + tail;
    }
}

//***********************************************************************
// FreezeScreen
// 目的 :	ボタン押下時に2度押しを防止するため、画面をフリーズさせる
// 戻り値 :	なし
//***********************************************************************
function FreezeScreen(msg) {
	//scroll(0,0); //2007.10.12 : メッセージを出さなくなったのでTOPまでスクロールする必要がない
	if(msg == undefined) msg= 'ただいま処理中です。しばらくお待ちください。';
	var outerPane = document.getElementById('FreezePane');
	var innerPane = document.getElementById('InnerFreezePane');
	var i1 = document.getElementById('i1');
    i1.focus();  //画面上でのキー連打防止のため、フォーカスを奪う。

	if (outerPane) outerPane.className = 'FreezePaneOn';//無色に変更
	
	if ((browserCheck()=="I")||(browserCheck()=="F")){
		var height = document.documentElement.clientHeight;
		if(document.documentElement.scrollHeight > height){
			height = document.documentElement.scrollHeight;
		}
	}else {
		var height = document.body.clientHeight;
		if(document.body.scrollHeight > height){
			height = document.body.scrollHeight;
		}
	}
	outerPane.style.height = height;
	i1.style.height = height;
	
	if ((browserCheck()=="I")||(browserCheck()=="F")){
		var width = document.documentElement.clientWidth;
		if(document.documentElement.scrollWidth > width){
			width = document.documentElement.scrollWidth;
		}
	}else {
		var width = document.body.clientWidth;
		if(document.body.scrollWidth > width){
			width = document.body.scrollWidth;
		}
	}
	outerPane.style.width = width;
	i1.style.width = width;
	
	if (innerPane) innerPane.innerHTML = msg;

    innerPane.style.display = 'block';
}
//***********************************************************************
// FreezeScreen2
// 目的 :	画面をフリーズさせる（無色/Ajax用等）
// 引数 :	CSS指定（定数を指定）
//            FREEZE_SCREEN_CLEAR = 透明 （デフォルト）
// 　　　　　　　　　　FREEZE_SCREEN_DARK  = 色つき（濃い目）
// 戻り値 :	なし
//***********************************************************************
var FREEZE_SCREEN_CLEAR = 'FreezePaneOn2';
var FREEZE_SCREEN_DARK = 'FreezePaneOn2Dark';

function FreezeScreen2( freezePaneOnCss ) {
	//var classOn = FREEZE_SCREEN_CLEAR;
	var classOn = 'FreezePaneOn';
	if( (freezePaneOnCss != null) && (freezePaneOnCss != '') ) {
		classOn = freezePaneOnCss;
	}

	var outerPane = document.getElementById('FreezePane');
	var innerPane = document.getElementById('InnerFreezePane');
	var i1 = document.getElementById('i1');
    i1.focus();  //画面上でのキー連打防止のため、フォーカスを奪う。

	if (outerPane) outerPane.className = classOn;
	
	if ((browserCheck()=="I")||(browserCheck()=="F")){
		var height = document.documentElement.clientHeight;
		if(document.documentElement.scrollHeight > height){
			height = document.documentElement.scrollHeight;
		}
	}else {
		var height = document.body.clientHeight;
		if(document.body.scrollHeight > height){
			height = document.body.scrollHeight;
		}
	}
	outerPane.style.height = height;
	i1.style.height = height;
	
	if ((browserCheck()=="I")||(browserCheck()=="F")){
		var width = document.documentElement.clientWidth;
		if(document.documentElement.scrollWidth > width){
			width = document.documentElement.scrollWidth;
		}
	}else {
		var width = document.body.clientWidth;
		if(document.body.scrollWidth > width){
			width = document.body.scrollWidth;
		}
	}
	outerPane.style.width = width;
	i1.style.width = width;

    innerPane.style.display = 'none';
}
//***********************************************************************
// UnFreezeScreen
// 目的 :	画面のフリーズを解除する
// 戻り値 :	なし
//***********************************************************************
function UnFreezeScreen() {
	var outerPane = document.getElementById('FreezePane');
	var innerPane = document.getElementById('InnerFreezePane');
	var i1 = document.getElementById('i1');

	if (outerPane) outerPane.className = 'FreezePaneOff';
	
	outerPane.style.height = '';
	i1.style.height = '';

	outerPane.style.width = '';
	i1.style.width = '';
	if (innerPane) innerPane.innerHTML = '';
}

//***********************************************************************
// 確認ダイアログ＆画面フリーズ
//***********************************************************************
function confirmAndFreezeScreen( msg ) {
    var cnf = confirm( msg );
    if( !cnf ) {
        return false;
    }

    FreezeScreen();

    return true;
}

//***********************************************************************
// invalidKey
// 目的 :	ショートカットキーの無効化(windowsIE6+FireFox2.0対応前提）
// ※event.srcElement←IE用。evt.target←Firefox用。
// 戻り値 :	boolean
//***********************************************************************
function invalidKey(evt) {
	if(document.all){
		kc = event.keyCode;
		ctrl = event.ctrlKey;
		alt = event.altKey;
		flg = true;
	}else{
		kc = evt.keyCode;
		ctrl = evt.ctrlKey;
		alt = evt.altKey;
		flg = false;
	}
	//alert(kc);
	if((flg && kc==8 && ((event.srcElement.tagName == 'INPUT' && event.srcElement.type == 'text')   || event.srcElement.tagName == 'TEXTAREA')&&event.srcElement.readOnly == false)||
		   (flg && kc==8 && ((event.srcElement.tagName == 'INPUT' && event.srcElement.type == 'password') || event.srcElement.tagName == 'TEXTAREA')&&event.srcElement.readOnly == false)){//back space
		return true;
	} else if(kc==13 && (event.srcElement.tagName == 'INPUT' && event.srcElement.type == 'file')){
		return false;
	} else if((!flg && kc==8 && ((evt.target.tagName == 'INPUT' && evt.target.type == 'text')   || evt.target.tagName == 'TEXTAREA')&&evt.target.readOnly == false)||
			 (!flg && kc==8 && ((evt.target.tagName == 'INPUT' && evt.target.type == 'password') || evt.target.tagName == 'TEXTAREA')&&evt.target.readOnly == false) || (event.srcElement.tagName == 'INPUT' && event.srcElement.type == 'file')){//back space
		return true;
	}else if(kc==8){
		return false;
	}else if(kc==116){//F5
		if(flg) event.keyCode= null;
		return false;
	}else if(ctrl && kc==78){//ctrl + N
		return false;
	}else if(ctrl && kc==84){//ctrl + T
		return false;
	}else if(ctrl && kc==82){//ctrl + R
		return false;
	}else if(alt && kc==37){//alt + ←
		return false;
	}
	return true;
}
//***********************************************************************
// enterCancel
// 目的 :	エンターキーを押したときにサブミットをキャンセルする
// 戻り値 :	なし
//***********************************************************************
function enterCancel(evt){
  alert('entercheck');
  if (evt.keyCode == 13) {
    if (evt.preventDefault) {
      evt.preventDefault();
    } else {
      evt.returnValue = false;
    }
  }
}


//***********************************************************************
// setStyleClass
// 目的：指定した項目にCSSのクラスをセットする
// @param targetId 対象項目
// @param className クラス
//***********************************************************************
function setStyleClass( targetId, className ) {
	var target = E( targetId );
	if( target == null ) {
		return;
	}
    var cls = target.className;        //対象項目のclass
    
    //一旦対象クラスを除去
    if( cls != '' ) {
        cls = cls.replace( ' ' + className + ' ', '' );
    }
    //クラスを追加
    cls = cls + ' ' + className + ' ';
    
    //項目のclassとして設定
    target.className = cls;
}
//***********************************************************************
// clearStyleClass
// 目的：指定した項目からCSSのクラスを除去する
// @param targetId 対象項目
// @param className クラス
// 
// ※!! 対象クラスは左右にスペースがある事が条件。タグに記述する際には注意する。
// ※例） Ｘ class="shohinNo"    Ｏ class=" shohinNo "
//***********************************************************************
function clearStyleClass( targetId, className ) {
    var cls = E( targetId ).className;        //対象項目のclass

    //対象クラスを除去
    if( cls != '' ) {
        cls = cls.replace( ' ' + className + ' ', '' );
    }
    //項目のclassとして設定
    E( targetId ).className = cls;
}

//***********************************************************************
// setButtonStyleClass
// 目的： ボタンにCSSを設定
// @param btnId
// @param upStyleClass 通常時のCSS
// @param downStyleClass 押込み時のCSS
//***********************************************************************
function setButtonStyleClass( btnId, upStyleClass, downStyleClass ) {
    var btn = document.getElementById( btnId );
    if( btn == null ) {
        return;
    }

    btn.downStyleClass  = downStyleClass;
    btn.upStyleClass = upStyleClass;
    setStyleClass( btn.id, btn.upStyleClass );

    this.setOn = function() {
        btn = event.srcElement;
        clearStyleClass( btn.id, btn.upStyleClass );
        setStyleClass( btn.id, btn.downStyleClass );
    }
    this.setOff = function() {
        btn = event.srcElement;
        clearStyleClass( btn.id, btn.downStyleClass );
        setStyleClass( btn.id, btn.upStyleClass );
    }
    this.onKeydown = function() {
        if( event.keyCode == 32 ) { //space
            setOn();
        }
    }

    btn.onmousedown = setOn;
    btn.onmouseup = setOff;
    btn.onmouseout = setOff;
    btn.onkeydown = onKeydown;
    btn.onkeyup = setOff;
}

//***********************************************************************
//省略可能なフラグの変換
//***********************************************************************
function toBoolean_( flg, nullcase ) {
    if( flg == null ) {
    	return nullcase;
    }
    return flg;
}

//***********************************************************************
//バイト数を取得
//***********************************************************************
function getLengthb(str) {
	if (str=="" || !str || str==null) return 0;
	str=trashGomi(str);
	var strS=str.replace(/[^0-9a-zｱ-ﾝ\!\"\#\$\%\&\'\(\)\-\=\^\~\\\|\@\`\[\{\;\+\:\*\]\}\,\<\.\>\/\?\_]/ig,"##");
	return strS.length;
}
function trashGomi(s) {
    s=unescape(escape(s).split("%00")[0]);
    return s;
}

//***********************************************************************
// onKeyDown
// 目的 :	キーイベント処理
// 引数 :	なし
// 戻り値 :	なし
//***********************************************************************
function onKeyDown(evt){    
	//keydownのイベントが上書きされたとき用
	if(!invalidKey(evt)) return false;
	
	if (navigator.appName == "Microsoft Internet Explorer") {
		if (event.keyCode == 13)
		{
			if(window.event.srcElement.type!='submit' && 
				window.event.srcElement.type!='button' && 
				window.event.srcElement.type!='cancel' && 
				window.event.srcElement.type!='' && 	 //aタグ
				window.event.srcElement.type!='textarea'){
				return false;
			}
		}
	}
}
//***********************************************************************
// 項目が使用可能状態であればフォーカスをセット
// @param targetId
// poaram isSelect gain時のみ(省略可能/デフォルト=false)
//***********************************************************************
function setFocusById( targetId, isSelect ) {
	var target = document.getElementById( targetId );
	if( target == null ) {
		return;
	}
	if( (target.disabled == undefined) || (target.disabled) ) {
		return;
	}

	//フォーカスセット
	target.focus();

	//選択状態
	if( (isSelect != undefined) && (isSelect == true) ) {
		if(target.select) { //selectメソッドを持っている項目なら呼ぶ
			target.select();
		}
	}
}
//***********************************************************************
// 項目が使用可能状態であればフォーカスを喪失させる
// @param targetId
//***********************************************************************
function lostFocusById( targetId ) {
	var target = document.getElementById( targetId );
	if( target == null ) {
		return;
	}
	if( (target.disabled == undefined) || (target.disabled) ) {
		return;
	}
	//フォーカス喪失
	target.blur();
}

//***********************************************************************
// 曜日を取得
// @param iy
// @param im
// @param id
//***********************************************************************
function getDayOfTheWeek( y, m, d, isNeedAlert ) {
	if( isNeedAlert == null ) isNeedAlert = true;
    //数値化
    var iy = eval( y );
    var im = eval( m );
    var id = eval( d );
	//日付化
    var dt = new Date( iy, im-1, id );
    if( isNaN(dt) ) {
    	if( isNeedAlert ) {
	    	alert( 'toDate-failure : iy[' + iy + '] im[' + im + '] id[' + id + ']' );
    	}
        return;
    }
	//曜日を取得
	return '日月火水木金土'.charAt( dt.getDay() );
}

//----------------------------------------
//指定したエレメントを表示します。
//----------------------------------------
function p_show(elementId){
	if(!E(elementId)) return;
	E(elementId).style.display ="";
}

//----------------------------------------
//指定したエレメントを非表示にします。
//----------------------------------------
function p_hide(elementId){
	if(!E(elementId)) return;
	E(elementId).style.display ="none";
}

//----------------------------------------
//指定したエレメントの表示/非表示を判定します。
//----------------------------------------
function p_visible(elementId){
	if(!E(elementId)) return false;
	return E(elementId).style.display != 'none';
}

//----------------------------------------
//ブラウザが何かを判定します。
//----------------------------------------
function browserCheck(){
strUA = navigator.userAgent.toLowerCase();

if (strUA.indexOf("chrome") != -1) {
  return "C";//GoogleChrome
	
}else if(strUA.indexOf("safari") != -1){
  return "S";//Safari

}else if(strUA.indexOf("firefox") != -1){
  return "F";//Firefox

}else if(strUA.indexOf("opera") != -1){
  return "O";//Opera

}else if(strUA.indexOf("netscape") != -1){
  return "N";//Netscape

}else if(strUA.indexOf("MSIE")!=-1 && strUA.indexOf("Trident/4.0")!=-1){
  return "IE8";//Internet Explorer 8

}else if(strUA.indexOf("msie") != -1){
  return "I";//Internet Explorer

}else if(strUA.indexOf("mozilla/4") != -1){
  return "N4";//Netscape.4
}

}

//----------------------------------------------------------------------
// searchWindowClose　受け渡された項目にテキストをセットする。（innerText対応）
// @param 1:セットするID、2:テキスト
//----------------------------------------------------------------------
function setInnerText(idName, text){
	if (typeof document.getElementById(idName).textContent != "undefined") {
		document.getElementById(idName).textContent = text;
	} else {
		document.getElementById(idName).innerText = text;
	}
}

//----------------------------------------------------------------------
//openProductWindow　商品簡易詳細画面をサブウィンドウで開く。
//@param pcd 商品コード
//@param cd 店舗コード
//@param isCatalog true:カタログ商品、falseカタログ商品以外
//----------------------------------------------------------------------
function openProductWindow(pcd, cd, isCatalog){
	
	var subWindow;
	if (isCatalog) {
		subWindow = window.open("NFE11004.jsp?pcd=" + pcd,
				'productWindow', 'height=660, width=850, dependent=yes, menubar=no, toolbar=no, scrollbars=yes');
	} else {
		subWindow = window.open("NFE11004.jsp?pcd=" + pcd + "&cd=" + cd,
				'productWindow', 'height=660, width=850, dependent=yes, menubar=no, toolbar=no, scrollbars=yes');
	}
	
	subWindow.focus();
	
	return false;
}

//----------------------------------------------------------------------
//openShopWindow　店舗簡易詳細画面をサブウィンドウで開く。
//@param cd 店舗コード
//----------------------------------------------------------------------
function openShopWindow(cd){
	
	var subWindow = window.open("NFE24003.jsp?cd=" + cd,
				'shopWindow', 'height=660, width=850, dependent=yes, menubar=no, toolbar=no, scrollbars=yes');
	
	subWindow.focus();
	
	return false;
}

//----------------------------------------------------------------------
//openNewWindow　新規ウィンドウを開く
//@param id HTML要素ID
//----------------------------------------------------------------------
function openNewWindow(id) {
	var obj = document.getElementById(id);
	var newWindow = window.open(obj.href);
	newWindow.focus();
	return false;
} 
