var param; 
var listTab=[];
var tmpName=[];
var tmpData=[];
var timerESD;
listTab[0]=0;
listTab[1]=0;
listTab[2]=0;
listTab[3]=0;

function secBoard(n)
{
_secTable=document.getElementById("secTable");
_mainTable=document.getElementById("mainTable");
	param=n;
	_row=_secTable.rows[0];
	for(i=0;i<_row.cells.length;i++){
		if (i!=n){
			_row.cells[i].className="sec1";
		}
	}
	_row.cells[n].className="sec2";
	//_tBodies=_mainTable.getElementsByTagName("tbody");
	//alert (_tBodies.length);

	for(i=0;i<4;i++){
		if (i!=n){
			document.getElementById("mainTable"+i).style.display="none";
		}
	}
	var obj=document.getElementById("mainTable"+n);
	if (listTab[n]==0){
		if (n==3){
			getProdCateInfo(n,obj);
		}else{
			getIndCateInfo(n,obj);
		}
		
	}
	//obj.style.display="block";
	obj.style.display="";
}

function getIndCateInfo(n,obj){
	IndexManager.queryCategory(n,
		{
			callback:function(list) { 
			display(n,list,obj); 
			},
			errorHandler:function(errorString, exception) {
			handleError(errorString, exception)
			} 
		});	
}

function getProdCateInfo(n,obj){
	IndexManager.queryProductCategory(
		{
			callback:function(list) { 
			display(n,list,obj); 
			},
			errorHandler:function(errorString, exception) {
			handleError(errorString, exception)
			}
		});	
}

function makeData(list){
	tmpName=[];
	tmpData=[];
	var l=0;
	var j=0;
	var k=0;
	if (list.length>0){	
		tmpName[j]=list[l++];
		tmpData[j]=[];
		while (l<list.length){			
			if (list[l].industry_level==1){
				tmpName[++j]=list[l++];
				tmpData[j]=[];
				k=0;
			}
			if (list[l].industry_level==2){
				tmpData[j][k++]=list[l++];
			}
		}	
	}
}

var display=function(n,list,obj){
	listTab[n]=1;
	makeData(list);
	var table1 = document.createElement("table");
	var tbody1 = document.createElement("tbody");
	table1.appendChild(tbody1);
	var type = ["e","s","d","p"];
	
	var i=0;    
	var tr1 = document.createElement("tr");
	
	var td1 = document.createElement("td");
	td1.setAttribute("width","48%");
	td1.vAlign="top";
	var td2 = document.createElement("td");   
	td2.setAttribute("width","2%");
	var td3 = document.createElement("td");
	td3.setAttribute("width","48%");
	td3.vAlign="top";
	len=tmpName.length;
	while (i<len){   
		var table_1 = document.createElement("table");
		table_1.setAttribute("width","100%");
		table_1.setAttribute("class","fenlei");
		table_1.className="fenlei"
		var tbody_1 = document.createElement("tbody");
		table_1.appendChild(tbody_1);		
		var tr_1 = document.createElement("tr");
		tbody_1.appendChild(tr_1);
		var td_1 = document.createElement("td");
		td_1.setAttribute("colspan",2);
		td_1.innerHTML="<img width=1 height=3>";
		tr_1.appendChild(td_1);
			
		var tr_2 = document.createElement("tr");
		var td_2_1 = document.createElement("td");    	
		var td_2_2 = document.createElement("td");
		td_2_1.setAttribute("width","2%");
		td_2_1.setAttribute("align","right");
		td_2_2.setAttribute("width","98%");
		td_2_2.setAttribute("height","20");
		td_2_2.setAttribute("class","orange_TU");
		td_2_2.className="orange_TU";
		td_2_1.innerHTML="<span class=\"tugao\"><img src=\"/images/an.gif\" width=\"4\" height=\"7\"></span>";
		td_2_2.innerHTML="<a href='index.do?method=categoryMessage&flag="+n+"&id="+tmpName[i].id+"' target='_blank' class='orange_TU_t'>"+tmpName[i].name+"</a>";
		tr_2.appendChild(td_2_1); 
		tr_2.appendChild(td_2_2); 
		tbody_1.appendChild(tr_2);

		var tr_3 = document.createElement("tr"); 
		var td_3_1 = document.createElement("td");
		td_3_1.innerHTML="&nbsp;";
		var td_3_2 = document.createElement("td");
		td_3_2.setAttribute("class","tugao");
		td_3_2.className="tugao";
		var str="";
		for (m=0;m<tmpData[i].length;m++){
			if (m == tmpData[i].length-1){
				str+="<nobr><a href='/industry/"+type[n]+"_"+tmpData[i][m].id+"/"+type[n]+"_"+tmpData[i][m].id+".htm' target='_blank'>" + tmpData[i][m].name + "</a></nobr>";
			}else{
				str+="<nobr><a href='/industry/"+type[n]+"_"+tmpData[i][m].id+"/"+type[n]+"_"+tmpData[i][m].id+".htm' target='_blank'>" + tmpData[i][m].name + "</a>&nbsp;|&nbsp;</nobr>";
			}
		}
		td_3_2.innerHTML=str;
		tr_3.appendChild(td_3_1); 
		tr_3.appendChild(td_3_2); 
		tbody_1.appendChild(tr_3);

		if (i%2==0){
			td1.appendChild(table_1);
		}else{
			td3.appendChild(table_1);
		}    	
		i++;
	}
	
	var table_1 = document.createElement("table");
	table_1.setAttribute("width","100%");
	var tbody_1 = document.createElement("tbody");
	table_1.appendChild(tbody_1);		
	var tr_1 = document.createElement("tr");
	tr_1.setAttribute("align","right");
	tbody_1.appendChild(tr_1);
	var td_1 = document.createElement("td");
	td_1.innerHTML="<a href='javascript:more()'>更多>></a>";
	tr_1.appendChild(td_1);	
	td3.appendChild(table_1);
	tr1.appendChild(td1); 
	tr1.appendChild(td2); 
	tr1.appendChild(td3);
	tbody1.appendChild(tr1);
	var o=obj.rows[0].cells[0];
	o.innerHTML="";
	o.appendChild(table1);
}

