var empid = "";
var empname = "";

var salary_issaved = false;
var emppost_issaved = false;
var sendcom_issaved = false;

var HR_Change_Salary_Table = function() {

	return {

		// main function to initiate the module
		init : function() {

			function restoreRow(oTable, nRow) {
				var aData = oTable.fnGetData(nRow);
				var jqTds = $('>td', nRow);

				for ( var i = 0, iLen = jqTds.length; i < iLen - 2; i++) {
					oTable.fnUpdate(aData[i], nRow, i, false);
				}
				oTable.fnUpdate('<a class="edit" href="">编辑</a>', nRow,
						jqTds.length - 2, false);
				oTable.fnUpdate('<a class="delete" href="">删除</a>', nRow,
						jqTds.length - 1, false);
				oTable.fnDraw();
			}

			function editRow(oTable, nRow) {
				var aData = oTable.fnGetData(nRow);
				var jqTds = $('>td', nRow);
				jqTds[0].innerHTML = '<input type="text" class="m-wrap small etcell" value="' + aData[0] + '">';
				jqTds[1].innerHTML = '<input type="text" class="m-wrap xsmall etcell" value="' + aData[1] + '">';
				jqTds[2].innerHTML = '<input type="text" class="m-wrap xsmall etcell" value="' + aData[2] + '">';
				jqTds[3].innerHTML = '<input type="text" onclick="HS_setDate(this)" class="m-wrap small etcell" value="' + aData[3] + '">';
				jqTds[4].innerHTML = '<input type="text" class="m-wrap small etcell" value="' + aData[4] + '">';
				jqTds[5].innerHTML = '<a class="edit" href="">更新</a>';
				jqTds[6].innerHTML = '<a class="cancel" href="">取消</a>';
			}

			function saveRow(oTable, nRow) {
				salary_issaved = true;
				var jqInputs = $('input', nRow);
				// alert(jqInputs[0].value);
				if (is_change_list == false) {
					$.post("empchange!add", {
						'change.changetype' : '薪资异动',
						'change.empid' : empid,
						'change.empname' : empname,
						'change.cursendcom' : jqInputs[0].value,
						'change.curemppost' : '',
						'change.cursalary' : jqInputs[1].value,
						'change.newsendcom' : '',
						'change.newemppost' : '',
						'change.newsalary' : jqInputs[2].value,
						'change.changedate' : jqInputs[3].value,
						'change.changedesc' : jqInputs[4].value
					}, function(data) {
						var addInfo = data.addInfo;
						if (addInfo == 'success') {
							alert('添加成功');
							oTable.fnUpdate(jqInputs[0].value, nRow, 0, false);
							oTable.fnUpdate(jqInputs[1].value, nRow, 1, false);
							oTable.fnUpdate(jqInputs[2].value, nRow, 2, false);
							oTable.fnUpdate(jqInputs[3].value, nRow, 3, false);
							oTable.fnUpdate(jqInputs[4].value, nRow, 4, false);
							oTable.fnUpdate('<a class="edit" href="">编辑</a>',
									nRow, 5, false);
							oTable.fnUpdate('<a class="delete" href="">删除</a>',
									nRow, 6, false);
							nRow.id = data.resid;
							oTable.fnDraw();
							oEmpTable.fnDraw();
						} else {
							alert(addInfo);
							oTable.fnDraw();
						}
					}, "json");
				} else {
					var list = change_list_empids;
					if (list == null || list == "") {
						alert('未选中任何记录');
						return false;
					}
					$.post("empchange!changeList", {
						'changeList' : list,
						'change.changetype' : '薪资异动',
						'change.empid' : empid,
						'change.empname' : empname,
						'change.cursendcom' : jqInputs[0].value,
						'change.curemppost' : '',
						'change.cursalary' : jqInputs[1].value,
						'change.newsendcom' : '',
						'change.newemppost' : '',
						'change.newsalary' : jqInputs[2].value,
						'change.changedate' : jqInputs[3].value,
						'change.changedesc' : jqInputs[4].value
					}, function(data) {
						var addInfo = data.addInfo;
						if (addInfo == 'success') {
							alert('添加成功');
							oTable.fnUpdate(jqInputs[0].value, nRow, 0, false);
							oTable.fnUpdate(jqInputs[1].value, nRow, 1, false);
							oTable.fnUpdate(jqInputs[2].value, nRow, 2, false);
							oTable.fnUpdate(jqInputs[3].value, nRow, 3, false);
							oTable.fnUpdate(jqInputs[4].value, nRow, 4, false);
							oTable.fnUpdate('<a class="edit" href="">编辑</a>',
									nRow, 5, false);
							oTable.fnUpdate('<a class="delete" href="">删除</a>',
									nRow, 6, false);
							nRow.id = count++;
							oTable.fnDraw();
							oEmpTable.fnDraw();
						} else {
							alert(addInfo);
							oTable.fnDraw();
						}
					}, "json");
				}

			}

			function updateRow(oTable, nRow) {
				salary_issaved = true;
				var jqInputs = $('input', nRow);
				// alert(jqInputs[0].value);
				if (is_change_list == false) {
					$.post("empchange!update", {
						'change.id' : nRow.id,
						'change.changetype' : '薪资异动',
						'change.empid' : empid,
						'change.empname' : empname,
						'change.cursendcom' : jqInputs[0].value,
						'change.curemppost' : '',
						'change.cursalary' : jqInputs[1].value,
						'change.newsendcom' : '',
						'change.newemppost' : '',
						'change.newsalary' : jqInputs[2].value,
						'change.changedate' : jqInputs[3].value,
						'change.changedesc' : jqInputs[4].value
					}, function(data) {
						var updateInfo = data.updateInfo;
						if (updateInfo == 'success') {
							alert('更新成功');
							oTable.fnUpdate(jqInputs[0].value, nRow, 0, false);
							oTable.fnUpdate(jqInputs[1].value, nRow, 1, false);
							oTable.fnUpdate(jqInputs[2].value, nRow, 2, false);
							oTable.fnUpdate(jqInputs[3].value, nRow, 3, false);
							oTable.fnUpdate(jqInputs[4].value, nRow, 4, false);
							oTable.fnUpdate('<a class="edit" href="">编辑</a>',
									nRow, 5, false);
							oTable.fnUpdate('<a class="delete" href="">删除</a>',
									nRow, 6, false);
							oTable.fnDraw();
							oEmpTable.fnDraw();
						} else {
							alert(updateInfo);
							oTable.fnDraw();
						}
					}, "json");
				}

			}

			var oTable = $('#hr_change_salary_table')
					.dataTable(
							{
								"aLengthMenu" : [ [ 5, 15, 20, -1 ],
										[ 5, 15, 20, "全部" ] // change per
								// page values
								// here
								],
								// set the initial value
								"iDisplayLength" : 7,
								"sDom" : "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
								"sPaginationType" : "bootstrap",
								"oLanguage" : {
									"sLengthMenu" : "_MENU_ records per page",
									"oPaginate" : {
										"sPrevious" : "Prev",
										"sNext" : "Next"
									}
								},
								"aoColumnDefs" : [ {
									'bSortable' : false,
									'aTargets' : [ 0 ]
								} ],
								"oLanguage" : {
									"sLengthMenu" : "每页显示 _MENU_ 条记录",
									"sZeroRecords" : "抱歉， 没有记录",
									"sInfo" : "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
									"sInfoEmpty" : "没有数据",
									"sInfoFiltered" : "(从 _MAX_ 条数据中检索)",
									"oPaginate" : {
										"sFirst" : "首页",
										"sPrevious" : "前一页",
										"sNext" : "后一页",
										"sLast" : "尾页"
									},
									"sSearch" : "搜索：",
									"sProcessing" : "正在加载数据..."
								}
							});

			HR_Change_Salary_Table = oTable;

			jQuery('#sample_editable_1_wrapper .dataTables_filter input')
					.addClass("m-wrap medium"); // modify table search input
			jQuery('#sample_editable_1_wrapper .dataTables_length select')
					.addClass("m-wrap small"); // modify table per page
			// dropdown
			// jQuery('#sample_editable_1_wrapper .dataTables_length select')
			// .select2( {
			// showSearchInput : false
			// // hide search box with special css class
			// }); // initialize select2 dropdown

			var nEditing = null;
			salary_issaved = false;
			$('#hr_change_salary_new')
					.click(
							function(e) {
								e.preventDefault();

								if (nEditing != null && !salary_issaved) {
									alert('有记录尚未保存');
									return;
								}
								salary_issaved = true;
								var aiNew = oTable.fnAddData( [ '', '', '', '',
										'', '', '' ]);
								var nRow = oTable.fnGetNodes(aiNew[0]);
								var aData = oTable.fnGetData(nRow);
								var jqTds = $('>td', nRow);
								if (is_change_list) {
									empid = "";
									empname = "";
								}
								editRow(oTable, nRow);
								jqTds[5].innerHTML = '<a class="edit" href="">保存</a>';
								jqTds[6].innerHTML = '<a class="cancel" data-mode="new" href="">取消</a>';
								nEditing = nRow;
							});

			$('#hr_change_salary_table a.delete').live('click', function(e) {
				e.preventDefault();

				if (confirm("确定删除这行记录吗 ?") == false) {
					return;
				}
				var nRow = $(this).parents('tr')[0];
				$.post("empchange!delete?id=" + nRow.id, {}, function(data) {
					var deleteInfo = data.deleteInfo;
					if (deleteInfo == 'success') {
						alert("删除成功");
						oTable.fnDeleteRow(nRow);
					} else {
						alert(deleteInfo);
					}
				}, "json");
				// alert("Deleted! Do not forget to do some ajax
					// to sync with backend :)");
				});

			$('#hr_change_salary_table a.cancel').live('click', function(e) {
				e.preventDefault();
				salary_issaved = true;
				if ($(this).attr("data-mode") == "new") {
					var nRow = $(this).parents('tr')[0];
					oTable.fnDeleteRow(nRow);
					nEditing = null;
				} else {
					restoreRow(oTable, nEditing);
					nEditing = null;
				}
			});

			$('#hr_change_salary_table a.edit').live('click', function(e) {
				e.preventDefault();

				/*
				 * Get the row as a parent of the link that was clicked on
				 */
				var nRow = $(this).parents('tr')[0];

				if (nEditing !== null && nEditing != nRow) {
					/*
					 * Currently editing - but not this row - restore the old
					 * before continuing to edit mode
					 */
					restoreRow(oTable, nEditing);
					editRow(oTable, nRow);
					nEditing = nRow;
				} else if (nEditing == nRow && this.innerHTML == "保存") {
					/* Editing this row and want to save it */
					saveRow(oTable, nEditing);
					nEditing = null;
					salary_issaved = true;
					// alert("Add! Do not forget to do some ajax to sync with
					// backend :)");
				} else if (this.innerHTML == '更新') {
					/* No edit in progress - let's start one */
					updateRow(oTable, nEditing);
					nEditing = null;
					salary_issaved = true;
				} else {
					editRow(oTable, nRow);
					nEditing = nRow;
				}
			});

		}

	};

}();

