var citycode;
function getstation(obj)
{
	var sel = document.getElementById("f_station");
	cleardata(sel);
	if(obj.selectedIndex==0||obj.value=="")
	{
		sel.options.add(new Option("选择展馆",""));
		return;
	}
	sel.options.add(new Option("数据加载中...",""));

	citycode = obj.value;
	var mls = new MLocalSearch();   
    var mlsp = new MLocalSearchOptions();   
    mls.setCallbackFunction(getAllstation); 
	mlsp.dataSources = MLocalSearch.USERPOI;
	mlsp.recordsPerPage = 50;
	
	mlsp.dataType = "旅之窗展馆";
	mlsp.eid = "5630";//企业ID
	mlsp.userId = "35072";//用户ID
    mls.poiSearchByKeywords("旅之窗展馆",citycode,mlsp);     
}

function getAllstation(data)
{
	var sel = document.getElementById("f_station");
	
	if (data.count != 0) 
	{
		for (var i = 0; i < data.poilist.length; i++) 
		{
			sel.options.add(new Option(data.poilist[i].name,data.poilist[i].x+"_"+data.poilist[i].y));
		}
		sel.options[0].text = "选择展馆";
	}
	else
	{
		sel.options[0].text = "此城市没有找到展馆";
	}
}
var point = null;
var curentpagenumber = 1;
var priorpagenumber = 1;
var totpagenum = 1;

function searchByKeyword(curpage)
{
	var sel = document.getElementById("f_station");
	if(sel.selectedIndex == 0)
	{
		alert("请选择展馆");
		return;
	}
	var point = sel.value.split("_");
	
	mapObj.removeAllOverlays();//在每次执行新查询时，先删除已经查出的POI点
	//以下是从文本框中得到查询参数
	var p_citycode = citycode;
	var p_keyword = "宾馆";
	curentpagenumber = curpage;

	var mls = new MLocalSearch();   
    var mlsp = new MLocalSearchOptions();   
    mls.setCallbackFunction(keywordCallBack);   
		
	mlsp.dataSources = MLocalSearch.USERPOI;
	
	mlsp.dataType = "住宿服务";
	mlsp.eid = "5630";//企业ID
	mlsp.userId = "35072";//用户ID
	
	mlsp.recordsPerPage = 10;
	mlsp.pageNum = curpage;	
	mlsp.range = document.getElementById("f_type").value;	
	
	mls.poiSearchByCenterXY(new MLngLat(point[0],point[1]),p_keyword,p_citycode,mlsp);//centerXY,keywords,citycode,localSearchOptions
}

