// copyright (C) Veritice 2008

//	isValidYMD( gengo, value )		日付文字列の桁チェック
//	isDigit( value )				半角数字かどうか
//  isValidDate_ById( gengoID, dateID )		日付が正しいか検査(コントロールIDで指定)[2008/12/17]
//  isValidDate_ByDateString( datestring )	日付が正しいか検査(yyyymmdd,yyyymm,yyyy)[2008/12/17]
//  getByteLength(str)			文字列のバイト数を取得(半角での文字数)[2009/01/06]->[2009/04/15]
//  containsZenkaku(str)		全角文字が含まれているか[2009/01/06]
//  containsHankaku(str)		半角文字が含まれているか[2009/01/06]
//
//   getAGE( 'yyyymmdd' ) ... 年齢取得[2008/12/03]
//
//
//   setOpacity		... 指定オブジェクトの透過度設定[2009/07/21]
//
// ■ 文字列処理
//   String.cropByBytes(num)  ... 指定バイト数以内になるように文字列を削る[2009/04/14]
//   String.escapeForPost()   ... POST用にエスケープ処理を施した文字列を返します
//
// ■ 書式
//   getNumberFormat( value ) ... カンマ区切りの
//   getZeroSuppressString    ... 頭の0を省きます( ゼロサプレス )
//
// ■ 税金関係
//   getZeinukiPrice		[2008/11/25]
//   getZeikomiPrice		[2008/11/25]
//   getMarumeValue( value, keta, hasuu )		数値丸め処理[2008/12/16]
//   getSotozei( value, ritsu ,keta, hasuu )	外税の取得[2008/12/16]
//   getUchizei( value, ritsu ,keta, hasuu )	内税の取得[2008/12/16]
//   getZeikomi( value, ritsu ,keta, hasuu )	税込価格の取得[2008/12/16]
//   getZeinuki( value, ritsu ,keta, hasuu )	税抜価格の取得[2008/12/16]
//
// ■ メッセージボックス関係
//   MessageDialog_Show( 表示ダイアログタイプ, 表示メッセージ, コールバック関数(またはnull) [,デフォルトボタンコード] );	[2009/03/24]
//
// ■ カレンダー関係( 要gengo.js , gengo_for_js.html)
//   showCalendar( 元号区分のSELECT要素のID, 日付入力のINPUT要素のID [ , コールバック関数 ] )	カレンダーの表示	[2008/11/28]( コールバック関数は任意 )
//   calendarValueToControl(pDate,元号コントロールID ,日付コントロールID)	カレンダー日付を日付コントロールに代入[2008/11/27]
//   calendarGetValueFromControl( 元号区分値 ,日付値 )						日付コントロール値をカレンダー日付に変換[2008/11/27]
//
// ■ Ajax補助
//   ajaxRequestSync     ... Ajaxの簡易同期通信(GET) [2009/03/06]
//   ajaxRequestSyncPost ... Ajaxの簡易同期通信(POST) [2009/06/19]
//   ajaxRequestSyncPost2 ... Ajaxの簡易同期通信(POST) 受信テキストをそのまま返す [2009/06/28]
//
// ■ キー操作補助
//   common_DisableSpecialKey_OnKeyPress	KeyPress時、特殊キー無効化(自動割り当て) [2009/03/12]
//   common_DisableSpecialKey_OnKeyDown		KeyDown時、特殊キー無効化(自動割り当て) [2009/03/12]->[2009/04/15]
//
// ■ セッション保持タイマー
//   commonClock_Initialize		タイマー環境初期化
//   commonClock_Exec			セッション保持用リクエスト
//   commonClock_Callback		レスポンス処理
//   
//
//
// var Domi   ... DOMイテレータ	[2008/10/27追加]

// 更新日：[2008/??/??]->[2009/04/15]->[2009/06/19]->[2009/06/28]
//**********************************************************************

// Common
$j=jQuery.noConflict();

var commonFocusId = '';		// 現在のフォーカス[2008/11/25]

//currentFNo = 0; function nextForm() { if (event.keyCode == 13) { currentFNo++; currentFNo %= document.myFORM.elements.length; document.myFORM[currentFNo].focus(); } } window.document.onkeydown = nextForm; 

// window.eventの誌錡( firefoxでも擬似のeventが取れるように[未完成])
function windowEvent(){
 if(window.event) return window.event;
 var caller = arguments.callee.caller;
 while(caller){
  var ob = caller.arguments[0];
  if(ob && ob.constructor == MouseEvent) return ob;
  caller = caller.caller;
 }
 return null;
}

// DOM Iterator
var Domi =
{
    each: function (collection, yield)
    {
	for (var i = 0; i < collection.length; i++)
	    yield(collection[i]);
    }
};


// 誕生日（yyyymmdd）から年齢を返す
// [2008/12/03]
function getAGE(birth){

		if (birth.length < 8 || !isDigit(birth)){
			return '';
		}
		
		var now = new Date();
		var y=now.getFullYear();
		var m=now.getMonth()+1;
		var d=now.getDate();
		if( m <10){ m = '0'+m; }
		if( d <10){ d = '0'+d; }
		
		now = parseInt(''+y +''+ m + ''+d,10);

	birth = parseInt(birth,10);
		
		return parseInt((now - birth) / 10000,10);
		
	}

// 
function getComboboxTextByValue( obj ,value ){

	var index = 0;
	var i = 0;
	var len = obj.length;
	for(i=0;i<len;i++){
		if( obj.options[i].value == value){
			return obj.options[i].label;
		}
	}
	return '';
}

function getComboboxSelectedValue( obj ){
	return obj.options[obj.selectedIndex].value;
}

// 指定のvalueを持つselectの項目を選択状態にする
function selectComboboxByValue( obj , value ){
	
	var index = 0;
	var i = 0;
	var len = obj.length;
	for(i=0;i<len;i++){
		if( obj.options[i].value == value){
			index = i;
			break;
		}
	}
	obj.selectedIndex = index;
}

//**********************************************************************
// 税金関係
//**********************************************************************


// ▼ 数値丸め処理[2008/12/16]
function getMarumeValue( value, keta, hasuu ){
	if( value == ''){ return 0;}
	var temp  = 0;
	temp = parseInt(value*10,10) + parseInt(hasuu*10,10);		// 切り上げ・四捨五入のための追加端数を追加
	temp /= 10;
	temp = parseInt(temp,10) / keta;					// アプリ版と同様
	temp = parseInt(temp,10) * keta;					// アプリ版と同様
	return parseInt(temp,10);
}

// ▼ 外税の取得[2008/12/16]
function getSotozei( value, ritsu ,keta, hasuu ){
	if( value == ''){ return 0;}
	var temp = ( parseInt(value,10) * parseInt(ritsu,10) ) / 1000 ;		// 外税計算
	temp = getMarumeValue( temp, keta, hasuu );	// 丸め処理
	return parseInt(temp,10);
}