// ////////////////////////////////////////////////////////////////////////
var emppost_issaved = false;
var HR_Change_Emppost_Table = function() {

	return {

		// main function to initiate the module
		init : function() {

			function restoreRow(oTable, nRow) {
				var aData = oTable.fnGetData(nRow);
				var jqTds = $('>td', nRow);

				for ( var i = 0, iLen = jqTds.length; i < iLen - 2; i++) {
					oTable.fnUpdate(aData[i], nRow, i, false);
				}
				oTable.fnUpdate('<a class="edit" href="">编辑</a>', nRow,
						jqTds.length - 2, false);
				oTable.fnUpdate('<a class="delete" href="">删除</a>', nRow,
						jqTds.length - 1, false);
				oTable.fnDraw();
			}

			function editRow(oTable, nRow) {
				var aData = oTable.fnGetData(nRow);
				var jqTds = $('>td', nRow);
				jqTds[0].innerHTML = '<input type="text" class="m-wrap xsmall etcell" value="' + aData[0] + '">';
				jqTds[1].innerHTML = '<input type="text" class="m-wrap xsmall etcell" value="' + aData[1] + '">';
				jqTds[2].innerHTML = '<input type="text" class="m-wrap small etcell" value="' + aData[2] + '">';
				jqTds[3].innerHTML = '<input type="text" onclick="HS_setDate(this)" class="m-wrap xsmall etcell" value="' + aData[3] + '">';
				jqTds[4].innerHTML = '<input type="text" class="m-wrap xsmall etcell" value="' + aData[4] + '">';
				jqTds[5].innerHTML = '<a class="edit" href="">更新</a>';
				jqTds[6].innerHTML = '<a class="cancel" href="">取消</a>';
			}

			function saveRow(oTable, nRow) {
				emppost_issaved = true;
				var jqInputs = $('input', nRow);
				// alert(jqInputs[0].value);
				if (is_change_list == false) {
					$.post("empchange!add", {
						'change.changetype' : '岗位异动',
						'change.empid' : empid,
						'change.empname' : empname,
						'change.cursendcom' : jqInputs[0].value,
						'change.curemppost' : jqInputs[1].value,
						'change.cursalary' : '',
						'change.newsendcom' : '',
						'change.newemppost' : jqInputs[2].value,
						'change.newsalary' : '',
						'change.changedate' : jqInputs[3].value,
						'change.changedesc' : jqInputs[4].value
					}, function(data) {
						var addInfo = data.addInfo;
						if (addInfo == 'success') {
							alert('添加成功');
							oTable.fnUpdate(jqInputs[0].value, nRow, 0, false);
							oTable.fnUpdate(jqInputs[1].value, nRow, 1, false);
							oTable.fnUpdate(jqInputs[2].value, nRow, 2, false);
							oTable.fnUpdate(jqInputs[3].value, nRow, 3, false);
							oTable.fnUpdate(jqInputs[4].value, nRow, 4, false);
							oTable.fnUpdate('<a class="edit" href="">编辑</a>',
									nRow, 5, false);
							oTable.fnUpdate('<a class="delete" href="">删除</a>',
									nRow, 6, false);
							nRow.id = data.resid;
							oTable.fnDraw();
							oEmpTable.fnDraw();
						} else {
							alert(addInfo);
							oTable.fnDraw();
							$("#change-info-modal").modal("toggle");
						}
					}, "json");
				} else {
					var list = change_list_empids;
					if (list == null || list == "") {
						alert('未选中任何记录');
						return false;
					}
					$.post("empchange!changeList", {
						'changeList' : list,
						'change.changetype' : '岗位异动',
						'change.empid' : empid,
						'change.empname' : empname,
						'change.cursendcom' : jqInputs[0].value,
						'change.curemppost' : jqInputs[1].value,
						'change.cursalary' : '',
						'change.newsendcom' : '',
						'change.newemppost' : jqInputs[2].value,
						'change.newsalary' : '',
						'change.changedate' : jqInputs[3].value,
						'change.changedesc' : jqInputs[4].value
					}, function(data) {
						var addInfo = data.addInfo;
						if (addInfo == 'success') {
							alert('添加成功');
							oTable.fnUpdate(jqInputs[0].value, nRow, 0, false);
							oTable.fnUpdate(jqInputs[1].value, nRow, 1, false);
							oTable.fnUpdate(jqInputs[2].value, nRow, 2, false);
							oTable.fnUpdate(jqInputs[3].value, nRow, 3, false);
							oTable.fnUpdate(jqInputs[4].value, nRow, 4, false);
							oTable.fnUpdate('<a class="edit" href="">编辑</a>',
									nRow, 5, false);
							oTable.fnUpdate('<a class="delete" href="">删除</a>',
									nRow, 6, false);
							nRow.id = count++;
							oTable.fnDraw();
							oEmpTable.fnDraw();
						} else {
							alert(addInfo);
							oTable.fnDraw();
							$("#change-info-modal").modal("toggle");
						}
					}, "json");
				}

			}

			function updateRow(oTable, nRow) {
				emppost_issaved = true;
				var jqInputs = $('input', nRow);
				// alert(jqInputs[0].value);
				if (is_change_list == false) {
					$.post("empchange!update", {
						'change.id' : nRow.id,
						'change.changetype' : '岗位异动',
						'change.empid' : empid,
						'change.empname' : empname,
						'change.cursendcom' : jqInputs[0].value,
						'change.curemppost' : jqInputs[1].value,
						'change.cursalary' : '',
						'change.newsendcom' : '',
						'change.newemppost' : jqInputs[2].value,
						'change.newsalary' : '',
						'change.changedate' : jqInputs[3].value,
						'change.changedesc' : jqInputs[4].value
					}, function(data) {
						var updateInfo = data.updateInfo;
						if (updateInfo == 'success') {
							alert('更新成功');
							oTable.fnUpdate(jqInputs[0].value, nRow, 0, false);
							oTable.fnUpdate(jqInputs[1].value, nRow, 1, false);
							oTable.fnUpdate(jqInputs[2].value, nRow, 2, false);
							oTable.fnUpdate(jqInputs[3].value, nRow, 3, false);
							oTable.fnUpdate(jqInputs[4].value, nRow, 4, false);
							oTable.fnUpdate('<a class="edit" href="">编辑</a>',
									nRow, 5, false);
							oTable.fnUpdate('<a class="delete" href="">删除</a>',
									nRow, 6, false);
							oTable.fnDraw();
						} else {
							alert(updateInfo);
							oTable.fnDraw();
							$("#change-info-modal").modal("toggle");
						}
					}, "json");
				}

			}

			var oTable = $('#hr_change_emppost_table')
					.dataTable(
							{
								"aLengthMenu" : [ [ 5, 15, 20, -1 ],
										[ 5, 15, 20, "全部" ] // change per
								// page values
								// here
								],
								// set the initial value
								"iDisplayLength" : 7,
								"sDom" : "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
								"sPaginationType" : "bootstrap",
								"oLanguage" : {
									"sLengthMenu" : "_MENU_ records per page",
									"oPaginate" : {
										"sPrevious" : "Prev",
										"sNext" : "Next"
									}
								},
								"aoColumnDefs" : [ {
									'bSortable' : false,
									'aTargets' : [ 0 ]
								} ],
								"oLanguage" : {
									"sLengthMenu" : "每页显示 _MENU_ 条记录",
									"sZeroRecords" : "抱歉， 没有记录",
									"sInfo" : "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
									"sInfoEmpty" : "没有数据",
									"sInfoFiltered" : "(从 _MAX_ 条数据中检索)",
									"oPaginate" : {
										"sFirst" : "首页",
										"sPrevious" : "前一页",
										"sNext" : "后一页",
										"sLast" : "尾页"
									},
									"sSearch" : "搜索：",
									"sProcessing" : "正在加载数据..."
								}
							});
			HR_Change_Emppost_Table = oTable;

			jQuery('#sample_editable_1_wrapper .dataTables_filter input')
					.addClass("m-wrap medium"); // modify table search input
			jQuery('#sample_editable_1_wrapper .dataTables_length select')
					.addClass("m-wrap small"); // modify table per page
			// dropdown
			// jQuery('#sample_editable_1_wrapper .dataTables_length select')
			// .select2( {
			// showSearchInput : false
			// // hide search box with special css class
			// }); // initialize select2 dropdown

			var nEditing = null;
			emppost_issaved = false;

			$('#hr_change_emppost_new')
					.click(
							function(e) {
								e.preventDefault();

								if (nEditing != null && !emppost_issaved) {
									alert('有记录尚未保存');
									return;
								}
								emppost_issaved = true;
								var aiNew = oTable.fnAddData( [ '', '', '', '',
										'', '', '' ]);
								var nRow = oTable.fnGetNodes(aiNew[0]);
								var aData = oTable.fnGetData(nRow);
								var jqTds = $('>td', nRow);
								if (is_change_list) {
									empid = "";
									empname = "";
								}
								editRow(oTable, nRow);
								jqTds[5].innerHTML = '<a class="edit" href="">保存</a>';
								jqTds[6].innerHTML = '<a class="cancel" data-mode="new" href="">取消</a>';
								nEditing = nRow;
							});

			$('#hr_change_emppost_table a.delete').live('click', function(e) {
				e.preventDefault();

				if (confirm("确定删除这行记录吗 ?") == false) {
					return;
				}
				var nRow = $(this).parents('tr')[0];
				$.post("empchange!delete?id=" + nRow.id, {}, function(data) {
					var deleteInfo = data.deleteInfo;
					if (deleteInfo == 'success') {
						alert("删除成功");
						oTable.fnDeleteRow(nRow);
					} else {
						alert(deleteInfo);
					}
				}, "json");
				// alert("Deleted! Do not forget to do some ajax
					// to sync with backend :)");
				});

			$('#hr_change_emppost_table a.cancel').live('click', function(e) {
				e.preventDefault();
				emppost_issaved = true;
				if ($(this).attr("data-mode") == "new") {
					var nRow = $(this).parents('tr')[0];
					oTable.fnDeleteRow(nRow);
					nEditing = null;
				} else {
					restoreRow(oTable, nEditing);
					nEditing = null;
				}
			});

			$('#hr_change_emppost_table a.edit').live('click', function(e) {
				e.preventDefault();

				/*
				 * Get the row as a parent of the link that was clicked on
				 */
				var nRow = $(this).parents('tr')[0];

				if (nEditing !== null && nEditing != nRow) {
					/*
					 * Currently editing - but not this row - restore the old
					 * before continuing to edit mode
					 */
					restoreRow(oTable, nEditing);
					editRow(oTable, nRow);
					nEditing = nRow;
				} else if (nEditing == nRow && this.innerHTML == "保存") {
					/* Editing this row and want to save it */
					saveRow(oTable, nEditing);
					nEditing = null;
					emppost_issaved = true;
					// alert("Add! Do not forget to do some ajax to sync with
					// backend :)");
				} else if (this.innerHTML == '更新') {
					/* No edit in progress - let's start one */
					updateRow(oTable, nEditing);
					nEditing = null;
					emppost_issaved = true;
				} else {
					editRow(oTable, nRow);
					nEditing = nRow;
				}
			});

		}

	};

}();

