

window.onresize=function()
{
 try{
  var objSearchFrame = getMapElementById('searchBar');

   if(typeof(objSearchFrame)=="object"&&objSearch.IsSearch==1)
   {
       objSearch.page=1;
      objSearch.putPopBar();
      objSearch.ApiHeightInit();
      window.setTimeout('objSearch.putPopBarInfo()',1000);
   }
   }
   catch(e)
   {
    ;
   }
    
}
function searchHelper(){}
searchHelper.prototype.page = 1;
searchHelper.prototype.VipCount=0;
searchHelper.prototype.pageSize = 9;
searchHelper.prototype.pageCount=1;
//searchHelper.prototype.pageSize1=0;
searchHelper.prototype.strTempVip = '';
//最后点击的点
searchHelper.prototype.NowKick = -1;
searchHelper.prototype.LastAroundCount = -1;
searchHelper.prototype.PopHeight = 420;//地图默认高度
searchHelper.prototype.IsSearch = 0;//popo内的信息
searchHelper.prototype.inIt = function()
{
	this.putPop();
	this.ApiHeightInit();
}
searchHelper.prototype.dataLoad = function(kw)
{
checkTxtValue('txtAddress', 'arrayAddress', 2);
 var keyword=document.getElementById('txtAddress').value
  if(keyword.length<1)
  {
   return;
  }
  
 
　　try
　　{
　　　　if(getMapStatus())
		{
　　　　　	checkMapIni();
			showDivWelcome(0);
			switchDivSearch(0);
			showDivMap(1);
			addCssFile('skins/'+SKINFOLDER+'/images_skin/search/text.css');
			//removePop('search');
			//搜索按钮框架
			window.setTimeout('objSearch.putPopBar()',500);
		}
　　　　else
　　　　{
　　　　	window.setTimeout('objSearch.dataLoad(\''+kw+'\')',500);
　　　　}
　　}
　　catch(e)
　　{
　　　　window.setTimeout('objSearch.dataLoad(\''+kw+'\')',500);
　　}
　　finally
　{
　　	//document.body.removeChild(document.getElementById('sData'));
　　	var num=GetRandomNum(0,10000);
		this.page = 1;
		this.strTempVip='';
		var searchData = document.createElement('script');
		searchData.language = 'javascript';
		searchData.id       = 'sDataID';
		searchData.src      = 'search.aspx?action=SearchData&kw='+keyword+'&node='+NODE+'&num='+num;
		//location.href=searchData.src;
		document.body.appendChild(searchData);
		this.IsSearch=1;
		
		//document.write(searchData.src);
		//setTimeout('')
	}
}
searchHelper.prototype.RemovePopBar = function()
{
 this.IsSearch=0;
 removeAllPop();
 removePop('search');
}
searchHelper.prototype.putPopBar = function()
{
	//var a = new mapAbb();
	//alert(getMapWidth());
	var left      = getMapWidth()-205;
	var frameHtml = '<div id="searchBar" style="height: 25px;width: 150px;background-color: #FFFFFF;filter:Alpha(Opacity=90)"><span class="top1">数据加载中.....</span></div>';
	putControlBar(frameHtml,'search',left,36,200);
	turnPage('search',false,true,10,1);
	//setTimeout("removePop('search')",500);
}
searchHelper.prototype.putPop = function()
{
	removeAllPop();
	for(i=0;i<sData.x.length;i++)
	{
		var popHtml = '<img src="skins/'+SKINFOLDER+'/images_skin/search/search.gif" width="20" height="23" style="cursor:pointer;" onclick="parent.objSearch.showPopInfo('+i+')" onmouseover="document.getElementById(\'{$ObjId}\').style.zIndex=100;" onmouseout="document.getElementById(\'{$ObjId}\').style.zIndex=1;"/>';
		popHtml =popHtml.replace("{$ObjId}",'putSearchPop_'+i).replace("{$ObjId}",'putSearchPop_'+i);
		var lx=parseInt(sData.x[i])+parseInt(sData.w[i]/2);
		var ly=parseInt(sData.y[i])+parseInt(sData.h[i]/2);
		putPop(lx,ly, 10,23, popHtml, 'putSearchPop_'+i);
	}
	if(IsInMap==0)
	{
	if(sData.x.length>0)
	{
	  this.scrl(0);
	  this.showPopInfo(0);
	}
	 zoomto(3);
	 IsInMap=1;
	}
	window.setTimeout('objSearch.putPopBarInfo()',600);
	
	//alert(sData.PopHtmlBar);
}
searchHelper.prototype.ChangePopStatus = function(i)
{
  removePop('putSearchPop_'+i);
  this.ChangePopStatusToCommon(this.NowKick);
  var popHtml = '<img src="skins/'+SKINFOLDER+'/images_skin/search/search3.gif" width="20" height="23" style="cursor:pointer;" onclick="parent.objSearch.showPopInfo('+i+')" onmouseover="document.getElementById(\'{$ObjId}\').style.zIndex=100;" onmouseout="document.getElementById(\'{$ObjId}\').style.zIndex=1;"/>';
  popHtml =popHtml.replace("{$ObjId}",'putSearchPop_'+i).replace("{$ObjId}",'putSearchPop_'+i);
  var lx=parseInt(sData.x[i])+parseInt(sData.w[i]/2);
  var ly=parseInt(sData.y[i])+parseInt(sData.h[i]/2);
  putPop(lx,ly, 10,23, popHtml, 'putSearchPop_'+i);
}
searchHelper.prototype.ChangePopStatusToCommon = function(i)
{
 removePop('putSearchPop_'+i);
  var popHtml = '<img src="skins/'+SKINFOLDER+'/images_skin/search/search.gif" width="20" height="23" style="cursor:pointer;" onclick="parent.objSearch.showPopInfo('+i+')" onmouseover="document.getElementById(\'{$ObjId}\').style.zIndex=100;" onmouseout="document.getElementById(\'{$ObjId}\').style.zIndex=1;"/>';
  popHtml =popHtml.replace("{$ObjId}",'putSearchPop_'+i).replace("{$ObjId}",'putSearchPop_'+i);
  var lx=parseInt(sData.x[i])+parseInt(sData.w[i]/2);
  var ly=parseInt(sData.y[i])+parseInt(sData.h[i]/2);
  putPop(lx,ly, 10,23, popHtml, 'putSearchPop_'+i);
 
}
searchHelper.prototype.putAroundPop = function()//显示查找的周边信息pop
{
    //removePop('SearchPopInfo');
	this.RemoveAllAroundPop();
	for(i=0;i<sAroundData.x.length;i++)
	{
	
		var popHtml = '<img src="skins/'+SKINFOLDER+'/images_skin/search/look.gif" width="20" height="23" style="cursor:pointer;" onclick="parent.objSearch.showAroundPopInfo('+i+')" onmouseover="document.getElementById(\'{$ObjId}\').style.zIndex=100;parent.objSearch.AroundPopOver('+i+');" onmouseout="removePop(\'AroundPopName\');document.getElementById(\'{$ObjId}\').style.zIndex=1;"/>';
		popHtml =popHtml.replace("{$ObjId}",'putAroundPop_'+i).replace("{$ObjId}",'putAroundPop_'+i);
		putPop(parseInt(sAroundData.x[i]),parseInt(sAroundData.y[i]), 10,23, popHtml, 'putAroundPop_'+i);
		
	}
	removePop('SearchNotes');
	
	if(sAroundData.x.length==0)
	{
	 alert('周围 '+sAroundData.len+'米 没有你要查询的:'+sAroundData.keyword);
	}
	else
	{
	 alert('周围 '+sAroundData.len+'米 你要查询的:'+sAroundData.keyword+ ' 有'+sAroundData.x.length +'条');
	}
	
	
}
searchHelper.prototype.AroundPopOver = function(popi)//周边信息,鼠标放上时的事件
{
  removePop('AroundPopName');
  var popHtml = '<div id="form1">'+sAroundData.OCName[popi]+'</div>'
  putPop(parseInt(sAroundData.x[popi])+35,parseInt(sAroundData.y[popi])-100, 0,0, popHtml, 'AroundPopName',999);
}
searchHelper.prototype.AroundPopOut = function(objpop,popi)//周边信息,鼠标放上时的事件
{

  removePop('AroundPopName');
}
searchHelper.prototype.RemoveAllAroundPop = function(i)
{
 var PopNum=this.LastAroundCount;
  if(i)
  {
    PopNum=i;
  }
  for(var i=0;i<PopNum;i++)
  {
   removePop('putAroundPop_'+i);
  }
}
searchHelper.prototype.showAroundPopInfo = function(i)
{
	scrltoXY(sAroundData.x[i],sAroundData.y[i],0,0);
	//alert('card.aspx?OwnerId='+sAroundData.OwnerId[i]+'&CompanyId='+sAroundData.CompanyID[i]+'&Node='+NODE);
	left.location.href = 'card.aspx?OwnerId='+sAroundData.OwnerId[i]+'&CompanyId='+sAroundData.CompanyID[i]+'&Node='+NODE;
}

