﻿var RANGE = 5000;
var MAP_WIDTH = 570;
var MAP_HEIGHT = 420;
var rownume = 9;
var nRouteStyle = 0;

function openwin(myurl){ 
    window.open(myurl,"","height=171,width=240,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no"); 
}
		
//nearby search
function nbSub(obj, str) {
    if(str == "1")
    {
	    if($("PointLatlon").value!='')
	    {
	       $("destLatlon").value = '';
           $("destName").value = '';
	       getDataByHash("#ac=nb&strlatlon=" + $("PointLatlon").value + "&city=" + $("city").value + "&customer=0&range=" + RANGE + "&width=" + MAP_WIDTH + "&height=" + MAP_HEIGHT + "&pn=1&rn="+rownume); 
	    }
	    else
	    {
	        kw = $("keyword").value;
	        if (kw == "您在本市的目的地") 
	            kw = "";
	        $("PointLatlon").value='';
	        $("destLatlon").value = '';
            $("destName").value = '';
	        if(kw == "")
	           getDataByHash("#ac=nb&keyword=" + kw + "&city=" + $("city").value + "&customer=0&range="+ RANGE +"&width=" + MAP_WIDTH + "&height=" + MAP_HEIGHT + "&pn=1&rn="+rownume);
	        else
	           getDataByHash("#ac=destnb&keyword=" + kw + "&city=" + $("city").value + "&customer=0&range="+ RANGE +"&width=" + MAP_WIDTH + "&height=" + MAP_HEIGHT + "&pn=1&rn="+rownume);
	    }
	}
	else if(str == "2")
	{
	   if($("selectdest").value != ""){
	       $("destLatlon").value = $("selectdest").options[$("selectdest").selectedIndex].value;
	       $("destName").value = $("selectdest").options[$("selectdest").selectedIndex].text;
	       getDataByHash("#ac=nb&strlatlon=" + $("destLatlon").value + "&strname=" + $("destName").value + "&city=" + $("city").value + "&customer=0&range=" + RANGE + "&width=" + MAP_WIDTH + "&height=" + MAP_HEIGHT + "&pn=1&rn="+rownume);
	   }
	   else
	   {
	       alert("请选择目的地！");
           $("selectdest").focus();
	   }
    }
}

function hotelRoute(hotellatlon,hotelname) {
     latlon1 =  $("destLatlon").value || $("PointLatlon").value;
     name1 = $("destName").value;
     if(latlon1 != '')
     {
        var busrurl="#ac=dnsr&origCity="+$("city").value+"&origLatLon="+latlon1+"&origName="+name1+"&destCity="+$("city").value+"&destLatLon="+hotellatlon+"&destName="+hotelname;
        getDataByHash(busrurl);
     }
}

function nbSubhotel(obj) {
    var kw;
    if(($("selectClass").value != "") || ($("keyword").value !="" && $("keyword").value != "所要查询的目的地")){
        rs_Panel = $("boxcontent");
        if($("keyword").value == "所要查询的目的地")
            kw = ""
        else
            kw = $("keyword").value;
        rs_Panel = $("query_over");
        rs_Panel.innerHTML = "<p>查询中，请稍后...</p>";
        var myurl="#ac=zb&strlatlon=" + $("strlatlon").value + "&city=" + $("city").value + "&poitype=" + $("selectClass").value + "&keytype=" + kw + "&range=" + RANGE + "&pn=1&rn="+rownume;
        getDataByHash(myurl);
    }
    else
    {
        alert("请输入所要查询的目的地！");
        $("keyword").focus();
    }
}
function listToSub(action) {
    var kw;
    if(($("toKeyword").value != "") && ($("toKeyword").value != "目的地的关键词或地址")){
        rs_Panel = $("boxcontent");
        kw = $("toKeyword").value;
        if(kw == "目的地的关键词或地址")
            kw = "";
                
        var busurl="#ac=lst&City="+$("city").value+"&Name="+kw+"&type="+action;
        getDataByHash(busurl);
    }
    else
    {
        alert("请输入目的地的关键词或地址！");
        $("toKeyword").focus();
    }
}
function listFromSub(action) {
    var kw;
    if($("fromKeyword").value !="" && $("fromKeyword").value != "出发地的关键词或地址"){
        rs_Panel = $("boxcontent");
        kw = $("fromKeyword").value;
        if(kw == "出发地的关键词或地址")
            kw = "";
                
        var busurl="#ac=lsf&City="+$("city").value+"&Name="+kw+"&type="+action;
       
        getDataByHash(busurl);
    }
    else
    {
        alert("请输入出发地的关键词或地址！");
        $("fromKeyword").focus();
    }
}
function busSub(obj) {
    if($("selectstar").value != "" && $("selectend").value != ""){
        var busrurl="#ac=bsr&city="+$("city").value+"&origLatLon="+$("selectstar").options[$("selectstar").selectedIndex].value+"&origName="+$("selectstar").options[$("selectstar").selectedIndex].text+"&destLatLon="+$("selectend").value+"&destName="+$("selectend").options[$("selectend").selectedIndex].text;
        getDataByHash(busrurl);
    }
    else
    {
        alert("请选择起点和终点！");
        if($("selectstar").value == "")
            $("selectstar").focus();
        if($("selectend").value == "")
            $("selectend").focus();
    }
}

function routeSub(obj) {
    if($("selectstar").value != "" && $("selectend").value != ""){
        var busrurl="#ac=nsr&origCity="+$("city").value+"&origLatLon="+$("selectstar").options[$("selectstar").selectedIndex].value+"&origName="+$("selectstar").options[$("selectstar").selectedIndex].text+"&destCity="+$("city").value+"&destLatLon="+$("selectend").value+"&destName="+$("selectend").options[$("selectend").selectedIndex].text;
        getDataByHash(busrurl);
    }
    else
    {
        alert("请选择起点和终点！");
        if($("selectstar").value == "")
            $("selectstar").focus();
        if($("selectend").value == "")
            $("selectend").focus();
    }
}


function nbSubhotelClass(obj,flag) {
    var kw;
    $("selectClass").value=flag;
    if((flag != "")){
        
        kw = ""
        var myurl="#ac=sctext&strlatlon=" + $("strlatlon").value + "&city=" + $("city").value + "&poitype=" + flag + "&keytype=" + kw + "&range=" + RANGE + "&pn=1&rn="+rownume;
        getDataByHash(myurl);
    }
    else
    {
        alert("请输选择分类！");
    }
}

