// JavaScript Document
/* 初始需设置
菜单选择位置
menu_stat="";
显示线程ID
show_id="";
选择图
r_sel_img="";
未选择图
r_no_img="";
当前选择栏目列
lcode="";
当前选择栏目数组
lcode_ary=lcode.split("|");
*/
var menu_sta;
var show_time=500;
//变更菜单图片
function init_showtime(){	show_time=500;}
function ch_menu_bgimg(obj,sel_img)
{
	if (obj==null){return ;}
	obj.background=sel_img;
	}
function select_menu(idobj,sel_img,no_img,selects)
{
	
	if (idobj==null){return ;}
	//if (idobj=='lb_td12')alert(idobj );
	var id_obj=document.getElementById(idobj);
	//if (!id_obj) {return;}
	change_img(id_obj,sel_img,no_img,"bg",selects);
	//alert(id_obj.background);
}
//如非lcode所指定ID，更换图片
function select_l_menu(LCode,idobj,selects)
{ 
	//设置显示位置;
	menu_stat=idobj;
	//延时（毫秒）执行显示 
	if(show_time>0)
	{setTimeout("select_lid_menu('"+LCode+"',lcode_ary,'"+idobj+"','"+selects+"',menu_stat,r_sel_img,r_no_img,'layer')",show_time);}
	else
	{select_lid_menu(LCode,lcode_ary,idobj,selects,menu_stat,r_sel_img,r_no_img,"layer");}
	//alert(LCode);
}
function select_lc_menu(LCode,idobj,selects)
{ 
	//设置显示位置;
	menu_stat=idobj;
	//延时（毫秒）执行显示 
	select_lid_menu(LCode,lcode_ary,idobj,selects,menu_stat,r_sel_img,r_no_img,"");
}

//如非lcode所指定ID，更换图片  LCode:当前选中的栏目总列,lcode_ary：总列数组,idobj：当前选中栏目号,selects：选择状态,
//stat：上次选择的位置,sel_img：选中图,no_img：未选中图
function select_lid_menu(LCode,lcode_ary,idobj,selects,stat,sel_img,no_img,types)
{
	
	if(LCode==""){return;}
	var chk_sel=false,chk_lay=false,chk_stat=false,se_menu=false,sh_menu=false;
	if (types=="layer"){chk_lay=true;}
	if (stat==idobj){chk_sel=true;}
	if (selects=="select"){chk_stat=true;}
	if(chk_lay && chk_stat && chk_sel){sh_menu=true;}
	
	if(!(!chk_sel && chk_sel)){se_menu=true;}
	
	var n_ary=LCode.split("|");
	var id_ary=show_id_ary(lcode_ary,n_ary,idobj);
	if(se_menu){
		//select_menu("lb_td"+idobj,sel_img,no_img,selects);
		
		for(var i=0;i<id_ary.length;i++){
			
			if(id_ary[i]!="" ){
				//if (id_ary[i]=='12')alert(idobj );
				select_menu("lb_td"+id_ary[i],sel_img,no_img,selects);	}}
	} //
	
	if(sh_menu){
		show_menu(idobj);
		
		for(i=class_num(n_ary,idobj);i>=0;i--){
			if(n_ary[i]!="" ){show_menu(n_ary[i]);}}
	}
	else{hid_menu(LCode);}  
	
}
//检测栏目ID号在数组内的位置
function class_num(lcode_ary,idobj)
{
	if(idobj=="") return -1;
	for (i=0;i<=lcode_ary.length;i++){if (idobj==lcode_ary[i]){return i;}}
	return -1;
}

//返回idobj在n_lary及o_lary中不同的栏目号数组
function show_id_ary(o_lary,n_lary,idobj)
{
		var str="";
		//var num;
		var n_num=class_num(n_lary,idobj);
		if (n_num<0) {return(str.split("|"));}
		var o_num=class_num(o_lary,idobj);
		if (o_num>0) {return(str.split("|"));}
		if (n_num==1) {str=idobj;return(str.split("|"));}
		else{
			for (var i=0;i<=n_num;i++){if (n_lary[i]!=""){if (class_num(o_lary,n_lary[i])==-1){str=str+n_lary[i]+"|";}}}
			//alert(str);
			return(str.split("|"));
		}
		
}
//选择当前菜单 
function select_this_menu(obj)
{	
	if (lcode_ary==null){return;}
	//
	var id_obj=document.getElementById("lb_"+obj);
	//alert(id_obj);
		for (i=0;i<lcode_ary.length;i++){if (lcode_ary[i]!=""){select_menu("lb_td"+lcode_ary[i],r_sel_img,r_no_img,'select');} }
}

