/*公共变量*/
var w3c=(document.getElementById)? true:false;
var agt=navigator.userAgent.toLowerCase();
var ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1) && (agt.indexOf("omniweb") == -1));
var ie5=(w3c && ie)? true : false;
var ns6=(w3c && (navigator.appName=="Netscape"))? true: false;
var op8=(navigator.userAgent.toLowerCase().indexOf("opera")==-1)? false:true;
/**/

function getObj(o){
	var o=document.getElementById(o)?document.getElementById(o):o;
	return o;
}

function getTargetElement(evt) {
    var elem;
    if (evt.target) {
        elem = (evt.target.nodeType == 3) ? evt.target.parentNode : evt.target;
    } else {
        elem = evt.srcElement;
    }
    return elem;
}


//菜单选择
//自动判断并选择当前页面所在菜单，并修正显示背景
function focusCurrentMenu(tagid){
	var isHereNum,urlPre,pagePath,menuPath,pagePathPre,menuPathPre;
	var obj=document.getElementById(tagid);
	if(!obj) return;
	isHereNum=-1;
	urlPre="http://"+location.host+window._Env_InstallPath;
	if (location.href.indexOf(urlPre)!=-1){
		pagePathPre=location.href.substr(urlPre.length);
		pagePathPre=pagePathPre.substring(0,pagePathPre.indexOf("/"));	//取第一个目录名
		if(obj){
			var liObjs=obj.getElementsByTagName("LI");
			//判断当前页面URL是否与菜单项URL完全相同，相同则选择
			for (var i=0;i<liObjs.length ;i++ ){
				if(liObjs[i].parentNode==obj){
					menuPath=liObjs[i].getElementsByTagName("A")[0].href;
					if(location.href==menuPath)
						isHereNum=i; 
					else
						liObjs[i].className="";
				}
			}
			if(isHereNum==-1){
				//判断当前页面目录是否与菜单项目录相同，相同则选择
				for (var i=0;i<liObjs.length ;i++ ){
					if(liObjs[i].parentNode==obj){
						menuPath=liObjs[i].getElementsByTagName("A")[0].href;
						if (menuPath.indexOf(urlPre)==-1) continue;
						menuPathPre=menuPath.substr(urlPre.length);
						menuPathPre=menuPathPre.substring(0,menuPathPre.indexOf("/"));
						if(menuPathPre==pagePathPre)
							isHereNum=i;
						else
							liObjs[i].className="";
					}
				}
			}
			if(isHereNum==-1)
				isHereNum=0;
			if(isHereNum>=0){
				liObjs[isHereNum].className="is-here";
				window.__CurrentMenuItemIndex=isHereNum;
				window.__CurrentMenuItem=liObjs[isHereNum].childNodes[0];	//记录当前选中菜单项
				window.__HoverMenuItem=null;
			}
			//if(liObjs[isHereNum-1]) liObjs[isHereNum-1].className="isHerePrev";
		}	
	}
}

function focusCurrentMenu2(tagid){
	var isHereNum,urlPre,pagePath,menuPath,pagePathPre,menuPathPre;
	var obj=document.getElementById(tagid);
	isHereNum=-1;
	urlPre="http://"+location.host+window._Env_InstallPath;
	if (location.href.indexOf(urlPre)!=-1){
		pagePathPre=location.href.substr(urlPre.length);
		pagePathPre=pagePathPre.substring(0,pagePathPre.indexOf("/"));	//取第一个目录名
		if(obj){
			var liObjs=obj.getElementsByTagName("LI");
			//判断当前页面URL是否与菜单项URL完全相同，相同则选择
			for (var i=0;i<liObjs.length ;i++ ){
				menuPath=liObjs[i].getElementsByTagName("A")[0].href;
				if(location.href==menuPath)
					isHereNum=i; 
				else
					liObjs[i].className="close";
			}
			if(isHereNum>=0){
				liObjs[isHereNum].className="open";
				if(liObjs[isHereNum].parentNode.parentNode.tagName=="LI"){
					liObjs[isHereNum].parentNode.parentNode.className="open";
				}
			}else{
				focusCurrentMenu3(tagid);
			}
		}	
	}
}

