// JavaScript Document
/////////////////////////////////////////
//网站共用JS函数
//版  本：v1.1
//作  者：freewind
//    QQ: 573704282
// //////////////////////////////////////
var d, kw, oResult, oInput, currentRow, bIsLoadComplete;
var theTimerID = 0;
var div;
var width = 0;

function $(id){
	return document.getElementById(id);
}

function setCookie(name,value)//两个参数，一个是cookie的名子，一个是值
{
    var Days = 365; //此 cookie 将被保存 30 天
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)//取cookies函数        
{
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return null;

}
function delCookie(name)//删除cookie
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}


bIsLoadComplete = false;

var Freewind = {};
Freewind.Ajax = function(){};
Freewind.Ajax.prototype = {
	createHttpRequest : function(){
		if(window.ActiveXObject){
			//var ver = ["MSXML5.XMLHTTP","MSXML4.XMLHTTP","MSXML3.XMLHTTP","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
			var ver = ["Microsoft.XMLHTTP","MSXML.XMLHTTP"];
			for(var i=0; i<ver.length; i++){
				try{
					return new window.ActiveXObject(ver[i]);
				}catch(e){}
			}		
		}else{
			try{
				return new XMLHttpRequest();		
			}catch(e){}
		}
		alert("Failure to create HttpRequest!");
	},
	
	get : function(url, async, fnCallBack){
		var xmlHttp = this.createHttpRequest();
		xmlHttp.open("GET", url, async);

		xmlHttp.onreadystatechange = function(){
			if(xmlHttp.readyState == 4 ){
				if(xmlHttp.status == 200){
					fnCallBack(xmlHttp.responseText);
				}else{
					fnCallBack("false");
				}
			}
		};
		xmlHttp.setRequestHeader("If-Modified-Since","0");
		xmlHttp.send(null);
	},
	
	post : function(url, async, fnCallBack){
		xmlHttp.open("POST", url, async);
		xmlHttp.onreadystatechange = function(){
			if(xmlHttp.readyState == 4 ){
				if(xmlHttp.status == 200){
					fnCallBack(xmlHttp.responseText);
				}else{
					fnCallBack("false");
				}
			}
		};
		xmlHttp.setRequestHeader("If-Modified-Since","0");
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=utf-8");
		//this.xmlHttp.setRequestHeader("Content-Type","text/html; charset=gb2312");
		xmlHttp.send(null);	
	}
};

function loadScript(url){
	var script = document.createElement("script");
	script.type = "text/javascript";
	script.charset = "gb2312";
	document.getElementsByTagName("head")[0].appendChild(script);
	script.src = url;
}

function checkKeyword(){
	if(arguments.length > 0){
		if($("txtKeyword2").value != "")
			$("txtKeyword").value = $("txtKeyword2").value;
		else
			return;
	}
	if($("txtKeyword").value != ""){
		document.forms[0].submit();
	}
}

function addPageToFavorite(pageTitle, pageUrl){
	if(arguments.length == 0){
		pageTitle = document.title;
		pageUrl = window.location.href;
	}
	if(document.all){
		window.external.AddFavorite(pageUrl ,pageTitle);
	}else{
		window.sidebar.addPanel(pageTitle, pageUrl,""); 
	}
}
function setHomePage(strHomePage)
{
	if(arguments.length == 0){
		strHomePage = window.location.href;
	}
	if(document.all){
		document.body.style.behavior = "url(#default#homepage)";
		document.body.setHomePage(strHomePage);
	}else if(window.sidebar){
		if(window.netscape){
			try{
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			}
			catch(e){
				alert("Firefox暂无此功能，请手动设置。");
				return;
			}
		}
		var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
    	prefs.setCharPref('browser.startup.homepage',strHomePage);
	}
}

function changeFont(size){
	if(size == 3){
		size = 16;
	}else if(size == 2){
		size = 14;
	}else{
		size = 12;
	}
	var tags = changeFontTags.split("|");
	for(var i=0; i<tags.length; i++){
	
		var obj = $(tags[i]);
		if(obj){
			obj.style.fontSize = size + "px";
		}
	}
}
function updateHits(){
	var ajax = new Freewind.Ajax();
	var url = "/services/updateHits.asp?i=" + pageInfo;
	
	//loadScript(url);
	ajax.get(url, true, function(){});
}

function setSearchType(){
	var nav = $("top5_nav");
	var li = nav.getElementsByTagName("li");
	var nIndex = 0;
	for(var i=0; i<li.length; i++){
		if(li[i].innerHTML.indexOf("_l.") > 0){
			nIndex = i;
			break;
		}
	}
	if(nIndex >= 2){
		nIndex --;
	}
	if(nIndex == 4 || nIndex == 5){
		nIndex = $("selType").options.length - (5 - nIndex);
	}else if(nIndex > 5){
		nIndex -= 2;
	}
	if(nIndex >1){
		$("selType").selectedIndex = nIndex - 1;
	}
}