//==================================nbsub==============================================//
function getDataByHash(newUrl) {
    var Request = request.init(newUrl);
    Request.width = Request.width || Element.getWidth("mapbar") || 570;
    Request.height = Request.height || Element.getHeight("mapbar") || 420;
   
    var url = "";
    if (Request.ac == "nb") {
        url = json_hotel_latlon + "?strlatlon=" + (Request.strlatlon || '') + "&keyword=" + encodeDURI(Request.keyword || "") + "&city=" + encodeDURI(Request.city || "上海市") + "&range=" + (Request.range||RANGE) +"&width=" + Request.width + "&height=" + Request.height + "&pn=" + (Request.pn || "1")+"&rn="+rownume;
        new Transfer.Request(url, {oncomplate:function () { cbk("1"); }});
    }
    else if (Request.ac == "nbc") {//查询本城市的所有酒店
        url = json_hotel_latlon + "?city=" + encodeDURI(Request.city || "上海市") + "&width=" + Request.width + "&height=" + Request.height + "&pn=" + (Request.pn || "1")+"&rn="+rownume;
        new Transfer.Request(url, {oncomplate:function () { cbk("15"); }});
    }else if (Request.ac == "destnb") {
        var desturl = json_keyword + "?city=" + encodeDURI(Request.city || "北京市") + "&keyword=" + encodeDURI(Request.keyword || "") + "&rn=20";
        new Transfer.Request(desturl, {oncomplate:function () { cbk("13"); }});
    }else if (Request.ac == "cd") {
        url = json_hotelcd + "?hotelcd="+(Request.hotelcd || "");
        new Transfer.Request(url, {oncomplate:function () { cbk("2"); }});
    }
    else if (Request.ac == "mcd") {
        url = json_hotelcd + "?hotelcd="+(Request.hotelcd || "");
        new Transfer.Request(url, {oncomplate:function () { cbk("12"); }});
    }
    else if (Request.ac == "zb") {
        var nearurl = json_nearby + "?strlatlon=" + (Request.strlatlon || "HEJWACXVVHEGS") + "&city=" + encodeDURI(Request.city || "北京市") + "&poitype=" + (Request.poitype || "") + "&keytype=" + encodeDURI(Request.keytype || "") + "&range="+ Request.range +"&width=" + Request.width + "&height=" + Request.height 
            + "&pn=" + (Request.pn || "1")+"&rn="+rownume;
        new Transfer.Request(nearurl, {oncomplate:function () { cbk("3"); }});
    }else if (Request.ac == "lst") {
         var busurl = json_busl + "?City=" + encodeDURI(Request.City || "北京市") + "&Name=" + encodeDURI(Request.Name || "") + "&type=" + (Request.type || "bus");
         var lt = Request.type || "bus";
         if(lt == "bus")
            new Transfer.Request(busurl, {oncomplate:function () { cbk("4"); }});
         else
            new Transfer.Request(busurl, {oncomplate:function () { cbk("7"); }});
    } else if (Request.ac == "lsf") {
         var busurl = json_busl + "?City=" + encodeDURI(Request.City || "北京市") + "&Name=" + encodeDURI(Request.Name || "") + "&type=" + (Request.type || "bus");
         var lt = Request.type || "bus";
         if(lt == "bus")
            new Transfer.Request(busurl, {oncomplate:function () { cbk("6"); }});
         else
            new Transfer.Request(busurl, {oncomplate:function () { cbk("8"); }});
         
    }else if (Request.ac == "bsr") {
         var busurl = json_busr + "?city="+ encodeDURI(Request.city || "北京市") +"&origLatLon="+(Request.origLatLon || "")+"&origName="+encodeDURI(Request.origName || "")+"&destLatLon="+(Request.destLatLon || "")+"&destName="+encodeDURI(Request.destName || "")+"&encode=utf-8";
         new Transfer.Request(busurl, {oncomplate:function () { cbk("5"); }});
    }else if (Request.ac == "nsr") {
         nRouteStyle = Request.style||0;
         var navurl = json_navr + "?style="+(Request.style||0)+"&origCity="+ encodeDURI(Request.origCity || "北京市") +"&origLatLon="+(Request.origLatLon || "")+"&origName="+encodeDURI(Request.origName || "")+"&destCity="+encodeDURI(Request.destCity||"",1)+"&destLatLon="+(Request.destLatLon || "")+"&destName="+encodeDURI(Request.destName || "")+"&encode=utf-8";
         new Transfer.Request(navurl, {oncomplate:function () { cbk("9"); }});
    }else if (Request.ac == "dnsr") {
         nRouteStyle = Request.style||0;
         var navurl = json_navr + "?style="+(Request.style||0)+"&origCity="+ encodeDURI(Request.origCity || "北京市") +"&origLatLon="+(Request.origLatLon || "")+"&origName="+encodeDURI(Request.origName || "")+"&destCity="+encodeDURI(Request.destCity||"",1)+"&destLatLon="+(Request.destLatLon || "")+"&destName="+encodeDURI(Request.destName || "")+"&encode=utf-8";
         new Transfer.Request(navurl, {oncomplate:function () { cbk("14"); }});
    }
    else if (Request.ac == "sc") {
         url = json_hotelcd + "?hotelcd="+(Request.hotelcd || "1");
         new Transfer.Request(url, {oncomplate:function () { cbk("10"); }});
    }else if (Request.ac == "sctext") {
        
        var nearurl = json_nearby + "?strlatlon=" + (Request.strlatlon || "HEJWACXVVHEGS") + "&city=" + encodeDURI(Request.city || "北京市") + "&poitype=" + (Request.poitype || "") + "&keytype=" + encodeDURI(Request.keytype || "") + "&range="+ Request.range +"&width=" + Request.width + "&height=" + Request.height 
            + "&pn=" + (Request.pn || "1")+"&rn="+rownume;
            
        new Transfer.Request(nearurl, {oncomplate:function () { cbk("11"); }});
    }  
}

function cbk(obj) {
    obj = parseInt(obj);
    switch (obj) {
        case 1:
            lsCbk.init("nb");
            break;
        case 2:
            hotelCbk.init("cd");
            break; 
        case 3:
            hotelNearbyCbk.init("zb");
            break;
        case 4:
            listToCbk.init("bus");
            break;
        case 5:
            bsCbk.init("bsr");
            break;
        case 6:
            listFromCbk.init("bus");
            break; 
        case 7:
            listToCbk.init("route");
            break;
        case 8:
            listFromCbk.init("route");
            break;  
        case 9:
            navCbk.init("nsr");
            break;  
        case 10:
            hotelCbk.init("sc");
            break;
        case 11:
            SctextCbk.init("sctext");
            break; 
        case 12:
            hotelCbk.init("mcd");
            break; 
        case 13:
            destCbk.init("destnb");
            break; 
        case 14:
            navCbk.init("dnsr");
            break; 
        case 15:
            lsCbk.init("nbc");
            break; 
        default:
    }
}
function showBlock(showname) {
    if($("boxcontent"))
        $("boxcontent").style.display = "none";
    if($("query_over"))
        $("query_over").style.display = "none";
    if($("bus"))
        $("bus").style.display = "none";
    if($("route"))
        $("route").style.display = "none";
    if($("query_dest"))
        $("query_dest").style.display = "none";
    if($(showname))
        $(showname).style.display = "block";
}
function NoMessage(blockname) {
        showBlock(blockname);
        rs_Panelss = $(blockname);
        rsAss = [];
        rsAss.push("<p class=\"title_back\"><a  href=\"javascript:void(0);\" onclick=\"showBlock('boxcontent');\" >返回</a></p>");
        rsAss.push("<div class='main_select'>");
        rsAss.push("<p>没有查询到结果！</p>");
        rsAss.push("</div>");
        rs_Panelss.innerHTML = rsAss.join("");
}
function show_LIbgC(num4c){
    for(j=0;j<100;j++)
    {
        if($('LIbgC0'+j))
        {
            $('LIbgC0'+j).style.background='';
        }
    }
    $('LIbgC0'+num4c).style.background='#D5EAD9';
}    

var destCbk = {
    init:function (action) {
        if (typeof APRS == "undefined") {
            throw new Error("failed to get destination point, some error occured,Please try again later.");
        }
        pois = APRS.result;
        lsCbk.clearPoi();
        lsCbk.clearLine();
        if(pois.length > 0)
        {
            destCbk.printPoint(action,pois);
        }else
        {
            NoMessage("query_dest");
        }
    },
    printPoint:function (action,pois) {
         showBlock("query_dest");
         rsArr = [];
         
         rs_Panel = $("query_dest"); 
         rsArr.push("<p class=\"title_back\"><a  href=\"javascript:void(0);\" onclick=\"showBlock('boxcontent');\" >返回</a></p>");
         rsArr.push("<div class='main_select'>");
         rsArr.push("<p>目的地：</p>");
         rsArr.push("<select name='' size=10 style='width:204px;' id='selectdest' onchange=\"destCbk.addDestPoint(this.options[this.selectedIndex].value,this.options[this.selectedIndex].text);\" >");
         for (var i = 0; i < pois.length; i++) {
            var poi = pois[i];
            rsArr.push("<option value='"+poi.strlatlon+"'" );
            if(i == 0){
                rsArr.push(" SELECTED");
                destCbk.addDestPoint(poi.strlatlon,poi.name);
            }
            rsArr.push(" > "+poi.name+"</option>"); 
         }
         rsArr.push("</select>");
         rsArr.push("<p style=\"text-align:center;margin-top:5px;\"><input type=\"image\" src=\"images/Part3_1202-map_d-2_10.jpg\" align=\"absmiddle\" border=\"0\" onclick=\"nbSub(this,2);return false;\" /></p>");
         rsArr.push("</div>");
         rs_Panel.innerHTML = rsArr.join("");
         
    },
    addDestPoint:function(latlon,name)
    {
        maplet.clearOverlays();
        maplet.centerAndZoom(latlon, 12);
        var marker = new MMarker(new MPoint(latlon),new MIcon("images/tack.gif"),null,new MLabel(name));
        maplet.addOverlay(marker);
    }
 }