function focusCurrentMenu3(tagid){
	var isHereNum,urlPre,pagePath,menuPath,pagePathPre,menuPathPre;
	var obj=document.getElementById(tagid);
	isHereNum=-1;
	urlPre="http://"+location.host+"/";
	if (location.href.indexOf(urlPre)!=-1){
		pagePathPre=location.href.substr(urlPre.length);
		pagePathPre=pagePathPre.substring(0,pagePathPre.lastIndexOf("/"));	//取第一个目录名
		if(obj){
			var liObjs=obj.getElementsByTagName("LI");
			//判断当前页面目录是否与菜单项目录相同，相同则选择
			for (var i=0;i<liObjs.length ;i++ ){
				menuPath=liObjs[i].getElementsByTagName("A")[0].href;
				if (menuPath.indexOf(urlPre)==-1) continue;
				menuPathPre=menuPath.substr(urlPre.length);
				menuPathPre=menuPathPre.substring(0,menuPathPre.lastIndexOf("/"));
				if(menuPathPre==pagePathPre)
					isHereNum=i;
				else
					liObjs[i].className="close";
			}
			if(isHereNum>=0)liObjs[isHereNum].className="open";
		}	
	}
}


function focusCurrentLink(tagid){
	var isHereNum;
	var obj=document.getElementById(tagid);
	isHereNum=-1;
	if(obj){
		var liObjs=obj.getElementsByTagName("LI");
		for(var i=0;i<liObjs.length;i++){
			if (location.href.indexOf(liObjs[i].getElementsByTagName("A")[0].href)==0){
				isHereNum=i;
			}
		}
		if(isHereNum>=0)liObjs[isHereNum].className="is-here";
	}
}

function focusCurrentMenu4(tagid){
	$("#"+tagid+" a").each(function(){
		if($(this).attr("href")==location.pathname){
			$(this).parent("li").attr("class","is-here");
		}else{
			$(this).parent("li").attr("class","");
		}
	});
}



//tank:菜单切换:20100110
function renderMenu(menu,index){
	if(!menu)return;
	var root=$("#menu-left");
	//主菜单离菜单条顶部边界的距离
	var menu_top=35*index+root.offset().top-5;
	var menu_left=menu.width()+root.offset().left+19;
	//显示子菜单准备并计算子菜单的显示位置
	$("div.menu-sub").each(function(n){
		if(n==index){
			$(this).css({"top":menu_top+"px","left":menu_left+"px"});
			//修正在IE6下菜单的显示问题
			if($.browser.msie && $.browser.version=="6.0"){
				$(this).css("width",170);
				$(this).find("a").each(function(){
												$(this).css("padding","0 10px");
												});
			}
			//向左箭头
			$("#menu-mask").css({"top":menu_top+9+"px","left":menu_left-7+"px","display":"block"});
			
			$(this).css("display","");
		}else{
			$(this).css("display","none");
		}
		$(this).mouseout(function(){
								  $(this).css("display","none");
								  $("#menu-mask").css("display","none");
								  });
		$(this).mouseover(function(){
								  $(this).css("display","");
								  $("#menu-mask").css("display","block");
								  });
	});
}


//tank:菜单下拉显示效果:20100110
function renderMenu2(obj){
	if(!obj)return;
	//tank:邦定菜单指向切换函数
	obj.find("ul > li").each(function(i){
		//自动展开与当前页面目录相同的菜单
		if($(this).children("a").attr("rel") == location.pathname.substring(0,location.pathname.lastIndexOf("/")+1)){
			$(this).children("a").blur();
			var child=$(this).children("ul");
			if(child.css("display")=="none"){
				$(this).css({"border-bottom":"1px solid #0078C4","font-weight":"bold"});
				$(this).children("a").css("color","#0078C4");
				//child.css("display","block");
				child.slideDown("normal");
			}
		}
		//自动高亮与当前页面地址相同的子菜单
		$(this).find("ul li a").each(function(){
			if($(this).attr("href") == location.pathname){
				$(this).css({"color":"#0078C4"});
			}else{
				$(this).css("color","#555");
			}
		});
		//菜单点击收拉效果
		$(this).click(function(){
			$(this).children("a").blur();
			var child=$(this).children("ul");
			if(child.css("display")=="none"){
				$(this).css({"border-bottom":"1px solid #0078C4","font-weight":"bold"});
				$(this).children("a").css("color","#0078C4");
				//child.css("display","block");
				child.slideDown("normal");
			}else{
				$(this).css({"border-bottom":"none","font-weight":"normal"});
				$(this).children("a").css("color","#000");
				//child.css("display","none");
				child.slideUp("normal");
			}
		});

	});


}