// ////////////////////////////////////////////////////////////////////////
var sendcom_issaved = false;
var HR_Change_Sendcom_Table = function() {

	return {

		// main function to initiate the module
		init : function() {

			function restoreRow(oTable, nRow) {
				var aData = oTable.fnGetData(nRow);
				var jqTds = $('>td', nRow);

				for ( var i = 0, iLen = jqTds.length; i < iLen - 2; i++) {
					oTable.fnUpdate(aData[i], nRow, i, false);
				}
				oTable.fnUpdate('<a class="edit" href="">编辑</a>', nRow,
						jqTds.length - 2, false);
				oTable.fnUpdate('<a class="delete" href="">删除</a>', nRow,
						jqTds.length - 1, false);
				oTable.fnDraw();
			}

			function editRow(oTable, nRow) {
				var aData = oTable.fnGetData(nRow);
				var jqTds = $('>td', nRow);
				jqTds[0].innerHTML = '<input type="text" class="m-wrap xsmall etcell" value="' + aData[0] + '">';
				jqTds[1].innerHTML = '<input type="text" class="m-wrap xsmall etcell" value="' + aData[1] + '">';
				jqTds[2].innerHTML = '<input type="text" onclick="HS_setDate(this)" class="m-wrap small etcell" value="' + aData[2] + '">';
				jqTds[3].innerHTML = '<input type="text" class="m-wrap small etcell" value="' + aData[3] + '">';
				jqTds[4].innerHTML = '<a class="edit" href="">保存</a>';
				jqTds[5].innerHTML = '<a class="cancel" href="">取消</a>';
			}

			function saveRow(oTable, nRow) {
				sendcom_issaved = true;
				var jqInputs = $('input', nRow);
				// alert(jqInputs[0].value);
				if (is_change_list == false) {
					$.post("empchange!add", {
						'change.changetype' : '用工单位异动',
						'change.empid' : empid,
						'change.empname' : empname,
						'change.cursendcom' : jqInputs[0].value,
						'change.curemppost' : '',
						'change.cursalary' : '',
						'change.newsendcom' : jqInputs[1].value,
						'change.newemppost' : '',
						'change.newsalary' : '',
						'change.changedate' : jqInputs[2].value,
						'change.changedesc' : jqInputs[3].value
					}, function(data) {
						var addInfo = data.addInfo;
						if (addInfo == 'success') {
							alert('添加成功');
							oTable.fnUpdate(jqInputs[0].value, nRow, 0, false);
							oTable.fnUpdate(jqInputs[1].value, nRow, 1, false);
							oTable.fnUpdate(jqInputs[2].value, nRow, 2, false);
							oTable.fnUpdate(jqInputs[3].value, nRow, 3, false);
							oTable.fnUpdate('<a class="edit" href="">编辑</a>',
									nRow, 4, false);
							oTable.fnUpdate('<a class="delete" href="">删除</a>',
									nRow, 5, false);
							nRow.id = data.resid;
							oTable.fnDraw();
							oEmpTable.fnDraw();
						} else {
							alert(addInfo);
							oTable.fnDraw();
						}
					}, "json");
				} else {
					var list = change_list_empids;
					if (list == null || list == "") {
						alert('未选中任何记录');
						return false;
					}
					$.post("empchange!changeList", {
						'changeList' : list,
						'change.changetype' : '用工单位异动',
						'change.empid' : empid,
						'change.empname' : empname,
						'change.cursendcom' : jqInputs[0].value,
						'change.curemppost' : '',
						'change.cursalary' : '',
						'change.newsendcom' : jqInputs[1].value,
						'change.newemppost' : '',
						'change.newsalary' : '',
						'change.changedate' : jqInputs[2].value,
						'change.changedesc' : jqInputs[3].value
					}, function(data) {
						var addInfo = data.addInfo;
						if (addInfo == 'success') {
							alert('添加成功');
							oTable.fnUpdate(jqInputs[0].value, nRow, 0, false);
							oTable.fnUpdate(jqInputs[1].value, nRow, 1, false);
							oTable.fnUpdate(jqInputs[2].value, nRow, 2, false);
							oTable.fnUpdate(jqInputs[3].value, nRow, 3, false);
							oTable.fnUpdate('<a class="edit" href="">编辑</a>',
									nRow, 4, false);
							oTable.fnUpdate('<a class="delete" href="">删除</a>',
									nRow, 5, false);
							oTable.fnDraw();
							oEmpTable.fnDraw();
						} else {
							alert(addInfo);
							oTable.fnDraw();
						}
					}, "json");
				}

			}

			function updateRow(oTable, nRow) {
				sendcom_issaved = true;
				var jqInputs = $('input', nRow);
				// alert(jqInputs[0].value);
				if (is_change_list == false) {
					$.post("empchange!update", {
						'change.id' : nRow.id,
						'change.changetype' : '用工单位异动',
						'change.empid' : empid,
						'change.empname' : empname,
						'change.cursendcom' : jqInputs[0].value,
						'change.curemppost' : '',
						'change.cursalary' : '',
						'change.newsendcom' : jqInputs[1].value,
						'change.newemppost' : '',
						'change.newsalary' : '',
						'change.changedate' : jqInputs[2].value,
						'change.changedesc' : jqInputs[3].value
					}, function(data) {
						var updateInfo = data.updateInfo;
						if (updateInfo == 'success') {
							alert('更新成功');
							oTable.fnUpdate(jqInputs[0].value, nRow, 0, false);
							oTable.fnUpdate(jqInputs[1].value, nRow, 1, false);
							oTable.fnUpdate(jqInputs[2].value, nRow, 2, false);
							oTable.fnUpdate(jqInputs[3].value, nRow, 3, false);
							oTable.fnUpdate('<a class="edit" href="">编辑</a>',
									nRow, 4, false);
							oTable.fnUpdate('<a class="delete" href="">删除</a>',
									nRow, 5, false);
							oTable.fnDraw();
							oEmpTable.fnDraw();
						} else {
							alert(updateInfo);
							oTable.fnDraw();
						}
					}, "json");
				}

			}

			var oTable = $('#hr_change_sendcom_table')
					.dataTable(
							{
								"aLengthMenu" : [ [ 5, 15, 20, -1 ],
										[ 5, 15, 20, "全部" ] // change per
								// page values
								// here
								],
								// set the initial value
								"iDisplayLength" : 6,
								"sDom" : "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
								"sPaginationType" : "bootstrap",
								"oLanguage" : {
									"sLengthMenu" : "_MENU_ records per page",
									"oPaginate" : {
										"sPrevious" : "Prev",
										"sNext" : "Next"
									}
								},
								"aoColumnDefs" : [ {
									'bSortable' : false,
									'aTargets' : [ 0 ]
								} ],
								"oLanguage" : {
									"sLengthMenu" : "每页显示 _MENU_ 条记录",
									"sZeroRecords" : "抱歉， 没有记录",
									"sInfo" : "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
									"sInfoEmpty" : "没有数据",
									"sInfoFiltered" : "(从 _MAX_ 条数据中检索)",
									"oPaginate" : {
										"sFirst" : "首页",
										"sPrevious" : "前一页",
										"sNext" : "后一页",
										"sLast" : "尾页"
									},
									"sSearch" : "搜索：",
									"sProcessing" : "正在加载数据..."
								}
							});
			HR_Change_Sendcom_Table = oTable;

			jQuery('#sample_editable_1_wrapper .dataTables_filter input')
					.addClass("m-wrap medium"); // modify table search input
			jQuery('#sample_editable_1_wrapper .dataTables_length select')
					.addClass("m-wrap small"); // modify table per page
			// dropdown
			// jQuery('#sample_editable_1_wrapper .dataTables_length select')
			// .select2( {
			// showSearchInput : false
			// // hide search box with special css class
			// }); // initialize select2 dropdown

			var nEditing = null;
			sendcom_issaved = false;

			$('#hr_change_sendcom_new')
					.click(
							function(e) {
								e.preventDefault();

								if (nEditing != null && !sendcom_issaved) {
									alert('有记录尚未保存');
									return;
								}
								sendcom_issaved = true;
								var aiNew = oTable.fnAddData( [ '', '', '', '',
										'', '' ]);
								var nRow = oTable.fnGetNodes(aiNew[0]);
								var aData = oTable.fnGetData(nRow);
								var jqTds = $('>td', nRow);
								if (is_change_list) {
									empid = "";
									empname = "";
								}
								editRow(oTable, nRow);
								jqTds[4].innerHTML = '<a class="edit" href="">保存</a>';
								jqTds[5].innerHTML = '<a class="cancel" data-mode="new" href="">取消</a>';
								nEditing = nRow;
							});

			$('#hr_change_sendcom_table a.delete').live('click', function(e) {
				e.preventDefault();

				if (confirm("确定删除这行记录吗 ?") == false) {
					return;
				}
				var nRow = $(this).parents('tr')[0];
				$.post("empchange!delete?id=" + nRow.id, {}, function(data) {
					var deleteInfo = data.deleteInfo;
					if (deleteInfo == 'success') {
						alert("删除成功");
						oTable.fnDeleteRow(nRow);
					} else {
						alert(deleteInfo);
					}
				}, "json");
				// alert("Deleted! Do not forget to do some ajax
					// to sync with backend :)");
				});

			$('#hr_change_sendcom_table a.cancel').live('click', function(e) {
				e.preventDefault();
				sendcom_issaved = true;
				if ($(this).attr("data-mode") == "new") {
					var nRow = $(this).parents('tr')[0];
					oTable.fnDeleteRow(nRow);
					nEditing = null;
				} else {
					restoreRow(oTable, nEditing);
					nEditing = null;
				}
			});

			$('#hr_change_sendcom_table a.edit').live('click', function(e) {
				e.preventDefault();

				/*
				 * Get the row as a parent of the link that was clicked on
				 */
				var nRow = $(this).parents('tr')[0];

				if (nEditing !== null && nEditing != nRow) {
					/*
					 * Currently editing - but not this row - restore the old
					 * before continuing to edit mode
					 */
					restoreRow(oTable, nEditing);
					editRow(oTable, nRow);
					nEditing = nRow;
				} else if (nEditing == nRow && this.innerHTML == "保存") {
					/* Editing this row and want to save it */
					saveRow(oTable, nEditing);
					nEditing = null;
					sendcom_issaved = true;
					// alert("Add! Do not forget to do some ajax to sync with
					// backend :)");
				} else if (this.innerHTML == '更新') {
					/* No edit in progress - let's start one */
					updateRow(oTable, nEditing);
					nEditing = null;
					sendcom_issaved = true;
				} else {
					editRow(oTable, nRow);
					nEditing = nRow;
				}
			});

		}

	};

}();