/*bus result cbk search callback*/
var bsCbk = {
    init:function (action) {
        showBlock("bus");
        rs_Panel = $("bus"); 
        if (typeof busResult == "undefined") {
            throw new Error("failed to get bus result, some error occured,Please try again later.");
        }
        buses = busResult.bus.item;
        rsArr = [];
        rsArr.push("<p class=\"title_back\"><a  href=\"javascript:void(0);\" onclick=\"showBlock('boxcontent');\" >返回</a></p>");
        rsArr.push("<div class='bus_select'>");
        rsArr.push("<ol>");
        for (var ic = 0; ic < buses.length; ic++) {
            rsArr.push("<li onclick=\"show_LIbgC("+ic+");bsCbk.addLine("+ic+")\" id=\"LIbgC0"+ic+"\" title=\"查看此条线路\" style=\"cursor:pointer;\"");
            if(ic == 0) rsArr.push("style=\"background:#D5EAD9;\"");
            rsArr.push(">");
            rsArr.push(bsCbk.getDetail(ic));
            rsArr.push("<p>距离" + buses[ic].distance + "公里</p></li>");
        }
        if(buses.length==0){
            rsArr.push("<p>查询结果为空，请更换查询条件！</p>");
        }
        rsArr.push("</ol>");
        rsArr.push("</div>");
        if($("route"))
            $("route").innerHTML="";
        rs_Panel.innerHTML=rsArr.join("");
        setTimeout(function(){bsCbk.addLine(0);},250);        
    },
    getDetail:function(ic){
        if(busResult.issmallcity=="true"){
            return  busResult.bus.item[ic].detail;
        }
        var detail=[];
        var stations=busResult.bus.item[ic].stations;
        for(var i=0;i<stations.length;i++){
            //如果线路的起点与查询起点不同，则需步行  huo 如果两条线路的换乘点不在一起，则步行
            var needWalk=false;
            if((i==0&&stations[i].pois[0][0]!=busResult.orig.name)||(i>0&&stations[i].pois[0][0]!=stations[i-1].pois[stations[i-1].pois.length-1][0])){
                needWalk=true;
            }
            if(needWalk){
                if(i>0)detail.push(",");
                detail.push("步行至<b>"+stations[i].pois[0][0]+"</b>");
            }
            var target="#ac=l&city="+encodeDURI(busResult.city)+"&keyword="+encodeDURI(stations[i].name,1);
            if(needWalk||i>0){detail.push(",");}
            detail.push("乘<u>" + stations[i].name + "</u>");
            detail.push(",至<b>" + stations[i].pois[stations[i].pois.length-1][0]+"</b>下车");
        }
        //如果线路的终点与查询终点不同，则需步行
        if(stations[stations.length-1].pois[stations[i-1].pois.length-1][0] != busResult.dest.name){
            detail.push(",步行至<b>" + busResult.dest.name+"</b>");
        }
        return detail.join("");
    },    
    addLine:function(i){
        if(busResult.bus.item.length==0){return;}
        i = i|| 0;
        if(busResult.issmallcity=="true") return ;
        maplet.centerAndZoom(busResult.bus.item[i].routecenter,busResult.bus.item[i].routezoom);
        lsCbk.clearLine();
        lsCbk.clearPoi();
        obj=new MapLine();
        this.addPois(i);
        this.addBusLine2(i);
        maplet.refresh();
     },
     addBusLine2:function(i){
         this.addLineItem("bus_line_",busResult.bus.item[i].routelatlons.toString());
     },
     addLineItem:function(id,strlatlon,color){
        var obj=new MapLine();
        obj.id=id;
        obj.method=1;
        obj.strlatlon=strlatlon;
        if(color){obj.color=color;}
        window.addLine(obj);
     },
     addPois:function(i){
        var pois=[];
        pois.push([busResult.orig.strlatlon,busResult.orig.name,busResult.city,"images/qidian.gif"]);
        pois.push([busResult.dest.strlatlon,busResult.dest.name,busResult.city,"images/zhongdian.gif"]);
        for(var ic = 0; ic < busResult.bus.item[i].pois.length; ic++){
            pois.push([busResult.bus.item[i].pois[ic].point,busResult.bus.item[i].pois[ic].name,busResult.city,"images/zhuan.gif"]);
        }
       
       for(var i=0;i<pois.length;i++){
            window.addPoint(pois[i][3],pois[i][0],pois[i][1],"",false,true);
        }
     }
}
 
function addPointbus(latlon, name, flag){
    latlon = latlon || "";
    var icon="images/zhongdian.gif";
    if(flag == 2){
        icon="images/qidian.gif";
    }
    else if(flag == 3){
        icon="images/tack.gif";
    }
    maplet.centerAndZoom(latlon, 12);
    var obj;
    if(getPoiById("list_"+flag)!=null) {
            obj = getPoiById("list_"+flag);
            obj.strlatlon=latlon;
            if(obj.strlatlon=="")return;
            obj.name=name;
            obj.icon=icon;
            obj.showIconName=true;
            window.updatePoi(obj);
    } else {
        obj = new MapPoi();
        obj.id = "list_"+flag;
        obj.strlatlon=latlon;
        if(obj.strlatlon=="")return;
        obj.name=name;
        obj.icon=icon;
        obj.showIconName=true;
        window.addPoi(obj);
    }
 }
 
/*listToCbk search callback*/
var listToCbk = {
    init:function (action) {
        if (typeof station == "undefined") {
            throw new Error("failed to get destination point, some error occured,Please try again later.");
        }
        
        pois = station.kvps;
        lsCbk.clearPoi();
        lsCbk.clearLine();
        if(pois.length > 0)
        {
            listToCbk.printPoint(action,pois);
        }else
		{
			NoMessage("bus");
		}
    },
    printPoint:function (action,pois) {
         showBlock("bus");
         rsArr = [];
         
         rs_Panel = $("bus"); 
         rsArr.push("<p class=\"title_back\"><a  href=\"javascript:void(0);\" onclick=\"showBlock('boxcontent');\" >返回</a></p>");
         rsArr.push("<div class='main_select'>");
         rsArr.push("<p>出发地：</p>");
         rsArr.push("<select name='' size=5 style='width:204px;height:124px;' id='selectstar' onchange=\"addPointbus(this.options[this.selectedIndex].value,this.options[this.selectedIndex].text);\">");
         rsArr.push("<option value="+$("strlatlon").value+" SELECTED>"+$("hotelnm").value+"</option>");
         rsArr.push("</select>");
         rsArr.push("<p>目的地：</p>");
         rsArr.push("<select name='' size=5 style='width:204px;height:124px;' id='selectend' onchange=\"addPointbus(this.options[this.selectedIndex].value,this.options[this.selectedIndex].text,1);\" >");
        
         for (var i = 0; i < pois.length; i++) {
            var poi = pois[i];
            rsArr.push("<option value='"+poi.strlatlon+"'" );
            if(i==0){
                rsArr.push(" SELECTED");
                addPointbus(poi.strlatlon,poi.name,1);
            }
            rsArr.push(" > "+poi.name+"</option>"); 
         }
         rsArr.push("</select>");
         if(action == "bus")
            rsArr.push("<p style='text-align:center'> <input type='image' src='images/Part3_1202-map_d-2_10.jpg' align='absmiddle' border='0' onclick=\"busSub(this);return false;\" /></p>");
         else
            rsArr.push("<p style='text-align:center'> <input type='image' src='images/Part3_1202-map_d-2_10.jpg' align='absmiddle' border='0' onclick=\"routeSub(this);return false;\" /></p>");

         rsArr.push("</div>");
         
         rs_Panel.innerHTML = rsArr.join("");
    
    }
 }
