// このcommon.js は、古い設定のため、新しいcommon.js の確認が出来たら削除する

/*
$(document).ready(function(){
	window.name = "";
	var divAjax =
		'<div style="text-align:center;z-index:10000;" class="Shadow" id="divAjax">'+
			'<div  style="width:48px;height:48px;position:absolute;top:50%;margin-top:-24px;left:50%;margin-left:-24px;">'+
				'<img src="../images/loading.gif" width="48" height="48">'+
			'</div>'+
		'</div>';
	$(divAjax).appendTo('body');
	
	var divDialog = '<div class="dialog" id="dialog"><p></p></div>'

	$(divDialog).appendTo('body');
	
	$('#dialog').dialog({
		autoOpen: false,
		closeOnEscape: false,
		buttons: {
			"OK": function(){
				$(this).dialog('close');
   		 	}
  		},
		open: function() {
			var thisObj = this;
			setTimeout(function(){
				$('.ui-dialog-buttonset button:eq(0)').focus();
			},100);
		},
	});
})
*/

function ajaxFunctionHtml(param,bAlert){
	if(typeof bAlert === 'undefined'){
		bAlert = '1';
	}
	var retData;
	$.ajaxSetup({ cache: false });	

	$.ajaxSetup({
		beforeSend : function(xhr) {
			xhr.overrideMimeType('text/html;charset=Shift_JIS');
		}
	});

	$.ajax({
		async : false,
		url: '../Magic33Scripts/MGrqispi.dll',
		data : param,
		dataType:'html',
		type : 'POST',
		scriptCharset: 'utf-8',
		success : function(retHtml){
			retData = retHtml;
		},
		error : function(XMLHttpRequest, textStatus, errorThrown){
			modalAlert('0','System Error','System Error');
			window.location = "../webnais/agency/new_login.html";
		}
	});
	return retData;
}