// ▼ 内税の取得[2008/12/16]
function getUchizei( value, ritsu ,keta, hasuu ){
	if( value == ''){ return 0;}
	var temp = ( parseInt(value,10) * parseInt(ritsu,10) ) / ( 1000 + parseInt(ritsu,10) );		// 内税計算
	temp = getMarumeValue( temp, keta, hasuu );		// 丸め処理
	return parseInt(temp,10);
}

// ▼ 税込価格の計算[2008/12/16]
function getZeikomi( value, ritsu ,keta, hasuu ){
	if( value == ''){ return 0;}
	return parseInt(value,10) + getSotozei(value, ritsu, keta, hasuu );
}

// ▼ 税抜価格の計算[2008/12/16]
function getZeinuki( value, ritsu ,keta, hasuu ){
	if( value == ''){ return 0;}
	return parseInt(value,10) - getUchizei(value, ritsu, keta, hasuu );
}






// **********************************************************************
// 税別価格を取得
// 
// 更新日：2008/11/20
// **********************************************************************
function getZeinukiPrice( value , hiduke ,targetId ){
	getZeinukiPrice2( value, hiduke,targetId,'');
}

// 税別価格を取得
function getZeinukiPrice2( value , hiduke ,targetId, kyotencode){

	value = value.replace(/,/g, '');
	var url = '/list/tax_calc.php?';
	url += 'mode=0&value=' + value + '&date=' + hiduke + '&kyoten=' + kyotencode;
	var varId = targetId;
	
    new Ajax.Request(url,
        {
            method: 'get',
            onComplete: getResponse
            
            ,onFailure: function(req) {  alert('FAIL:読み込みに失敗しました' + req);}
			,onException: function (request, e) { alert('EXCEPTION:読み込み中にエラーが発生しました' + e.name + ': '+ e.message); } 
        });

	function getResponse(req) {
		eval("var result = " + req.responseText);
        if (!result.success) { return; }
		
		// 0の場合は空文字にする
		if( result.value == 0 ){ result.value = '';}
		 
		// 非同期対策：消費税計算より先にフォーカス移動が済んだ場合、
		// 税価格を書き換えると選択状態が解除されるため、再選択を行う
		// また、選択状態ではカンマ区切りを行わない
		if( varId == commonFocusId ){
			$(varId).value = result.value;
			$(varId).select();
			return;
		}

		// 空文字で無い場合はカンマ区切り数値を反映
		if( result.value != ''){ result.value = getNumberFormat(result.value);}
		$(varId).value = result.value;

	}
}

// 税込価格を取得
function getZeikomiPrice( value , hiduke , targetId){

	value = value.replace(/,/g, '');
	var url = '/list/tax_calc.php?';
	url += 'mode=1&value=' + value + '&date=' + hiduke;
	var varId = targetId;
	
    new Ajax.Request(url,
        {
            method: 'get',
            onComplete: getResponse
            
            ,onFailure: function(req) {  alert('FAIL:読み込みに失敗しました' + req);}
			,onException: function (request, e) { alert('EXCEPTION:読み込み中にエラーが発生しました' + e.name + ': '+ e.message); } 
        });

	function getResponse(req) {
		eval("var result = " + req.responseText);
        if (!result.success) { return; }
		
		// 0の場合は空文字にする
		if( result.value == 0 ){ result.value = '';}

		// 非同期対策：消費税計算より先にフォーカス移動が済んだ場合、
		// 税価格を書き換えると選択状態が解除されるため、再選択を行う
		// また、選択状態ではカンマ区切りを行わない
		if( varId == commonFocusId ){
			$(varId).value = result.value;
			$(varId).select();
			return;
		}
		
		// 空文字で無い場合はカンマ区切り数値を反映
		if( result.value != ''){ result.value = getNumberFormat(result.value);}
		$(varId).value = result.value;
	}
}



// **********************************************************************
// メッセージボックス関係
// **********************************************************************

var funcMessageDialogResult = null;		// メッセージダイアログ

/*
// メッセージブロック裏側にあるブロックを隠す
function hideMessageBlockBackward(){
	$('main_base_inner').style.display='none';
	$('command_button_base').style.display='none';
}
function showMessageBlockBackward(){
	$('main_base_inner').style.display='block';
	$('command_button_base').style.display='block';
}
*/




if (typeof document.documentElement.style.msInterpolationMode == "undefined"){
	window.addEventListener('load', MessageDialog_Initialize,false);
}else{
	window.attachEvent('onload', MessageDialog_Initialize);
}

function MessageDialog_Initialize(){
	if( document.getElementById("message_block_buttons") == null ){
		return;
	}
	
	$$("#message_block_buttons input.messagedialog_focus").each(function(obj){
		Event.observe( obj, 'keypress', function(e){ return common_OnKeyFocusControl(e,this,"messagedialog_focus");},false);
		Event.observe( obj, 'keydown', function(e){ return common_IE7CursorKeyMoveFocus(e,this,"messagedialog_focus");},false);
	});
}