/*listFromCbk search callback*/
var listFromCbk = {
    init:function (action) {
      
        if (typeof station == "undefined") {
            throw new Error("failed to get start point, some error occured,Please try again later.");
        }
        
        pois = station.kvps;
        lsCbk.clearPoi();
        lsCbk.clearLine();
        if(pois.length > 0)
        {
            listFromCbk.printPoint(action,pois);
        }else
		{
			NoMessage("bus");
		}
    },
    printPoint:function (action,pois) {
         showBlock("bus");
         rsArr = [];
         
         rs_Panel = $("bus"); 
         rsArr.push("<p class=\"title_back\"><a  href=\"javascript:void(0);\" onclick=\"showBlock('boxcontent');\" >返回</a></p>");
         rsArr.push("<div class='main_select'>");
         rsArr.push("<p>出发地：</p>");
           rsArr.push("<select name='' size=5 style='width:204px;height:124px;' id='selectend' onchange=\"addPointbus(this.options[this.selectedIndex].value,this.options[this.selectedIndex].text,2);\">");
         for (var i = 0; i < pois.length; i++) 
         {
            var poi = pois[i];
            rsArr.push("<option value='"+poi.strlatlon+"'") ;
            if(i==0){
                rsArr.push(" SELECTED");
                addPointbus(poi.strlatlon,poi.name,2);
            }
            rsArr.push(">"+poi.name+"</option>");
         }
         rsArr.push("</select>");
         
         rsArr.push("<p>目的地：</p>");
         rsArr.push("<select name='' size=5 style='width:204px;height:124px;' id='selectstar'>");
         rsArr.push("<option value="+$("strlatlon").value+" SELECTED>"+$("hotelnm").value+"</option>");
         rsArr.push("</select>");
         
         if(action == "bus")
            rsArr.push("<p style='text-align:center'> <input type='image' src='images/Part3_1202-map_d-2_10.jpg' align='absmiddle' border='0' onclick=\"busSub(this);return false;\" /></p>");
         else
            rsArr.push("<p style='text-align:center'> <input type='image' src='images/Part3_1202-map_d-2_10.jpg' align='absmiddle' border='0' onclick=\"routeSub(this);return false;\" /></p>");

         rsArr.push("</div>");
         
         rs_Panel.innerHTML = rsArr.join("");
    
    }
 }
 

/*hotelNearbyCbk search callback*/
var hotelNearbyCbk = {
    init:function (action) {
        if (typeof MYNEAR == "undefined") {
            throw new Error("failed to get near by hotel, some error occured,Please try again later.");
        }
        pois = MYNEAR.result;
        if(typeof pois != "undefined")
        {
            hotelNearbyCbk.printPoint(pois, "images/icon.gif", MYNEAR.mapinfo.center, MYNEAR.mapinfo.scale);
        }
    }, 
    printPoint:function (pois, icon, center, zoom) {
        center = center || "";
        zoom = zoom || "";
        maplet.centerAndZoom(center, zoom);
        lsCbk.clearPoi();
        lsCbk.clearLine();
        rsArr = [];
        showBlock("query_over");
        rs_Panel = $("query_over");
        rsArr.push("<p style=\"position:relative;font-size:1px;height:1px;\"><a style=\"position:absolute;right:8px;top:-28px;\" href=\"javascript:void(0);\" onclick=\"showBlock('boxcontent');\">返回</a></p>");
        if(pois.length > 0)
        {
	        for (var i = 0; i < pois.length; i++) {
	            var poi = pois[i];
	            icon = "images/gif1/tb" + (i + 1) + ".gif";
	            rsArr.push("<p><a href=\"javascript:;\" onclick=\"showOpenWindow(" + i + ",'" + poi.strlatlon + "');\" title=\"" + poi.name + "\">" + poi.name + "</a></p>");
	            var detail = "<table border=0 width='100%' cellpadding='0' cellspacing='1'>" ;
	            detail += "<tr><td colspan=2 height=2><hr style=\"BORDER-BOTTOM-STYLE: dotted; BORDER-LEFT-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP-STYLE: none\" color=#000000 size=1></td><tr>";
	            detail += "<tr><td width=70 valign=top><b>地址:</b></td><td>" + poi.address + "</td></tr>";
	            detail += "<tr><td height=7></td><td></td></tr>";
	            detail += "<tr><td><b>联系电话:</b></td><td>" + poi.phone + "</td></tr>";
	            detail += "</table>&nbsp;";
	            window.addPoint(icon, poi.strlatlon, poi.name, detail, true, false);
	        }
	        
	        pageCtrlHotelNearby(MYNEAR.pn, MYNEAR.dn, MYNEAR.keyType, MYNEAR.poiTypeSrc, MYNEAR.city, MYNEAR.range, rsArr);
        }
        else
        {
            rsArr.push("<p>未找到合适信息！</p>");
            rsArr.push("<p>&nbsp;</p>");
            rsArr.push("<p>&nbsp;</p>");
            rsArr.push("<p>&nbsp;</p>");
            rsArr.push("<p>&nbsp;</p>");
            rsArr.push("<p>&nbsp;</p>");
            rsArr.push("<p>&nbsp;</p>");
            rsArr.push("<p>&nbsp;</p>");
            rsArr.push("<p>&nbsp;</p>");
        }
        rs_Panel.innerHTML = rsArr.join("");
    }
    
};

/*hotel search callback*/
var hotelCbk = {
    init:function (action) {
        if (typeof APRS == "undefined") {
            throw new Error("failed to get hotel detail, some error occured,Please try again later.");
        }
        pois = APRS.result;
        if(pois.length > 0)
        {
            hotelCbk.printHotel(action, pois, "images/rujia.gif", APRS.mapinfo.center, APRS.mapinfo.scale);
        }
        else
        {
            alert("没有这个酒店");
        }
    },
    printHotel:function (action, pois, icon, center, zoom) {
        center = center || pois[0].city;
        zoom = zoom || "9";
        maplet.centerAndZoom(new MPoint(center), zoom);
        lsCbk.clearPoi();
        lsCbk.clearLine();
        
        for (var i = 0; i < pois.length; i++) 
        {
            var poi = pois[i];
            var book_url = "http://www.homeinns.com/ResvHomeinns/Resv/resv_stage2_1.aspx?hotelcd=" + poi.hotelcd;
            var mail_url = "http://www.homeinns.com/ResvHomeinns/Resv/Resv_Map_Email.aspx?hotelcd=" + poi.hotelcd;
            var detail = "<table border=0 width='100%' cellpadding='0' cellspacing='1'>" ;
            detail += "<tr><td colspan=2 height=2><hr style=\"BORDER-BOTTOM-STYLE: dotted; BORDER-LEFT-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP-STYLE: none\" color=#000000 size=1></td><tr>";
            detail += "<tr><td width=70 valign=top><b>地址:</b></td><td>" + poi.address + "</td></tr>";
            detail += "<tr><td height=5></td><td></td></tr>";
            detail += "<tr><td valign=top><b>联系电话:</b></td><td>" + poi.tel + "</td></tr>";
            detail += "</table>&nbsp;";
            detail += "<table border=0 width='100%' cellpadding='0' cellspacing='1' style='margin-top:0px;'>";
            detail += "<tr><td width=140 align=center><a href='"+book_url+"'><img src='images/ding.jpg' border=0></a></td>";
            detail += "<td aligh=center><a href='javascript:openwin(\""+mail_url+"\");'><img src='images/mail.jpg' border=0></a></td>";
            detail += "</tr></table>";
            if(poi.strlatlon.length > 0)
            {
	            if(action != "mcd")
	                window.addPoint(icon, poi.strlatlon, poi.hotelnm, detail, true, false, false);
	            else
	                window.addPoint(icon, poi.strlatlon, poi.hotelnm, detail, false, false, false);
	        }
            if(action == "cd")
            {
	            $("strlatlon").value=poi.strlatlon;
	            $("city").options[0] = new Option(poi.city, poi.city);
	            $("hotelnm").value=poi.hotelnm;
	            $("citystr").innerHTML=poi.hotelnm;
	            $("citystr2").innerHTML=poi.hotelnm; 
	        }
	        else if(action == "sc")
	        {
	           $("detailtext").value=detail;
               $("strlatlon").value=poi.strlatlon;
               $("city").value=poi.city;
               $("hotelnm").value=poi.hotelnm;
	        }
        }
    }
};

