// JavaScript Document
//===gotCode 2005-5-9==
//===for SS_treeView==
//说明：由于程序切换图片与图片名称有关，所以如果不使用这程序所带的图片时，请把你的图片名称改成与这程序相对应的图片的名称一样。
//空白图:				TreeBlank.gif
//直线图:				treeI.gif
//根目录图:				tree_root.gif	
//分支图:				treeT.gif
//分支图(含下级未打开):	treeT_plus.gif
//分支图(含下级已打开):	treeT_less.gif
//文件夹(未打开):		icon_file_close.gif
//文件夹(已打开):		icon_file_open.gif
//文件图:				treeFile.gif
	
//---style---
styleHTML = '' +
'<style>\n'+
'#SS_treeALL div{\n'+
'	font:9pt;\n'+
'	white-space:nowrap;\n'+
'}\n'+
'#SS_treeALL img{\n'+
'	width:18px;\n'+
'	align:absmiddle;\n'+
'}\n'+
'#SS_treeViewName{\n'+
'	margin-left:4px;\n'+
'	padding:2px px 0px 0px;\n'+
'	display:inline;\n'+
'	cursor:default;\n'+	
'}\n'+
'</style>'
document.write(styleHTML)

//---创建根目录---
function SS_treeView( root ){
	treeItem = root[0]														//指定根目录的数组中第一项
	treeItemID = treeItem.id || 1											//取得根目录的id（如果没有，设为1）
	
	oHtml =	'<div id="SS_treeALL" style="margin-left:0;">\n'+
 				'<div id="SS_treeRoot" treeID="'+treeItem.id +'" '+							//设定treeID
					'onclick="'+
							'SS_treeView_ShowHide(this,' + treeItem.children + ',\'0\');'+	//打开文件夹
							'SS_treeView_new(this)'+										//取得当前treeID
							'"'+
				'>\n'+
					'<img src="images/TreeBlank.gif" align="absmiddle">'+
					'<img src="images/tree_root.gif" align="absmiddle">'+ 
					'<div id="SS_treeViewName"><font color=#0054AD>' + treeItem.name + '</font></div>' +				//名称
  				'</div>\n'+
  				'<div style="display:none"></div>\n'+
			'</div>\n'
			
	document.write(oHtml)
}

//---根据类型拼凑树轨迹--- icoType:字符串类型(1=用treeI,0=用treeBlank)，例如:0100101
function SS_treeView_track( icoType ){		
	oHtml = ""
	for( var i = 0 ; i < icoType.length ; i ++ ){
		if( icoType.substr(i,1) == '1' ){
			oHtml += '<img src="images/treeI.gif" align="absmiddle">'
		}else{
			oHtml += '<img src="images/TreeBlank.gif" align="absmiddle">'
		}
	}
	return oHtml
}

//---根据类型显示图标--- children:数组(不等于null代表是文件夹) ,lastOne:是否数组中最后一个
function SS_treeView_ico( children , lastOne ){
	if( lastOne ){
		ico = "treeL"
	}else{
		ico = "treeT"
	}	
	
	if( children == null ){	
		return '<img src="images/'+ico+'.gif" align="absmiddle" id="trackStyle"><img src="images/treeFile.gif" align="absmiddle" id="icoStyle">'				//注意给与 树的分支线id为“trackStyle”，图标id为“icoStyle”，改变状态时需用到
	}else{
		return '<img src="images/'+ico+'_plus.gif" align="absmiddle" id="trackStyle"><img src="images/icon_file_close.gif" align="absmiddle" id="icoStyle">'
	}
	
}