//**********************************************************************
// メッセージダイアログの表示
//
// type       ... メッセージダイアログ種別( 1:確認、2:警告、3:エラー、4:インフォメーション、5:ラベル無し、6:確認( Yes/No/Cancel))
// message    ... 表示する文字列
// funcReturn ... コールバック関数。メッセージダイアログを閉じた後に何も呼び出さない場合はnullを指定
//
// 【任意パラメータ】
//    四番目の引数 ... 初めにフォーカスを当てるボタンのID[ 0:規定、1:OK、2:キャンセル、3:閉じる、5:はい、6:いいえ、-1:フォーカス設定を行わない ]
//
// 更新日：2008/11/19、2009/03/24
//**********************************************************************
function MessageDialog_Show( type , message , fncReturn ){
	
	funcMessageDialogResult = fncReturn;

	
	var id_nextfocus  = null;	// 初めにフォーカスを当てるボタンの情報
	var defaultButton = 0;		// フォーカス手動設定パラメータ
	
	
	
	// 【任意パラメータ】初めにフォーカスを当てるボタンのID
	if( arguments.length >= 4 ){
		defaultButton = arguments[3];
	}

	
	
	
	//hideMessageBlockBackward();
	
	var blockBase = $('message_block_base');
	var blockCover = $('message_block_cover');
	
	var buttonOK     = $('message_block_button_ok');
	var buttonCancel = $('message_block_button_cancel');
	var buttonYes    = $('message_block_button_yes');
	var buttonNo     = $('message_block_button_no');
	var buttonClose  = $('message_block_button_close');
	var title        = $('message_block_title');
	var text         = $('message_block_text');
	
	text.innerHTML = '<div>' + message + '</div>';
	
	// ボタンの初期化
	buttonOK.style.display     = 'none';
	buttonCancel.style.display = 'none';
	buttonYes.style.display    = 'none';
	buttonNo.style.display     = 'none';
	buttonClose.style.display  = 'none';
	
	if( type == 1 ){
		buttonOK.style.display     = 'inline';
		buttonCancel.style.display = 'inline';
		title.innerHTML = '<div>確認</div>';
		id_nextfocus = "message_block_button_cancel";
	}
	else if( type == 2 ){
		buttonOK.style.display     = 'inline';
		title.innerHTML = '<div>警告</div>';
		id_nextfocus = "message_block_button_ok";
	}
	else if( type == 3 ){
		buttonOK.style.display     = 'inline';
		title.innerHTML = '<div>エラー</div>';
		id_nextfocus = "message_block_button_ok";
	}
	else if( type == 4 ){
		buttonOK.style.display     = 'inline';
		title.innerHTML = '<div>インフォメーション</div>';
		id_nextfocus = "message_block_button_ok";
	}
	else if( type == 5 ){
		buttonOK.style.display     = 'inline';
		title.innerHTML = '';
		id_nextfocus = "message_block_button_ok";
	}
	else if( type == 6 ){
		buttonYes.style.display     = 'inline';
		buttonNo.style.display     = 'inline';
		buttonCancel.style.display     = 'inline';
		id_nextfocus = "message_block_button_cancel";
		title.innerHTML = '<div>確認</div>';
	}
	

	// ■ フォーカス手動設定時処理
	switch( defaultButton ){
		case 1 :
			id_nextfocus = "message_block_button_ok";
			break;
		
		case 2 :
			id_nextfocus = "message_block_button_cancel";
			break;
		
		case 3 :
			id_nextfocus = "message_block_button_close";
			break;
		
		case 5 :
			id_nextfocus = "message_block_button_yes";
			break;
		
		case 6 :
			id_nextfocus = "message_block_button_no";
			break;
		
		case -1 :
			id_nextfocus = "";
			break;
			
	}

	// ■ もし処理中イメージが表示されているなら閉じる
	closeLoadingImage();
	
	blockCover.style.display = 'block';
	blockBase.style.display = 'block';

	// ボタンにフォーカスを当てる
	// setTimeout("$('message_block_button_ok').focus()",0);
	if( id_nextfocus != "" ){
		setTimeout("$('"+ id_nextfocus +"').focus()",0);
	}
	
}

// ボタンクリックイベント
// 更新日：2008/11/19
function MessageDialog_ButtonClick( buttontype ){
	//showMessageBlockBackward();
	$('message_block_base').style.display = 'none';
	$('message_block_cover').style.display = 'none';
	if( funcMessageDialogResult != null ){
		funcMessageDialogResult(buttontype);
	}
}


// **********************************************************************
// マスタリスト関係
// **********************************************************************

var funcMasterList_Search = null;		// マスタリスト検索のfunctionリファレンス
var funcMasterList_OnSubmit = null;		

var valMasterList_SearchMode = 0;		// マスタリスト絞り込み検索モード
var valMasterList_SearchKanaCode = 0;		// マスタリスト絞り込み検索モード
var valMasterList_SearchWord = '';		// フリーワード検索文字列
var valMasterList_Info = null;			// マスタリスト用パラメータ

// マスタリストの初期化
function initMasterlist( searchmode ){

	valMasterList_SearchMode = 0;
	valMasterList_SearchKanaCode = 0;
	valMasterList_SearchWord = '';

	// 検索ボックススタイル
	var styleIndex = 'none';
	var styleWord  = 'none';
	if( searchmode == '1' || searchmode == '3' ){
		styleIndex = 'block';
	}
	if( searchmode == '2' || searchmode == '3' ){
		styleWord  = 'block';
	}
	$('master_list_search_code').value = valMasterList_SearchKanaCode;
	$('master_list_search_word_text').value = valMasterList_SearchWord;
	$('master_list_search_index').style.display = styleIndex;
	$('master_list_search_word').style.display  = styleWord;

}

// タイトル設定
function setMasterListTitle( value ){
	$('master_list_header').innerHTML = value;
}

// マスタリスト裏側にあるブロックを隠す
function hideMasterListBackward(){
	$('master_list_base').style.display = 'block';
	$('master_list_cover').style.display = 'block';
//	$('main_base_inner').style.display='none';
}

// 閉じる
function closeMasterList(){
	$('master_list_base').style.display = 'none';
	$('master_list_cover').style.display = 'none';

	//	$('main_base_inner').style.display  = 'block';
}


// 読み込み中のテーブルを表示する
function getMasterListLoadingInfo(){
	return '<table><tr><td>Loading...</td></tr><table>';
}

// 50音検索開始
function reloadMasterList_IndexSearch( value ){
	valMasterList_SearchMode = 1;
	valMasterList_SearchKanaCode = value;
	funcMasterList_Search();
}