/*SctextCbk search callback*/
var SctextCbk = {
    init:function (action) {
        if (typeof MYNEAR == "undefined") {
            throw new Error("failed to get near by hotel, some error occured,Please try again later.");
        }
        pois = MYNEAR.result;
        if(pois.length > 0)
        {
            SctextCbk.printPoint(pois, MYNEAR.mapinfo.center, MYNEAR.mapinfo.scale);
        }
        else
        {
            $("boxcontent").innerHTML="<p align='center'>未找到符合条件的结果！</p>";
            lsCbk.clearPoi();
            lsCbk.clearLine();
        }
        
    }, 
    printPoint:function (pois, center, zoom) {
        center = center || "";
        zoom = zoom || "";
        maplet.centerAndZoom(center, zoom);
        lsCbk.clearPoi();
        lsCbk.clearLine();
        rsArr = [];
        rs_Panel = $("boxcontent");
        rsArr.push("<ol class=\"mapOl\">");
        for (var i = 0; i < pois.length; i++) {
            var poi = pois[i];
            icon = "images/gif1/tb" + (i + 1) + ".gif"; 
            rsArr.push("<li><a href=\"javascript:;\" onclick=\"showOpenWindow(" + i + ",'" + poi.strlatlon + "')\" title=\"" + poi.name + "\">" + poi.name + "</a></li>");
            var detail = "<table border=0 width='100%' cellpadding='0' cellspacing='1'>" ;
                detail += "<tr><td colspan=2 height=2><hr style=\"BORDER-BOTTOM-STYLE: dotted; BORDER-LEFT-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP-STYLE: none\" color=#000000 size=1></td><tr>";
                detail += "<tr><td width=70 valign=top><b>地址:</b></td><td>" + poi.address + "</td></tr>";
                detail += "<tr><td height=7></td><td></td></tr>";
                detail += "<tr><td><b>联系电话:</b></td><td>" + poi.phone + "</td></tr>";
                detail += "</table>&nbsp;";
            window.addPoint(icon, poi.strlatlon, poi.name, detail, true, false);
        }
        rsArr.push("</ol>");
        pageCtrlScNearby(MYNEAR.pn, MYNEAR.dn, MYNEAR.keyType, MYNEAR.poiTypeSrc, MYNEAR.city, MYNEAR.range, rsArr);
        rs_Panel.innerHTML = rsArr.join("");
    }
};

function pageCtrlScNearby(nPage, tp,  keytype, poitype, city, range, rsArr) {
    tp = Math.ceil(parseInt(tp) / rownume);
    var nTotalPages = (tp > 100) ? 10 : tp;
    var iCurr = parseInt(nPage);
    var nTotalPage = nTotalPages;
    var iMinPage = Math.max(1, iCurr - 10);
    var iMaxPage = Math.min(nTotalPage, 10);
    rsArr.push("<div class=\"turnPage\">");
    if (iCurr > 1) {
        var hash = "#ac=sctext&city="+encodeDURI(city)+"&keytype="+encodeDURI(keytype)+"&range="+range+"&poitype="+poitype+"&pn="+(iCurr-1)+"&strlatlon="+$("strlatlon").value+"&rn="+rownume;        
        rsArr.push("<a href='" + hash + "' onclick=\"getDataByHash('" + hash + "');return false;\">&lt;  Prev</a>");
    }
    if (!$("divpage")) {
        for (var ie = iMinPage; ie <= iMaxPage; ie++) {
            if (ie == iCurr) {
                rsArr.push("<b>" + ie + "</b>");
            } else {
                if (ie > 10) {
                    rsArr.push("<a href='alert(\"\u7ed3\u679c\u8fc7\u591a\uff0c\u8bf7\u8f93\u5165\u66f4\u591a\u67e5\u8be2\u6761\u4ef6\u4ee5\u4fbf\u60a8\u7684\u7ed3\u679c\u66f4\u51c6\u786e\u3002\\n\u5982:\u60a8\u5982\u679c\u67e5\u627e\u5ddd\u83dc\u9986\u7684\u4f4d\u7f6e\uff0c\u53ef\u4ee5\u8f93\u5165\u201c\u4e2d\u5173\u6751 \u5ddd\u83dc \u6c34\u716e\u9c7c\u201d\")'>" + ie + "</a>");
                } else {
                    var hash = "#ac=sctext&city="+encodeDURI(city)+"&keytype="+encodeDURI(keytype)+"&range="+range+"&poitype="+poitype+"&pn="+ie+"&strlatlon="+$("strlatlon").value+"&rn="+rownume;
                    rsArr.push("<a href='" + hash + "' onclick=\"getDataByHash('" + hash + "');return false;\">" + ie + "</a>&nbsp;");
                }
            }
        }
    }    
    if (iCurr < nTotalPage) {
        if (iCurr < 10) {
            var hash = "#ac=sctext&city="+city+"&keytype="+encodeDURI(keytype)+"&range="+range+"&poitype="+poitype+"&pn="+(iCurr+1)+"&strlatlon="+$("strlatlon").value+"&rn="+rownume;
            rsArr.push("<a href='" + hash + "' onclick=\"getDataByHash('" + hash + "');return false;\">Next  &gt;</a>");
        } else {
            rsArr.push("&nbsp;<a href='javascript:alert(\"\u7ed3\u679c\u8fc7\u591a\uff0c\u8bf7\u8f93\u5165\u66f4\u591a\u67e5\u8be2\u6761\u4ef6\u4ee5\u4fbf\u60a8\u7684\u7ed3\u679c\u66f4\u51c6\u786e\u3002\\n\u5982:\u60a8\u5982\u679c\u67e5\u627e\u5ddd\u83dc\u9986\u7684\u4f4d\u7f6e\uff0c\u53ef\u4ee5\u8f93\u5165\u201c\u4e2d\u5173\u6751 \u5ddd\u83dc \u6c34\u716e\u9c7c\u201d\")'></a>");
        }
    }
    rsArr.push("</div>");
}

