
efform_onload = function(){
	var grid = efgrid.getGridObject("ef_grid_result");
	var rows = grid.getRowCount();
	for(var i = 0 ; i < rows ; i ++){
		var switchCon = grid.blockData.getCell(i,"switchCon");
		if(switchCon == "开"){
			grid.setRowChecked(i,true);
			grid.refreshRow(i);
		}
	}
	
}


efgrid.cellClick_x=function (data_type, event, dbclick){
	var div_node=event.srcElement || event.target;
	if (div_node.tagName=="A")
	div_node=div_node.parentNode;
	if (div_node.tagName!="DIV")return;
	var grid_node=efgrid.getEfGridNode(div_node);
	var grid=grid_node.efgrid;
	if (!grid)return;
	var not_cell=(div_node.getAttribute("efVal")==null);
	var row_index=0, col_index=0;
	if (!not_cell){
		row_index=div_node.parentNode.parentNode.rowIndex;
		col_index=div_node.parentNode.cellIndex;
	}
	var old_node=grid.cellOriginEditNode;
	if ((old_node) && (old_node==div_node))return;
	if (old_node)efgrid._saveOldCell(old_node, grid);
	efform.showErrorMessage();
	if (not_cell)return;
	var table_node=grid.getGridTableNode();
	var fixDiv=efgrid.getFixDiv(table_node);
	var fixTable=fixDiv.firstChild;
	var dataDiv=efgrid.getDataDiv(table_node);
	var dataTable=dataDiv.firstChild;
	div_node=(data_type==TYPE_FIX) ? fixTable.rows[row_index].childNodes[col_index].firstChild : dataTable.rows[row_index].childNodes[col_index].firstChild;
	efgrid._genEditNode(grid, div_node, data_type);
}

efgrid._genEditNode=function (grid, div_node, data_type){
//	if (!grid.isEnable() || grid.isReadonly())return;
	var row_index=div_node.parentNode.parentNode.rowIndex;
	var col_index=div_node.parentNode.cellIndex;
	var newline=grid.isNewLine(row_index);
	if (data_type==TYPE_FIX && !newline)return;
	if (typeof efgrid_onBeforeCellEditNodeDisplay=="function"){
		try{
			if (efgrid_onBeforeCellEditNodeDisplay(grid.gridId, row_index, col_index, data_type)==false)
			return;
		}catch (ex){
			efgrid.processException(ex, "Callback to efgrid_onBeforeCellEditNodeDisplay failed");
		}
	}
	var column=grid.getColumn(col_index, data_type);
	div_node=grid.getCellDivNode(row_index, col_index, data_type);
	div_node=column.getEditNode(div_node, newline);
	if (!div_node)return null;
	if (typeof efgrid_onCellEditNodeDisplayReady=="function"){
		try{
			var cell_value=grid.getCellValue(row_index, col_index, data_type);
			efgrid_onCellEditNodeDisplayReady(grid.gridId, row_index, col_index, cell_value, data_type, div_node);
		}catch (exception){
			efgrid.processException(exception);
		}
	}
	div_node=grid.getCellDivNode(row_index, col_index, data_type);
	efgrid._setEditNodeEvent(div_node);
	grid.cellOriginEditNode=div_node;
	grid.cellOriginNodeType=data_type;
	grid.cellOriginNodeValue=grid.getCellValue(row_index, col_index, data_type);
}
efgrid.divData.onclick=function (event, dbclick){
	return efgrid.cellClick_x(0, event, dbclick);
}
//grid全选按钮点击事件(当启用页面readonly="false",并同时做了chexkbox单选时,将全选的checkbox点击屏蔽)
efgrid_onSelectAllClicked = function( grid_id, div_node ){
//	debugger;
//	alert(div_node.firstChild.uniqueID);
	//设置全选按钮失效
	div_node.firstChild.disabled = true;
	//设置选中状态失效
	div_node.firstChild.checked = false;
	return false;
}

efgrid_onRowCheckboxClicked = function( grid_id, row_index,div_node ){  //checkBox单选
//	if(grid_id == 'ef_grid_switch'){
			var grid = efgrid.getGridObject(grid_id);
			var info = new EiInfo();
			var switchType = grid.blockData.getCell(row_index, "switchType");
//			var switchCon = grid.blockData.getCell(row_index, "switchCon");
			var segNo = ef.get("inqu_status-0-segNo").value;
			var custLocalSegNo = grid.blockData.getCell(row_index,"custLocalSegNo");
			var customerId = grid.blockData.getCell(row_index,"customerId");
//      			info.set("switchCon",switchCon);
				info.set("switchType",switchType);
				info.set("segNo",segNo);
				info.set("custLocalSegNo",custLocalSegNo);
				info.set("customerId",customerId);
				
		if(div_node.firstChild.checked){
				info.set("switchCon","1");
				var value = efutils.trimString(grid.blockData.getCell(row_index,"customerId"));
				if( ""==value || value.length > 10){
					alert("请输入客户代码！");
				}else{
					EiCommunicator.send("STXT1301","saveSwitchUser",info,node_call_back );
					grid.blockData.setCell(row_index,"switchCon",'开');
				    grid.setRowChecked ( row_index , true );
				}
				
			    
				
		}else if(!div_node.firstChild.checked){
			if(div_node.firstChild.length >1){
				grid.setRowChecked ( row_index , true );
				
			}else{
				info.set("switchCon","0");
				EiCommunicator.send("STXT1301","saveSwitchUser",info,node_call_back );
					grid.blockData.setCell(row_index,"switchCon",'关');
					grid.setRowChecked ( row_index , false );
					
			}

		}

//	}
	grid.refreshRow(row_index);
}
var node_call_back = {
	onSuccess :
		function(eiInfo){
//			alert(eiInfo.getMsg());		
		},
 	 onFail    : 
   		 function(eMsg) {
      	 alert("failure");
    	}		
	};
	
//button_save_onclick = function(){
//	//	if(grid_id == 'ef_grid_switch'){
//			var grid = efgrid.getGridObject("ef_grid_result");
//			var info = new EiInfo();
//			var rows = grid.getCheckedRows();
//			for(var i = 0 ; i < rows.length ; i ++){
//					var switchType = grid.blockData.getCell(rows[i], "switchType");
//		//			var switchCon = grid.blockData.getCell(rows[i], "switchCon");
//					var segNo = ef.get("inqu_status-0-segNo").value;
//					var custEbsName = grid.blockData.getCell(row_index,"custEbsName");
//					var customerId = grid.blockData.getCell(row_index,"customerId");
//		//      		info.set("switchCon",switchCon);
//						info.set("switchType",switchType);
//						info.set("segNo",segNo);
//						info.set("custEbsName",custEbsName);
//						info.set("customerId",customerId);
//						
//						if(div_node.firstChild.checked){
//								info.set("switchCon","1");
//							    EiCommunicator.send("STXT1301","saveSwitchUser",info,node_call_back );
//								grid.blockData.setCell(row_index,"switchCon",'1');
//							    grid.setRowChecked ( row_index , true );
//								
//						}else if(!div_node.firstChild.checked){
//							if(div_node.firstChild.length >1){
//								grid.setRowChecked ( row_index , true );
//								
//							}else{
//								info.set("switchCon","0");
//								EiCommunicator.send("STXT1301","saveSwitchUser",info,node_call_back );
//									grid.blockData.setCell(row_index,"switchCon",'0');
//									grid.setRowChecked ( row_index , false );
//									
//							}
//				
//						}
//			}
//
////	}
//	grid.refreshRow(row_index);
//}