function showFlash(flashUrl,width,height,type){
	document.write('<object id="flashplayer" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+width+'" height="'+height+'">');
	document.write('<param name="movie" value="'+flashUrl+'" />');
	document.write('<param name="quality" value="high" />');
	if(type!=1){
		document.write('<param name="wmode" value="transparent" />');
	}
	document.write('<param name="menu" value="false" />');
	document.write('<param name="allowFullScreen" value="true" />');
	document.write('<embed src="'+flashUrl+'" quality="high" wmode="transparent" menu="false" allowFullScreen="true" allowScriptAccess="true"  pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"></embed>');
	document.write('</object>');
}

function addFavorite(title){
	var url = window.location.href;
	if(document.all){
		window.external.addFavorite(url,title);
	}else if (window.sidebar){
		window.sidebar.addPanel(title, url, "");
	}
}

function printme()
{
    document.body.innerHTML=document.getElementById('printcontent').innerHTML;
    window.print();
}

function pageprint(){
	var content="";
	if(!document.getElementById("printcontent")) return;
	content=document.getElementById("printcontent").innerHTML;
	var newwin=window.open(window._Env_InstallPath+"templets/default/print.htm","printWindow","");
	alert("打印页面已生成!\n\n请使用页面中的“打印”功能打印页面内容");
	newwin.document.title=document.title;
	if(ie){
		newwin.document.body.innerHTML="<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT><div class='printbar'><a href='javascript:window.print()'>[点击打印]</a>&nbsp;<a href='#' onclick='document.getElementById(\"WebBrowser\").ExecWB(7,1);return false;'>[打印预览]</a>&nbsp;<a href='#' onclick='document.getElementById(\"WebBrowser\").ExecWB(8,1);return false;'>[页面设置]</a></div>"+content;
	}else{
		newwin.document.body.innerHTML="<div class='printbar'><a href='javascript:window.print()'>[点击打印]</a></div>"+content;
	}
	newwin.document.body.style.background="none";
	if(newwin.document.getElementById("toolbar")){
		newwin.document.getElementById("toolbar").innerHTML="";
	}
	if(newwin.document.getElementById("order")){
		newwin.document.getElementById("order").innerHTML="";
	}
	newwin.window.focus();
}

//改变字体大小
function ChangeFontSize(objId,size)
{
	var obj=document.getElementById(objId);
	if (obj){
		obj.style.fontSize=size+"px";
	}
	var tagArr="DIV,P,SPAN,TD,LI,DD,PRE".split(",")
	for (var t=0;t<tagArr.length ;t++ )
	{
		var objs=obj.getElementsByTagName(tagArr[t]);
		for (var i=0;i<objs.length ;i++ )
		{
			objs[i].style.fontSize=size+"px";
		}
	}
}



//切换tab标签及内容
function switchTab(target,index,curObj){
	curObj.blur();
	//消除原有CSS类
	$(curObj).parent().siblings().each(function(i){
		if(this.className=='is-here'){
			this.className="";
		}
	});
	curObj.parentNode.className="is-here";
	$(curObj).parents("div.list-tab-1").find(".more a").attr("href",curObj.href);
	//遍历目标内容，显示顺序等于指定index的标签
	$(target).each(function(i){
		if(i==index){
			$(this).css("display","");
		}else{
			$(this).css("display","none");
		}
	});
}


//超宽图片自动缩小
function ResizeImage(objid,resWidth){
	if (!document.getElementById(objid))
		return;
	var imgs=document.getElementById(objid).getElementsByTagName("IMG");
	for(i=0; i<imgs.length; i++){
		//if (imgs[i].className=="MyEventImage"){
			if (ie){
				imgs[i].attachEvent("ondblclick",ImageDblClick);
			}else{
				imgs[i].addEventListener("dblclick",ImageDblClick,false);
			}
			if (imgs[i].width>resWidth){
				imgs[i].height=(imgs[i].height/imgs[i].width)*resWidth;
				imgs[i].width=resWidth;
				imgs[i].alt="";
			}
		//}
	}
}

//


function picFlashObject(files,links,texts,configs,focus_width,focus_height){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ focus_width +'" height="'+ focus_height +'">');
	document.write('<param name="movie" value="'+window._Env_InstallPath+'images/bcastr3.swf"><param name="quality" value="high">');
	document.write('<param name="menu" value="false"><param name=wmode value="opaque">');
	document.write('<param name="FlashVars" value="bcastr_file='+files+'&bcastr_link='+links+'&bcastr_title='+texts+'&menu=false&bcastr_config='+configs+'">');
	document.write('<embed src="'+window._Env_InstallPath+'images/bcastr3.swf" wmode="opaque" FlashVars="bcastr_file='+files+'&bcastr_link='+links+'&bcastr_title='+texts+'&menu=false&bcastr_config='+configs+'" quality="high" width="'+ focus_width +'" height="'+ focus_height +'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>'); 
}