//创建层及内容,用于显示菜单
function creat_layer(bodys_name,layer_name,layer_cont,style_name,style_cont,style_w_h,html)
{
	//alert(html);
	//var bodys_obj=document.getElementById(bodys_name);

	//if(!bodys_obj){return;}
	var layer_name_obj=document.getElementById(layer_name);
	//alert(layer_name_obj);	
	if (!layer_name_obj){
	    var style_name_obj=document.createElement("<style id='"+style_name+"'></style>");
		layer_name_obj=document.createElement("<div id='"+layer_name+"' "+layer_cont+"></div>");
		var bodys_obj=document.getElementById(bodys_name);
		if(!bodys_obj){bodys_obj=window.document.body;}
		bodys_obj.appendChild(style_name_obj);
		document.styleSheets[style_name].addRule("#"+layer_name,style_cont);
		var ifram_name_obj=document.createElement("<iframe frameborder=0 marginheight=0 marginwidth=0 hspace=0 vspace=0 scrolling=no></iframe>");
		//alert(style_w_h);
		ifram_name_obj.name="if_"+layer_name;
		ifram_name_obj.id="if_"+layer_name;
		layer_name_obj.appendChild(ifram_name_obj);
		bodys_obj.appendChild(layer_name_obj);
		document.all("if_"+layer_name).style.cssText=style_w_h;
		var ifm=window.frames[ifram_name_obj.id];
		ifm.document.write("<link href='/public/css/index.css' rel='stylesheet' type='text/css'><script  src='/news/news_fun.js'></script><body leftmargin=0 topmargin=0>"+html+"</body>");
	}
	else
	{
		var layer_name_obj=document.getElementById(layer_name);
		if (!layer_name_obj){return;}
		var style_name_obj=document.styleSheets[style_name];
		if (!style_name_obj){return;}
		var num=get_styleSheet_rules_num(style_name_obj,"#"+layer_name);
		if (num<0) {return;}
		var ifram_name_obj=window.frames["if_"+layer_name];
		if (!ifram_name_obj) {return;}
		style_name_obj.rules[num].style.cssText=style_cont+" "+style_w_h;
		document.all("if_"+layer_name).style.cssText=style_w_h;
		ifram_name_obj.document.body.innerHTML=html;		
	}
	layer_name_obj.style.visibility="";
	show_time=0;
	setTimeout("init_showtime()",10000);
	//alert(document.all.show_menu.outerHTML);
}

//creat_layer(document.all.bodys,layer_name,style_name,obj_cont,html,style_cont);
function go_news_page(state,from_name)
{
	
	go_page(totals,pagesizes,pagenums,state,news_Lid_url,from_name);
}
//生成栏目列表注：必须列表出alllist及sublist数组
function creat_menu()
{
 var style_name_obj=document.styleSheets["st_clb"];
 if (!style_name_obj){return;}
 //var F_left,F_top,F_width,F_height,obj_obj,cld_obj,num
 var time=1000;
 for(var i=0;i<sublist.length;i++)
 {
	//time=time*i;
	setTimeout("creat_menu_id('"+sublist[i]+"')",time*i);
 }
}
function creat_menu_id(obj)
{
	var style_name_obj=document.styleSheets["st_clb"];
	var obj_obj=document.getElementById("lb_"+obj);
	var cld_obj=document.getElementById("clb_"+obj);
	//alert(obj_obj && cld_obj);
	if (obj_obj && cld_obj){
	var num=get_styleSheet_rules_num(style_name_obj,"#clb_"+obj);
	if (num<0) {
		var F_left=obj_obj.getBoundingClientRect().left+window.top.document.body.scrollLeft+obj_obj.clientWidth-2;
		var F_top=obj_obj.getBoundingClientRect().top+window.top.document.body.scrollTop-3;//-obj_obj.clientHeight;
		var F_width=cld_obj.clientWidth;//obj_obj.clientWidth+
	 	var F_height=cld_obj.clientHeight;//obj.clientHeight+
		style_name_obj.addRule("#clb_"+obj,"left: "+F_left+"px; top:"+F_top+"px;");
		//setTimeout("document.styleSheets['st_clb'].addRule('#clb_"+sublist[i]+"','left: "+F_left+"px; top:"+F_top+"px;')",2000);
	   //alert(style_name_obj.cssText);
	   }
	}
}



