/*  */
function file_import_input(path, sval, mode, ditem, fdname, dform, iname, fow) {
	var msg = '',loary = JSON.parse(return_language_str(path, sval, '', '', ''));
	$('#popup_box .proj_imptckbt_td').css('background-color', '#FFFFFF');
	$('#popup_box #impt_page').css('background-color', '#FFFFFF');
	$('#popup_box #impt_tite').css('background-color', '#FFFFFF');
	var ckbary = new Array(), total = 0, msgArray = new Array();
	if ($('#popup_box #imptsave').val() == '1' && $('#popup_box #imptclass').val().trim() == '' &&
		$('#popup_box #imptname').val().trim() == '') {
		$('#popup_box #imptname').css('background-color', '#FF7744');
		msg += ((loary['F_IMPORT_INAME_NOT_EMPTY']) ? loary['F_IMPORT_INAME_NOT_EMPTY'] : 'F_IMPORT_INAME_NOT_EMPTY')+'\n';
	}
	$('#popup_box input[name="imptckbt[]"]').each( function(i) {
		ckbary[i] = $(this).val();
		total = parseInt(total)+parseInt($(this).val());
	});
	if (total <= 0) {
		$('#popup_box .proj_imptckbt_td').css('background-color', '#FF7744');
		msg += ((loary['F_IMPORT_ER_EXCELPAGE']) ? loary['F_IMPORT_ER_EXCELPAGE'] : 'F_IMPORT_ER_EXCELPAGE')+'\n';
	}
	if ($('#popup_box #impt_page').length > 0 && $('#popup_box #impt_page').val().trim() == '') {
		$('#popup_box #impt_page').css('background-color', '#FF7744');
		msg += ((loary['F_IMPORT_ER_DETAIL_CHA']) ? loary['F_IMPORT_ER_DETAIL_CHA'] : 'F_IMPORT_ER_DETAIL_CHA')+'\n';
	}
	if (total > 0 && $('#popup_box #impt_page').val().trim() != '') {
		var secttype = false, qtytype = false;
		for (var i = 0; i < ckbary.length; i++) {
			$('#popup_box .proj_all_trddiv_'+i.toString()).css('background-color', '#FFFFFF');
			if (ckbary[i] == '0') continue;
			var mstr = '';
			$('#popup_box select[name="imptfield_TABLE'+i.toString()+'[]"]').each( function() {
				mstr += $(this).val();
			});
			if (mstr == '') {
				$('#popup_box .proj_all_trddiv_'+i.toString()).css('background-color', '#FF7744');
				secttype = true;
			}
			if ($('#popup_box #imptqty_'+i.toString()).length > 0 && $('#popup_box #imptqty_'+i.toString()).val() == '1' &&
				$('#popup_box #impt_tite').length > 0 && $('#popup_box #impt_tite').val() == '1') {
				$('#popup_box #impt_tite').css('background-color', '#FF7744');
				$('#popup_box .proj_all_trddiv_'+i.toString()).css('background-color', '#FF7744');
				qtytype = true;
			}
		}
		if (secttype) {
			msg += ((loary['F_IMPORT_ER_DET_FID']) ? loary['F_IMPORT_ER_DET_FID'] : 'F_IMPORT_ER_DET_FID')+'\n';
		}
		if (qtytype) {
			msg += ((loary['F_IMPORT_ER_QTY_ONE']) ? loary['F_IMPORT_ER_QTY_ONE'] : 'F_IMPORT_ER_QTY_ONE')+'\n';
		}
	}
	if (msg.length > 0) {
		$('#popup_box .proj_import_loading').empty().append("<img src=\"images/Cancel.png\" alt=\"error\" width=\"16px\">");
		alert(msg);
		return false;
	}
	if (confirm(((loary['CONFIRM_SUBMIT']) ? loary['CONFIRM_SUBMIT'] : 'CONFIRM_SUBMIT'))) {
		var inid = $(iname),eri = '',
			fdata = new FormData(),
			djson = (fromid_output_json('#popup_box','name')).replace(/'/g, "''");
		var zmode = $('#SUB_MODE'+fow).val(),subph = $('#SUB_SUBPATH'+fow).val();
		var dform = '#detail_form_'+zmode+fow,sform = '#sub_form_'+zmode+fow;
		var eform = ((zmode == subph) ? dform : sform);
		var djson2 = (fromid_output_json(eform,'name')).replace(/'/g, "''");
		var meri = $(dform+' #ERI').val(), teri = $(dform+' #TEMPERI').val(),
			dbtyp = (($('#popup_box #impt_page').length > 0 && $('#'+$('#popup_box #impt_page').val()+'_db_list #dblt_type_'+$('#popup_box #impt_page').val()).length > 0) ? EncodeURLutf8($('#'+$('#popup_box #impt_page').val()+'_db_list #dblt_type_'+$('#popup_box #impt_page').val()).val()) : 'N');
		var type = ((zmode == subph) ? 'D' : 'S');
		if (type == 'D') eri = meri;
		else {
			var suberis = $('#SUB_ERIPATH'+fow).val().split('/');
			eri = suberis[suberis.length-1];
		}
		var maperi = ($(dform+' #HIDEFLOW_ERI').length > 0) ? $(dform+' #HIDEFLOW_ERI').val() : '';
		var verlen = djson.length, verlen2 = djson2.length;
		fdata.append('file', inid[0].files[0]);
		fdata.append('htmljson', djson);
		fdata.append('htmljson2', djson2);
		var url = path+'core/cw5e_import.php?sid='+sval+'&parent='+EncodeURLutf8(path)+'&act=impting';
		url += '&mode='+mode+'&ditem='+ditem+'&fdname='+fdname+'&fow='+fow+
			   '&type='+type+'&meri='+meri+'&teri='+teri+'&dbtyp='+dbtyp+
			   '&zmode='+zmode+'&eri='+eri+'&maperi='+maperi;
		url += '&verlen='+verlen.toString()+'&verlen2='+verlen2.toString();
		//console.log(url);
		var stopimpt = {}, ajaximpt = {};
		ajaximpt = $.ajax({
			url: url,
			type: 'POST',
			data: fdata,
			processData: false,
			contentType: false,
			beforeSend: function(){
				// 開始前執行 
				stopimpt = setInterval(function(){
					if ($('#popup_box').html() == '') {
						ajaximpt.abort();
						clearInterval(stopimpt);
					}
				}, 1000);
				$('#popup_box :input').prop('disabled', true);
				$('#popup_box .proj_import_loading').empty().append("<img src=\"images/loading.gif\" alt=\"loading\" width=\"16px\">");
			},
			success: function(msg){
				// 成功後執行 
				//console.log(msg);
				clearInterval(stopimpt);
				if ($('#popup_box').html() == '') {
					return false;
				}
				var ret_msg = JSON.parse(msg);
				if (ret_msg[0].result == 'false') {
					$('#popup_box :input').prop('disabled', false);
					$('#popup_box .proj_import_loading').empty().append("<img src=\"images/Cancel.png\" alt=\"error\" width=\"16px\">");
					alert(ret_msg[0].message);
					return false;
				} else {
					$('#popup_box .proj_import_loading').empty().append("<img src=\"images/ok-16x16.png\" alt=\"success\" width=\"16px\">");
					if ((ret_msg[0].mdme) && ret_msg[0].mdme == 'D') {
						$(eform+' #tab_'+ret_msg[0].page+' a').click();
						if (ret_msg[0].html_str) {
							$(eform+' #table_'+ret_msg[0].page+' tbody').empty();
							$(eform+' #table_'+ret_msg[0].page+' tbody').append(ret_msg[0].html_str);
							$(eform+' input[name="'+ret_msg[0].page+'_DERI[]"]').each( function() {
								$(eform+' #SERNO_'+$(this).val()).val($(this).closest('tr').index()+1);
								$(eform+' #SERNO_'+$(this).val()).attr('value',$(this).closest('tr').index()+1);
								$(eform+' #SERIAL_'+$(this).val()).html($(this).closest('tr').index()+1);
							});
							mode_sum_number(path, sval, mode, ret_msg[0].page, eform, fow);
						}
					} else if ((ret_msg[0].mdme) && ret_msg[0].mdme == 'DB') {
						$('#'+ret_msg[0].page+'_db_list #dblt_type_'+ret_msg[0].page).val('E');
						$(eform+' #tab_'+ret_msg[0].page+' a').click();
						detail_pagedb_load(path, sval, mode, ret_msg[0].page, '#'+ret_msg[0].page+'_db_list', fow, '1');
					}
					$('#page_body').height($('#content').height()+10);
					alert(((loary['REAMOUNT_COMPLETE']) ? loary['REAMOUNT_COMPLETE'] : 'REAMOUNT_COMPLETE'));
					close_popup_box();
				}
			},
			error: function(msg){
				// 失敗後執行 
				//console.log(msg);
				clearInterval(stopimpt);
				if ($('#popup_box').html() == '') {
					return false;
				}
				$('#popup_box .proj_import_loading').empty().append("<img src=\"images/Cancel.png\" alt=\"error\" width=\"16px\">");
			},
			complete: function(msg){
				// 完成後執行 
				//console.log(msg);
				clearInterval(stopimpt);
				if ($('#popup_box').html() == '') {
					return false;
				}
				$('#popup_box .proj_import_loading').empty().append("<img src=\"images/ok-16x16.png\" alt=\"success\" width=\"16px\">");
			}
		});
	}
}