


function search()
{
	var s = document.getElementById("keyword").value;


	
	var href = "search_result.jsp?key=" + encodeURIComponent( s );

	update_data( href );

	return false;
}


function initDisplayStyle(){
	/lmbh=(\d+)/.test( document.URL );
	var lmbh = RegExp.$1;
	setTimeout(function(){
		
		if( lmbh == 100035){//家装咨询窗口
			picRotater.init("arList");
		}
		if( lmbh == 100045){//设计精英窗口
			picRotater.init("arList");
		}
		if( lmbh == 100043){//协会推荐企业展播窗口
			picRotater.init("arList");
		}
	},0)
}

var picRotater={
	selIdx:-1,
	urls:[],
	imgContener:null,
	init:function ( id){
		var div = $(id);
		div.className="listBody sidePicList";
		var imgContener = document.createElement("div");
		div.appendChild(   imgContener  );
		imgContener.className = "imgDiv";
		
		var ul = div.getElementsByTagName("ul")[0];
		if(!ul )
			return ;
		var lis = ul.getElementsByTagName("li");
		for(var i=0;i<lis.length;i++){
			lis[i].onmouseover=this.movr(i);
			var lnk = lis[i].getElementsByTagName("a")[0];
			this.urls[ i ] = {
					xnp:lnk.getAttribute("xnp"),
					url:lnk.getAttribute("href")
					};
			
			lis[i].id="li-" + i ;
		}
		this.imgContener = imgContener;
		this.select( 0 );
		
	},
	movr:function(idx){
		return function(){
			picRotater.select( idx );
		}
	},
	select:function (indx){
		var preli = $("li-"+ this.selIdx);
		if( preli){
			preli.className = "";
		}
		this.imgContener.innerHTML = "<img src='"+  this.urls[indx].xnp +"' "+
		 " onclick='window.open(\""+ this.urls[indx].url +"\")' onload='fiximagesize(this);' />";
		
		this.selIdx = indx;
		 $("li-"+ this.selIdx).className="selected";
	}
	
}




