/*  */
function mode_relatod_load(path, sval, mode, txat, fow, deri) {
	var zmode = $('#SUB_MODE'+fow).val(),fdata = new FormData(),pgary = new Array(),
		type = ($('#SUB_MODE'+fow).val() == $('#SUB_SUBPATH'+fow).val()) ? 'D' : 'S';
	var zdiv = '#detail_div_'+zmode+fow,zform = '#detail_form_'+zmode+fow,
		sdiv = '#sub_div_'+zmode+fow,sform = '#sub_form_'+zmode+fow;
	var dform = (type == 'D') ? zform : sform,sberis = $(sdiv+' #SUB_ERIPATH'+fow).val().split('/'),
		zeri = ($(zform+' #ERI').length > 0 && $(zform+' #ERI').val() != '') ? $(zform+' #ERI').val() : '',
		teri = ($(zform+' #TEMPERI').length > 0 && $(zform+' #TEMPERI').val() != '') ? $(zform+' #TEMPERI').val() : '',
		maperi = ($(zform+' #HIDEFLOW_ERI').length > 0) ? $(zform+' #HIDEFLOW_ERI').val() : '';
	var meri = (mode == zmode) ? zeri : sberis[sberis.length-1],
		djson1 = (fromid_output_json(dform,'name')).replace(/'/g, "''"),
		djson2 = (fromid_output_json('#popup_box','name')).replace(/'/g, "''");
	fdata.append('htmljson1', djson1);fdata.append('htmljson2', djson2);
	$('#popup_box input[name="LISTPAGE[]"]').each( function() {
		var lpage = $(this).val();
		if ($(dform+' .hidden_'+lpage).length > 0) {
			fdata.append('htmljson_'+lpage, (fromid_output_json(dform+' .hidden_'+lpage,'name','id')).replace(/'/g, "''"));
		} else pgary.push(lpage);
	});
	var url = path+'core/cw5e_engine_detail.php?sid='+sval+'&parent='+EncodeURLutf8(path)+'&mode='+mode+'&fow='+fow+'&deri='+deri+
			  '&act=rtod&type='+type+'&zmode='+zmode+'&zeri='+zeri+'&teri='+teri+'&meri='+meri+'&txat='+txat+'&maperi='+maperi+
			  '&verlen1='+(djson1.length).toString()+'&verlen2='+(djson2.length).toString();
	$.ajax({
		url: url,
		type: 'POST',
		data: fdata,
		processData: false,
		contentType: false,
		beforeSend: function(){
			// 開始前執行 
			$('#popup_box #detail_rtod_form :input').prop('disabled', true);
			$('#popup_box .detail_rtod_loader').empty().append('<img src="images/loading.gif" width="20px" height="20px">');
		},
		success: function(msg){
			// 成功後執行 
			//console.log(msg);
			var ret_msg = JSON.parse(msg);
			if (ret_msg[0].result == 'false') {
				alert(ret_msg[0].message);
				$('#popup_box #detail_rtod_form :input').prop('disabled', false);
				$('#popup_box .detail_rtod_loader').empty();
				return false;
			} else {
				if (ret_msg[0].data) {
					mode_valchange_action(ret_msg[0].data, dform);
					if (ret_msg[0].sum) mode_sum_number(path, sval, mode, pgary.join(','), dform, fow);
				}
			}
		},
		error: function(msg){
			// 失敗後執行 
			//console.log(msg);
		},
		complete: function(msg){
			// 完成後執行 
			//console.log(msg);
		}
	});
}