var zTree;

//设置配置参数 和 方法
var setting =
{
	editable: false,//参数设置为true便可使用拖拽功能
	edit_renameBtn:false,
	edit_removeBtn:false,
	dragCopy: true,//拖拽功能为复制然后在目的菜单添加
	dragMove: false,//拖拽功能为先删除然后在目的菜单添加
	data: {
		key: {
			children: "nodes"
		},
		simpleData: {
			enable : false,
			idKey : "id",
			pIdKey : "pId",
			rootPId : null
		}
	},
	view: {
		showLine: true,
		showTitle:false,
		selectedMulti: false
	},
	callback: {
				onClick: treeOnClick
			  }
};

var TREE_BLANK_HEIGHT = 38;
var IFRAME_BLANK_HEIGHT = 17;
var rightIframeHeight;
var id;
var muxServiceId;
var serviceIdChange = false;

function treeOnClick(event, treeId, treeNode) 
{
	self.frames[0].location.replace(treeNode.href);
}

function resizeHeight()
{
	//GetMainContentHeight(BUTTON_TOP_NO_MENU, NO_BUTTON_CHANGE);
	$(".mux_tree_content").css("height", function(index, value)
	{
		return (($("#mainContent").height() - TREE_BLANK_HEIGHT) + "px");
	});	
	rightIframeHeight = $("#mainContent").height() - IFRAME_BLANK_HEIGHT;
	$(".iframe").css("height", function(index, value)
	{
		return (rightIframeHeight + "px");
	});	
}

window.onresize = function()
{
	resizeHeight();
}

$(document).ready(function()
{
	var group;
	var userName;
	var mainIpAddr;
	var args = GetArgs();
	id = args["ID"];
	
	group = args["group"];
	userName = args["userName"];
	mainIpAddr = args["mainIpAddr"];
	if(language ==  CHINESE)
	{
		var breadCrumbText = encodeURIComponent("详细", "utf-8");
	}
	else
	{
		var breadCrumbText = encodeURIComponent("Detail", "utf-8");
	}
	$("#transferFrame").attr("src", "http://" + mainIpAddr + "/asp/transfer.asp?group=" + group + "&userName=" + userName +"&information=" + breadCrumbText);
	resizeHeight();	
	funcUpdateDisplay();
});

function funcUpdateDisplay()
{
	PageLoadStatus(true);
	
	zTree = $.fn.zTree.init($("#outputTree"), setting, zNodesOutput);
	displayParam();
	
	PageLoadStatus(false);
}

function displayParam()
{
	var selectNode;
	var oldUrl;
	var oldUrlString;
	
	if(zTree.getSelectedNodes()[0] == null)
	{
		selectNode = zTree.getNodeByParam("level", 0);
		zTree.selectNode(selectNode, false);
	}
	else
	{
		selectNode = zTree.getSelectedNodes()[0];
	}
	if(serviceIdChange == true)
	{
		oldUrl = selectNode.href;
		oldUrlString = oldUrl.split("=");
		if(language == ENGLISH)
		{
			selectNode.name = "SID:" + muxServiceId;
		}
		else
		{
			selectNode.name = "节目号:" + muxServiceId;
		}		
		selectNode.href = oldUrlString[0] + "=" + id + "_" + Number(muxServiceId);
		zTree.updateNode(selectNode, false);
		serviceIdChange = false;
	}
	self.frames[0].location.replace(selectNode.href);
}