function ajaxFunction(param,bAlert){
	if(typeof bAlert === 'undefined'){
		bAlert = '1';
	}
	var retData;
	$.ajaxSetup({ cache: false });	

	$.ajaxSetup({
		beforeSend: function(xhr){
			xhr.overrideMimeType("text/html;charset=utf-8");
		}
	});

	$.ajax({
		async : false,
		url: '../Magic33Scripts/MGrqispi.dll',
		data : param,
		dataType:'xml',
		type : 'POST',
		scriptCharset: 'utf-8',
		success : function(xml){
			var ret = $(xml).find('ret').text();
			var msg = $(xml).find('message').text();
			if(ret != 'I001' && bAlert == '1' ){
				modalAlert('0','エラー！',msg);
			}
			retData = xml;
		},
		error : function(XMLHttpRequest, textStatus, errorThrown){
			modalAlert('0','System Error','System Error');
			window.location = "../webnais/agency2/agency.html";
		}
	});

	return retData;
}
function modalAlert(alertType,title,message,callBack,cbParam){
	//alertType:モーダル種類（'0'/'1'）'1'を指定した場合は「はい」「いいえ」の確認モーダルになります
	//title：タイトル（空白可）
	//message：表示メッセージ
	//callBack：「閉じる」もしくは「はい」ボタン押下後に実行する関数を指定
	//cbParam：callBackで指定した関数に渡すパラメータを指定
	$('#mdlAlert').remove();
	var alertButtonHtml = '';
	switch(alertType){
		case '0':
			// メッセージ表示モーダル
			alertButtonHtml = 	'<button type="button" id="btnMdlAlertYes" class="btn btn-secondary" data-bs-dismiss="modal">閉じる</button>'
			break;
		case '1':
			// 確認用モーダル
			alertButtonHtml = 	'<button type="button" id="btnMdlAlertYes" class="btn btn-secondary" data-bs-dismiss="modal">はい</button>' +
								'<button type="button" id="btnMdlAlertNo" class="btn btn-secondary" data-bs-dismiss="modal">いいえ</button>';
			break;
	}
	var addHtml = 	'<div class="modal fade" id="mdlAlert" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="mdlAlertLabel" aria-hidden="true">'+
						'<div class="modal-dialog modal-dialog-scrollable">'+
							'<div class="modal-content">'+
								'<div class="modal-header">'+
									'<h5 class="modal-title" id="mdlAlertLabel"></h5>'+
									'<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>'+
								'</div>'+
								'<div class="modal-body">'+
									'<span id="spnMdlAlertMsg"></span>'+
								'</div>'+
								'<div class="modal-footer">'+
									alertButtonHtml +
								'</div>'+
							'</div>'+
						'</div>'+
					'</div>';
	$('body').append(addHtml);
	$('#mdlAlertLabel').text(title);
	$('#spnMdlAlertMsg').text(message);
	$('#btnMdlAlertYes').on('click',function(){
		if( !(typeof callBack === 'undefined' )){
			callBack(cbParam);
		}
	});
	var myModal= document.getElementById('mdlAlert');
	var modal= bootstrap.Modal.getOrCreateInstance(myModal)
	modal.show();
}
/*
function cmAlert(title,message,callBack,cbParam){
	if($('#dialog').parent().css('display') === 'block'){
		return
	}
	$('#dialog p').html(message);
	$('#dialog').dialog({
		autoOpen: false,
		title: title,
		modal: true,
		width: 600,
		close : function(event){
			if( typeof callBack === 'undefined' ){
			}else{
				callBack(cbParam);
			}
		},
	    overlay:{ opacity:0.3, background:'#225B7F' }
	});
	$('#dialog').dialog('open');
}
*/
function callTopMenu(pw_kubun,hideFlg){
	var param = {
		'appname': nasiappname,
		'prgname':'A021',
		'param1': nasiappname,
		'param2': $('#user').val(),
		'param3': pw_kubun,
		'arguments':'param1,param2,param3'
	};
	var menuHtml = ajaxFunctionHtml(param);
	$('#divTopMenuList').append($(menuHtml).find('#form_A021')[0].innerHTML);
	if(hideFlg){
		$('#navMenu').addClass('hideMenu');
	}
	//parent.REL_LINK.location.replace("<!$MG_requester>?APPNAME=<!$MG_appname>&PRGNAME=C070&ARGUMENTS=-A<!$MG_appname>,-A<!$MG_user>");
}

function MenuSelect(form,MenuIdx){
	if (MenuIdx == 1){
		ExecPgm("A020");
	}
	if (MenuIdx == 2){
		ExecPgm("A110");
	}
	if (MenuIdx == 3){
		ExecPgm("A130");
	}
	if (MenuIdx == 4){
		ExecPgm("A140");
	}
	if (MenuIdx == 5){
		ExecPgm("A400");
	}
	if (MenuIdx == 6){
		ExecPgm("A700");
	}
	if (MenuIdx == 9){
		NAClose();
	}
}

function ExecPgm(pgmId){
	window.location.replace(naisserver+"?APPNAME="+nasiappname+"&PRGNAME=" + pgmId + "&ARGUMENTS=-A"+nasiappname+",-A"+$('#user').val());
	//parent.location.replace(naisserver+"?APPNAME="+nasiappname+"&PRGNAME=" + pgmId + "&ARGUMENTS=-A"+nasiappname+",-A"+$('#user').val());
}

function DispStatus(form){
	status = ("");
}

function NAClose(){
	top.location.replace(web_doc_alias+"naclose.html");
}

function NAHelp(){
	chk = Number($('#pw_kubun').val());
	switch(chk){
		case 0: window.open(web_doc_alias+"help/nahelp_menu.htm"); break;
		case 1: window.open(web_doc_alias+"help/nahelp_rireki.htm"); break;
		case 2: window.open(web_doc_alias+"help/nahelp_seikyu.htm"); break;
	}
}