var updateBlockID = "td-list";
function initleftNav(){
	
	var anchors = document.getElementById("td-left-nav")
				.getElementsByTagName("a");
	
	/N_LB=([^&#]*)/.test(document.URL);
	var N_LB = RegExp.$1;
	var hash = (location.hash + "").replace(/^#/,"");
	if(hash=="null") hash = "";
	hash_lb = hash.split(":")[0];
	
	var selected = null;
	for(var i=1;i<anchors.length;i++)
	{
		anchors[i].onclick=new Function("evt","hashMonitor.set(this.getAttribute('linkid'));ajaxLinkUpdate(this,updateBlockID,evt||window.event,ajaxUpdateCallBack)");
		//anchors[i].setAttribute("index",i);

		/N_LB=([^&#]*)/.test(anchors[i].getAttribute("href"));
		/*
		if(RegExp.$1 == N_LB)//hash的第一部分和链接的第一部分相同，加载该类别下的列表
		{
			alert([1,RegExp.$1 ,N_LB]);
			ajaxUpdateCallBack(anchors[i]);
		}*/
		//找到hash选中的类别
		if(hash_lb == RegExp.$1)
		{
			
			selected=anchors[i];
		}
	}
	/*
	if(selected)
	{
		selected.onclick();
	}
	else if(typeof N_LB =="undefined" || N_LB=="" )
	{
		anchors[1].onclick();
		//hashMonitor.init();
	}
	*/
		anchors[1].onclick();
}

var hashMonitor={
	hash:"",
	asyn:0,
	ready:false,
	init:function(){
		var _cnt=0;
		setInterval(function(){
			return;
			var hash = location.hash;
			if(hash===null || hash ==="null")
				hash="";
			hash=hash.replace(/^#/g,"");
			hash = location.href.replace(/.*#/g,"");
			//document.title =[hash,hashMonitor.hash,hashMonitor.asyn,_cnt++] 
			if(hashMonitor.asyn==0 &&  hash!=hashMonitor.hash)
			{
				var anchors = document.getElementById("td-left-nav")
						.getElementsByTagName("a");
				
				//类别
				if(hashMonitor.hash!=null && hash.split(":")[0] == hashMonitor.hash.split(":")[0]  && hash.split(":")[1]!=null)
				{
					if(hashMonitor.ready)
					{
						loadSubListByHash();
					}
					return ;
				}
				
				//明细
				for(var i=0;i<anchors.length;i++)
				{
					if(anchors[i].getAttribute("linkid")== hash)
					{
						
						hashMonitor.ready=false;
						hashMonitor.hash = hash;
						anchors[i].onclick();
						return ;
					}
				}
			}
			//alert(hash);
			//this.hash=hash;
		},100);
	},
	set:function(hash){
		hashMonitor.asyn = 1;
		//location.href=document.URL.replace(/#.*/g,"")+"#"+hash;
		//location.hash = hash;
		hashMonitor.hash=hash;
		hashMonitor.asyn = 0;
	}
}
/*加载项目列表后回调*/
function ajaxUpdateCallBack(Anchor){
	hashMonitor.ready=true;
	var subHeader=document.getElementById("sub-header")
	subHeader.innerHTML = "";
	var newAnchor = Anchor.cloneNode(true);
	subHeader.appendChild( newAnchor);
	newAnchor.refAnchor = Anchor;
	newAnchor.onclick = new Function("evt","this.refAnchor.onclick(evt||window.event);");

	loadSubListByHash();
	
};

function loadSubListByHash(){
	var hash = (location.hash+"").replace(/^#/,"");
	var subHash = hash.split(":")[1];
	if(subHash!=null)
	{
		var links = document.getElementById("td-list").getElementsByTagName("a");
		for(var i=0;i<links.length;i++)
		{
			if(links[i].getAttribute("linkid")==hash)
			{
				links[i].onclick();
				return;
			}
		}
	}
}
window.selectbszndetail=function(id){
	var dls = document.getElementById("bszn-detail").getElementsByTagName("dl");
	for(var i=0;i<dls.length;i++)
	{
		dls[i].className="";
	}
	document.getElementById(id).className="selected";
	
	document.getElementById("bszn-detail").style.height=
		document.getElementById(id).getElementsByTagName("dd")[0].offsetHeight + 100 +"px"
	
	return false;
}
/*通过ajax方式列出子项目详细内容后的回调*/
function BSZN_LIST_callBack(){
	var header= document.getElementById("sub-header");
	try{
		document.getElementById("bszn-sxlx").innerHTML = header.innerHTML;
		document.getElementById("bszn-sxlx").getElementsByTagName("a")[0].onclick = 
			new Function("document.getElementById('sub-header').getElementsByTagName('a')[0].onclick();");
	}catch(ignore){};
}
/*清除无效链接*/
function clearNullLink(obj){
	var links = obj.getElementsByTagName("a");
	var pageFolder = document.URL.replace(/[^\\\/]+$/g,"");
	for(var i=0;i<links.length;i++){
		if(links[i].getAttribute("href")=="" || links[i].href=="" || links[i].href==pageFolder )
			links[i].style.visibility="hidden";
	}
}