var s_page=1;
function getSupply()
{	
	IndexManager.getLimitSuply(s_page,{
			callback:function(childCategorys) { 
			setRefreshOptions(childCategorys); 
			},
			errorHandler:function(errorString, exception) {
			handleError(errorString, exception)
			}  
		});
}


setRefreshOptions = function(childCategorys){
		 var container = document.getElementById("supplyTest");
		 var table = document.createElement("table");
		 table.setAttribute("width","272");
		 table.setAttribute("border","0");
		 table.setAttribute("cellspacing","0");
		 table.setAttribute("cellpadding","0");
		 var supplyList = childCategorys.suplyList;
		 var size = childCategorys.size;
		 var length = supplyList.length;

		 if(supplyList.length==7){
			s_page++;
		 }else{
			s_page=1;
		 }

		 if(size==0){
			s_page=2;
		 }	

		 if(supplyList.length>7){
			length = 7;
		 }
		
		 for(var i=0;i<length;i++){			
			var tr = table.insertRow(i);
			if(i%2==0){
				tr.bgColor="#f3f3f3";
			} 
			
			var list = [supplyList[i].title,supplyList[i].tradePrice,supplyList[i].tradeNuit,supplyList[i].id,supplyList[i].enterpriseId,supplyList[i].name];
			for(var j=0;j<3;j++){
				var td = tr.insertCell(j);
				
				if(j==0){
					td.setAttribute("width","5");
		 			td.setAttribute("align","left");
		 			
		 			td.className="orange";
		 			td.innerHTML="<font color='#000000'>[</font>供<font color='#000000'>]</font>";
				} else if(j==1){
					td.setAttribute("width","160");
		 			td.setAttribute("align","left");
		 			
		 			td.className="orange";
					td.innerHTML="<span class='chanpin'><u><FONT color='#011D4D'><a href='javascript:openurl2("+list[3]+","+list[4]+");'><div style='white-space:nowrap;width:130px;height:17px;text-overflow:ellipsis;overflow: hidden;cursor:hand' title="+list[0]+">"+list[0]+"</div></a></FONT></U></span>";
				} else {
					
					td.setAttribute("width","112");
		 			td.className="orange";
					td.setAttribute("align","center");
					td.innerHTML = "<a href='/enterprise/index.jsp?enterpriseId="+list[4]+"' target='_blank'><div style='white-space:nowrap;width:108px;height:17px;text-overflow:ellipsis;overflow: hidden;cursor:hand' title="+list[5]+"><FONT color='#011D4D'>&nbsp;&nbsp;"+list[5]+"</font></div></a>"
					

				}
			}
		}
		var tr = table.insertRow(i);
		var td = tr.insertCell(0);
		td.colSpan=4;
		td.align="right";
		td.innerHTML="<a href='/moreInfo.do?method=more'>更多</a>&nbsp;&nbsp;";
		container.innerHTML="";
		container.appendChild(table);
}

var d_page=1;