function keywordCallBack(data)
{
	//判断返回值是否为空
	//document.getElementById("aaaaa").innerHTML = JSON.stringify(data);   
	//return;
	var html = "	<div class='main_r_b_t'><img src='/image/emap07.gif' alt='查询结果' /></div>";
	html += "			<div class='main_r_b_m'>";
	html += "			<ul class='hotel_ul' >";

	if (data.count != 0) {
		//在html里加入表格
		var hotelarr = new Array();
		totpagenum= Math.ceil(data.count/10)   ;
		for (var i = 0; i < data.poilist.length; i++) {
			//用data.poilist[i].属性名称 得到值
			var pid = data.poilist[i].pguid;
			var data_citycode = data.poilist[i].citycode;
			var x = data.poilist[i].x;
			var y = data.poilist[i].y;
			var v_page;
			
			var pointStyle = new MMarkerOptions();   
            pointStyle.canShowTip = true;   
            pointStyle.isDimorphic = true;
			pointStyle.dimorphicColor = "0x00ff00"
			pointStyle.imageUrl ="http://map.tabimado.net.cn/image/marker_"+(i+1)+".png";  
			
		    var type = data.poilist[i].type;
		    if (type == "" || type == "undefined" || type == null) {
		    	type = "";
		    }
		    var address = data.poilist[i].address;
			/*if (address.indexOf('$')>0){
				address = address.substring(0,address.indexOf('$'));}*/

		    if (address == "" || address == "undefined" || address == null) {
		    	address = "";
		    }
		    /*var urlid = data.poilist[i].url;
		    if (urlid == "" || urlid == "undefined" || urlid == null) {
		    	urlid = "暂无";
		    }*/	    
		    var tel = data.poilist[i].tel;
		    if (tel == "" || tel == "undefined" || tel == null) {
		    	tel = "";
		    }	    
			var href_around_here ="aroundsearch.html?a,"+data_citycode+","+escape(data.poilist[i].name)+","+x+","+y+",NAN";//+$('f_hotelname').value;
			var href_from_here = "transport.html?b," + data_citycode + "," + data_citycode + "," + escape(data.poilist[i].name) + "," + escape("NAN") ;
			var href_to_here =  "transport.html?b," + data_citycode + "," + data_citycode + "," + escape("NAN")+ "," + escape(data.poilist[i].name)   ;
			
		    var sContent = "<br/>";

		   	if (!address == "" && address != null) {
				sContent += "&nbsp;<font color='#000000'>地址:"+address+"</font><br/>";
			}
			if (!tel == "" && tel != null) {
				sContent += "&nbsp;<font color='#000000'>电话:"+tel+"</font><br/>";
			}
			/*if (!urlid == "" && urlid != null) {
				if (urlid == "暂无")
				{sContent += "&nbsp;<font color='#000000'>"+urlid+"</font><br/>";
				}else{	
				sContent += "&nbsp;<u><font color='#000000'>"+urlid+"</font></u><br/>";}
			}*/
			//sContent += "<font color='#000000'><a href=\"javascript:jumpurl('" + href_around_here + "');\"><u>周边搜索</u></a>&nbsp;<a href=\"javascript:jumpurl('" + href_from_here + "');\"><u>从这里去</u></a>&nbsp;<a href=\"javascript:jumpurl('" + href_to_here + "');\"><u>到这里来</u></a>&nbsp;<a href=\"javascript:zoom('"+x+"','"+y+"')\"><u>定位放大</u></a></font>";
			sContent += "&nbsp;<font color='#000000'><a href=\"" + hosturl + "/hotelinfo/" + data.poilist[i].extid + "\"  target=\"_blank\"><u>详细信息</u></a>&nbsp;<a href=\"javascript:jumpurl('" + href_around_here + "');\"><u>周边搜索</u></a>&nbsp;<a href=\"javascript:jumpurl('" + href_from_here + "');\"><u>从这里去</u></a>&nbsp;<a href=\"javascript:jumpurl('" + href_to_here + "');\"><u>到这里来</u></a>&nbsp;<a href=\"javascript:zoom('"+x+"','"+y+"','+(i+1)+')\"><u>定位放大</u></a></font>";
			
			var tipOption = new MTipOptions();   
            tipOption.title="<a href=\"" + hosturl + "/hotelinfo/" + data.poilist[i].extid + "\"  target=\"_blank\">"+(i+1)+".  <u>"+data.poilist[i].name+"</u></a>";		
			var mfontstyle=new MFontStyle();
			mfontstyle.size=14;
			mfontstyle.bold=true;
			tipOption.titleFontStyle=mfontstyle;
            tipOption.content=sContent;  //tip内容   
            var mfillstyle=new MFillStyle();  //定义填充类   
                mfillstyle.color=0x99FF33;   
                mfillstyle.alpha = 1;   
            tipOption.titleFillStyle = mfillstyle;   
            var linestyle = new MLineStyle();   
                linestyle.thickness = 2;    
                linestyle.color = 0x00BD0A;   
                linestyle.alpha = 1;   
            tipOption.borderStyle = linestyle;   
            pointStyle.tipOption = tipOption;    
			
			var ll=new MLngLat(x,y);   
            var pointsearch =  new MMarker(ll,pointStyle);   
			pointsearch.id=(i+1);  
			hotelarr.push(pointsearch);
			
			html += "<li class='hotel_li' onclick=\"mapObj.setCenter(new MLngLat('"+x+"','"+y+"'));mapObj.openOverlayTip('"+(i+1)+"')\"   style='cursor:pointer'>"+(i+1)+".  "+data.poilist[i].name+"</li>";
		}
		
		html +="<li class='hotel_li1'>[&nbsp;";
		var lastIntNum;
		var totIntNum;
		if(totpagenum%5==0){totIntNum = totpagenum/5 - 1;}
		else{totIntNum = Math.floor(totpagenum/5);}
		if (curentpagenumber%5==0){lastIntNum=curentpagenumber/5-1;}
		else{lastIntNum=Math.floor(curentpagenumber/5);	}
		
		if  (lastIntNum>0 ) {html +="<a href='javascript:searchByKeyword("+(5*lastIntNum)+")'><<&nbsp;</a>";};
		for (var i = (5*lastIntNum);  i < (5*lastIntNum+5); i++) { 
			if ( (i+1) == curentpagenumber) {html +=""+(i+1)+"&nbsp;</a>";}
			else
			{html +="<a href='javascript:searchByKeyword("+(i+1)+")'>"+(i+1)+"&nbsp;</a>";	}
			if ( (i+1) == totpagenum ) {break;}
		};
		if (lastIntNum<totIntNum) {
			html +="<a href='javascript:searchByKeyword("+( 5*lastIntNum+6)+")'>>>&nbsp;</a>";
		};
		html +="]</li>";
		html +="<li class='hotel_li1'>page("+curentpagenumber+"/<a href='javascript:searchByKeyword("+totpagenum+")'>"+totpagenum+"</a>)&nbsp;<a href='javascript:searchByKeyword(1)'>返回</a></li>";
		
		priorpagenumber = curentpagenumber;		
		
		mapObj.addOverlays(hotelarr, true); 
	} 
	else {
		alert("对不起！此城市没有您要查找的关键字");
	}
	html += "</ul>";
	html += "		</div>";
	html += "	<div class='main_r_b_b'><img src='/image/emap22.gif'></div>";
	$('#result').html(html);
}

function cleardata(obj)
{
	for(i=obj.length-1;i>=0;i--)
    {
		obj.remove(i);
	}
}
function zoom(x,y)
{
	mapObj.setZoomAndCenter(17,new MLngLat(x,y));
}
function selectstation(obj)
{
	var point = obj.value.split("_");
	zoom(point[0],point[1]);
}
function jumpurl(s){
	location.href = s;
}