// フリーワード検索開始
function reloadMasterList_WordSearch(value){
	valMasterList_SearchMode = 2;
	valMasterList_SearchWord = value;
	funcMasterList_Search();
}

	
	
	
	
	
	
	
	
	//**********************************************************************
	// マスタリスト二世代目
	//**********************************************************************
	
	// ▼ 共通呼び出し部
	function showMasterList_General(obj){

		valMasterList_Info = obj;
		
		// 動作設定部
		initMasterListBase(obj.searchmode);	// マスタリスト土台のHTMLを生成( パラメータは検索モード 0:なし、1:50音、2:フリーワード、3:両方)

		obj.selectedsearchmode = 0;
		obj.searchkanacode = 0;
		obj.searchword = '';		// 検索キーワードの初期化
		$('master_list_header2').innerHTML = obj.title;

		
		// リスト作成
		obj.searchfunc();

		// マスタリストとカバーの表示
		$('master_list_base2').style.display = 'block';
		$('master_list_cover2').style.display = 'block';
		
		document.getElementById('master_list_close2').focus();		// フォーカス指定

	}


	// ▼ マスタリストの土台を生成
	function initMasterListBase( searchmode ){

		// 検索ボックススタイル
		var styleIndex = ( searchmode == '1' || searchmode == '3' )?'display:block;':'display:none;';
		var styleWord  = ( searchmode == '2' || searchmode == '3' )?'display:block;':'display:none;';
		
		
		var elmCover = document.createElement('div');
		elmCover.id= 'master_list_cover2';
		elmCover.style.position = 'absolute';
		elmCover.style.left = '0px';
		elmCover.style.top = '0px';
		elmCover.style.display = 'none';
		elmCover.style.border = '1px solid black';
		elmCover.style.backgroundColor = 'black';
		elmCover.onclick = function(){ Element.remove("master_list_base2");Element.remove("master_list_cover2");};
		elmCover.style.width = '1024px';
		elmCover.style.height = '768px';
		elmCover.style.zIndex = 9998;
		
		
		elmCover.style.filter  = 'alpha(opacity=0)';
		elmCover.style.opacity = 0.00;
		elmCover.MozOpacity    = 0.00;

		
		var elmBase = document.createElement('div');
		
		var inner = '';
		var indexes = Array('','あ','か','さ','た','な','は','ま','や','ら','わ','');
		
		
		
		
		
		inner += '<div id="master_list_base2" style="position : absolute; left:372px; top:40px; display:none; z-index:9999; border:1px solid black; background-color:white; color:black; width:280px; height:660px;">';
		inner += '  <div style="margin:50px 0px 5px 50px;">';
		inner += '    <div style="width:180px; background-color:#ECE9D8; border:1px solid gray; text-align:center; font-weight:bold; font-size:12px; margin-bottom:10px;"><div id="master_list_header2" style="margin:4px 0px 4px 0px;"></div></div>';
		inner += '    <div style="margin-bottom:10px;">';
		inner += '      <div style="'+ styleIndex +'">';
		inner += '      <input type="hidden" id ="master_list_search_code2" value="0" />';
		inner += '<input type="button" value="全体" onclick="masterlistIndexSearch(0);" style="width:90px;border:1px solid gray;background-color:beige;" />';
		inner += '<input type="button" value="英数" onclick="masterlistIndexSearch(11);" style="width:90px;border:1px solid gray;background-color:beige;" />';
		inner += '<br />';
		
		for( var i=1;i<=10;i++){
			inner += '<input type="button" value="'+ indexes[i] +  '" onclick="masterlistIndexSearch('+ i +');" style="width:36px;border:1px solid gray;background-color:beige;" />';
			if(i==5){
				inner += '      <br />';
			}
		}

		inner += '      </div>';
		inner += '      <div style="'+ styleWord +'">';
		inner += '        <input id="master_list_search_word_text2" type="text"  value="" />';
		inner += '        <input type="button" value="検" onclick="masterlistWordSearch($(' + "'master_list_search_word_text2'" + ').value);" />';
		inner += '      </div>';
		inner += '    </div>';
		inner += '    <div id="master_list_tableblock2" style="width:180px;height:431px;overflow:scroll;border:1px solid gray;">テーブル</div>';
		inner += '    <div id="master_list_button2">';
		inner += '      <input type="button" value="　閉じる　" id="master_list_close2" style="width:180px;" onclick="Element.remove(' + "'master_list_base2'" +');Element.remove(' + "'master_list_cover2'" + ');" />';
		inner += '    </div>';
		inner += '';
		inner += '      </div>';
		inner += '  </div>';
		inner += '</div>';

		elmBase.innerHTML = inner;
		var bodyObj = document.getElementsByTagName("body").item(0);
		
		
		bodyObj.appendChild( elmCover );
		bodyObj.appendChild( elmBase );
		
	}

	// 50音検索開始
	function masterlistIndexSearch( value ){
		var obj = valMasterList_Info;
		obj.selectedsearchmode = 1;
		obj.searchkanacode = value;
		obj.searchfunc();
	}

	// フリーワード検索開始
	function masterlistWordSearch(value){
		var obj = valMasterList_Info;
		obj.selectedsearchmode = 2;
		obj.searchword = value;
		obj.searchfunc();

	}


//**********************************************************************
// ゼロサプレスした文字列を取得します
// [ 頭の0を削る ]
//**********************************************************************
function getZeroSuppressString( value ){
	
	var index = 0;
	value = String(value);
	
	// 0以外が出てくる位置を取得
	while( value.substr(index,1) == "0" ){
		index++;
	}
	
	// 0 が見つからない場合はそのまま返す
	if( index == 0 ){
		return value;
	}
	
	// 頭の0を除いて取得
	return value.substr(index);

}


	
//**********************************************************************
// その他
//**********************************************************************

// 指定文字列をカンマ区切りにします
function getNumberFormat( value ){
	var to = String( value );
	var temp = "";
	
	// 頭の0をカットします
	to = getZeroSuppressString(to);
	
	while (to != (temp = to.replace(/^([+-]?\d+)(\d\d\d)/,"$1,$2"))){
		to = temp;
	}
	return to;
}


// 半角数字かどうか検査します
function isDigit( value ){
	if( value.match(/[^0-9]+/) ){
		return false;
	}
	return true;
}


	//**********************************************************************
	// 日付の妥当性チェック
	// 更新日：2008/12/17
	// gengoObjId ... 元号オブジェクトID
	// dateObjId  ... 日付オブジェクトID
	//**********************************************************************
	function isValidDate_ById( gengoObjId, dateObjId ){

		var str = $F(dateObjId);
		var gengocode = $F(gengoObjId);

		if( str == ''){ return true; }				// 空になっている場合は検証を行わない

		var date = getNoFormattedDate( str, gengocode );

		return isValidDate_ByDateString( date );
	}

	//**********************************************************************
	// 日付の妥当性チェック
	// パラメータ yyyy or yyyymm or yyyymmdd
	// 更新日：2008/12/17
	//**********************************************************************
	function isValidDate_ByDateString( date ){
		
		if( date.length!=8 && date.length!=6 && date.length!=4){ return false; }		// 日付は8,6,4文字
		if( !isDigit( date ) ){ return false; }	// 半角英数以外が入っている場合はfalse
		
		if( date.length == 8){
			var year = parseInt( date.substr(0,4),10);
			var month = parseInt( date.substr(4,2),10);
			var day = parseInt( date.substr(6,2),10);
		}else if( date.length== 6 ){
			var year = parseInt( date.substr(0,4),10);
			var month = parseInt( date.substr(4,2),10);
			var day = 1;
		}else if( date.length== 4 ){
			var year = parseInt( date.substr(0,4),10);
			var month = 1;
			var day = 1;
		}
			
			
	    var dt = new Date(year, month - 1, day);
	    if(dt == null || dt.getFullYear() != year || dt.getMonth() + 1 != month || dt.getDate() != day) {
	        return false;
	    }
		
		return true;
		
	}
	
	
	
	
// 有効な年月日かどうか検査。年式は他で
function isValidYMD( gengo, value ){
	
	var len = value.length;
	
	if( !isDigit( value )){ return false; }
	
	if( gengo == 0 && len==8 ){ return true; }
	if( gengo != 0 && len==6 ){ return true; }
	
	return false;
}

