
/**保存客户记录**/
var clientsJSON = null;

function isIncludeClientNode(){
	var status = curUserIncludeClientFlag();
	return (status != null && status == 1) ? true : false;
}

var isIncludeClientFlag = null;
function curUserIncludeClientFlag(){
	
	if(isIncludeClientFlag == null){
		var status = findbsCookie("showClientGroup_" + $("#userId").val());
		isIncludeClientFlag = (status != null && status == 1) ? status : 0;
	}
	return isIncludeClientFlag;
}
function loadTreeNodeCss(){
	var style = "";
	if(isIncludeClientNode()){
		style = "/css/monitor/accordion_client.css";
	}else{
		style = "/css/monitor/accordion.css";
	}
	addCSS(basePath_ZH + style);
}

function loadClientData(){

	doRequest(basePath_ + "json/cltAction_tree.action", null, function(json){
		
		
		
		if(json.flag){
		
			$("#group").remove();//删除么有客户节点的分组节点容器
			
			json.data.splice(0, 0, {id : 0, name : "默认客户"});//添加默认分组
			clientsJSON = json;//保存客户记录
			
			var clientNodes = [];
			//clientNodes.push(createClientNode("默认客户", 0));
			
			for(var i = 0, len = json.data.length; i < len; i++){
				clientNodes.push(createClientNode(json.data[i].name, json.data[i].id));
			}
			
			$("#leftList").append(clientNodes.join(""));
			
			addListtenerOfClientNode();
			
		}else{
			alert(json.msg);
		}
	});
}

function createClientNode(name, id){
	
	return "<div id=\"client_" + id + "\" class=\"tree_list_main\" >" + 
				"<a id=\"client_node_switch_" + id + "\" title=\"" + name + "\" href=\"javascript:;\" name='client_node_switch' class='kehu_link'>" + 
						(name.length > 10 ? (name.substring(0, 10) + "..") : name) + 
						"<span id=\"client_group_count_" + id + "\" count=\"0\">&nbsp;</span>" +
						"<img id=\"client_status_img_" + id + "\" status=\"close\" src=\"" + basePath_ZH + "/image/monitor/client_c.gif\" style=\"float:right\" />" + 
				"</a>" +
				"<dl id=\"client_group_content_" + id + "\" name=\"client_group_content\" class=\"accordion\" style=\"display:none\">" +			
				"</dl>" +
			"</div>";
}

function addListtenerOfClientNode(){
	
	$("a[name=client_node_switch]").each(function(){
		$(this).click(function(){
			var clientNodeId = $(this).attr("id").split("_")[3],
			    statusImg = $("#client_status_img_" + clientNodeId),
			    status = statusImg.attr("status"),
			    groupPanel = $("#client_group_content_" + clientNodeId);
			    
			    if(status == "open"){
			    	statusImg.attr("status", "close");
			    	statusImg.attr("src", basePath_ZH + "/image/monitor/client_c.gif");
			    	groupPanel.hide();			    	
					
			    }else{
			    	statusImg.attr("status", "open");
			    	statusImg.attr("src", basePath_ZH + "/image/monitor/client_o.gif");
			    	groupPanel.show();
			    	
			    }
		});
	});
}

function expandClientNode(id){
	
	var clientTreeSwitch = $("#client_node_switch_" + id);
	if(clientTreeSwitch.find("img").attr("status") == "close" ){
		clientTreeSwitch.click();							
	}

}