function getOffset(obj, endObj){
	var x = 0, y = 0;
	do{
		x += obj.offsetLeft;
		y += obj.offsetTop;
		
		obj = obj.offsetParent;
	}while(obj && obj != endObj);
	return {x:x, y:y};
}

function moveLeft(){
	var temp = div[0];
	for(var i=0; i<div.length; i++){
		div[i].style.left = (i - 1) * width + "px";
		if(i < div.length - 1)
			div[i] = div[i+1];
	}
	div[div.length-1] = temp;
}

function moveImages(){
	var container = $("picContainer");
	div = [$("container1"), $("container2"), $("container3")];
	width = div[0].offsetWidth;
	container.style.height = div[0].offsetHeight + "px";
	div[1].style.left = width + "px";
	div[1].style.top = "0px";
	div[1].style.display = "block";
	div[2].style.left = width * 2 + "px";
	div[2].style.top = "0px";
	div[2].style.display = "block";
	
	theTimerID = setInterval(moveLeft, delay);
	
	container.onmouseover = function(){
		if(theTimerID > 0){
			clearInterval(theTimerID);
			theTimerID = 0;
		}
	};
	container.onmouseout = function(){
		theTimerID = setInterval(moveLeft, delay);
	};
}

function showNav(){
	this.getElementsByTagName("dt")[0].className = "on";
	this.getElementsByTagName("dd")[0].style.display = "block";
}
function hideNav(){
	this.getElementsByTagName("dt")[0].className = "";
	this.getElementsByTagName("dd")[0].style.display = "none";
}
function letterCategory(letterContainer){
	this.LC = $(letterContainer);
	this.timerID1 = 0;
	this.timerID2 = 0;
	this.timerID3 = 0;
	this.delay = 100;
	this.flag = false;
}
letterCategory.prototype = {
	init : function(){
		var self = this;
		var list = this.LC.getElementsByTagName("li");
		if(arguments.length > 0){
			this.flag = arguments[0];
		}
		for(var i=1; i<list.length; i++){  //warning    i = 0
			list[i].onmouseover = function(){
				if(self.timerID1 > 0){
					clearTimeout(self.timerID1);
				}
				var me = this;
				self.timerID1 = setTimeout(function(){
					me.className = "on";
					self.showContent(me.id);
				}, self.delay);
			};
			list[i].onmouseout = function(){
				if(self.timerID2 > 0){
					//clearTimeout(self.timerID2);
				}
				var me = this;
				self.timerID2 = setTimeout(function(){
					me.className = "";
					var content = $("content"+me.id) || $("div0");
					content.style.display = "none";
				}, self.delay);
			};
		}
	},
	showContent : function(id){
		var self = this;
		var content = $("content"+id) || $("div0");
		content.style.display = "block";
		if(this.flag){
			content.style.top = "-36px";
			content.parentNode.style.zIndex =100;
		}else{
			content.style.top = "-4px";
			content.parentNode.style.zIndex = 80;
		}
		content.onmouseover = function(){
			if(self.timerID2 > 0){
				clearTimeout(self.timerID2);
				self.timerID2 = 0;
			}
			if(self.timerID3 > 0){
				clearTimeout(self.timerID3);
				self.tieerID3 = 0;
			}
			if(this.style.display != "block")
				this.style.display = "block";
		};
		content.onmouseout = function(oEvent){
			var me = this;
			self.timerID3 = setTimeout(function(){
				$(id).className = "";
				me.style.display = "none";
			}, self.delay);
		};
	}
};

function getPYContent(){
	/*var ajax = new Freewind.Ajax();
	ajax.get("/letter.htm", true, function(data){
		alert(data);
		$("pycontent").innerHTML = data;
	});*/
	loadScript("/Js/Letter.js");
};

function activeTab(titleContainer, contentContainer){
	this.TC = $(titleContainer);
	this.CC = $(contentContainer);
	this.prevTab = null;
}
activeTab.prototype = {
	init : function(){
		var self = this;
		var lst = this.TC.getElementsByTagName("li");
		if(lst.length > 0){
			this.prevTab = lst[1];
		}
		var len = lst.length - 1;
		for(var i=1; i<len; i++){
			lst[i].nIndex = i - 1;
			lst[i].onmouseover = function(){
				var divs = self.CC.getElementsByTagName("div");
				if(self.prevTab){
					self.prevTab.className = "";
					if(divs.length == len - 1) divs[self.prevTab.nIndex].style.display = "none";
				}
				this.className = "tabActive";
				
				if(divs.length == len - 1) divs[this.nIndex].style.display = "block";
				self.prevTab = this;
			};
		}
	}
};
function initEvent1(){
	$("tb1").onmouseover = showNav;
	$("tb2").onmouseover = showNav;
	$("tb3").onmouseover = showNav;
	$("tb3").onmouseout = hideNav;
	$("tb1").onmouseout = hideNav;
	$("tb2").onmouseout = hideNav;
};