function getDemand()
{	
	IndexManager.getLimitDemand(d_page,{
			callback:function(demands) { 
			setRefreshDemand(demands); 
			},
			errorHandler:function(errorString, exception) {
			handleError(errorString, exception)
			}  
		});
}


var setRefreshDemand = function(demands){
		var childCategorys = demands.demandList;
		var size = demands.size;
		 var container = document.getElementById("demandTest");
		 var table = document.createElement("table");
		 table.setAttribute("width","272");
		 table.setAttribute("border","0");
		 table.setAttribute("cellspacing","0");
		 table.setAttribute("cellpadding","0");
		 var length = childCategorys.length;

		 if(childCategorys.length>7){
			length = 7;
		 }
		
		if(childCategorys.length==7){
			d_page++;
		}else{
			d_page=1;
		}

		if(size==0){
			d_page=2;
		}

		for(var i=0;i<length;i++){
	
			var tr = table.insertRow(i);
			if(i%2==0){
				tr.bgColor="#f3f3f3";
			} 
			
			var list = [childCategorys[i].title,childCategorys[i].pubDate,childCategorys[i].id,childCategorys[i].enterpriseId];
			for(var j=0;j<3;j++){
				var td = tr.insertCell(j);
				
				if(j==0){
					td.setAttribute("width","5");
		 			td.setAttribute("align","left");
		 			td.className="orange";
		 			td.innerHTML="<font color='#000000'>[</font>求<font color='#000000'>]</font>";
				} else if(j==1){
					td.setAttribute("width","187");
		 			td.setAttribute("align","left");
		 			td.className="orange";
					td.innerHTML="<span class='chanpin'><u><FONT color='#011D4D'><a href='javascript:openurl3("+list[2]+","+list[3]+");'><div style='white-space:nowrap;width:140px;height:17px;text-overflow:ellipsis;overflow: hidden;cursor:hand' title="+list[0]+">"+list[0]+"</div></a></FONT></U></span>";
				} else {
					if(j==2){
						td.setAttribute("width","80");
		 				td.className="gray";
		 				
					} 
					td.setAttribute("align","center");
					
					if(list[1]==null||list[1]==""){
						td.innerHTML="待定";
					}else {
						td.innerHTML=formatDate(new Date(),"yyyy-MM-dd");//+list[1];
					}
					
					
				}
			}
		}

		var tr = table.insertRow(i);
		var td = tr.insertCell(0);
		td.colSpan=4;
		td.align="right";
		td.innerHTML="<a href='/moreInfo.do?method=more'>更多</a>&nbsp;&nbsp;";
		container.innerHTML="";
		container.appendChild(table);
}

var e_page=1;

function getEnterprise()
{	
	IndexManager.getLimitEnterprise(e_page,{
			callback:function(enterprises) { 
			setRefreshEnterprise(enterprises); 
			},
			errorHandler:function(errorString, exception) {
			handleError(errorString, exception)
			}  
		});
}


var setRefreshEnterprise = function(enterprises){
		var childCategorys = enterprises.enterpriseList;
		var size = enterprises.size;
		var container = document.getElementById("enterpriseTest");
		var table = document.createElement("table");
		table.setAttribute("width","100%");
		table.setAttribute("border","0");
		table.setAttribute("cellspacing","0");
		table.setAttribute("cellpadding","0");
		var length = childCategorys.length;
		 
		if(childCategorys.length>6){
			length = 6;
		}
		
		if(childCategorys.length==6){
			e_page++;
		}else{
			e_page=1;
		}

		if(size==0){
			e_page=2;
		}
		
		var tr = table.insertRow(0);
		var td = tr.insertCell(0);
		td.className="tugao";	
		str="";
		for(var i=0;i<length;i++){
			var list = [childCategorys[i].name,childCategorys[i].id];
			str+="<div style='white-space:nowrap;width:150px;height:20px;text-overflow:ellipsis;overflow: hidden;cursor:hand' title="+list[0]+">&nbsp;<a href='javascript:openurl1("+list[1]+","+0+");'>"+list[0]+"</a></div>";
		}
		td.innerHTML=str;
		container.innerHTML="";
		container.appendChild(table);
}

function getFocusLinks()
{	
	LinkFocusManager.getLinks({
			callback:function(focusLinks) { 
			setRefreshFocusLinks(focusLinks); 
			},
			errorHandler:function(errorString, exception) {
			handleError(errorString, exception)
			}  
		});
}