// 有効な年・年月かどうか検査。年式は他で
function isValidY_YM( gengo, value ){
	
	var len = value.length;
	
	if( !isDigit( value )){ return false; }
	
	if( gengo == 0 && ( len==6 || len == 4) ){ return true; }
	if( gengo != 0 && ( len==4 || len == 2) ){ return true; }
	
	return false;
}
// FROM : http://furyu.tea-nifty.com/annex/2007/12/javascriptie6ta_5874.html
function replaceInnerHtml(tgtElm, innerHTML) {
    for (;;) {
        if (typeof innerHTML!='string'||typeof tgtElm!='object'||tgtElm.nodeType!=1/*ELEMENT_NODE*/) break;
        try {
            tgtElm.innerHTML=innerHTML;
        }
        catch (e) {
            var chld;
            while (chld=tgtElm.firstChild) tgtElm.removeChild(chld);    //  remove all child elements
            if (innerHTML.match(/^\s*$/) ) break;   //  clear only
            
            var tagName=tgtElm.tagName.toLowerCase(), tmp, html='<'+tagName+'>'+innerHTML+'</'+tagName+'>';
            switch (tagName) {
                case    'thead' :
                case    'tbody' :
                case    'tfoot' :
                    tmp=document.createElement('table');
                    replaceInnerHtml(tmp, html);
                    break;
                case    'tr'    :
                    tmp=document.createElement('table');
                    replaceInnerHtml(tmp, '<tbody>'+html+'</tbody>');
                    tmp=tmp.firstChild;
                    break;
                default         :
                    tmp=document.createElement('div');
                    tmp.innerHTML=html;
                    break;
            }
            var tmpElm=tmp.firstChild;
            while (chld=tmpElm.firstChild) tgtElm.appendChild(chld);
        }
        break;
    }
    return tgtElm;
}