//---打开文件夹(第一次打开时创建文件夹内容)--- which:鼠标点击对象,children:数组(不等于null代表是文件夹),type:字符串类型(根据类型拼凑树轨迹)
var mNameCount = 0
function SS_treeView_ShowHide( which , children , type ){
	var Obj = which.nextSibling								//包含下级目录的<div>对象
	var oTrackStyle	= which.all('trackStyle')				//取得树分支线的图形对象
	var oIcoStyle 	= which.all('icoStyle')					//取得图标图形对象
	
	if( children != null ){								//当含有下级目录时
		if( Obj.style.display != 'none' ){					//当下级目录打开时，使其关闭
			Obj.style.display 	= 'none'
			if( which.all('trackStyle') != null ){
				oTrackStyle.src 	= oTrackStyle.src.replace(/\_less/g,'_plus')	//改变图形状态（替换的字符串与图形名称相关，为了程序设计的方便，使用的图形名称应该具有一定的规律性）
				oIcoStyle.src 		= oIcoStyle.src.replace(/\_open/g,'_close')
			}
			
		}else{												//当下级目录关闭时，使其打开	
			Obj.style.display = ''
			if( which.all('trackStyle') != null ){
				oTrackStyle.src = oTrackStyle.src.replace(/\_plus/g,'_less')
				oIcoStyle.src 	= oIcoStyle.src.replace(/\_close/g,'_open')
			}
		}
	}
	
	if( children != null && which.ignore != true ){		//当含有下级目录时，而且并未创建下级目录内容时( ignore默认是“false”,当创建下级目录后，改为“true”)
		
		oHtml = ""
		for( var i = 0 ; i < children.length ; i ++ ){
			lastOne = (i==children.length-1)				//当变量“i”等于对应下级目录数组的最后一个项目序号时，代表已经是最后一个项目了
			
			if( lastOne ){									//根据项目位置创建树的数字轨迹图（用数字表示用什么图，例如:010010）
				icoType = type + '0'						//继承当前的数字轨迹图“type”加上当前位置需用的图，就创建了下级的轨迹图
			}else{											//(1=用treeI,0=用treeBlank)
				icoType = type + '1'
			}
			
			treeItemID	= children[i].id	|| 1				//取得当前项目的id（如果没有，设为1）
			treeItemUrl = children[i].url	|| 'javascript:;'	//取得当前项目的url（如果没有，设为“javascript:;”）
			
			oHtml += '<div>\n'+
 						'<div '+
							'treeID="'+treeItemID +'" '+		//设定treeID
							'onclick="'+
									'SS_treeView_ShowHide(this,'+children[i].children+',\''+ icoType +'\');'+	//打开文件夹(第一次打开时创建文件夹内容)
									'SS_treeView_select(mName'+mNameCount+');'+									//高亮被选择的项目
									'SS_treeView_new(this)'+													//取得当前项目的id
									'"'+
							'title="投资者问答分类导航（单击进行）"'+
						'>\n'+
								SS_treeView_track( type ) + 													//创建树的轨迹图
								SS_treeView_ico( children[i].children , lastOne ) +								//创建数的分支图与图标				
								
								'<div id="SS_treeViewName" onmouseup="SS_treeView_ctrlPad(mName'+mNameCount+')" '+
									'onclick="relocation(\'' + treeItemUrl + '\')" '+							//点击时执行
									'oncontextmenu="window.event.returnValue=false"'+							//取消右键菜单
								'><span id="mName'+mNameCount+'"><font color=#0054AD>' + children[i].name + '</font></span></div>' +		//名称
								
  						'</div>\n'+
			 			'<div style="display:none"></div>\n'+													//这里是装载下级目录的地方
					 '</div>\n'
					 mNameCount++
		}	
		
		Obj.innerHTML = oHtml
		which.ignore = true																						//下次执行此程序时忽略创建部分	
	}
}

//---显示被选择---
var SS_treeView_lastSelected = null

function SS_treeView_select( which ){
	Obj = SS_treeView_lastSelected
	//which = which.all('SS_treeViewName')
	if( Obj != null && Obj != which ){
		Obj.style.cssText = 'background:none;color:windowtext;border:none'
	}
	
	which.style.cssText = 'background:highlight;color:highlighttext;border:1px solid'
	
	SS_treeView_lastSelected = which
}

//---获得被选中的id---
function SS_treeView_new( which ){
	if( document.all('form1') != undefined ){
		id = which.treeID
		form1.id.value = id
	}
}

//---显示操作面板---
function SS_treeView_ctrlPad( which ){
	if( event.button == 2 ){
		if( document.all('SS_treeViewCtrlPad') != undefined ){
			SS_treeViewCtrlPad.style.display = ""
			SS_treeViewCtrlPad.style.top = which.offsetTop + 10
			SS_treeViewCtrlPad.style.left = which.offsetLeft + which.offsetWidth - 10
		}
		SS_treeView_select(which.parentNode);
		SS_treeView_new( which.parentNode )
		
		SS_treeView_currentName		= which.innerText
		SS_treeView_currentAction	= which.onclick
	}
}

//---操作面板中的内容显示
var SS_treeView_currentName = null
var SS_treeView_currentAction = null

function SS_treeView_form( type ){
	SS_treeViewForm.style.display = ""
	SS_treeViewChooseType.style.display = "none"
	
	form1.subType.value = type
	
	if( type == "new" ){
		SS_treeViewFormTitle.innerText = "在此级下添加新项目"
		
	}else if( type == "edit" ){
		SS_treeViewFormTitle.innerText = "修改名称"
		form1.cName.value 	= SS_treeView_currentName
		form1.cAction.value = SS_treeView_currentAction
		
	}else if( type == "delete" ){
		SS_treeViewFormTitle.innerText = "删除此级项目"
		form1.cName.value = "是否删除？"
	}
}
//---隐藏操作面板---
function SS_treeView_formHide(){
	SS_treeViewCtrlPad.style.display = "none"
	SS_treeViewForm.style.display = "none"
	SS_treeViewChooseType.style.display = ""
	form1.cName.value = ""
}

//---操作面板按钮效果---
function SS_treeView_buttonEffect(){
	btn = document.all('SS_treeViewButton')
	for( var i = 0 ; i < btn.length ; i ++ ){
		btn[i].onmouseover = function(){
								with(this){
									style.background = "highlight"
									style.color = "highlighttext"
								}
							}
		btn[i].onmouseout = function(){
								with(this){
									style.background = "none"
									style.color = ""
								}
							}
	}
}

function relocation(str){
	window.location.href = str
}