var setRefreshFocusLinks = function (focusLinks){
	
	var container = document.getElementById("focusLinksDiv");
	var table = document.createElement("table");
	table.setAttribute("width","98%");
	table.setAttribute("border","0");
	table.setAttribute("cellspacing","0");
	table.setAttribute("cellpadding","0");
	var length = focusLinks.length ;
	if(length>3){
		length = 3
	}
	for(var i=0 ;i<length;i++){
			var v_tr = table.insertRow(i);
			var v_td = v_tr.insertCell(0);
			v_td.setAttribute("align","left");
			v_td.className="BLACK_tugao";

			if(i%2==0){
				v_td.bgColor = "#ECECEC";
			}

			v_td.innerHTML = '<span class="style4">【'+focusLinks[i].source+'】</span>：<a href="'+focusLinks[i].link+'" target="_blank">'+focusLinks[i].title+'</a>';
	}
	
	container.innerHTML="";
	container.appendChild(table);

}

var n_page=1;
function getNewsLimit()
{	
	
	IndexManager.getNews(n_page,{
			callback:function(news) { 
			setRefreshNews(news); 
			},
			errorHandler:function(errorString, exception) {
			handleError(errorString, exception)
			}  
		});
}

var setRefreshNews = function (news){
	var newsList = news.newsList;
	var size = news.size;
	var container = document.getElementById("newsDiv");
	var v_table = document.createElement("table");
	var v_news = "";
	var length = newsList.length;
	

	if(newsList.length > 5){
		length = 5;
	}
	
	if(newsList.length==5){
		n_page++;
	}else{
		n_page=1;
	}

	if(size=='0'){
		n_page=2;
	}

	for(var i=0 ;i<length;i++){
		var v_tr = v_table.insertRow(i);

		for(var j=0;j<3 ;j++){
			var v_td = v_tr.insertCell(j);

			if(j==0){
				v_td.setAttribute("width","20%");
				v_td.innerHTML = "&nbsp;【新闻】";
			}	
			
			if(j==1){
				v_td.setAttribute("width","71%");
				v_td.innerHTML = "<a href='javascript:openurl(\"news\","+newsList[i].id+",\"index\");'><div style='white-space:nowrap;width:180px;height:17px;text-overflow:ellipsis;overflow: hidden;cursor:hand' title="+newsList[i].name+">"+newsList[i].name+"</div></a>";
			}	

			if(j==2){
				v_td.setAttribute("width","9%");
				
				if(formatDate(newsList[i].create_time,"yyyy-MM-dd")==formatDate(new Date(),"yyyy-MM-dd")){
					v_td.innerHTML = "<img src='/images/new.gif' height='11'>";
				}
				
			}	

		}
		
	}
	
	container.innerHTML = "" ;
	container.appendChild(v_table);

}

var f_page=1;
function getReferLimit()
{	
	IndexManager.getRefer(f_page,{
			callback:function(refer) { 
			setRefreshRefer(refer); 
			},
			errorHandler:function(errorString, exception) {
			handleError(errorString, exception)
			}  
		});
}

var setRefreshRefer = function (refer){
	var referList = refer.referList;
	var size = refer.size;
	var container = document.getElementById("referDiv");
	var v_table = document.createElement("table");
	var v_refer = "";

	var length = referList.length;
	
	if(referList.length>5){
		length = 5;
	}
	
	if(referList.length==5){
		f_page++;
	}else{
		f_page=1;
	}

	if(size==0){
		f_page=1;
	}

	for(var i=0 ;i<length;i++){
		var v_tr = v_table.insertRow(i);

		for(var j=0;j<3 ;j++){
			var v_td = v_tr.insertCell(j);

			if(j==0){
				v_td.setAttribute("width","20%");
				v_td.innerHTML = "【资讯】";
			}	
			
			if(j==1){
				v_td.setAttribute("width","70%");
				v_td.innerHTML = "<a href='javascript:openurl(\"refer\","+referList[i].id+",\"index\");'><div style='white-space:nowrap;width:180px;height:17px;text-overflow:ellipsis;overflow: hidden;cursor:hand' title="+referList[i].name+">"+referList[i].name+"</div></a>";
			}
			
			if(j==2){
				v_td.setAttribute("width","10%");

				if(formatDate(referList[i].create_time,"yyyy-MM-dd")==formatDate(new Date(),"yyyy-MM-dd")){
					v_td.innerHTML = "<img src='/images/new.gif' height='11'>";
				}
			}	

		}
		
	}
	
	container.innerHTML = "" ;
	container.appendChild(v_table);

}

function getData(){
	getSupply();
	getDemand();
	getEnterprise();
}

function getNewsAndRefer(){
	getNewsLimit();
	getReferLimit();
}

function clearTimer(){
	clearInterval(timerESD);
}