searchHelper.prototype.putPopBarInfoByPage = function(currentpage)
{
  if(currentpage)
  {
   this.page=currentpage;
  }
  this.putPopBarInfo();
}
searchHelper.prototype.PopInfoInit = function()
{
 
}
searchHelper.prototype.ApiHeightInit = function()
{
  
  var Apihight=getMapHeight()-70;
  var pagesize=(Apihight-50)/39;
  this.pageSize=parseInt(pagesize);
  this.PopHeight=Apihight;
  if(sData.keyWord.length>18)
  {
   this.PopHeight=this.PopHeight-10;
   this.pageSize=this.pageSize-1;
  }
 //alert(this.pageSize);
  
}
searchHelper.prototype.putPopBarInfo = function()
{
    
	//if(getMapHeight()<=100)//
//	{
	// return;
	//}
	//this.putPopBar();
	var strPopHtmlBar = sData.PopHtmlBar;
	var strVipRecord  = ReadSign('VipRecord',strPopHtmlBar);
	var strRecord     = ReadSign('Record',strPopHtmlBar);
	
	strPopHtmlBar = strPopHtmlBar.replace(strVipRecord,'{$VipRecord}');
	strPopHtmlBar = strPopHtmlBar.replace(strRecord,'{$Record}');
	strPopHtmlBar = strPopHtmlBar.replace('{$RecordCount}',sData.x.length);
	strPopHtmlBar = strPopHtmlBar.replace('{$KeyWord}',sData.keyWord);

	
	var strTemp = '';
	if(this.page==1)//第一次,计算Vip数及总的页数
	{
	 
	 this.VipCount=0;
	 this.strTempVip='';
	 for(var k=0;k<3;k++)
	 {
	  if(sData.VipClass[k]==1)
		{
		  this.strTempVip = this.strTempVip + strVipRecord.replace('{$Title}',this.manageString(sData.OCName[k],24));
		  this.strTempVip = this.strTempVip.replace('{$Address}',this.manageString(sData.Address[k],24));
		  this.strTempVip = this.strTempVip.replace('{$Address}',this.manageString(sData.Address[k],24));
		  this.strTempVip = this.strTempVip.replace('{$ShowPop}','parent.objSearch.showPopInfo('+k+')');
		  
		  this.VipCount++;
		}
	
	  } 
	 if(this.pageSize-this.VipCount<0)
	 {
	  alert('你的地图窗口太小,无法正常显示数据!');
	  return;
	 }
	var recordsize=sData.x.length-this.VipCount;
	if(recordsize%(this.pageSize-this.VipCount)==0)
	 {
	   this.pageCount=recordsize/(this.pageSize-this.VipCount);
	 }
	 else
	 {
	   
	    this.pageCount=int(recordsize,(this.pageSize-this.VipCount))+1;
	 }
	  //alert(this.page);
	 //this.pageSize1=this.pageSize-this.VipCount;
	}
	//alert(this.pageCount);
	var intBegin  = (this.page-1)*(this.pageSize-this.VipCount);
	var intEnd     = this.page*(this.pageSize-this.VipCount)+this.VipCount-1;
	intBegin=intBegin+this.VipCount;
	
	if(intEnd>sData.x.length)
	{
	 intEnd=sData.x.length-1;
	}
    var HasRows=0;//记录多少企业有地址
	for(i=intBegin;i<=intEnd;i++)
	{
			strTemp = strTemp + strRecord.replace('{$Title}',this.manageString(sData.OCName[i],24));
	        strTemp = strTemp.replace('{$ShowPop}',';parent.objSearch.showPopInfo('+i+')');
	          HasRows=HasRows+1;
	          try{
	             if(sData.Address[i].length>0)
	             {
	               HasRows=HasRows+1;
	               strTemp = strTemp.replace('{$Address}',this.manageString(sData.Address[i],24));
	             }
	             else
	             {
	              strTemp = strTemp.replace('<div class="eds_search04">{$Address}</div>','');
	             }
	             }
	             catch(e)
	             {
	              strTemp = strTemp.replace('<div class="eds_search04">{$Address}</div>','');
	             }
	         
	      
	        
	         
	        
	}
	
	var strPage=pageShow(this.page,this.pageCount,5,'word','parent.putPopBarInfoByPage');//当前页,总的页数,每页显示的数,css样式名称
	strPopHtmlBar = strPopHtmlBar.replace('{$VipRecord}',this.strTempVip);
	strPopHtmlBar = strPopHtmlBar.replace('{$Record}','<div>'+strTemp+'</div>');
	strPopHtmlBar = strPopHtmlBar.replace('{$PageStr}',strPage);
	
	var objSearchFrame = getMapElementById('searchBar');
	var k=HasRows/(this.pageSize*2);
	//alert(HasRows);
	var NowBarHeight=(this.PopHeight-45)*k;
	if(NowBarHeight<=0)
	{
	 alert('地图页面太小,无法显示搜索数据');
	 return;
	}
	if(strLength(sData.keyWord)>=6)
    {
      NowBarHeight=NowBarHeight+10;
     }
	NowBarHeight=parseInt(NowBarHeight);
	NowBarHeight=NowBarHeight+'px';
	//objSearchFrame.innerHTML='';
	objSearchFrame.style.height=NowBarHeight;
	objSearchFrame.style.width='200px';
	//this.PopInfo=strPopHtmlBar;
	
	objSearchFrame.innerHTML = strPopHtmlBar;
	//alert(objSearchFrame.style.height);
}
searchHelper.prototype.showPopInfo = function(i)
{
    if(i!=this.NowKick)//和上一次点的不是同一个pop,移掉上次搜索的周边信息pop
    {
    this.ChangePopStatus(i);
    
     if(typeof(sAroundData)=="object")//如果上次已搜索了周边信息
     {
      this.RemoveAllAroundPop(sAroundData.x.length);
      }
    }
	removePop('SearchPopInfo');
	this.NowKick=i;//记录当前点的是哪个.
	this.scrl(i);
	var strAuthority = 'http://'+Authority+'/?'+sData.UnitID[i]+'&cid='+sData.CompanyID[i];
	var PopHtmlInfo = sData.PopHtmlInfo.replace("{$Title}",this.manageString(sData.OCName[i],24)).replace("{$Address}",sData.Address[i]).replace("{$Telephone}",sData.Telephone[i]);
	PopHtmlInfo = PopHtmlInfo.replace("{$I}",i);
	PopHtmlInfo = PopHtmlInfo.replace("{$I}",i);
	PopHtmlInfo = PopHtmlInfo.replace("{$Authority}",strAuthority);
	PopHtmlInfo = PopHtmlInfo.replace("{$Authority}",strAuthority);
	var lx=parseInt(sData.x[i])+parseInt(sData.w[i]/2);
	var ly=parseInt(sData.y[i])+parseInt(sData.h[i]/2);
	//putPop(lx,ly, 10,23,PopHtmlInfo, 'SearchPopInfo');//y偏移量修改
	putPop(lx,ly, -10,23,PopHtmlInfo, 'SearchPopInfo');
	left.location.href = 'card.aspx?OwnerId='+sData.OwnerID[i]+'&CompanyId='+sData.CompanyID[i]+'&Node='+NODE;
}
searchHelper.prototype.AroundSearch = function(kw,lth)//关键字,距离
{
 
  if(kw.length==0)
  {
    alert('请输入关键字!');
    return;
  }
  if(this.NowKick>=0)
  {
  if(typeof(sAroundData)=="object")
   {
    this.LastAroundCount=sAroundData.x.length;//上一次pop的数量
   }
   if(kw==sData.keyWord)
   {
    alert('周边搜索不能与你主题搜索同关键字!');
    return;
   }
  
 var num=GetRandomNum(0,10000);
 removePop('SearchPopInfo');
  
  var searchAroundData = document.createElement('script');
  var x=sData.x[this.NowKick];
  var y=sData.y[this.NowKick];
  putPop(x,y, 10,23,'<img src="skins/'+SKINFOLDER+'/images_skin/search/dataload.gif">', 'SearchNotes');//<span class="top1">周边数据搜索中.....</span>
  searchAroundData.language = 'javascript';
  searchAroundData.id = 'sAroundDataID';
  searchAroundData.src = 'search.aspx?action=SearchAround&kw='+kw+'&x='+x+'&y='+y+'&len='+lth+'&Node='+NODE;
  document.body.appendChild(searchAroundData);
  }
}
searchHelper.prototype.showPopAround = function(i)//显示搜索周边框
{
	removePop('SearchPopInfo');
	var PopHtmlInfo = sData.PopHtmlAround.replace("{$Title}",this.manageString(sData.OCName[i],24)).replace("{$I}",i);
	var lx=parseInt(sData.x[i])+parseInt(sData.w[i]/2);
	var ly=parseInt(sData.y[i])+parseInt(sData.h[i]/2);
	putPop(lx,ly, 10,23,PopHtmlInfo, 'SearchPopInfo');
}
searchHelper.prototype.showBusInfo = function(i,txt)//搜索公交
{
if(txt=='')
 {
  alert('请输入起点!');
  return;
 }
 var x=sData.x[i];
 var y=sData.y[i];
 var target=sData.OCName[i];

labSearch.style.display = '';
 url = 'search/search.aspx?node=' + NODE + '&City=' + CITYCODE + '&PageSite=2&Submit=busstation&SearchType=25&stattion=' + txt +'&x='+x+'&y='+y+'&target='+target;
 goSearch(url);
 

}
searchHelper.prototype.showPopBus = function(i)//显示公交搜索框
{
	removePop('SearchPopInfo');
	var PopHtmlInfo = sData.PopHtmlBus.replace("{$Title}",this.manageString(sData.OCName[i],24)).replace("{$I}",i).replace("{$I}",i);
	var PopHtmlInfo  = PopHtmlInfo.replace("{$I}",i);
	var lx=parseInt(sData.x[i])+parseInt(sData.w[i]/2);
	var ly=parseInt(sData.y[i])+parseInt(sData.h[i]/2);
	putPop(lx,ly, 10,23,PopHtmlInfo, 'SearchPopInfo');
}
searchHelper.prototype.scrl = function(i)
{
	
	var lx = sData.x[i];
	var ly = sData.y[i];
	var a = mapAbb();
    var sizex = 150;
	var sizey = 0;
	
	if(lx>=a.px1&&lx<=a.px3&&ly>=a.py1&&ly<=a.py3)
	{
	   scrltoXY(lx,ly,70,-40);
	}
	else
	{ 
	  go2xy(lx,ly);
	  scrltoXY(lx,ly,70,-40);
	}

}
searchHelper.prototype.scrl1 = function(i)
{
	
	var lx = sData.x[i];
	var ly = sData.y[i];
	var a = mapAbb();
    var sizex = 150;
	var sizey = 0;
	var scrl_lx=GetCenterx()-lx;
	var scrl_ly=GetCentery()-ly;
	scrl_lx=scrl_lx/Math.pow(2,GetZoom()-1);
	scrl_ly=scrl_ly/Math.pow(2,GetZoom()-1);
	scrl_lx=scrl_lx-sizex;
	scrl_ly=scrl_ly+sizey;
	if(lx>=a.px1&&lx<=a.px3&&ly>=a.py1&&ly<=a.py3)
	{
	   scrl(scrl_lx,scrl_ly);
	}
	else
	{
		go2xy(lx,ly);
	}

}
searchHelper.prototype.manageString = function(str,len)
{
    if(typeof(str)=="undefined")
    {
     return '';
    }
	if(strLength(str)>len)
	{
		str = getsubstr(str,len)+'..';
	}
	str = str.toString();
	str = str.replace(sData.keyWord,'<font color="red">'+sData.keyWord+'</font>');
	return str;
}
function putPopBarInfoByPage(currentpage)
{
  if(currentpage)
  {
   objSearch.page=currentpage;
  }
  objSearch.putPopBarInfo();
}
var objSearch = new searchHelper();