/*localsearch callback */
var cur_index;
var cur_hotelcd;
var cur_hoteladdress;
var cur_hoteltel;
var cur_hotelnm;
var lsCbk = {
    init:function (action) {
        var Request = request.init();
        rsArr = [];
      
        if (typeof APRS == "undefined") {
            throw new Error("localsearch, some error occured,Please try again later.");
        }
        //$("top_img").className = "top_img fix";
        //$("querybox").className = "query";
        showBlock("query_over");
        rs_Panel = $("query_over");
        
        pois = APRS.result;
        lsCbk.printPoint(action, pois, "images/rujia.gif", APRS.mapinfo.center, APRS.mapinfo.scale);
    },
     
    printPoint:function (action, pois, icon, center, zoom) {
        center = center || "";
        zoom = zoom || "";
        maplet.centerAndZoom(center, zoom);
        lsCbk.clearPoi();
        lsCbk.clearLine();
        var latlon1 =  $("destLatlon").value || $("PointLatlon").value;
        var poiIndex = 0;
        for (var i = 0; i < pois.length; i++) {
            var poi = pois[i];
            if(poi.strlatlon.length > 0)
            {
	            rsArr.push("<p><a href=\"javascript:void(0);\" onclick=\"lsCbk.clickItem("+ poiIndex +");return false;\" title=\"" + poi.Hotelnm + "\">" + poi.Hotelnm + "</a></p>");
	            
	            var book_url = "http://www.homeinns.com/ResvHomeinns/Resv/resv_stage2_1.aspx?hotelcd=" + poi.Hotelcd;
	            var mail_url = "http://www.homeinns.com/ResvHomeinns/Resv/Resv_Map_Email.aspx?hotelcd=" + poi.Hotelcd;
	            var detail = "<table border=0 width='100%' cellpadding='0' cellspacing='1'>" ;
	            detail += "<tr><td colspan=2 height=2><hr style=\"BORDER-BOTTOM-STYLE: dotted; BORDER-LEFT-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP-STYLE: none\" color=#000000 size=1></td><tr>";
	            detail += "<tr><td width=70 valign=top><b>地址:</b></td><td>" + poi.Address + "</td></tr>";
	            detail += "<tr><td height=5></td><td></td></tr>";
	            detail += "<tr><td valign=top><b>联系电话:</b></td><td>" + poi.Tel + "</td></tr>";
	            detail += "</table>&nbsp;";
	            detail += "<table border=0 width='100%' cellpadding='0' cellspacing='1' style='margin-top:0px;'>";
	            detail += "<tr><td width=140 align=center><a href='"+book_url+"'><img src='images/ding.jpg' border=0></a></td>";
	            detail += "<td aligh=center><a href='javascript:openwin(\""+mail_url+"\");'><img src='images/mail.jpg' border=0></a></td>";
	            detail += "</tr></table>";
	            var marker = window.addPoint(icon, poi.strlatlon, poi.Hotelnm, detail, true, false);
	            if(latlon1 != '')
	            {
	                MEvent.addListener(marker, "click", lsCbk.clickMarker);
	            }
	            poiIndex ++;
	        }
        }
        pageCtrl(action, APRS.pn, APRS.dn, APRS.keyword, APRS.city, rsArr);
        if((action != 'nbc') && (latlon1 != ''))
        {
            rsArr.push("<div><strong>*注：以与目的地直线距离(5KM以内)由近及远顺序排列，具体行车距离请点击进入</strong></div>");
        }
        var cityHash="#ac=nbc&city=" + encodeDURI(APRS.city) + "&customer=0&width=" + MAP_WIDTH + "&height=" + MAP_HEIGHT + "&pn=1&rn=" + rownume;
        rsArr.push("<div style=\"text-align:center;\"><a href='javascript:void(0);' onclick=\"getDataByHash('" + cityHash + "');return false;\"><font color='#FF0000'>点击查询本市所有酒店</font></a></div>");
        rs_Panel.innerHTML = rsArr.join("");
    }, 
    clearPoi:function () {
        clearPoint();
        delPoiByType(0);
    }, 
    clearLine:function () {
        delLineByType(0);
    },
    clickItem:function(idx)
    {
        latlon1 =  $("destLatlon").value || $("PointLatlon").value;
        if(latlon1 == '')
        {
            show(idx);
        }
        else
        {
	        var poi = APRS.result[idx];
	        cur_index = idx;
	        cur_hotelcd = poi.Hotelcd;
	        cur_hoteladdress = poi.Address;
	        cur_hoteltel = poi.Tel;
	        cur_hotelnm = poi.Hotelnm;
	        hotelRoute(poi.strlatlon,poi.Hotelnm);
	    }
    },
    clickMarker:function(obj)
    {
        for(var i=0; i<mapinfo.markers.length; i++)
        {
            var poi = APRS.result[i];
            if(mapinfo.markers[i] == obj)
            {
                cur_index = i;
                cur_hotelcd = poi.Hotelcd;
                cur_hoteladdress = poi.Address;
                cur_hoteltel = poi.Tel;
                cur_hotelnm = poi.Hotelnm;
                hotelRoute(poi.strlatlon,poi.Hotelnm);
                break;
            }
        }
    }
};