function initEvent2(){	
	new letterCategory("pinyin").init();
	new activeTab("rpt_title", "rpt_content").init();
	//new activeTab("mrpt_title", "mrpt_content").init();
	new activeTab("ebook_title", "ebook_content").init();
	new activeTab("market_title", "market_content").init();
	new activeTab("hrpt_title", "hrpt_content").init();
	new activeTab("company_title", "company_content").init();
	new activeTab("knowledge_title", "knowledge_content").init();
	new activeTab("law_title", "law_content").init();
	new activeTab("show_title", "show_content").init();
};

var currentColor2 = 1
function changeColor2(){
	var rpt = $("divFavorite");
	var srh = $("phone");
	if(currentColor2 == 1){
		rpt.className = rpt.className.replace(/ cat_changeColor/g, "");
		if(srh) srh.className = srh.className.replace(/ cat_changeColor/g, "");
		currentColor2 = 0;
	}else{
		rpt.className += " cat_changeColor";
		if(srh) srh.className += " cat_changeColor";
		currentColor2 = 1;
	}
	setTimeout(changeColor2, 800);
}

function clickCount(id){
	window.pageInfo = "AD|" + id;
	updateHits();
}

function download(id){
	window.pageInfo = "Download|" + id;
	updateHits();
}

function closeFloater(){
	if(floater && floaterMin){
		floater.style.display = "none";
		floaterMin.style.display = "block";
		floaterScroll = floaterMin;
		setCookie("Floater", "0");
		onScroll();
	}
}
function openFloater(){
	if(floater && floaterMin){
		floater.style.display = "block";
		floaterMin.style.display = "none";
		floaterScroll = floater;
		setCookie("Floater", "1");
		onScroll();
	}
}
var f_current = 1, f_isMin = false;
function f_onOver(n){
	$("f_td" + f_current).className = "button2";
	$("f_content" + f_current).style.display = "none";
	$("f_td" + n).className = "button1";
	$("f_content" + n).style.display = "";
	f_current = n;
}
function f_min(img){
	var f = floatBox, hei = 195;
	if(f){
		if(f_isMin){
			img.src = "/images2/small.jpg";
			f.style.height = "223px";
			f.style.top = parseInt(f.style.top) - hei + "px"
			f_isMin = false;
			nY2 -= hei;
		}else{
			img.src = "/images2/max.jpg";
			f.style.height = "31px";
			f.style.top = parseInt(f.style.top) + hei + "px";
			f_isMin = true;
			nY2 += hei;
		}
	}
}
function f_close(){
	var f = $("floatBox");
	f.innerHTML = "";
	f.parentNode.removeChild(f);
	if(floatBox){
		floatBox = null;
	}
}

window.onload = function(){
	bIsLoadComplete = true;
	
	if($("floatBox")){
		$("floatBox").style.display = "";
	}
	if($("tb1")){
		initEvent1();
	}
	if(typeof pageInfo != 'undefined'){
		updateHits();
		if($("pinyin2")){
			new letterCategory("pinyin2").init(true);
		}
		if(pageInfo.indexOf("weekly") >= 0){
			initMarquee2();
		}
		loadScript("/Js/right.js");
	}
	if(typeof isReport != 'undefined'){
		new letterCategory("pinyin").init();
	}
	if(typeof homePage != 'undefined'){
		initMarquee();
		initScrollImgs();
		initEvent2();
	}
	if(typeof keywords != 'undefined'){
		document.getElementById("txtKeyword").value = keywords;
	}
	if(typeof searchType == 'undefined'){
		//setSearchType();
	}
	if(typeof currentColor != 'undefined'){
		changeColor();
	}
	if(typeof delay != 'undefined'){
		moveImages();
		//initMarquee3();
	}
	if(typeof Marquee4 != 'undefined'){
		initMarquee4();
	}
	if(typeof noScroll == 'undefined'){
		var frameSearch = $("frameSearch");
		if(frameSearch)
			frameSearch.src = "/Services/SearchReport.html";
		initScroll();
	}
	if($("divFavorite")){
		changeColor2();
	}
	if(typeof py != 'undefined'){
		getPYContent();
	}
	if(floatBox){
		setTimeout(function(){
			if(f_isMin == false){
				f_min($("imgMin"));
			}
		}, 10000);
	}
};