//中间下拉式显示栏目列表，
function shows_menu(obj)
{
	
	if (obj==""){return;}
	//alert(class_num(alllist,obj));
	//alert(class_num(sublist,obj));
	//检测网页是否生成有obj指定的栏目列表
	//alert("lb_"+obj);
	var obj_obj=document.getElementById("lb_"+obj);
	//if (!obj_obj){return;}
	var cld_obj=document.getElementById("clb_"+obj);
	//if (!cld_obj){return;}
	var style_name_obj=document.styleSheets["st_clb"];
	//if (!style_name_obj){return;}
	
	var num=get_styleSheet_rules_num(style_name_obj,"#clb_"+obj);
	if (num<0) {
		var F_left=obj_obj.getBoundingClientRect().left+window.top.document.body.scrollLeft-obj_obj.clientWidth-2;
		var F_top=obj_obj.getBoundingClientRect().top+window.top.document.body.scrollTop+obj_obj.clientHeight-2;
		var F_width=cld_obj.clientWidth;//obj_obj.clientWidth+
	 	var F_height=cld_obj.clientHeight;//obj.clientHeight+
		style_name_obj.addRule("#clb_"+obj," left: "+F_left+"px; top:"+F_top+"px;");
	}
    //setTimeout("init_showtime",10000);
	show_time=0;
	cld_obj.style.visibility="";
	cld_obj.style.display="";
}
//栏目隐藏，
function hids_menu(lcode)
{
	//alert("clb_"+lcode);
	style_disp_obj("clb_"+lcode,"visibility","hidden");

}

//显示栏目列表，
function show_menu(obj)
{
	
	if (obj==""){return;}
	//alert(class_num(alllist,obj));
	//alert(class_num(sublist,obj));
	//检测网页是否生成有obj指定的栏目列表
	
	if (class_num(alllist,obj)==-1) {return;}
	if (class_num(sublist,obj)==-1) {return;}
	
	var obj_obj=document.getElementById("lb_"+obj);
	//if (!obj_obj){return;}
	var cld_obj=document.getElementById("clb_"+obj);
	//if (!cld_obj){return;}
	var style_name_obj=document.styleSheets["st_clb"];
	//if (!style_name_obj){return;}
	
	var num=get_styleSheet_rules_num(style_name_obj,"#clb_"+obj);
	if (num<0) {
		var F_left=obj_obj.getBoundingClientRect().left+window.top.document.body.scrollLeft+obj_obj.clientWidth-2;
		var F_top=obj_obj.getBoundingClientRect().top+window.top.document.body.scrollTop;//-obj_obj.clientHeight;
		var F_width=cld_obj.clientWidth;//obj_obj.clientWidth+
	 	var F_height=cld_obj.clientHeight;//obj.clientHeight+
		style_name_obj.addRule("#clb_"+obj," left: "+F_left+"px; top:"+F_top+"px;");
	}
    //setTimeout("init_showtime",10000);
	show_time=0;
	cld_obj.style.visibility="";
	cld_obj.style.display="";
}
function hid_menu(lcode)
{
	var i,cld_obj;
	var lcode_ary=lcode.split("|");
	var lcode_num=lcode_ary.length;
	if(lcode_num<3){return;}
	//alert(show_time);
	for (i=lcode_num-2;i>=1;i=i-2)//{cld_obj=document.getElementById("clb_"+lcode_ary[i]);if (cld_obj){cld_obj.style.visibility="hidden";}}
	{style_disp_obj("clb_"+lcode_ary[i],"visibility","hidden");}
	//alert(cld_obj.style.display);
	//alert(show_id);
}
//设置对象显示状态
function style_disp_obj(name,style_type,stat)
{
	var obj=document.getElementById(name);
	if (!obj){return;}
	if (style_type=="display"){obj.style.display=stat;}
	else if(style_type=="visibility"){obj.style.visibility=stat;}
}
function init_show()
{
	show_this_news();

}
function show_id(id)
{
	go_url("/news/shownews.jsp?table="+database+"&id="+id,"new");
	
}