/*nav search result*/
var navCbk={
    init:function(action){
        showBlock("route");
        rs_Panel = $("route"); 
        rsArr=[];
        if (typeof drive == "undefined"){
            throw new Error("failed to get navigate result,some error occured,Please try again later.");
        }
        if(action == "dnsr")
            rsArr.push("<p class=\"title_back\" style=\"position:relative;z-index:10;height:1px;\"><a  href=\"javascript:void(0);\" onclick=\"showBlock('query_over');\" >返回</a></p>");
        else
            rsArr.push("<p class=\"title_back\" style=\"position:relative;z-index:10;height:1px;\"><a  href=\"javascript:void(0);\" onclick=\"showBlock('boxcontent');\" >返回</a></p>");
        
        rsArr.push("<div class=\"route_01\">");
        rsArr.push("起点："+drive.orig.name+"<br />");
        rsArr.push("终点："+drive.dest.name+"<br />");
        rsArr.push("距离：全程"+drive.distance+"公里<br /><br />");
       
        rsArr.push("<div class=\"route\">");
        for (var ic = 0; ic < drive.routes.item.length; ic++) {
            if(ic == 0)
                rsArr.push("<p onclick=\"show_LIbgC("+ic+");navCbk.showTurn('"+ic+"');\" id=\"LIbgC0"+ic+"\" title=\"查看该段线路\" style=\"cursor:pointer;\"><img src=\"images/Part3_map_b_10.png\" align=\"absmiddle\" />&nbsp;"+drive.routes.item[ic].strguide+"</p>");
            else if(ic == drive.routes.item.length - 1)
                rsArr.push("<p onclick=\"show_LIbgC("+ic+");navCbk.showTurn('"+ic+"');\" id=\"LIbgC0"+ic+"\" title=\"查看该段线路\" style=\"cursor:pointer;\"><img src=\"images/Part3_map_b_12.png\" align=\"absmiddle\" />&nbsp;"+drive.routes.item[ic].strguide+"</p>");
            else
                rsArr.push("<p onclick=\"show_LIbgC("+ic+");navCbk.showTurn('"+ic+"');\" id=\"LIbgC0"+ic+"\" title=\"查看该段线路\" style=\"cursor:pointer;\"><img src=\"images/Part3_map_b_14.png\" align=\"absmiddle\" />&nbsp;"+drive.routes.item[ic].strguide+"</p>");
        }
        rsArr.push("</div>");
        if(nRouteStyle == 2)
            rsArr.push("<div><span>其他路线：</span><a href=\"javascript:navCbk.setStyle('"+action+"',0);\">1</a>&nbsp;|&nbsp;<a href=\"javascript:navCbk.setStyle('"+action+"',1);\">2</a>&nbsp;|&nbsp;<a href=\"javascript:navCbk.setStyle('"+action+"',2);\" class=\"line_on\">3</a></div>");
        else if(nRouteStyle == 1)
            rsArr.push("<div><span>其他路线：</span><a href=\"javascript:navCbk.setStyle('"+action+"',0);\">1</a>&nbsp;|&nbsp;<a href=\"javascript:navCbk.setStyle('"+action+"',1);\" class=\"line_on\">2</a>&nbsp;|&nbsp;<a href=\"javascript:navCbk.setStyle('"+action+"',2);\">3</a></div>");
        else
            rsArr.push("<div><span>其他路线：</span><a href=\"javascript:navCbk.setStyle('"+action+"',0);\" class=\"line_on\">1</a>&nbsp;|&nbsp;<a href=\"javascript:navCbk.setStyle('"+action+"',1);\">2</a>&nbsp;|&nbsp;<a href=\"javascript:navCbk.setStyle('"+action+"',2);\">3</a></div>");
        rsArr.push("</div><div class=\"line_02\"/>");
        if($("bus"))
            $("bus").innerHTML="";
        rs_Panel.innerHTML=rsArr.join("");
        setTimeout(function(){navCbk.draw(action);},250);
    },
    draw:function(action){
        lsCbk.clearLine();
        if(action != "dnsr")
        {
            if(drive.mapinfo.center&&drive.mapinfo.scale){maplet.centerAndZoom(drive.mapinfo.center,drive.mapinfo.scale);}
            lsCbk.clearPoi();
            this.addPois();
        }
        this.addLine();
        if(action == "dnsr")
        {
            show(cur_index);
        }
    },
    setStyle:function(action,nStyle){
        nRouteStyle = nStyle;
        var nsrurl="#ac="+action+"&origCity="+drive.orig.city+"&origLatLon="+drive.orig.strlatlon+"&origName="+drive.orig.name+"&destCity="+drive.dest.city+"&destLatLon="+drive.dest.strlatlon+"&destName="+drive.dest.name+"&style="+nStyle;
        getDataByHash(nsrurl);
    },
    addPois:function(){
        var pois=[];
        pois.push([drive.orig.strlatlon,drive.orig.name,drive.orig.city,"images/qidian.gif"]);
        pois.push([drive.dest.strlatlon,drive.dest.name,drive.dest.city,"images/zhongdian.gif"]);
        for(var i=0;i<pois.length;i++){
            this.addPoiItem(pois[i][0],pois[i][1],pois[i][2],pois[i][3]);
        }
     },
     addPoiItem:function(strlatlon,name,city,icon){
        if(!strlatlon){return;}
        window.addPoint(icon,strlatlon,name,'',false,true);
    },
    addLine:function(){
        obj=new MapLine();
        obj.id="drive_line";
        obj.strlatlon=drive.routelatlon;
        obj.method=1;
        window.addLine(obj);
        maplet.refresh();
    },
    findSectByPois:function(v1,v2){
        var end=0;
        if(v2==""){end=drive.routelatlon.length}
        else{
            end=drive.routelatlon.indexOf(v2)+v2.length ;
        }
        return drive.routelatlon.substring(drive.routelatlon.indexOf(v1),end);
    },
    showTurn:function(i){
        var j=parseInt(i)+1;
        var v1=drive.routes.item[i].turnlatlon;
        var v2=i==drive.routes.item.length-1?"":drive.routes.item[j].turnlatlon;
        this.addTurnLine(this.findSectByPois(v1,v2),i);
    },
    addTurnLine:function(routelatlon,i){
        if(getLineById("drive_Turn_line")!=null){
            obj=getLineById("drive_Turn_line");
            obj.strlatlon=routelatlon;
            obj.color="blue";
            obj.stroke=5;
            obj.name=drive.routes.item[i].strguide;
            window.updateLine(obj);
        }else{
            obj=new MapLine();
            obj.id="drive_Turn_line";
            obj.strlatlon=routelatlon;
            obj.color="blue";
        obj.stroke=5;
            obj.name=drive.routes.item[i].strguide;
            window.addLine(obj);
         }
         maplet.refresh();
    }
}

var request = {init:function (newUrl) {
    newUrl = newUrl || window.location.hash;
    var Request = {};
    var strs = newUrl;
    switch (newUrl.indexOf("#")) {
      case 0:
        strs = newUrl.substr(1);
        break;
      case -1:
        break;
    }
    strs = strs.split("&");
    for (var id = 0; id < strs.length; id++) {
        Request[strs[id].split("=")[0]] = strs[id].split("=")[1];
    }
    return Request;
}, toHashString:function (Request) {
    var newHash = "";
    for (var i in Request) {
        if ((i != undefined) && (i != "")) {
            if (eval("Request." + i) != undefined && eval("Request." + i) != "" && eval("Request." + i) != "undefined") {
                newHash += (newHash == "" ? "" : "&") + i + "=" + eval("Request." + i);
            }
        }
    }
    return newHash;
}};

var mapinfo = {
	markers : new Array(),
	add : function(marker){mapinfo.markers.push(marker);},
	clean : function(){mapinfo.markers=new Array();}
};
/*******
*jsLoader
*
*/
var Transfer={}
Transfer.Base = function() {}
Transfer.Base.prototype = {
  setOptions: function(options) {
    if(typeof options!="object"){options={};}
    this.options = {
        bCache:options.bCache||false,
        id:options.id||"scriptTemp",
        onfailure:options.onfailure||function(){},
        oncomplate:options.oncomplate||function(){}
    }
  }
}
/**
new Transfer.Request(url,{oncomplate:'',id:''})
*/
Transfer.Request=Class.create();
Transfer.Request.prototype=Object.extend(new Transfer.Base(),{
    initialize: function(url, options) {
    this.setOptions(options);
    this.request(url);
    },
    request:function(url){
        this.url=url;
        this.bCache=this.options.bCache;
        this.id=this.options.id;
        this.oncomplate=this.options.oncomplate;
        this.onfailure=this.options.onfailure;
        this.symbol="?";
        if(this.url.indexOf("?")!="-1")this.symbol="&";
        var head=document.getElementsByTagName("head")[0];
        var sT = $(this.id);
        if(sT&&sT.src&&sT.src==this.url){
            this.oncomplate();
            return;
        }
        if (sT) {sT.parentNode.removeChild(sT);}
        var s = document.createElement("script");
        head.appendChild(s);
        s.setAttribute("language", "javascript");
	    s.setAttribute("type", "text/javascript");
	    s.setAttribute("id", this.id);
	    s.setAttribute("src", (this.bCache && this.bCache == true) ? this.url + this.symbol + Math.random() : this.url);
        var self=this;
        s.onload=s.onreadystatechange=function()
        {
            if (typeof ActiveXObject!="undefined") {
                if(s.readyState&&s.readyState=="loaded")self.oncomplate();
                if(s.readyState&&s.readyState=="complete")return;
            }else{
                self.oncomplate();
            }
        }
        s.onerror=function(){ //ie not work
            if(s&&s.parentNode)s.parentNode.removeChild(s);
            self.onfailure();
            throw new Error("connect faild,please try later;");
        }
     }
});
/****jsLoader end****/
/*
* justify ie
*/
var ie = document.all ? 1 : 0;
var ie6 = navigator.userAgent.split(";")[1].toLowerCase().indexOf("msie 6.0") == "-1" ? 0 : 1;
/**
 * @description keyword round spiltPage HotelNearby
 */
 