HR_Change_Sendcom_Table.init();
HR_Change_Emppost_Table.init();
HR_Change_Salary_Table.init();

// ////////////////////////////////////////////////////////////////////////

function setSalaryEditTable(oTable, change) {
	// oTable._fnClearTable();
	var aiNew = oTable.fnAddData( [ change.cursendcom, change.cursalary,
			change.newsalary, change.changedate, change.changedesc, '', '' ]);
	var nRow = oTable.fnGetNodes(aiNew[0]);
	var aData = oTable.fnGetData(nRow);
	var jqTds = $('>td', nRow);
	jqTds[0].innerHTML = aData[0];
	jqTds[1].innerHTML = aData[1];
	jqTds[2].innerHTML = aData[2];
	jqTds[3].innerHTML = aData[3];
	jqTds[4].innerHTML = aData[4];

	nRow.id = change.id;
	jqTds[5].innerHTML = '<a class="edit" href="">编辑</a>';
	jqTds[6].innerHTML = '<a class="delete" href="">删除</a>';
}

function setEmppostEditTable(oTable, change) {
	// oTable._fnClearTable();
	var aiNew = oTable.fnAddData( [ change.cursendcom, change.curemppost,
			change.newemppost, change.changedate, change.changedesc, '', '' ]);
	var nRow = oTable.fnGetNodes(aiNew[0]);
	var aData = oTable.fnGetData(nRow);
	var jqTds = $('>td', nRow);
	jqTds[0].innerHTML = aData[0];
	jqTds[1].innerHTML = aData[1];
	jqTds[2].innerHTML = aData[2];
	jqTds[3].innerHTML = aData[3];
	jqTds[4].innerHTML = aData[4];

	nRow.id = change.id;
	jqTds[5].innerHTML = '<a class="edit" href="">编辑</a>';
	jqTds[6].innerHTML = '<a class="delete" href="">删除</a>';
}

function setSendcomEditTable(oTable, change) {
	// oTable._fnClearTable();
	var aiNew = oTable.fnAddData( [ change.cursendcom, change.newsendcom,
			change.changedate, change.changedesc, '', '' ]);
	var nRow = oTable.fnGetNodes(aiNew[0]);
	var aData = oTable.fnGetData(nRow);
	var jqTds = $('>td', nRow);
	nRow.id = change.id;
	jqTds[0].innerHTML = aData[0];
	jqTds[1].innerHTML = aData[1];
	jqTds[2].innerHTML = aData[2];
	jqTds[3].innerHTML = aData[3];
	jqTds[4].innerHTML = '<a class="edit" href="">编辑</a>';
	jqTds[5].innerHTML = '<a class="delete" href="">删除</a>';
}

// /////////////////////////////////////////////////////////////////////////////////////////////////////