//**********************************************************************
// カレンダー操作系スクリプト
//**********************************************************************

	//**********************************************************************
	// ▼ カレンダーを表示する
	// 第三引数にコールバック関数を指定することができます。
	// コールバック関数には引数として 配列objが渡されます。
	// obj.date      ... 元号区分に沿った日付
	// obj.gengocode ... 元号区分
	// obj.caldate   ... カレンダー日付( yyyy/mm/dd )
	// obj.gengoObjId  ... 呼び出し時に渡された元号コントロールのID
	// obj.dateObjId   ... 呼び出し時に渡された日付コントロールのID
	//**********************************************************************
	function showCalendar(pGengoId,pValueId){	
		
		var lGengo = getComboboxSelectedValue( document.getElementById(pGengoId));		// 元号オブジェクトから元号コードの取得
		var lFormattedDate = document.getElementById(pValueId).value;					// フォーマット済み日付の取得
		var lSeirekiDate = calendarGetValueFromControl( lGengo,lFormattedDate);						// 西暦日付の取得

		var callbackfunc = ( arguments.length >= 3)?arguments[2]:'';

		
		var cl = new Calendar(0, lSeirekiDate, function(cal,date){calendarOnSelected(cal,date,pGengoId,pValueId);},calendarOnClose);
		cl.callbackfunc = callbackfunc;
		cl.weekNumbers = false;
		cl.setDateFormat("%Y/%m/%d");
		cl.setRange(1900, 2050);
		cl.showsTime = false;
		cl.create();
		cl.showAtElement($(pValueId), 'Bc');
	}

	// ▼ カレンダーで日付が選択された場合の処理
	function calendarOnSelected(cal,pDate,pGengoId,pValueId){
		if (!cal.dateClicked) { return; }

		if( cal.callbackfunc == ''){
			calendarValueToControl(pDate,pGengoId,pValueId);

			// [2009/04/08] 日付コントロールにフォーカスを入れる
			setTimeout( '$("' + pValueId + '").focus();',0 );

		}else{
			calendarValueToCallbackFunc( cal, pDate, pGengoId,pValueId );
		}
		cal.callCloseHandler();
	}

	// ▼ カレンダーが閉じられる場合の処理
	function calendarOnClose(cal){
		cal.hide();
	}

	// ▼ カレンダー日付をコールバック関数に渡す
	function calendarValueToCallbackFunc( cal , pDate ,pGengoId,pValueId){
		var obj        = Array();
		var lDate      = pDate.replace(/\//g, "");
		var gengoindex = document.getElementById(pGengoId).selectedIndex;

		if( gengoindex == 0 ){
			// 西暦表示の場合はそのまま
			obj.date      = pDate;
			obj.gengocode = 0;
		}else{
			// 和暦表示処理開始
			loadDateInfo( lDate );
			obj.gengocode = gengoJS_tempGengoCode;
			obj.date      = ( obj.gengocode != 0 )?getSlashFormattedDate( gengoJS_tempWarekiDate, obj.gengocode):pDate;
		}

		obj.caldate = pDate;
		obj.gengoObjId = pGengoId;
		obj.dateObjId = pValueId;
		cal.callbackfunc( obj );
		//alert(obj);
	}


	// ▼ カレンダー日付をコントロールに代入
	function calendarValueToControl(pDate,pGengoId,pValueId){

		var lDate    = pDate.replace(/\//g, "");
		var lValueObj = document.getElementById(pValueId);
		var gengoindex = document.getElementById(pGengoId).selectedIndex;

		if( lDate == ""){
			return '';
		}
		// 西暦表示の場合はそのまま
		if( gengoindex == 0 ){
			lValueObj.value = pDate;
			return;
		}
		
		// 和暦表示処理開始
		loadDateInfo( lDate );
		
		if( gengoJS_tempGengoCode != 0 ){
			lDate = getSlashFormattedDate( gengoJS_tempWarekiDate, gengoJS_tempGengoCode);
		}else{
			lDate = pDate;
		}

		// 元号コントロールの更新
		selectComboboxByValue($(pGengoId),gengoJS_tempGengoCode);

		// 日付コントロールの更新
		lValueObj.value = lDate;

		return;
		
	}

	// ▼ コントロール日付をカレンダー日付に変換
	function calendarGetValueFromControl( pGengo ,pValue ){
		
		var lSrcValue = pValue.replace(/\//g, "");
		
		// 入力値チェック：英数字6桁(または8桁)かどうか検査
		var lLen = lSrcValue.length;
		var lGengoIndex = pGengo;
		var flg = 0;
		if( lGengoIndex == 0 && lLen == 8){
			flg = 1;
		}else if( lGengoIndex > 0 && lLen == 6){
			flg= 1;
		}
		
		if( flg != 1 ){
			return "";
		}
		
		var lDat = lSrcValue;
		
		// 和暦の場合は年部分を編集
		if( lGengoIndex > 0){
			var lDate  = lDat.slice(2,6);
			var lYear  = lDat.slice(0,2);

			hoge = parseInt(pGengo);
			hoge = gengo[hoge].value;
			lDat = String(parseInt(hoge,10)+parseInt(lYear,10)) + String(lDate);
		}
		
		
		// 西暦表示の場合は区切るのみで確定
		lDat = lDat.slice(0,4) + '/' + lDat.slice(4,6) + '/' + lDat.slice(6,8);

		
		return lDat;
		
	}

//**********************************************************************



/****************************************************************
* SJIS文字とした場合のバイト数を数える
*
* 引数 ： str 文字列
* 戻り値： バイト数
* 更新日：2009/01/06
* 参考：http://www.kanaya440.com/contents/tips/javascript/006.html
****************************************************************/
function getByteLength(str) {
    var r = 0;

	str = String(str).replace(/\r\n/g,"\n");
	str = String(str).replace(/\r/g,"\n");
	str = String(str).replace(/\n/g,"\r\n");
	
	for (var i = 0; i < str.length; i++) {
        var c = str.charCodeAt(i);

    	// Shift_JIS: 0x0 ～ 0x80, 0xa0 , 0xa1 ～ 0xdf , 0xfd ～ 0xff
        // Unicode : 0x0 ～ 0x80, 0xf8f0, 0xff61 ～ 0xff9f, 0xf8f1 ～ 0xf8f3
        if ( (c >= 0x0 && c < 0x81) || (c == 0xf8f0) || (c >= 0xff61 && c < 0xffa0) || (c >= 0xf8f1 && c < 0xf8f4)) {
            r += 1;
        } else {
            r += 2;
        }
    }
    return r;
}




/****************************************************************
* 全角文字が含まれているか判定
*
* 引数 ： str チェックする文字列
* 戻り値： true:含まれている、false:含まれていない
* 参考：http://www.kanaya440.com/contents/tips/javascript/007.html
****************************************************************/
function containsZenkaku(str) {
	var flg = 1;
    for (var i = 0; i < str.length; i++) {
        var c = str.charCodeAt(i);
        // Shift_JIS: 0x0 ～ 0x80, 0xa0 , 0xa1 ～ 0xdf , 0xfd ～ 0xff
        // Unicode : 0x0 ～ 0x80, 0xf8f0, 0xff61 ～ 0xff9f, 0xf8f1 ～ 0xf8f3
        if ( (c >= 0x0 && c < 0x81) || (c == 0xf8f0) || (c >= 0xff61 && c < 0xffa0) || (c >= 0xf8f1 && c < 0xf8f4)) {
            if(!flg) return true;
        } else {
            if(flg) return true;
        }
    }
    return false;
}


/****************************************************************
* 半角文字が含まれているか判定
*
* 引数 ： str チェックする文字列
* 戻り値： true:含まれている、false:含まれていない
* 参考：http://www.kanaya440.com/contents/tips/javascript/007.html
****************************************************************/
function containsHankaku(str) {
	var flg = 0;
    for (var i = 0; i < str.length; i++) {
        var c = str.charCodeAt(i);
        // Shift_JIS: 0x0 ～ 0x80, 0xa0 , 0xa1 ～ 0xdf , 0xfd ～ 0xff
        // Unicode : 0x0 ～ 0x80, 0xf8f0, 0xff61 ～ 0xff9f, 0xf8f1 ～ 0xf8f3
        if ( (c >= 0x0 && c < 0x81) || (c == 0xf8f0) || (c >= 0xff61 && c < 0xffa0) || (c >= 0xf8f1 && c < 0xf8f4)) {
            if(!flg) return true;
        } else {
            if(flg) return true;
        }
    }
    return false;
}

/****************************************************************
*
* モニタの解像度の幅が1024*768であるかを判断し、スクロール制御
*
****************************************************************/
/*
var w,h,pixel;

w = screen.width;
h = screen.height;
pixel = w * h;

//moveTo(0,0);

//ブラウザ表示画面を常に最大化する（Firefoxのみ）
//window.resizeTo(window.screen.availWidth, window.screen.availHeight);

//画面が1024*768ならスクロールなし
if (pixel == 786432) {
	
document.write("<style type=\"text/css\"><!-- html{overflow:hidden;} --></style>");

} else {

document.write("<style type=\"text/css\"><!-- html{overflow-y:scroll;} --></style>");

}
*/
	
	
//**********************************************************************
// Ajaxの簡易同期通信
// 
// 【パラメータ】
//    url、GETパラメータ用配列
// 【戻り値】
//    成功時：返って来たJSON文字列のlist要素
//    失敗時：false
//
// 【使用例】
//	var url   = '/dir1/ajaxtest.php';
//	var param = new Object();
//	param["code1"] = "test1";
//	param["code2"] = "test2";
//	var result = ajaxRequestSync( url, param );
//
// 2009/03/06
//**********************************************************************
function ajaxRequestSync( baseurl, params ){
	
	var url = baseurl + '?';
    var sParamArray = $H(params).toQueryString()
	if (sParamArray != ''){
		url += sParamArray;
    }

	var request = new Ajax.Request(url ,{
	    method: 'get',
	    asynchronous: false,
	    onFailure: function (response, options) {
	        return false;
	    }
	});
	try {
	    var result = eval('(' + request.transport.responseText + ')');
		if( !result.success ){ return false; }
		return result.list;	
	
	} catch(err) {
	    return false;
	}

}


//**********************************************************************
// Ajaxの簡易同期通信( POST )
// 
// 【パラメータ】
//    url、GETパラメータ用配列
// 【戻り値】
//    成功時：返って来たJSON文字列のlist要素
//    失敗時：false
//
// 2009/06/19
//**********************************************************************
function ajaxRequestSyncPost( baseurl, params ){
	
	var url = baseurl;
	var send_param = "";
    
	/*
	var sParamArray = $H(params).toQueryString()
	if (sParamArray != ''){
		send_param += sParamArray;
    }
	*/

	for (var key in params) {
		if (send_param != '') send_param += "&";
		send_param += key + "=" + String(params[key]).escapeForPost();
	}
	
	var request = new Ajax.Request(url ,{
	    method: 'post',
		parameters: send_param,
	    asynchronous: false,
	    onFailure: function (response, options) {
	        return false;
	    }
	});
	try {
	    var result = eval('(' + request.transport.responseText + ')');
		if( !result.success ){ return false; }
		return result.list;	
	
	} catch(err) {
	    return false;
	}

}

//**********************************************************************
// Ajaxの簡易同期通信( POST )
// 
// 【パラメータ】
//    url、GETパラメータ用配列
// 【戻り値】
//    成功時：返って来たJSON文字列のlist要素
//    失敗時：false
//
// 2009/06/28
//**********************************************************************
//同期
function ajaxRequestSyncPost2( baseurl, params ){
	
	var url = baseurl;
	var send_param = "";
    
	for (var key in params) {
		if (send_param != '') send_param += "&";
		send_param += key + "=" + String(params[key]).escapeForPost();
	}
	
	var request = new Ajax.Request(url ,{
	    method: 'post',
		parameters: send_param,
	    asynchronous: false,
	    onFailure: function (response, options) {
	        return false;
	    }
	});
	try {
	    var result = eval('(' + request.transport.responseText + ')');
		return result;
	
	} catch(err) {
	    return null;
	}

}
//非同期
function ajaxRequestSyncPost3( baseurl, params ){
	
	var url = baseurl;
	var send_param = "";
    
	for (var key in params) {
		if (send_param != '') send_param += "&";
		send_param += key + "=" + String(params[key]).escapeForPost();
	}
	
	var request = new Ajax.Request(url ,{
	    method: 'post',
		parameters: send_param,
	    asynchronous: true,
	    onFailure: function (response, options) {
	        return false;
	    }
	});
	try {
	    var result = eval('(' + request.transport.responseText + ')');
		return result;
	
	} catch(err) {
	    return null;
	}

}



//**********************************************************************
// 特殊キー無効処理
// ・自動的に反映されます
// ・ALT＋左カーソルキー、バックスペースキーを無効化
//
//
// 2009/03/12
//**********************************************************************
window.document.onkeypress =common_DisableSpecialKey_OnKeyPress;
window.document.onkeydown = common_DisableSpecialKey_OnKeyDown;

//**********************************************************************
// 特殊キー無効化処理[ onKeyDown ]
//**********************************************************************
function common_DisableSpecialKey_OnKeyDown(){

	//**********************************************************************
	// ■ IE用特殊キー無効処理
	//**********************************************************************
	// IE以外は無視
	if (typeof document.documentElement.style.msInterpolationMode == "undefined"){
		return;
	}
	
	var obj     = event.srcElement;
	var objtype = event.srcElement.type;

	//ALT＋←の無効
	// if( event.keyCode == 0x25 && event.altKey ) { return false ; }

	// バックスペースの無効[ テキスト入力部以外 ]
	if( objtype != 'text'  &&  objtype != 'password'  && objtype != 'textarea' ){
		if( event.keyCode == 8 ){
			return false;
		}
	}
	
	// バックスペースの無効[ テキスト特殊時 ]
	if( objtype == 'text' &&  obj.readOnly == true ){
		if( event.keyCode == 8 ){
			return false;
		}
	}

}

//**********************************************************************
// 特殊キー無効化処理[ onKeyPress ]
//**********************************************************************
function common_DisableSpecialKey_OnKeyPress(e) {
	
	//**********************************************************************
	// FireFox用処理
	//**********************************************************************
	// 条件：IE7でない場合
	if (typeof document.documentElement.style.msInterpolationMode != "undefined"){
		return;
	}

	/* keyCode : F1=112, F5=116 */

	event = e;
	var objtype = event.target.type;
	
	// ALT + ←の無効
	// if( event.altKey && event.keyCode == 0x25 ){ return false ; }
	
	// バックスペースの無効[ テキスト入力部以外 ]
	if( objtype != 'text'  &&  objtype != 'password'  && objtype != 'textarea' ){
		if( event.keyCode == 8 ){
			return false;
		}
	}
	return true;
} 







var commonClockDisabled = true;

/**********************************************************************
  定期セッション保持処理

  ・commonClockDisabled が true の場合は無効
  ・commonClockInvisible が true の場合は不可視

 [2009/03/17] 
**********************************************************************/

//Event.observe( window, 'load', commonClock_Initialize);
// 条件：IE7でない場合
if (typeof document.documentElement.style.msInterpolationMode == "undefined"){
	window.addEventListener('load', commonClock_Initialize,false);
}else{
	window.attachEvent('onload', commonClock_Initialize);
}

// ■ 時計の初期化
function commonClock_Initialize(){
	
	if (typeof document.documentElement.style.msInterpolationMode == "undefined"){
		window.removeEventListener('load', commonClock_Initialize,false);
	}else{
		window.detachEvent('onload', commonClock_Initialize);
	}

	
	if( typeof commonClockDisabled != 'undefined' ){
		return;
	}
	
	// 定期アクセスの開始
	var elmCover = document.createElement('div');
	elmCover.id= 'common_clock_base';
	elmCover.style.position = 'absolute';
	elmCover.style.left = '722px';
	elmCover.style.top = '10px';
	elmCover.style.width = '200px';
	elmCover.style.height = '14px';
	elmCover.style.textAlign = 'right';
	elmCover.style.fontSize = '12px';
	elmCover.style.zIndex = 3;

	/*
	elmCover.style.filter  = 'alpha(opacity=80)';
	elmCover.style.opacity = 0.80;
	elmCover.MozOpacity    = 0.80;
	*/

	if( typeof commonClockInvisible == 'undefined' ){

		$$('body')[0].appendChild( elmCover );
	}
	
	// 時計の発動
	//commonClock_Exec();
}

// ■ 時計の発動
/*
function commonClock_Exec(){
	strClock = "";
	url = "/list/session_timer.php";

	new Ajax.Request(url,
	{
		method: 'get'
		,onComplete: getResponse
		,onFailure: function(req) {
			commonClock_Callback("--:-- ");
		}
	});

	function getResponse(req) {
		eval("var result = " + req.responseText);
		commonClock_Callback( String(result.list) );
	}
	
}


// ■ 時計の結果設定と再発動処理
function commonClock_Callback( value ){
	
	if( typeof commonClockInvisible == 'undefined' ){
		$('common_clock_base').innerHTML = String(value);
	}
	setTimeout( commonClock_Exec , 30 * 1000);
}
*/
	
	
	
	
	
	

//**********************************************************************
// を表示
//
// 【パラメータ】 第一引数：カバー非表示フラグ ... true:カバーを生成しない、null:カバーを生成する
//
// [2009/04/08]
//**********************************************************************
function showLoadingImage(){
	
	var flg_IconOnly = arguments[0];
	var id_cover = "common_loading_cover";
	var id_icon  = "common_loading_icon";

	// プログレスの既存チェック。既存の場合は中断
	var obj = $(id_icon);
	if( obj != null ){
		return;
	}

	var body_obj = 	$$("body")[0];

	// 透明カバー( カバー表示設定時 )
	if( flg_IconOnly != true ){
		var cover = document.createElement("div");
		cover.id  = id_cover;
		body_obj.appendChild( cover );
	}
	
	// アイコン
	var icon = document.createElement("div");
	icon.id  = id_icon;
	body_obj.appendChild( icon );
	
}

//**********************************************************************
// プログレスを閉じる
// [2009/04/08]
//**********************************************************************
function closeLoadingImage(){
	
	var id_cover = "common_loading_cover";
	var id_icon  = "common_loading_icon";

	// アイコンの破棄
	var obj = $(id_icon);
	if( obj != null ){
		Element.remove(obj);
	}

	// カバーの破棄
	var obj = $(id_cover);
	if( obj != null ){
		Element.remove(obj);
	}

}


//**********************************************************************
// 指定バイト数を超えないように、文字列を削る
// パラメータ num ... 最大バイト数
// [2009/04/13]
// [2009/04/14] \r\n を \nに置き換える
//**********************************************************************
String.prototype.cropByBytes = function(num) {

	var str = this.replace(/\r\n/g,"\n");
	
	str = String(str).replace(/\r/g,"\n");
	str = String(str).replace(/\n/g,"\r\n");

	
	var lastindex = str.length-1;
	var i = 0;
	var bytes = 0;
	var croplength = 0;
	
	while (i <= lastindex) {

        var c = str.charCodeAt(i);
        // Shift_JIS: 0x0 ～ 0x80, 0xa0 , 0xa1 ～ 0xdf , 0xfd ～ 0xff
        // Unicode : 0x0 ～ 0x80, 0xf8f0, 0xff61 ～ 0xff9f, 0xf8f1 ～ 0xf8f3
        if ( (c >= 0x0 && c < 0x81) || (c == 0xf8f0) || (c >= 0xff61 && c < 0xffa0) || (c >= 0xf8f1 && c < 0xf8f4)) {
            bytes += 1;
        } else {
            bytes += 2;
        }
		
		if( bytes > num ){ break; }
		croplength++;
		i++;
	}

	return str.substr(0,croplength);
};

//**********************************************************************
// POST用にエスケープ処理を施した文字列を返します
// [2009/04/17] 作成
//**********************************************************************
String.prototype.escapeForPost = function() {
	var val = this;
	val = val.replace(/%/g, "%25");		// %
	val = val.replace(/&/g, "%26");		// &
	val = val.replace(/\?/g, "%3F");	// ?
	val = val.replace(/#/g, "%23");		// #

	return val;
}





function getRadioValue( name ){
	
	
	var objs = document.getElementsByName( name );
	var result = "";

	$A(objs).each( function(obj){
		if( obj.checked ){
			result = obj.value;
			return;
		}
	});
	
	return result;
}

//**********************************************************************
// ▼ 透明度の設定
//
// [2009/07/22] Toshihiko Kyuwa 追加
//**********************************************************************
function setOpacity( objId, value ){
	
	var obj = $(objId);
	var intvalue = parseInt(value * 100,10);
	
	obj.style.filter = "alpha(opacity=" + String(intvalue) + ")";
	obj.style.MozOpacity = value;
	obj.style.opacity = value;
}


/*--------------------------------------------------------------------------
	画像の入替時、使用する
--------------------------------------------------------------------------*/
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<body>タグにオンロード時
  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.01
  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 && d.getElementById) x=d.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];}
}