function searchgoogle(){
	window.open("http://www.google.cn/search?hl=zh-CN&q=" + 
		encodeURIComponent( document.getElementById("keyword").value + " site:www.xnghjs.gov.cn")  );
}
function update(evt ){
	evt=evt||window.event;
	if(update.xh)
	{
		try{
			update.xh.abort();
		}catch(ex){}
	}

	var href = this.getAttribute("href");
	if(href == null)
		return;
	if(href.indexOf("key=")==-1)
	{
		href = href.replace(/^.*\?/,"list.jsp?");
	}
	else{
		href = href.replace(/^.*\?/,"search_result.jsp?");
	}
	update_data(href);
	if( evt.preventDefault)
		evt.preventDefault();
	return false;
}
var count=0;
function update_data(href){
	var t = (new Date()).getTime();
	if( (t-update.time)<1000 )
		return;
	try{
		if(href==null)return;
		href = href.replace( /#.*$/ , "" );
		if(href=="")
		{
			return;
		}
		location.hash = count++;
		var oDiv = document.getElementById("listBody");
		if( oDiv )
			oDiv.innerHTML="<div class='loading wrap1'><span>载入中...</span></div>";
		oDiv = null;
		update.xh = getXMLHttpRequest();
		update.xh.open("GET",href,true);
		update.xh.onreadystatechange=function(){
	
			try{
			if(update.xh.readyState=="4")
			{
				//alert(update.xh.responseText);
				document.getElementById("mainContent").innerHTML =  update.xh.responseText ;
				updatepaging();
				update.xh = null;

			}
			}catch(ex){alert(1);}
		}
		update.xh.send(null);
	}catch(ex){
		return true;
	}
}
update.time = 0;
function updatepaging(){
	
	var divs ;
	try{	
		divs= document.getElementById("listBody")
		if(divs==null)return;
		divs=divs.getElementsByTagName("div");
		var links = divs[0].getElementsByTagName("a");
		for(var i=0;i<links.length;i++)
		{
			if( String.prototype.toLocaleLowerCase.call(links[i].parentNode.tagName) =="li")
				continue;
			links[i].onclick = new Function("evt","update.call(this,evt,false);");
		}
		links = null;
		divs = null;
	}catch(ex){return;};
	
	
	if( /picList=1/.test( document.URL )){
		
				showPicList();
	}
}

function jumpKeypress(obj,evt){
	if( evt.keyCode==13 )
	{
		jumppage( obj , evt );
	}
}
function jumppage(obj,evt){
	var input = document.getElementById("input-page-jump");
	var v= parseInt( input.value ) || "";
	var href = input.getAttribute("pagemore");

	if(href.indexOf("key=")==-1)
	{
		//href = href.replace(/^.*\?/,"list.jsp?");
	}
	else{
		//href = href.replace(/^.*\?/,"search_result.jsp?");
	}
	if( v == ""  )
	{
			input.value ="";
			return;
	}
	else if(v> parseInt( input.getAttribute("max") )){
		input.value = v =  parseInt( input.getAttribute("max") );
	}
	location = href +"&page=" + v;
	//update_data( href +"&page=" + v );
	
}
//转换图片新闻
function showPicList(){
	var ul = document.getElementById("listBody").getElementsByTagName("ul")[0];
	var links = ul.getElementsByTagName("a");
	var artcleData = [];
	for( var i=0;i<links.length;i++ )
	{
		artcleData.push({
			href : links[i].href,
			imgUrl : links[i].getAttribute("xnp"),
			title : links[i].innerHTML 	,
			data	: links[i].parentNode.getElementsByTagName("i")[0].innerHTML
		})
	}
	var sHtml =[];
	for( var i=0;i<artcleData.length;i++)
	{
		sHtml .push("<li style='text-align:left' class='picItem'>"
				+ "<div class='imgCntnr' >"
				+ 	"<img onerror='picError(this)' onclick='clickPicture(this,event)' onload='fiximagesize(this);' src='" + artcleData[i].imgUrl  + "'/>"
				+ "</div>"
				+ "<a  href='" + artcleData[i].href + "'  target='_blank' >" + artcleData[i].title + "</a>"
			+ "</li>") ;
		
	}
	ul.innerHTML = sHtml.join("");
	//var link = document.getElementById("subClassName").getElementsByTagName("a")[0];
	//link.href = link.href + "&picList=1";
}
function clickPicture( oImg ,evt){
	showImg(oImg.src ,evt );

	
}
function picError( obj ){
	///document.title = obj;
	setTimeout(function(){
		o = obj.parentNode;
		o.className+=" noimage";
		o.innerHTML ="";
	
	},0);
}
var tmpdeiv;
if( showImg )
  tmpdeiv= showImg.tmpdeiv
function showImg( src ,evt){
	var div ;
	if( ! showImg.div )
	{
		div = showImg.div = document.createElement("div");
		document.body.appendChild( div );
		div.style.position="absolute";
		div.className = "picShow";
		div.innerHTML = "<div class='bg'><iframe name='xxvsdfdfcv'></iframe></div><div class='imgp' id='picShow-Img'></div>";
		div.onclick = showImg_hide;
	}
	div = showImg.div;
	div.style.display="block";
	imgDiv = document.getElementById("picShow-Img");
	imgDiv.innerHTML="<img onload='resetPicture(this)'  src='"+ src +"'/>";
	imgDiv.style.position="absolute";
	var docTop = document.documentElement;
	imgDiv.style.top = docTop.scrollTop + (docTop.clientHeight/2)  +"px";
	imgDiv.style.left = docTop.scrollLeft + (docTop.clientWidth/2)  +"px";
	div.style.width = docTop.scrollWidth +"px";
	div.style.height = docTop.scrollHeight +"px";
	if( window.frames["xxvsdfdfcv"] )
	 	window.frames["xxvsdfdfcv"].document.write("<body bgcolor='#000000'>");


	
	
}
showImg.div=tmpdeiv;
function showImg_hide(){
	showImg.div.style.display= "none";
}
function resetPicture( oimg ){
	
	document.getElementById("picShow-Img").style.marginTop = - oimg.offsetHeight /2  +"px";
	document.getElementById("picShow-Img").style.marginLeft = - oimg.offsetWidth /2  +"px";
}



function initLeftLink(){
	try{	
		var links = document.getElementById("sideLeft")
				.getElementsByTagName("ul")[0]
				.getElementsByTagName("a");
		for(var i=0;i<links.length;i++)
		{
			links[i].onclick = update;
		}
	}catch(ex){return;};
}









/**************************
 * 
 *  menu
 */



function initMenu(){
	var ul;
	try{
		ul = getChildNodesByTagName(
			 document.getElementById("lmlist") , "ul" )[0];
	}catch(ignore){
		return
	}
	if( ul == null )
		return;
	var lis = getChildNodesByTagName( ul , "li");
	for(var i=0;i<lis.length;i++)
	{

		lis[i].onmouseover = menuHandlers.showMenuHandler;
		lis[i].onmouseout = menuHandlers.hideMenuHandler;
	}
}
var zIndex=10000;
var menuHandlers = {
	showMenuHandler:function(evt){
			
			if(!evt) evt = window.event;
			var li = this;
			if( li._menuObj )
			{
				li._menuObj.show( evt , li );
			}
			else{
				var firstUl = getChildNodesByTagName( li ,"ul" )[0];
				if(!firstUl)
					return;
				li.style.zIndex = zIndex++;
				firstUl.style.display="block";
				//firstUl.style.top = - firstUl.offsetHeight/2 +"px";
			}
	},
	hideMenuHandler:function(evt){
			
			if(!evt) evt = window.event;
			var li = this;
			if( li._menuObj )
			{
				li._menuObj.show( evt , li );
			}
			else{
				var firstUl = getChildNodesByTagName( li ,"ul" )[0];
				if(!firstUl)
					return;
				firstUl.style.display="none";
			}
	}

}


function MenuObject( ul , contextNode ){
	document.body.appendChild( ul );
	ul.style.postion = "absolute" ;
	this._ul = ul;
	this._timer = -1;
	ul = null;
	
}
function getElRect( el ){
	var rect = { top:0 , left:0 , width:0 , height:0 }
	rect.width = el.offsetWidth;
	rect.height = el.offsetHeight;
	while(el)
	{
		rect.top += el.offsetTop;
		rect.left += el.offsetLeft;
		el = el.offsetParent;
		
	}
	rect.bottom = rect.height + rect.top;
	rect.right = rect.width + rect.left; 
	return rect;
}



MenuObject.prototype.show = function( evt , srcEl ){
	var div = document.getElementById("--menuObj-outer-div");
	if(!div)
	{
		div = document.createElement("div");
		div.id ="--menuObj-outer-div" ;
		document.body.appendChild(div);
		if(document.documentElement.addEventListener)
			document.documentElement.addEventListener("mousedown",MenuObject.hide,false);
		else 
			document.body.attachEvent("onmousedown",MenuObject.hide);
	}
	div.style.display = "block";
	div.style.position = "absolute";
	for(var i=div.childNodes.length-1;i>-1;i--)
	{
		//try{
			div.removeChild( div.childNodes[i] );
		//}catch(ignore){}
	}
	div.className="popMenu";
	div.appendChild( this._ul );
	this._ul.style.display="block";
	clearTimeout( this._timer );
	var r = getElRect( srcEl  );
	div.style.left = r.right +"px";
	div.style.top = r.top + r.width/2 - this._ul.offsetHeight/2 +"px";
	div.onmouseover = menuHandlers.getShowMenuHandler( srcEl );
	div.onmouseout = MenuObject.hide;

}
MenuObject.hide = 
MenuObject.prototype.hide = function(  ){
	var div = document.getElementById("--menuObj-outer-div");
	
	if( div )
	{
		div.style.dispay = "none";
		/*
		for(var i=div.childNodes.length-1;i>-1;i--)
		{
			try{
				div.removeChild( div.childNodes[i] );
			}catch(ignore){}
		}*/
	
	}

}
MenuObject.prototype.delayHide = function(){
	clearTimeout( this._timer );
	var T = this;
	this._timer = setTimeout(function (){
		T.hide();
		T = null;
	},1000);
}