function pageCtrlHotelNearby(nPage, tp, keytype, poitype, city, range, rsArr) {
    tp = Math.ceil(parseInt(tp) / rownume);
    var nTotalPages = (tp > 100) ? 10 : tp;
    var iCurr = parseInt(nPage);
    var nTotalPage = nTotalPages;
    var iMinPage = Math.max(1, iCurr - 10);
    var iMaxPage = Math.min(nTotalPage, 10);
    rsArr.push("<div><span>\u9875\u6b21\uff1a" + nPage + "/"+iMaxPage+"</span>&nbsp;&nbsp;");
    if (iCurr > 1) {
        var hash = "#ac=zb&city="+encodeDURI(city)+"&keytype="+encodeDURI(keytype)+"&range="+range+"&poitype="+poitype+"&pn="+(iCurr-1)+"&strlatlon="+$("strlatlon").value+"&rn="+rownume;
        rsArr.push("<a href='" + hash + "' onclick=\"getDataByHash('" + hash + "');return false;\">|<<");
    }
    if (!$("divpage")) {
        for (var ie = iMinPage; ie <= iMaxPage; ie++) {
            if (ie == iCurr) {
                rsArr.push("&nbsp;<b>" + ie + "</b>");
            } else {
                if (ie > 10) {
                    rsArr.push("<a href='alert(\"\u7ed3\u679c\u8fc7\u591a\uff0c\u8bf7\u8f93\u5165\u66f4\u591a\u67e5\u8be2\u6761\u4ef6\u4ee5\u4fbf\u60a8\u7684\u7ed3\u679c\u66f4\u51c6\u786e\u3002\\n\u5982:\u60a8\u5982\u679c\u67e5\u627e\u5ddd\u83dc\u9986\u7684\u4f4d\u7f6e\uff0c\u53ef\u4ee5\u8f93\u5165\u201c\u4e2d\u5173\u6751 \u5ddd\u83dc \u6c34\u716e\u9c7c\u201d\")'>" + ie + "</a>");
                } else {
                    var hash = "#ac=zb&city="+encodeDURI(city)+"&keytype="+encodeDURI(keytype)+"&range="+range+"&poitype="+poitype+"&pn="+ie+"&strlatlon="+$("strlatlon").value+"&rn="+rownume;
                    rsArr.push("&nbsp;<a href='" + hash + "' onclick=\"getDataByHash('" + hash + "');return false;\">" + ie + "</a>");
                }
            }
        }
    }
    if (iCurr < nTotalPage) {
        if (iCurr < 10) {
            var hash = "#ac=zb&city="+encodeDURI(city)+"&keytype="+encodeDURI(keytype)+"&range="+range+"&poitype="+poitype+"&pn="+(iCurr+1)+"&strlatlon="+$("strlatlon").value+"&rn="+rownume;
            rsArr.push("&nbsp;<a href='" + hash + "' onclick=\"getDataByHash('" + hash + "');return false;\">>>|</a>");
        } else {
            rsArr.push("&nbsp;<a href='javascript:alert(\"\u7ed3\u679c\u8fc7\u591a\uff0c\u8bf7\u8f93\u5165\u66f4\u591a\u67e5\u8be2\u6761\u4ef6\u4ee5\u4fbf\u60a8\u7684\u7ed3\u679c\u66f4\u51c6\u786e\u3002\\n\u5982:\u60a8\u5982\u679c\u67e5\u627e\u5ddd\u83dc\u9986\u7684\u4f4d\u7f6e\uff0c\u53ef\u4ee5\u8f93\u5165\u201c\u4e2d\u5173\u6751 \u5ddd\u83dc \u6c34\u716e\u9c7c\u201d\")'></a>");
        }
    }
}

/**
 * @description keyword round spiltPage 
 */
function pageCtrl(action, nPage, tp, strQueryUTF, strCityUTF, rsArr) {
    tp = Math.ceil(parseInt(tp) / rownume);    
    var nTotalPages = (tp > 100) ? 10 : tp;
    var iCurr = parseInt(nPage);
    var nTotalPage = nTotalPages;
    var iMinPage = Math.max(1, iCurr - 10);
    var iMaxPage = Math.min(nTotalPage, 10);
    var latlon = $("destLatlon").value || $("PointLatlon").value;
    rsArr.push("<div><span>\u9875\u6b21\uff1a" + nPage + "/"+iMaxPage+"</span>&nbsp;&nbsp;");
    if (iCurr > 1) {
        var hash = "#ac=" + action + "&city=" + encodeDURI(strCityUTF) + "&keyword=" + encodeDURI(strQueryUTF) + "&range=" + RANGE + "&customer=0&width=570&height=420&pn=" + (iCurr - 1) + "&strlatlon=" + latlon + "&rn=" + rownume;
        rsArr.push("<a href='" + hash + "' onclick=\"getDataByHash('" + hash + "');return false;\">|<<");
    }
    if (!$("divpage")) {
        for (var ie = iMinPage; ie <= iMaxPage; ie++) {
            if (ie == iCurr) {
                rsArr.push("&nbsp;<b>" + ie + "</b>");
            } else {
               var hash = "#ac=" + action + "&&city=" + encodeDURI(strCityUTF) + "&keyword=" + encodeDURI(strQueryUTF) + "&range=" + RANGE + "&customer=0&width=570&height=420&pn=" + ie + "&strlatlon=" + latlon + "&rn=" + rownume;
               rsArr.push("&nbsp;<a href='" + hash + "' onclick=\"getDataByHash('" + hash + "');return false;\">" + ie + "</a>");
            }
        }
    }
    if (iCurr < nTotalPage) {
        var hash = "#ac=" + action + "&&city=" + encodeDURI(strCityUTF) + "&keyword=" + encodeDURI(strQueryUTF) + "&customer=0&range=" + RANGE + "&width=570&height=420&pn=" + (iCurr + 1) + "&strlatlon=" + latlon + "&rn=" + rownume;
        rsArr.push("&nbsp;<a href='" + hash + "' onclick=\"getDataByHash('" + hash + "');return false;\">>>|</a>");
    }
}

function clearInput()
{
    $("PointLatlon").value='';
    $("destLatlon").value = '';
    $("destName").value = '';
}


function addPoint(icon, latlon, name, detail, bInfoWindow, bLabel, bAddToArray) {

    var marker;
    var infowindow;
    var label;
    if (bInfoWindow) {
        infowindow = new MInfoWindow("<font color=#F8BF0E>"+name+"</font>", detail);
    }
    if (bLabel) {
        label = new MLabel(name, 7, -15);
    }
    if(icon.indexOf("tack.gif") > 0){
        marker = new MMarker(new MPoint(latlon), new MIcon(icon, 16, 16), infowindow, label);
    }
    else if(icon.indexOf("rujia.gif") > 0){
        marker = new MMarker(new MPoint(latlon), new MIcon(icon, 17, 17), infowindow, label);
    }
    else if (icon.indexOf("qidian.gif") > 0 || icon.indexOf("zhongdian.gif") > 0 ) {
        marker = new MMarker(new MPoint(latlon), new MIcon(icon, 20, 20), infowindow, label);
    } else {
        marker = new MMarker(new MPoint(latlon), new MIcon(icon, 28, 28), infowindow, label);
    }
    maplet.addOverlay(marker);
    if(typeof bAddToArray == "undefined" || bAddToArray)
        mapinfo.add(marker);
    return marker;
}
function clearPoint(count) {
    var markers = mapinfo.markers;
    mapinfo.clean();
    for (var i = 0; i < markers.length; i++) {
        if (i < count) {
            mapinfo.add(markers[i]);
        } else {
            maplet.removeOverlay(markers[i]);
        }
    }
}
function showNearbyBox() {
    var busDiv = document.getElementById("Box01");
    busDiv.style.display = "none";
    var nearbyDiv = document.getElementById("Box00");
    nearbyDiv.style.display = "block";
    $("nearkey").focus();
}

/**
* encode after decode void double encode
*/
function encodeDURI(uri, com) {
    if (com) {
        return encodeURIComponent(decodeURIComponent(uri));
    }
    return encodeURI(decodeURI(uri));
}
function decodeDURI(uri, com) {
    if (com) {
        return decodeURIComponent(decodeURIComponent(uri));
    }
    return decodeURI(decodeURI(uri));
}
//convert string to html format
function toHtmlStr(str) {
    str = str.replace(/</ig, "&lt;");
    str = str.replace(/>/ig, "&gt;");
    str = str.replace(/\r\n|\n\r|\n|\r/g, "<br>");
    str = str.replace(/\"/ig, "&quot;");
    str = str.replace(/\ /ig, "&nbsp;");
    return str;
}
function showOpenWindow(i, latlon) {
    maplet.centerAndZoom(latlon, 12);
    //show(i);
}
function show(i) {
    mapinfo.markers[i].openInfoWindow();
}

function printmap(){
	window.print(); 
	return false;
}	