/*--------------------------------------------------------------------------
	各DIVエレメントの表示・非表示
--------------------------------------------------------------------------*/
function MM_showHideLayers() { //v9.0(CSSがvisibilityの場合)
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function MM_showHideLayers2() { //v9.0(CSSがdisplayの場合)
  var i,p,v,obj,args=MM_showHideLayers2.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v=='hide')?'none':v; }
    obj.display=v; }
}

//**************************************************************
//　各ブラウザ別スタイルシート適用
//
//　デフォルトは「全ブラウザ対象」、「.class、#ID」の前にブラウザ記号挿入
//　IE　⇒　「.ie」、「.ie6、.ie7」で個別に設定可能
//  FF　⇒　「.gecko」
//  opera　 ⇒　「.opera」
//  Safari　⇒　「.webkit」
//
//**************************************************************

function css_browser_selector(u){var ua=u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1},g='gecko',w='webkit',s='safari',o='opera',m='mobile',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3.6')?g+' ff3 ff3_6':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('blackberry')?m+' blackberry':is('android')?m+' android':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?m+' j2me':is('iphone')?m+' iphone':is('ipod')?m+' ipod':is('ipad')?m+' ipad':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win'+(is('windows nt 6.0')?' vista':''):is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);


/*--------------------------------------------------------------------------
	FireFox用OnClick（）イベントの生成
--------------------------------------------------------------------------*/
if (window.navigator.userAgent.toLowerCase().indexOf("firefox") > 0) { //firefoxでClick()イベント生成
HTMLElement.prototype.click = function() { 
var evt = this.ownerDocument.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
this.dispatchEvent(evt);
	}
}

