/*  */
function mode_add_detail(path, sval, mode, ditem, act, dform, dedit, dtabid, mod, fow, maperi) {
	if ($(dform+' '+dedit).val() == '') {
		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 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 url = path+'core/cw5e_engine_detail.php?sid='+sval+'&parent='+EncodeURLutf8(path)+'&mode='+mode+'&ditem='+ditem+'&act='+act+'&fow='+fow+'&eri='+eri;
		url += '&ftype='+ftype+'&maperi='+maperi+'&zmode='+zmode+'&zeri='+zeri;
		var djson = (fromid_output_json(dform,'name')).replace(/'/g, "''");
		var verlen = djson.length, deri = '';
		url += '&verlen='+verlen.toString();
		if (mod == 'br') $.ajaxSetup({ async:false });
		$.post(url, 'htmljson='+EncodeURLutf8(djson), function(msg) {
			//console.log(msg);
			var ret_msg = JSON.parse(msg);
			if (ret_msg[0].result == 'false') {
				alert(ret_msg[0].message);
				return false;
			} else {
				deri = ret_msg[0].deri;
				$(dform+' '+dtabid).append(ret_msg[0].html_str);
				$(dform+' input[name="'+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);
				});
			}
		});
		if (mod == 'br') $.ajaxSetup({ async:true });
		if (mod == 'mr') {
			return deri;
		} else if (mod == 'br') {
			mode_sum_number(path, sval, mode, ditem, dform, fow);
			eval('if (typeof add_detail_br_'+ditem+' == "function") add_detail_br_'+ditem+'("'+sval+'","'+ditem+'");');
		}
	}
}