function show_flash(pics,links,texts,configs,swf_width,swf_height)
{
    var button_pos=4; //按扭位置 1左 2右 3上 4下
    var stop_time=6000; //图片停留时间(1000为1秒钟)
    var show_text=0; //是否显示文字标签 1显示 0不显示
    var txtcolor="000000"; //文字色
    var bgcolor="eeeeee"; //背景色

    var text_height = 0;
    var focus_width = swf_width;
    var focus_height = swf_height - text_height;
    var total_height = focus_height + text_height;

//    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cabversion=6,0,0,0" width="'+ focus_width +'" height="'+ total_height +'">'+'<param name="movie" value="'+window._Env_InstallPath+'images/dynfocus.swf">'+'<param name="quality" value="high"><param name="wmode" value="opaque">'+'<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&pic_width='+focus_width+'&pic_height='+total_height+'&show_text='+show_text+'&txtcolor='+txtcolor+'&bgcolor='+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'">'+'<embed src="'+window._Env_InstallPath+'images/dynfocus.swf" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&pic_width='+focus_width+'&pic_height='+total_height+'&show_text='+show_text+'&txtcolor='+txtcolor+'&bgcolor='+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'" quality="high" width="'+ focus_width +'" height="'+ total_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent"/>'+'</object>');

    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ focus_width +'" height="'+ total_height +'">'+'<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="'+window._Env_InstallPath+'images/redfocus.swf"><param name="quality" value="high"><param name="bgcolor" value="#F0F0F0">'+'<param name="menu" value="false"><param name=wmode value="opaque">'+'<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'">'+'<embed src="'+window._Env_InstallPath+'images/redfocus.swf" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" quality="high" width="'+ focus_width +'" height="'+ total_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent"/>'+'</object>');

}

/*检测留言表单*/
function checkFeedbackForm(frmobj){
	if(!frmobj)return false;
	if(isBlank(frmobj.title.value)){
		alert("请输入留言标题");
		frmobj.title.focus();return false;
	}
	if(isBlank(frmobj.uname.value)){
		alert("请输入您的姓名");
		frmobj.uname.focus();return false;
	}
	if(isBlank(frmobj.msg.value)){
		alert("请输入留言内容");
		frmobj.msg.focus();return false;
	}
	if(isBlank(frmobj.validate.value)){
		alert("请输入验证码");
		frmobj.validate.focus();return false;
	}
	return true;
}
function isBlank(str){
	return str.replace(/\s/g,"")=="";
}


var menuT;
//tank:FLASH菜单回调显示子菜单
function callBackSubMenu(itemIndex){
	mainMenu=$("#menu-middle");
	$("#menu-middle-sub li").each(function(i){
		switch(i){
			case 0:
				leftPosition=55;
				break;
			case 1:
				leftPosition=150;
				break;
			case 2:
				leftPosition=220;
				break;
			case 3:
				leftPosition=270;
				break;
		}
		if(i == (itemIndex-1)){
			$(this).fadeIn("normal");
			$(this).css({"left":mainMenu.offset().left+leftPosition+"px","top":mainMenu.offset().top+45+"px"});
		}else{
			$(this).stop(true,true);
			$(this).fadeOut("fast");
		}

		$(this).mouseover(function(){
			clearTimeout(window.menuT);
		});
//		$(this).mouseout(function(){
//			window.menuT=setTimeout(function(){$("#menu-middle-sub li").eq(i).fadeOut("normal")},3000);
//		});
	});
	$("body").click(function(){
		$("#menu-middle-sub li").fadeOut("normal");
	});
}