/*--------------------------------------------------------------------------
	ページのトップをスムーズに
	ex) <a href="#" onclick="backToTop(); return false">
--------------------------------------------------------------------------*/
function backToTop() {
  var x1 = 0;
  var x2 = 0;
  var x3 = 0;

  var y1 = 0;
  var y2 = 0;
  var 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()", 50);
  }
}

/*-----------------------------------------------------------
	テーブルのマウスHover
-----------------------------------------------------------*/
function tdMouseOver(index, mode) {
	if( mode === 1 ) {
		$j("#AP_CustomerSchRst_tr"+index).css("background-color", "#FFC");
	} else if( mode === 2 ) {
		$j("#AP_CustomerSchRst_tr"+index).css("background-color", "#FFF");
	}
}
function tdMouseOver2(id, mode) {
	if( mode === 1 ) {
		$j("#"+id).css("background-color", "#FFC");
	} else if( mode === 2 ) {
		$j("#"+id).css("background-color", "#FFF");
	}
}

function tdMouseOver3(id, kbn) {
	if( kbn === 0 ) {
		$j("#"+id).css("background-color", "#FFF");
	} else if( kbn === 1 ) {
		$j("#"+id).css("background-color", "#EEE");
	}
}

/*-----------------------------------------------------------
	必要な桁数まで0を埋める。
	引数 ：number 数値
 		   size 桁数
-----------------------------------------------------------*/
function fillZero( number, size ) {
	var ret = "" + number;
	while(ret.length < size){ ret = "0" + ret; }
	return (ret);
	
}

/*------------------------------------------------
  ログアウト
------------------------------------------------*/
function Shop_Logout() {
	var kakunin =confirm("ログアウトしますか?"); 
		
	if (kakunin == true) { 
		// ログアウト処理
		location.href = "/admin_shop/logout.php";
	} else {
		return;
	}
}

/*-----------------------------------------------------------
	AP_coverの高さを取得
-----------------------------------------------------------*/
function get_AP_CoverHeight_common() { 
	var item = $('Wrap'); 
	var ret = Element.getDimensions(item);
	$j("#AP_cover_Common").css("height", ret.height);
}

function get_AP_CoverHeight_Sch() { 
	var item = $('RightDisp'); 
	var ret = Element.getDimensions(item);
	$j("#AP_cover_Sch").css("height", ret.height);
}

/*MenuLocation */
function MenuLocation(url) {
	location.href = url;
}

/*-----------------------------------------------------------
	文字数のカウント
-----------------------------------------------------------*/
function ShowTxtLength( str, id ,maxTxt) {
	var txt = $F(str).length;
	
	$j('#'+id).html(maxTxt-txt + "文字");
}


