/*  */
function mode_mtod_detail(path, sval, mode, ditem, field, dform, fow, pitem) {
	loading_create('Y');
	var zmode = $('#SUB_MODE'+fow).val(),eri = '';
	var zform = '#detail_form_'+zmode+fow;
	var zeri = ($(zform+' #ERI').length > 0 && $(zform+' #ERI').val() != '') ? $(zform+' #ERI').val() : $(zform+' #TEMPERI').val();
	var loary = JSON.parse(return_language_str(path, sval, zmode, '', ''));
	//if (confirm(((loary['CONFIRM_'+ditem+'_'+field]) ? loary['CONFIRM_'+ditem+'_'+field] : 'CONFIRM_'+ditem+'_'+field))) {
	var ftype = ($('#SUB_MODE'+fow).val() == $('#SUB_SUBPATH'+fow).val()) ? 'D' : 'S';
	if (ftype == 'D') eri = zeri;
	else {
		var suberis = $('#SUB_ERIPATH'+fow).val().split('/');
		eri = suberis[suberis.length-1];
	}
	var maperi = ($(zform+' #HIDEFLOW_ERI').length > 0) ? $(zform+' #HIDEFLOW_ERI').val() : '';
	var url = path+'core/cw5e_engine_detail.php?sid='+sval+'&parent='+EncodeURLutf8(path)+'&mode='+mode+'&ditem='+ditem+'&field='+field+'&act=enmtod&fow='+fow;
	url += '&ftype='+ftype+'&zmode='+zmode+'&zeri='+zeri+'&eri='+eri+'&maperi='+maperi;
	if (pitem != '' && $('#'+pitem+'_db_list').length > 0) {
		url += '&dbtyp='+EncodeURLutf8($('#'+pitem+'_db_list #dblt_type_'+pitem).val());
	}
	var djson = (fromid_output_json(dform,'name')).replace(/'/g, "''");
	var verlen = djson.length;
	url += '&verlen='+verlen.toString();
	//console.log(djson);
	$.ajax({
		type: 'post',
		url: url,
		data: 'htmljson='+EncodeURLutf8(djson),
		beforeSend: function(){
			// 開始前執行 
		},
		success: function(msg){
			// 成功後執行 
			// console.log(msg);
			var ret_msg = JSON.parse(msg);
			if (ret_msg[0].result == 'false') {
				alert(ret_msg[0].message);
				if (ret_msg[0].sql) console.log(ret_msg[0].sql);
				return false;
			} else {
				$(dform+' #tab_'+ret_msg[0].ditem+' a').click();
				if (ret_msg[0].mdme == 'D') {
					$(dform+' #table_'+ret_msg[0].ditem+' tbody').empty();
					if (ret_msg[0].html_str) {
						$(dform+' #table_'+ret_msg[0].ditem+' tbody').append(ret_msg[0].html_str);
						$(dform+' input[name="'+ret_msg[0].ditem+'_DERI[]"]').each( function() {
							$(dform+' #SERNO_'+$(this).val()).val($(this).closest('tr').index()+1);
							$(dform+' #SERNO_'+$(this).val()).attr('value',$(this).closest('tr').index()+1);
							$(dform+' #SERIAL_'+$(this).val()).html($(this).closest('tr').index()+1);
						});
						mode_sum_number(path, sval, mode, ret_msg[0].ditem, dform, fow);
						//檢查欄位mask.js 
						eval('if (typeof '+ditem+'_chk == "function") '+ditem+'_chk();');
					}
				} else if (ret_msg[0].mdme == 'DB') {
					$('#'+ret_msg[0].ditem+'_db_list #dblt_type_'+ret_msg[0].ditem).val('E');
					detail_pagedb_load(path, sval, mode, ret_msg[0].ditem, '#'+ret_msg[0].ditem+'_db_list', fow, '1');
				}
				alert(((loary['REAMOUNT_COMPLETE']) ? loary['REAMOUNT_COMPLETE'] : 'REAMOUNT_COMPLETE'));
			}
		},
		error: function(msg){
			// 失敗後執行 
			console.log(msg);
			loading_close('');
		},
		complete: function(msg){
			// 完成後執行 
			// console.log(msg);
			loading_close('');
		}
	});
	//}
}