﻿var Left_Panel_Width = 347;
var arrSearchMapResult = new Array();
var current_index = 0;
var Screen_Width = 1000;
var nLanguage = 0;
var resultActive = -1;
var currentSelectedResAB_Id = -1;
var currentSelectedResAB_Lat = -1;
var currentSelectedResAB_Lng = -1;
var currentSelectedResAB_Text = "";
var plHighlight = null;


var selectedResAB_Text = "";
var prev_selectedResAB_Text = "";
var toFirstFlag = false;

function AJAXPost(strURL, str,type) 
{
                
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    /*    
    var temx = xscrool;
    var temy = yscrool;
    var image = document.getElementById('loading');
    
    if(image == null)
    {
        image	=	document.createElement('div');											
        image.id	=	'loading';	
        document.body.appendChild(image);
        image.innerHTML = "<img src=vbd_images/loading.gif>";
        
    }
    image.style.overflow	=	'hidden';					
    image.style.position	=	'absolute';
    image.style.width	=	Icon_Width+8;
    image.style.height	=	Icon_Height;
    image.style.left = temx + 10 ;
    image.style.top = temy + 10;
    */
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) 
        {
            Loading = false;
            image = document.getElementById('loading');
            if(image != null)
                document.body.removeChild(image);
			if(type == 1)	
				FindPlaceChange(self.xmlHttpReq.responseText);
			else if(type == 2)	
	            SearchPlaceChange(self.xmlHttpReq.responseText);
	        else if(type == 3)	
	            UploadPointChange(self.xmlHttpReq.responseText);
	        else if(type == 4)	
	            UpdatePointChange(self.xmlHttpReq.responseText);
	        else if(type == 5)	
	            RemovePointChange(self.xmlHttpReq.responseText);
	        else if(type == 6)	
	            GetAllPointChange(self.xmlHttpReq.responseText);
	        else if(type == 7)	
               GetAllInMBRChange(self.xmlHttpReq.responseText);
	        else if(type == 8)	
	           UpLoadTourPointChange(self.xmlHttpReq.responseText);
            else if(type == 9)	
	           PopUpChange(self.xmlHttpReq.responseText);    
            else if(type == 10)	
	           DisplayNeighbourNameChange(self.xmlHttpReq.responseText);    
            else if(type == 11)	
	           N_PopUpChange(self.xmlHttpReq.responseText);    
	        else if(type == 12)	
	           LoadThematicRealEstateMapChange(self.xmlHttpReq.responseText);
	        else if(type == 13)	
	           LoadThematicMapChange(self.xmlHttpReq.responseText);        
   	        else if(type == 14)	
	           FindThematicProjectChange(self.xmlHttpReq.responseText);        
        }
    };
    self.xmlHttpReq.send(str);
}
function FindPlaceEnter(e)
{
    var key;
	if(document.all)
		key = event.keyCode;
	else
		key = e.keyCode;
	if(key == 13)
	{	
	    FindPlace(1);
	}
	
}

function FindPlace(pageindex,key,what,where,lx,ly,rx,ry,searchType)
{
  	var nX, nY;
	var dbLX, dbLY, dbRX, dbRY;
	if (searchType == null)
	    searchType = current_searchtype;
	showBusyDiv("");
	if (key == null)
	{
  	    what="";
  	    where="";
  	    if(searchType == GLOBAL_SEARCH_MAP) // Search map
	    {
            key = document.getElementById('mapinput').value;
	    }
   	    /*else if(searchType == GLOBAL_SEARCH_BUSINESS) // Search Business
	    {
	        if(document.getElementById('businesswhere').value != "" && document.getElementById('businesswhat').value != "")
	            key = document.getElementById('businesswhat').value + " | " + document.getElementById('businesswhere').value;
	        else if (document.getElementById('businesswhat').value != "")
	            key = document.getElementById('businesswhat').value + " |";
	        else if (document.getElementById('businesswhere').value != "")
	            key = "| " + document.getElementById('businesswhere').value;
	    }
        else if(searchType == GLOBAL_SEARCH_ADDRESS) // Search address
        {
            key = document.getElementById('addressinput').value;
        }*/
    }
    if (key!=null)
    {
//        if (key.length > 0 && key.indexOf('&') > -1)
//        {
//	        key	= key.replace('&','!');
//	        key	= key.replace("'", "`");
//        }
                       
        if (key.length > 0)
        {
            if (lx==null || ly==null || rx==null || ry==null)
            {
                var bound = map.getBounds();
                dbLX = bound.getNorthWest().longitude;
                dbLY = bound.getNorthWest().latitude;
                dbRX = bound.getSouthEast().longitude;
                dbRY = bound.getSouthEast().latitude;
            }
            else
            {
                dbLX = lx;
                dbLY = ly;
                dbRX = rx;
                dbRY = ry;
            }
            var nCurrentLevel = map.getLevel();
            //AJAXPost("SmallMapRender.aspx?action=32&status=place&search_type=" + search_type + "&type=" + type + "&pindex=" + pageindex + "&flag=" + Math.random() + "&CurrentLevel=" + nCurrentLevel + "&LeftX=" + dbLX + "&LeftY=" + dbLY + "&RightX=" + dbRX + "&RightY=" + dbRY,"content="+key,1);
            // Ghi lai cau query vao cac o search cho hop ly                        
            FillQueryToTextBox(key);
            //var s = document.getElementById('businesswhere').value;
            var s = "";
            if (s.toLowerCase().indexOf("đoạn đường ")==0 || s.toLowerCase().indexOf("doan duong ")==0)
            {                                
                var radius = 25.0;
                s = s.substring(11);
                s = s.replace(/^\s+|\s+$/g, '') ;
                var sectionid = GetSectionId(s[0]);
                //SearchNearByLucenceExt(sectionid, document.getElementById('businesswhat').value,"", 1, radius);
            }   
            else if (s.toLowerCase().indexOf("gần ")==0 || s.toLowerCase().indexOf("gan ")==0)
            {
                s = s.substring(4);
                s = s.replace(/^\s+|\s+$/g, '') ;
                var firstIdx = s.indexOf(',');
                //var bkIdx = s.indexOf('bk:');
                var objectName = s.substring(0,firstIdx);
                var objectAddress = s.substring(firstIdx+1);
                var bk = 2000.0;
                if (firstIdx>=0)
                {
                    objectName = s.substring(0,firstIdx);
                    //if (bkIdx<0)
                        objectAddress = s.substring(firstIdx+1);
//                    else
//                    {
//                        objectAddress = s.substring(firstIdx+1, bkIdx - firstIdx - 1);
//                        bk = s.substring(bkIdx+3);
//                        bk = bk.replace(/^\s+|\s+$/g, '');                
//                    }
                    objectAddress = objectAddress.replace(/^\s+|\s+$/g, '') ;
                }
                else
                {
                    objectName = s;
                    objectAddress = "";    
                }
                //SearchNearByPointExt(objectName, objectAddress,'','', document.getElementById('businesswhat').value,"", pageindex,bk);
            }
            else   
            {                          
                vbdmap.SearchResult(key, what, where, pageindex, nCurrentLevel, dbLX, dbLY, dbRX, dbRY, searchType, FindPlaceChange_CallBack);                       
            }
        }
        else
            hideBusyDiv();
    }    
}
function Trim(s)
{
    s = s.replace(/^\s+|\s+$/g, '')
    return s;
}
function FillQueryToTextBox(key)
{        
    // Chuẩn hóa 1 số từ chỉ quan hệ giữa what và where    
    key = key.replace(" ở gần "," gần ");
    key = key.replace(" o gan "," gần ");
    key = key.replace(" ở trên đoạn đường "," | đoạn đường ");
    key = key.replace(" o tren doan duong "," | đoạn đường ");
    key = key.replace(" trên đoạn đường "," | đoạn đường ");
    key = key.replace(" tren doan duong "," | đoạn đường ");
    key = key.replace(" ở "," | ");
    key = key.replace(" ở"," |");      
    key = key.replace(", gần "," gần ");
    key = key.replace(" gần "," | gần ");
    // End Chuẩn hóa    
    document.getElementById('mapinput').style.background = '#ffffff';
    document.getElementById('mapinput').value = Trim(key.replace("$ ","").replace(' | ',', ')); //Trim(key.replace("$ ","").replace(' | ',', ').replace('| ','').replace(' |',''));
    document.getElementById('mapinput').value = document.getElementById('mapinput').value.replace(' đoạn đường ',' trên đoạn đường ');
    /*document.getElementById('addressinput').style.background = '#ffffff';
    document.getElementById('addressinput').value = Trim(key.replace("$ ","").replace(' | ',', ')); //Trim(key.replace("$ ","").replace(' | ',', ').replace('| ','').replace(' |',''));
    document.getElementById('addressinput').value = Trim(document.getElementById('addressinput').value.replace(' đoạn đường ',' trên đoạn đường '));
    document.getElementById('businesswhat').style.background = '#ffffff';*/
    var idxOfComma = key.indexOf('|');
//    if (idxOfComma == -1)
//        idxOfComma = key.indexOf(',');
    /*if (idxOfComma != -1)
    {
        document.getElementById('businesswhat').value = Trim(key.substring(0,idxOfComma));
        document.getElementById('businesswhere').style.background = '#ffffff';
        document.getElementById('businesswhere').value = Trim(key.substring(idxOfComma+2));
    }
    else
    {
        //document.getElementById('businesswhere').style.background = '#ffffff';
        if (key.indexOf('$ ')==0)
        {
            document.getElementById('businesswhere').value = Trim(key.substring(2));
            document.getElementById('businesswhat').value = "";
        }
        else
        {
            document.getElementById('businesswhat').value = Trim(key);
            document.getElementById('businesswhere').value = "";
        }
    }*/
}
var arrLogoPath;
var PointArray = new Array();
var PAGE_ROWS = 10;
var PAGE_SHOW = 7;
var DELTA_FROM_CENTER = 3;
var dsResultData;
function ReplaceString(text, src, des)
{
     // Remove <B>, </B>
    var literal = src;
    var replacement = des;
    var re = new RegExp(literal,"g");
    text = text.replace(re, replacement);
    return text;
}
function FindPlaceChange_CallBack(dss)
{
	isRegionSelected = false;
	hideBusyDiv();
	dsResultData = dss.value;
	var info = new Array();
	if ((null != dsResultData)  && ("object" == typeof(dsResultData)))
	{   
        isTreeClick = false;
        ClearSearchMapResult();
        if (plHighlight != null)
        {
            for(var j= 0 ; j< plHighlight.length;j++)
            {
                map.removeOverlay(plHighlight[j]);
            }
            plHighlight = null;
        }
        DeletePlaceTable();
        var length = dsResultData.Tables[0].Rows.length;
        var nHitSize = dsResultData.Tables[1].Rows[0].HitSize;
        var key = dsResultData.Tables[1].Rows[0].Key;//.replace(/\|/g,'ở');
        var what = dsResultData.Tables[1].Rows[0].What;
        var where = dsResultData.Tables[1].Rows[0].Where;
        var idx = key.indexOf("|");
        var oriwhat, oriwhere;
        if (idx>=0)
        {
            oriwhat = key.substring(0, idx-1);
            oriwhat = Trim(oriwhat);
            oriwhere = key.substring(idx+1);
            oriwhere = Trim(oriwhere);
            oriwhere = oriwhere.substring(3,oriwhere.length - 4);
        }
        if (oriwhere!="")
        {
            if (oriwhat!="")
                FillQueryToTextBox(Trim(oriwhat)+" | "+Trim(oriwhere));            
            else
                FillQueryToTextBox("$ " + Trim(oriwhere));
        }
        else
        {
            FillQueryToTextBox(Trim(oriwhat));
            oriwhere = "";
        }
        var nSumOfPage = parseInt((nHitSize + PAGE_ROWS - 1) / PAGE_ROWS);
        var nPageShow = nSumOfPage>PAGE_SHOW?PAGE_SHOW:nSumOfPage;
        var nCurPage = dsResultData.Tables[1].Rows[0].PageIdx;
        var lx = dsResultData.Tables[1].Rows[0].Lx;
        var ly = dsResultData.Tables[1].Rows[0].Ly;
        var rx = dsResultData.Tables[1].Rows[0].Rx;
        var ry = dsResultData.Tables[1].Rows[0].Ry;
        var searchType = dsResultData.Tables[1].Rows[0].SearchType;
        var suggestedKey = dsResultData.Tables[1].Rows[0].SuggestedKey;
        var nStartResIdx = (nCurPage - 1) * PAGE_ROWS + 1;
        var nEndResIdx = nStartResIdx + PAGE_ROWS - 1 > nHitSize?nHitSize:nStartResIdx + PAGE_ROWS - 1;
        info[info.length] = "<table id=TablePlace width=100% border=0 cellspacing=0 cellpadding=0 style=\"overflow:auto;\">";
        if (nHitSize > 0)
        {           
            if (dsResultData.Tables[1].Rows[0].IsLonLat)
                info[info.length] = "<tr><td height=20px align=left valign=middle style=\"font-size:11px;\">Tọa độ: <b>"+key.replace('|','')+"</b></td></tr>";
            else if (dsResultData.Tables[1].Rows[0].IsAddress)
            {
                if (nHitSize > 1)
                    info[info.length] = "<tr><td height=20px align=left valign=middle style=\"font-size:11px;\">Kết quả từ <b>"+nStartResIdx+"-"+ nEndResIdx +"</b> trong số <b>"+nHitSize+"</b> cho địa chỉ <b>"+key.replace('|','')+"</b></td></tr>";                            
                else
                    info[info.length] = "<tr><td height=20px align=left valign=middle style=\"font-size:11px;\">Kết quả tìm kiếm cho địa chỉ <b>"+key.replace('|','')+"</b></td></tr>";    
            }
            else
            {                
                if (suggestedKey!="")
                {
                    info[info.length] = "<tr>";
                    if (current_searchtype == GLOBAL_SEARCH_MAP)
                        info[info.length] = "<td height=20px align=left valign=middle style=\"font-size:11px;\"><span style=\"color:#FF0000; font-size:12px;\">Có phải bạn muốn tìm: </span><b><span style=\"color:#006699\"><a style=\"text-decoration:underline; cursor:pointer; font-size:12px;\" id=\"dym\" onclick=\"MapExampleClick(this.id)\">"+suggestedKey+"</a></span>?</b><br/><br/><br/>";                
                    if (current_searchtype == GLOBAL_SEARCH_BUSINESS)
                        info[info.length] = "<td height=20px align=left valign=middle style=\"font-size:11px;\"><span style=\"color:#FF0000; font-size:12px;\">Có phải bạn muốn tìm: </span><b><span style=\"color:#006699\"><a style=\"text-decoration:underline; cursor:pointer; font-size:12px;\" id=\"dym\" onclick=\"BusinessExampleClick(this.id)\">"+suggestedKey+"</a></span>?</b><br/><br/><br/>";                
                    if (current_searchtype == GLOBAL_SEARCH_ADDRESS)
                        info[info.length] = "<td height=20px align=left valign=middle style=\"font-size:11px;\"><span style=\"color:#FF0000; font-size:12px;\">Có phải bạn muốn tìm: </span><b><span style=\"color:#006699\"><a style=\"text-decoration:underline; cursor:pointer; font-size:12px;\" id=\"dym\" onclick=\"AddressExampleClick(this.id)\">"+suggestedKey+"</a></span>?</b><br/><br/><br/>";                
                    if (nHitSize > 1)
                        info[info.length] = "Kết quả từ <b>"+nStartResIdx+"-"+ nEndResIdx +"</b> trong số <b>"+nHitSize+"</b> cho <b>"+key.replace('|','')+"</b></td></tr>";
                    else
                        info[info.length] = "Kết quả tìm kiếm cho <b>"+key.replace('|','')+"</b></td></tr>";
                    info[info.length] = "</tr>";                     
                }
                else
                {
                    if (nHitSize > 1)
                    {
                        if (oriwhere!="" && oriwhat!="")
                            info[info.length] = "<tr><td height=20px align=left valign=middle style=\"font-size:11px;\">Kết quả từ <b>"+nStartResIdx+"-"+ nEndResIdx +"</b> trong số <b>"+nHitSize+"</b> cho <b>"+oriwhat+"</b> ở <b>"+oriwhere+"</td></tr>";
                        else if (oriwhere!="" && oriwhat=="")
                            info[info.length] = "<tr><td height=20px align=left valign=middle style=\"font-size:11px;\">Kết quả từ <b>"+nStartResIdx+"-"+ nEndResIdx +"</b> trong số <b>"+nHitSize+"</b> cho <b>"+oriwhere+"</b></td></tr>";
                        else
                            info[info.length] = "<tr><td height=20px align=left valign=middle style=\"font-size:11px;\">Kết quả từ <b>"+nStartResIdx+"-"+ nEndResIdx +"</b> trong số <b>"+nHitSize+"</b> cho <b>"+oriwhat+"</b></td></tr>";                        
                    }
                    else
                    {
                        if (oriwhat!="" && oriwhere!="")
                            info[info.length] = "<tr><td height=20px align=left valign=middle style=\"font-size:11px;\">Kết quả tìm kiếm cho <b>"+oriwhat+"</b> ở <b>"+oriwhere+"</td></tr>";                    
                        else if (oriwhere=="")
                            info[info.length] = "<tr><td height=20px align=left valign=middle style=\"font-size:11px;\">Kết quả tìm kiếm cho <b>"+oriwhat+"</b></td></tr>";
                        else if (oriwhat=="")
                            info[info.length] = "<tr><td height=20px align=left valign=middle style=\"font-size:11px;\">Kết quả tìm kiếm cho <b>"+oriwhere+"</b></td></tr>";
                    }
                }                                
            }
        }
        else
        {
            if (dsResultData.Tables[1].Rows[0].IsLonLat)
                info[info.length] = "<tr><td height=20px align=left valign=middle style=\"font-size:11px;\">Không xác định được tọa độ: <b>"+key.replace('|','')+"</b></td></tr>";
            else if (dsResultData.Tables[1].Rows[0].IsAddress)
                info[info.length] = "<tr><td height=20px align=left valign=middle style=\"font-size:11px;\">Không tìm thấy địa chỉ <b>"+key.replace('|','')+"</b><br /><br />&nbspĐề xuất:<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"vbd_images/dot.gif\" width=\"8\" height=\"8\"/> Xin bạn chắc chắn đã viết đúng địa chỉ.<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"vbd_images/dot.gif\" width=\"8\" height=\"8\"/> Nếu bạn viết tắt, hãy thử không viết tắt.</td></tr>";                            
            else
            {                
                info[info.length] = "<tr>";
                if (suggestedKey!="")
                {
                    if (current_searchtype == GLOBAL_SEARCH_MAP)
                        info[info.length] = "<td height=20px align=left valign=middle style=\"font-size:11px;\"><span style=\"color:#FF0000; font-size:12px;\">Có phải bạn muốn tìm: </span><b><span style=\"color:#006699\"><a style=\"text-decoration:underline; cursor:pointer; font-size:12px;\" id=\"dym\" onclick=\"MapExampleClick(this.id)\">"+suggestedKey+"</a></span>?</b><br/><br/><br/>";                
                    if (current_searchtype == GLOBAL_SEARCH_BUSINESS)
                        info[info.length] = "<td height=20px align=left valign=middle style=\"font-size:11px;\"><span style=\"color:#FF0000; font-size:12px;\">Có phải bạn muốn tìm: </span><b><span style=\"color:#006699\"><a style=\"text-decoration:underline; cursor:pointer; font-size:12px;\" id=\"dym\" onclick=\"BusinessExampleClick(this.id)\">"+suggestedKey+"</a></span>?</b><br/><br/><br/>";                
                    if (current_searchtype == GLOBAL_SEARCH_ADDRESS)
                        info[info.length] = "<td height=20px align=left valign=middle style=\"font-size:11px;\"><span style=\"color:#FF0000; font-size:12px;\">Có phải bạn muốn tìm: </span><b><span style=\"color:#006699\"><a style=\"text-decoration:underline; cursor:pointer; font-size:12px;\" id=\"dym\" onclick=\"AddressExampleClick(this.id)\">"+suggestedKey+"</a></span>?</b><br/><br/><br/>";                
                    info[info.length] = "Không tìm thấy dữ liệu liên quan đến <b>"+key.replace('|','')+"</b><br /><br />&nbspĐề xuất:<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"vbd_images/dot.gif\" width=\"8\" height=\"8\"/> Xin bạn chắc chắn đã viết đúng chính tả.<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"vbd_images/dot.gif\" width=\"8\" height=\"8\"/> Nếu bạn viết tắt, hãy thử không viết tắt.<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"vbd_images/dot.gif\" width=\"8\" height=\"8\" /> Hãy thử dùng các từ khóa khác có nghĩa tương tự.<br /></td>";
                }
                else
                {
                    info[info.length] = "<td height=20px align=left valign=middle style=\"font-size:11px;\">Không tìm thấy dữ liệu liên quan đến <b>"+key.replace('|','')+"</b><br /><br />&nbspĐề xuất:<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"vbd_images/dot.gif\" width=\"8\" height=\"8\"/> Xin bạn chắc chắn đã viết đúng chính tả.<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"vbd_images/dot.gif\" width=\"8\" height=\"8\"/> Nếu bạn viết tắt, hãy thử không viết tắt.<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"vbd_images/dot.gif\" width=\"8\" height=\"8\" /> Hãy thử dùng các từ khóa khác có nghĩa tương tự.<br /></td>";
                }
                info[info.length] = "</tr>";                
            }
        }
        
        for(var i=0; i<length; i++)
        {
            if (dsResultData.Tables[0].Rows[i].Address != dsResultData.Tables[0].Rows[i].Name && dsResultData.Tables[0].Rows[i].Address!="")
                info[info.length] = ResultItemHTML(i+1, dsResultData.Tables[0].Rows[i].Latitude, dsResultData.Tables[0].Rows[i].Longitude, dsResultData.Tables[0].Rows[i].Name+', '+dsResultData.Tables[0].Rows[i].Address);
            else
                info[info.length] = ResultItemHTML(i+1, dsResultData.Tables[0].Rows[i].Latitude, dsResultData.Tables[0].Rows[i].Longitude, dsResultData.Tables[0].Rows[i].Name);
            var latlng = new VLatLng(dsResultData.Tables[0].Rows[i].Latitude,dsResultData.Tables[0].Rows[i].Longitude);
            //var icon = new VIcon(dsResultData.Tables[0].Rows[i].Logo);
            var icon = new VIcon("images/"+(i+1)+".gif");
            icon.iconSize = new VSize(26,29);
            var mopt = new VMarkerOptions(icon);
            var marker = new VMarker(latlng,mopt);
            marker.order = i + 1;
            marker.type = MARKER_POI;
            map.addOverlay(marker);
            arrSearchMapResult.push(marker);
            VEvent.addListener(marker, 'mouseover', function(mk)
            {
                var element = document.getElementById("resultItem_"+mk.order);
                ResultEntryMouseOver(element);
            }
            );
            VEvent.addListener(marker, 'mouseout', function(mk)
            {
                var element = document.getElementById("resultItem_"+mk.order);
                ResultEntryMouseOut(element);
            }
            );
        }
        if (nSumOfPage == 1 && nHitSize <= PAGE_ROWS)
        {
            info[info.length] = "</table>";
      	    ChangeFunctionType(GLOBAL_SEARCH_FUNCTION);
            document.getElementById('searchresult_div').innerHTML	= info.join("");
	        if (nHitSize > 0)
	            map.setCenter(new VLatLng(dsResultData.Tables[1].Rows[0].CenterLat,dsResultData.Tables[1].Rows[0].CenterLng),dsResultData.Tables[1].Rows[0].Level);	        
	        //hideBusyDiv();
	        document.getElementById('clearResultText').style.display = 'block';
	        return;
        }
        // Paging - Phan trang
        
        info[info.length] = "<tr><td height=10px></td></tr>";
        info[info.length] = "<tr><td align=\"center\" valign=\"middle\">";
        info[info.length] = "<table border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">";
        info[info.length] = "<tr>";    
                     
        if (nCurPage > 1)
        {
            info[info.length] = "<td align=\"center\" valign=\"middle\" class=\"paging\" style=\"cursor:pointer;\" onmouseover=\"ChangeBorderColor(this,'#66cc00')\" onmouseout=\"ChangeBorderColor(this,'#cccccc')\" onclick=\"FindPlace("+1+",'"+key+"','"+what+"','"+where+"',"+lx+","+ly+","+rx+","+ry+","+searchType+")\" >Đầu</td>";
            info[info.length] = "<td class=\"paging_space\"></td>";
            info[info.length] = "<td align=\"center\" valign=\"middle\" style=\"width:14px; height:14px;\"><img src=\"images/backpage.gif\" onmouseover=\"ChangeImageSrc(this,'images/backpage_over.gif')\" onmouseout=\"ChangeImageSrc(this,'images/backpage.gif')\" onclick=\"FindPlace("+(nCurPage-1)+",'"+key+"','"+what+"','"+where+"',"+lx+","+ly+","+rx+","+ry+","+searchType+")\" style=\"cursor:pointer;\" alt=\"Trang trước\" /></td>";
            info[info.length] = "<td class=\"paging_space\"></td>";    
        }
        var number;        
        var delta = 0;
        for (var i=0;i<nPageShow;i++)
        {
             number = nCurPage - DELTA_FROM_CENTER + i;
             if (number <= 0)
                delta = DELTA_FROM_CENTER + 1 - nCurPage;
             if (number > nSumOfPage)
             {
                break;
             }
             number += delta;   
             if (number == nCurPage)
                 info[info.length] = "<td align=\"center\" valign=\"middle\" class=\"paging_active\" ><b>" + number + "</b></td>";   
             else       
                info[info.length] = "<td align=\"center\" valign=\"middle\" class=\"paging\" style=\"cursor:pointer;\" onmouseover=\"ChangeBorderColor(this,'#66cc00')\" onmouseout=\"ChangeBorderColor(this,'#cccccc')\" onclick=\"FindPlace("+number+",'"+key+"','"+what+"','"+where+"',"+lx+","+ly+","+rx+","+ry+","+searchType+")\" >" + number + "</td>";
             info[info.length] = "<td class=\"paging_space\"></td>";
        }
        if (nCurPage < nSumOfPage)
        {
            info[info.length] = "<td align=\"center\" valign=\"middle\" style=\"width:14px; height:14px;\"><img src=\"images/nextpage.gif\" onmouseover=\"ChangeImageSrc(this,'images/nextpage_over.gif')\" onmouseout=\"ChangeImageSrc(this,'images/nextpage.gif')\" onclick=\"FindPlace("+(nCurPage+1)+",'"+key+"','"+what+"','"+where+"',"+lx+","+ly+","+rx+","+ry+","+searchType+")\" style=\"cursor:pointer;\" alt=\"Trang tiếp\" /></td>";            
            info[info.length] = "<td class=\"paging_space\"></td>";
            info[info.length] = "<td align=\"center\" valign=\"middle\" class=\"paging\" style=\"cursor:pointer;\" onmouseover=\"ChangeBorderColor(this,'#66cc00')\" onmouseout=\"ChangeBorderColor(this,'#cccccc')\" onclick=\"FindPlace("+nSumOfPage+",'"+key+"','"+what+"','"+where+"',"+lx+","+ly+","+rx+","+ry+","+searchType+")\" >Cuối</td>";
        }                      
        info[info.length] = "</tr>";
        info[info.length] = "</table>";
        info[info.length] = "</td></tr>";
        info[info.length] = "<tr><td height=10px></td></tr>";
        // End Paging
        info[info.length] = "</table>";
      	ChangeFunctionType(GLOBAL_SEARCH_FUNCTION);
        document.getElementById('searchresult_div').innerHTML	= info.join("");
	    if (nHitSize > 0)
	        map.setCenter(new VLatLng(dsResultData.Tables[1].Rows[0].CenterLat,dsResultData.Tables[1].Rows[0].CenterLng),dsResultData.Tables[1].Rows[0].Level);    
        pre = cur = -1;	        
	}
	//hideBusyDiv();
	/*var string = str;
	var level = string.substring(string.indexOf("begin")+5,string.indexOf("end"));
	var center = string.substring(string.indexOf("bcenter")+7,string.indexOf("scenter")).split(":");
	var stringpath = string.substring(string.indexOf("end")+3,string.indexOf(",startresult"));
	var stringpath1 = string.substring(string.indexOf("arrlogopath")+11,string.indexOf(";endarrlogopath"));
	arrLogoPath = stringpath1.split(';');
    
	ClearSearchMapResult();
	PointArray = stringpath.split(',');
	if(PointArray.length >= 2)
	{
        for(var i = 0 ; i < PointArray.length;i+=2)
        { 
            var j = i/2;
            var latlng = new VLatLng(PointArray[i+1],PointArray[i]);
            var icon = new VIcon(arrLogoPath[j]);
            var mopt = new VMarkerOptions(icon);
            var marker = new VMarker(latlng,mopt);
            map.addOverlay(marker);
            arrSearchMapResult.push(marker);
        }
        //map.fitOverlays();
        map.setCenter(new VLatLng(center[1],center[0]),level);
	}
	ChangeFunctionType(GLOBAL_SEARCH_FUNCTION);
	var result = string.substring(string.indexOf("startresult")+11,string.lastIndexOf('</table>')+8);
    document.getElementById('searchresult_div').innerHTML	= result;
    */
    document.getElementById('clearResultText').style.display = 'block';

}
function SearchPage(npage,key,lx,ly,rx,ry,nSearchType)
{
	FindPlace(npage,key,lx,ly,rx,ry,nSearchType);	
}

function ClearSearchMapResult()
{
    for(var i = 0 ; i < arrSearchMapResult.length;i++)
    {
        map.removeOverlay(arrSearchMapResult[i]);
    }
    arrSearchMapResult = new Array();        
}

function ClearResult()
{
    if (current_functype == GLOBAL_SEARCH_FUNCTION)
    {
        ClearSearchMapResult();
        isRegionSelected = false;
        if (plHighlight != null)
        {
            for(var j= 0 ; j< plHighlight.length;j++)
            {
                map.removeOverlay(plHighlight[j]);
            }
            plHighlight = null;
        }
        if (current_searchtype == GLOBAL_SEARCH_MAP)
            Show_Map_Help();
        else if (current_searchtype == GLOBAL_SEARCH_BUSINESS)
            Show_Business_Help();
        else if (current_searchtype == GLOBAL_SEARCH_ADDRESS)
            Show_Address_Help();
    }
    else if (current_functype == GLOBAL_FINDPATH_FUNCTION)
    {
        isFinding = false;
        isChanging = false;
        for(var i = PlaceToFindPathArray.length - 1; i>= 0; i--)
            RemovePlace(i+",0", 1);
        vbdmap.RemoveDirectionPlaces(-1,-1);
    }
    document.getElementById('clearResultText').style.display = 'none';
}

function Fromhere(lat,lng,text)
{
    AddPlaceFromFind(new VLatLng(lat,lng),text);
}
function Tohere(lat,lng,text)
{
    AddPlaceToFind(new VLatLng(lat,lng),text);
}
function ResultItemHTML(order, lat, lng, text)
{    
    var info = new Array();
    info[info.length] = "<tr><td align=\"center\" valign=\"middle\">";
    info[info.length] = "<table id=resultItem_"+ order +" width=\"99%\" border=\"0\" align=\"left\" cellpadding=\"0\" cellspacing=\"0\" onmouseover=\"ResultEntryMouseOver(this)\" onmouseout=\"ResultEntryMouseOut(this)\" style=\"border:1px #ffffff solid; border-bottom:1px #efefef solid; margin-left:2px; margin-right:2px;\">";
    info[info.length] = "<tr><td colspan=\"2\" style=\"height:5px;\"></td></tr>";
    info[info.length] = "<tr>";
    info[info.length] = "<td align=\"center\" valign=\"middle\" style=\"width:40px;\">";
    info[info.length] = "<img  id=resultimage_"+order+" src=images/"+order+".gif alt=\"\" /></td>";
    info[info.length] = "<td align=\"left\">";
    info[info.length] = "<span style=\"color:#0066cc; font-size:12px;\">";
    var comment = dsResultData.Tables[0].Rows[order-1].ShortComment;
    var dolgisId = dsResultData.Tables[0].Rows[order-1].DolGisId;
    var name = dsResultData.Tables[0].Rows[order-1].Name;
    var table = dsResultData.Tables[0].Rows[order-1].Table;
    var address = dsResultData.Tables[0].Rows[order-1].Address;
    var tinhly = "";
    if (comment!="")
    {
        info[info.length] = "<a style=\"color:#0066cc;font-size:12px; font-family:Verdana; cursor:pointer;\" onmouseover=\"ChangeTextColor(this,\'#558800\')\" onmouseout=\"ChangeTextColor(this,\'#0066cc\')\" onclick=ViewDetailCurrentLevel("+order+","+lat+","+lng+")>"+dsResultData.Tables[0].Rows[order-1].Name+"</a></span><br />"+dsResultData.Tables[0].Rows[order-1].Address+"<br />"+comment+"<br/><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,\'#558800\')\" onmouseout=\"ChangeTextColor(this,\'#cc6600\')\" onclick=\"ViewDetail("+order+","+lat+","+lng+",'"+text+"')\">Xem trên bản đồ</a><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,\'#558800\')\" onmouseout=\"ChangeTextColor(this,\'#cc6600\')\" onclick=\"ViewDetailInfo("+order+","+lat+","+lng+",'"+name+"',"+dolgisId+",'"+table+"')\">Xem chi tiết</a><span style=\"color:#cc6600;\"> | </span>";
        //info[info.length] = "<a style=\"color:#0066cc;font-size:12px; font-family:Verdana; cursor:pointer;\" onmouseover=\"ChangeTextColor(this,\'#558800\')\" onmouseout=\"ChangeTextColor(this,\'#0066cc\')\" onclick=ViewDetailInfo("+order+","+lat+","+lng+",'"+name+"',"+dolgisId+",'"+table+"')>"+dsResultData.Tables[0].Rows[order-1].Name+"</a></span><br />"+dsResultData.Tables[0].Rows[order-1].Address+"<br />"+comment+"<br/><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,\'#558800\')\" onmouseout=\"ChangeTextColor(this,\'#cc6600\')\" onclick=\"ViewDetail("+order+","+lat+","+lng+",'"+text+"')\">Xem trên bản đồ</a>";
        //info[info.length] = "<a style=\"color:#0066cc;font-size:12px; font-family:Verdana; cursor:pointer;\" onmouseover=\"ChangeTextColor(this,\'#558800\')\" onmouseout=\"ChangeTextColor(this,\'#0066cc\')\" onclick=ViewDetailCurrentLevel("+order+","+lat+","+lng+")>"+dsResultData.Tables[0].Rows[order-1].Name+"</a></span><br />"+dsResultData.Tables[0].Rows[order-1].Address+"<br />"+comment+"<br/><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,\'#558800\')\" onmouseout=\"ChangeTextColor(this,\'#cc6600\')\" onclick=\"FromHere("+order+","+lat+","+lng+",'"+text+"')\">Từ đây</a> <span style=\"color:#cc6600;\">|</span> <a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,\'#558800\')\" onmouseout=\"ChangeTextColor(this,\'#cc6600\')\" onclick=\"ToHere("+order+","+lat+","+lng+",'"+text+"')\">Đến đây</a> <span style=\"color:#cc6600;\"> | </span><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,\'#558800\')\" onmouseout=\"ChangeTextColor(this,\'#cc6600\')\" onclick=\"ViewDetail("+order+","+lat+","+lng+")\">Xem trên bản đồ</a>";
    }
    else
        //info[info.length] = "<a style=\"color:#0066cc;font-size:12px; font-family:Verdana; cursor:pointer;\" onmouseover=\"ChangeTextColor(this,\'#ff0000\')\" onmouseout=\"ChangeTextColor(this,\'#0066cc\')\" onclick=ViewDetailCurrentLevel("+order+","+lat+","+lng+")>"+dsResultData.Tables[0].Rows[order-1].Name+"</a></span><br />"+dsResultData.Tables[0].Rows[order-1].Address+"<br /><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,\'#ff0000\')\" onmouseout=\"ChangeTextColor(this,\'#cc6600\')\" onclick=\"ViewDetail("+order+","+lat+","+lng+",'"+text+"')\">Xem trên bản đồ</a><span style=\"color:#cc6600;\"> | </span><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,\'#ff0000\')\" onmouseout=\"ChangeTextColor(this,\'#cc6600\')\" onclick=\"ViewDetailInfo("+order+","+lat+","+lng+",'"+name+"',"+dolgisId+",'"+table+"')\">Xem chi tiết</a>";
        info[info.length] = "<a style=\"color:#0066cc;font-size:12px; font-family:Verdana; cursor:pointer;\" onmouseover=\"ChangeTextColor(this,\'#558800\')\" onmouseout=\"ChangeTextColor(this,\'#0066cc\')\" onclick=ViewDetailCurrentLevel("+order+","+lat+","+lng+")>"+dsResultData.Tables[0].Rows[order-1].Name+"</a></span><br />"+dsResultData.Tables[0].Rows[order-1].Address+"<br /> <a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,\'#558800\')\" onmouseout=\"ChangeTextColor(this,\'#cc6600\')\" onclick=\"ViewDetail("+order+","+lat+","+lng+",'"+text+"')\">Xem trên bản đồ</a><span style=\"color:#cc6600;\"> | </span><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,\'#ff0000\')\" onmouseout=\"ChangeTextColor(this,\'#cc6600\')\" onclick=\"ViewDetailInfo("+order+","+lat+","+lng+",'"+name+"',"+dolgisId+",'"+table+"','"+address+"','"+tinhly+"')\">Xem chi tiết</a>";    
    info[info.length] = "</td>";
    /*var s = "./images/"+order+".gif";
    if (dsResultData.Tables[0].Rows[order-1].Logo != s)
    {
        info[info.length] = "<td align=\"center\" valign=\"middle\" style=\"width:40px;\">";
        info[info.length] = "<img  id=resultlogo_"+order+" src="+dsResultData.Tables[0].Rows[order-1].Logo+" alt=\"\" /></td>";
        info[info.length] = "<tr><td colspan=\"2\" style=\"height:5px;\"></td></tr>";
    } */          
    info[info.length] = "</tr>";
    info[info.length] = "<tr>";
    info[info.length] = "<td colspan=\"2\" style=\"height:5px;\"></td>";
    info[info.length] = "</tr>";
    info[info.length] = "</table>";
    info[info.length] = "</td></tr>";
    return info.join("");
}
function ResultItemHTML_InfoWindowInfo(order, lat, lng, text,dolgisId,table)
{  
    if (order==null)
        return;
    var name;
    var address;
    var comment;
    var logo;
    var pic;
    var tel;
    name = text;
    address = "";
    comment = "";
    logo = "";
    pic = "";
    tel = "";
    var info = new Array();
    info[info.length] = '<table cellpadding="0" cellspacing="0" style="width:270px; height:auto; background-color:#FFFFFF; margin-left:6px; margin-right:8px; margin-top:8px; margin-bottom:8px;">';
    info[info.length] = '<tr>';
    if (pic!="")
    {
        info[info.length] = "<td><img src=\""+pic+"\" style=\"border:1px #cccccc solid; margin-right:3px; width:85px; height:100px;\" /></td>";                
    }
    info[info.length] = '<td align="left" valign="top"><span style="color:#0066cc;"><strong>'+name+'</strong></span><br />';
    //info[info.length] = '<img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/spacer.gif" width="10" height="24" align="absmiddle" /><br />';
    if (address!="")
        info[info.length] = '<img src="images/diachi.gif" width="20" height="20" align="absmiddle"/>'+address+'<br />';
    if (tel!="")
        info[info.length] = '<img src="images/dienthoai.gif" width="20" height="20" align="absmiddle"/>'+tel+'<br />';
    if (comment!="")
        info[info.length] = '<img src="images/ghichu.gif" width="20" height="20" align="absmiddle"/>\"'+comment+'...\"<br />';
    info[info.length] = '</td>';
    info[info.length] = '</tr>';
    info[info.length] = '<tr>';
    //info[info.length] = "<td align=\"left\" colspan=\"2\"><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#ff0000')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"ViewDetailInfo("+order+","+lat+","+lng+",'"+name+"',"+dolgisId+",'"+table+"')\">Chi tiết </a>";
    //info[info.length] = "<td align=\"left\" colspan=\"2\"><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#ff0000')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"ViewDetailInfo("+order+","+lat+","+lng+",'"+name+"','"+address+"','"+comment+"','"+logo+"','"+pic+"','"+tel+"')\">Chi tiết </a>";
    info[info.length] = "<td align=\"left\" colspan=\"2\"> <a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#ff0000')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"ViewDetailInfo("+order+","+lat+","+lng+",'"+name+"',"+dolgisId+",'"+table+"')\">Chi tiết </a>";
    info[info.length] = "<span style=\"color:#cc6600;\">| </span><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#ff0000')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"ViewDetailCurrentLevelWithSearchNearByInfo("+order+","+lat+","+lng+",'"+text+"',"+dolgisId+",'"+table+"')\">Tìm xung quanh</a></td>";// <span style=\"color:#cc6600;\"> | </span> <a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"\">Lưu vào bản đồ của tôi </a> </td>";
    info[info.length] = '</tr>';
    info[info.length] = '</table>';
    return info.join("");
}

function ResultItemHTML_InfoWindow(order, lat, lng, text)
{  
    if (order==null)
        return;
    var name;
    var address;
    var comment;
    var logo;
    var pic;
    var tel;
    var table = dsResultData.Tables[0].Rows[order-1].Table;
    var dolgisId;
    dolgisId = dsResultData.Tables[0].Rows[order-1].DolGisId;
    name = dsResultData.Tables[0].Rows[order-1].Name;
    address = dsResultData.Tables[0].Rows[order-1].Address;
    comment = dsResultData.Tables[0].Rows[order-1].Comment;
    logo = dsResultData.Tables[0].Rows[order-1].Logo;
    pic = dsResultData.Tables[0].Rows[order-1].Picture;
    tel = dsResultData.Tables[0].Rows[order-1].Tel;
    if (pic!="")
    {
        pic = "tourist"+"\\"+pic;        
    }

    var info = new Array();
    info[info.length] = '<table cellpadding="0" cellspacing="0" style="width:270px; height:auto; background-color:#FFFFFF; margin-left:6px; margin-right:8px; margin-top:8px; margin-bottom:8px;">';
    info[info.length] = '<tr>';
    if (pic!="")
    {
        info[info.length] = "<td><img src=\""+pic+"\" style=\"border:1px #cccccc solid; margin-right:3px; width:85px; height:100px;\" /></td>";                
    }
    info[info.length] = '<td align="left" valign="top"><span style="color:#0066cc;"><strong>'+name+'</strong></span><br />';
    //info[info.length] = '<img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/spacer.gif" width="10" height="24" align="absmiddle" /><br />';
    if (address!="")
        info[info.length] = '<img src="images/diachi.gif" width="20" height="20" align="absmiddle"/>'+address+'<br />';
    if (tel!="")
        info[info.length] = '<img src="images/dienthoai.gif" width="20" height="20" align="absmiddle"/>'+tel+'<br />';
    if (comment!="")
        info[info.length] = '<img src="images/ghichu.gif" width="20" height="20" align="absmiddle"/>\"'+comment+'...\"<br />';
    info[info.length] = '</td>';
    info[info.length] = '</tr>';
    info[info.length] = '<tr>';
    //info[info.length] = "<td align=\"left\" colspan=\"2\"><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#ff0000')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"ViewDetailInfo("+order+","+lat+","+lng+",'"+name+"',"+dolgisId+",'"+table+"')\">Chi tiết </a>";
    //info[info.length] = "<td align=\"left\" colspan=\"2\"><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#ff0000')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"ViewDetailInfo("+order+","+lat+","+lng+",'"+name+"','"+address+"','"+comment+"','"+logo+"','"+pic+"','"+tel+"')\">Chi tiết </a>";
    info[info.length] = "<td align=\"left\" colspan=\"2\"> <a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#ff0000')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"ViewDetailInfo("+order+","+lat+","+lng+",'"+name+"',"+dolgisId+",'"+table+"')\">Chi tiết </a>";
    info[info.length] = "<span style=\"color:#cc6600;\">| </span><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#ff0000')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"ViewDetailCurrentLevelWithSearchNearBy("+order+","+lat+","+lng+")\">Tìm xung quanh</a></td>";// <span style=\"color:#cc6600;\"> | </span> <a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"\">Lưu vào bản đồ của tôi </a> </td>";
    info[info.length] = '</tr>';
    info[info.length] = '</table>';
    return info.join("");
}
function loadMapMoreInfo(lat,lng)
{
    var map1 = new VMap(document.getElementById('InfoMap'));
    map1.addControl(new VSmallZoomControl());
    map1.setCenter(new VLatLng(lat,lng),map.numLevels-1);
    var icon = new VIcon('images/mymap_icon/point_7.gif');
    icon.iconSize = new VSize(32,32);
    var mopt = new VMarkerOptions(icon);
    var marker = new VMarker(new VLatLng(lat,lng),mopt);
    map1.addOverlay(marker);   
}
function MoreDetail(order,lat,lng,name,area,popu,dantoc,comment,address,tinhly)
{
    var info = new Array();
    /*info[info.length] = '<table cellpadding="0" cellspacing="0" class="infowindow_max">';
    info[info.length] = '<tr>';
    info[info.length] = '<td align="left" valign="top" style="width:250px; height:175px;">';
    info[info.length] = '<table cellspacing="0" cellpadding="0" class="thongtinchitiet">';
    info[info.length] = '<tr>';
    info[info.length] = '<td align="left" valign="top"><span style="color:#0066cc;"><strong>'+name+'</strong></span><br />';
    //info[info.length] = '<img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/spacer.gif" width="10" height="24" align="absmiddle" /><br />';
    //info[info.length] = '<img src="images/diachi.gif" width="20" height="20" align="absmiddle"/>'+area+'<br />';
    if(tinhly != "")
        info[info.length] = '<B>Tỉnh lỵ</B>: '+tinhly+' <br />';
    if(area != "")
        info[info.length] = '<B>Diện tích</B>: '+area+' km<sup>2</sup><br />';
    if(popu != "")
        info[info.length] = '<B>Dân số</B>: '+popu+'<br />';

 if(LayerNameInfo.indexOf('district') >= 0)
    {
        if(dantoc != "")
            info[info.length] = '<B>Tỉnh/Thành</B>: '+dantoc+'<br />';
    }
    if(comment != "")
        info[info.length] = '<I>( '+comment+' )</I><br /></td>';
    info[info.length] = '</td>';
    info[info.length] = '</tr>';
    info[info.length] = '<tr>';
    if(dsResultData != null)
        info[info.length] = "<td align=\"left\" valign=\"top\"><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"FromHere("+order+","+lat+","+lng+",'"+name+", "+address+"')\">Từ đây</a> <span style=\"color:#cc6600;\">|</span> <a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"ToHere("+order+","+lat+","+lng+",'"+name+", "+address+"')\">Đến đây</a> <br/> <span style=\"color:#cc6600;\"> « </span><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"ViewDetailCurrentLevel("+order+","+lat+","+lng+")\">Quay lại</a><img src=\"images/spacer.gif\" width=\"10\" height=\"20\" align=\"absmiddle\" /></td>";
    else
        info[info.length] = "<td align=\"left\" valign=\"top\"><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"FromHere("+order+","+lat+","+lng+",'"+name+", "+address+"')\">Từ đây</a> <span style=\"color:#cc6600;\">|</span> <a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"ToHere("+order+","+lat+","+lng+",'"+name+", "+address+"')\">Đến đây</a> </td>";
    //info[info.length] = "<td align=\"left\" valign=\"top\"><br/> <span style=\"color:#cc6600;\"> « </span><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"ViewDetailCurrentLevel("+order+","+lat+","+lng+")\">Quay lại</a><img src=\"images/spacer.gif\" width=\"10\" height=\"20\" align=\"absmiddle\" /></td>";
    info[info.length] = '</tr>';
    info[info.length] = '</table></td>';
    info[info.length] = '<td align="right" valign="bottom" style="width:273px; height:175px;"><div id="InfoMap" style="width:265px; height:155px; border:1px #cccccc solid; margin-bottom:5px;position:relative; left:0px; top:0px;"></div></td>';
    info[info.length] = '</tr>';
    info[info.length] = '<tr>';
    info[info.length] = '<td valign="bottom" colspan="2" style="height:25px;">';
    info[info.length] = '<div class="tab_over">';
	info[info.length] = '<table align="left" cellspacing="0" cellpadding="0" class="table_over">';
	info[info.length] = '<tr>';
	info[info.length] = '<td align="center" valign="middle" class="bg_tab" style="background-image:url(images/btgreen.gif);">';
	info[info.length] = '<a href="#" class="tablink">Tổng quan </a></td>';
	info[info.length] = '<td style="width:3px;"></td>';
	info[info.length] = '<td align="center" valign="middle" class="bg_tab" style="background-image:url(images/btwhite.gif);">';
	info[info.length] = '<a href="#" class="tablink">Hình ảnh </a></td>';
	info[info.length] = '</tr>';
	info[info.length] = '</table>';
	info[info.length] = '</div>';
	info[info.length] = '</td>';
	info[info.length] = '</tr>';
	info[info.length] = '<tr>';
	info[info.length] = '<td colspan="2" style="height:175px;">';
	info[info.length] = '<div id="tongquat" align="justify" class="overview">';
	info[info.length] = '</div></td>';
	info[info.length] = '</tr>';
	info[info.length] = '</table>';*/	        
		//<!-- START DIV INFOWINDOWN MAX -->
	info[info.length] = '<div id="popup_max" style="width:475px; height:200px;">';
	info[info.length] = '<div style="width:475px; height:200px;">';
	info[info.length] = '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
	info[info.length] = '<tr>';
	info[info.length] = '<td width="50%" align="left" valign="top"><table cellspacing="0" cellpadding="0">';
    info[info.length] = '<tr>';
    info[info.length] = '<td align="left" valign="top"><span style="color:#0000FF; font-weight:bold; font-size:10pt;"><img src="images/spacer.gif" width="1" height="25" align="absmiddle" />'+name+'</span><br />';
    if(tinhly != "")
        info[info.length] = '<B>Tỉnh lỵ</B>: '+tinhly+' <br />';
    if(area != "")
        info[info.length] = '<B>Diện tích</B>: '+area+' km<sup>2</sup><br />';
    if(popu != "")
        info[info.length] = '<B>Dân số</B>: '+popu+'<br />';
  if(LayerNameInfo.indexOf('district') >= 0)
    {
        if(dantoc != "")
            info[info.length] = '<B>Tỉnh/Thành</B>: '+dantoc+'<br />';
    }
    if(comment != "")
        info[info.length] = '<I>( '+comment+' )</I><br /></td>';
    info[info.length] = '</tr>';
    info[info.length] = '<tr>';
    if(dsResultData != null)
        info[info.length] = "<td align=\"left\" valign=\"top\"><img src=\"images/spacer.gif\" width=\"10\" height=\"20\" align=\"absmiddle\" /><br /><a style=\" font-size:9pt;color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,\'#ff0000\')\" onmouseout=\"ChangeTextColor(this,\'#cc6600\')\" onclick=\"ViewDetailCurrentLevel("+order+","+lat+","+lng+")\"><< Quay lại</a></td>";
    else
        info[info.length] = "<td align=\"left\" valign=\"top\"><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#ff0000')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"ViewDetailCurrentLevelWithSearchNearBy_Tree("+order+","+lat+","+lng+")\">Tìm xung quanh</a><img src=\"images/spacer.gif\" width=\"10\" height=\"20\" align=\"absmiddle\" />";    
    info[info.length] = '</tr>';
    info[info.length] = '</table></td>';
	info[info.length] = '<td width="50%" align="left" valign="top"><div id=InfoMap style="width:225px; height:170px; margin-left:5px;margin-top:15px;border:1px #999999 solid;position:relative;left:0px;top:0px;">Bản đồ nhỏ</div></td>';
	info[info.length] = '</tr>';
	info[info.length] = '</table>';
	info[info.length] = '</div>';
	info[info.length] = '</div>';
		//<!-- END DIV INFOWINDOWN MAX -->
    return info.join("");
}
function MoreDetailInfo(order,dolgisId,table,lat,lng,name,area,popu,dantoc,comment,address,tinhly)
{
    var info = new Array();
    /*info[info.length] = '<table cellpadding="0" cellspacing="0" class="infowindow_max">';
    info[info.length] = '<tr>';
    info[info.length] = '<td align="left" valign="top" style="width:250px; height:175px;">';
    info[info.length] = '<table cellspacing="0" cellpadding="0" class="thongtinchitiet">';
    info[info.length] = '<tr>';
    info[info.length] = '<td align="left" valign="top"><span style="color:#0066cc;"><strong>'+name+'</strong></span><br />';
    //info[info.length] = '<img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/spacer.gif" width="10" height="24" align="absmiddle" /><br />';
    //info[info.length] = '<img src="images/diachi.gif" width="20" height="20" align="absmiddle"/>'+area+'<br />';
    if(tinhly != "")
        info[info.length] = '<B>Tỉnh lỵ</B>: '+tinhly+' <br />';
    if(area != "")
        info[info.length] = '<B>Diện tích</B>: '+area+' km<sup>2</sup><br />';
    if(popu != "")
        info[info.length] = '<B>Dân số</B>: '+popu+'<br />';

 if(LayerNameInfo.indexOf('district') >= 0)
    {
        if(dantoc != "")
            info[info.length] = '<B>Tỉnh/Thành</B>: '+dantoc+'<br />';
    }
    if(comment != "")
        info[info.length] = '<I>( '+comment+' )</I><br /></td>';
    info[info.length] = '</td>';
    info[info.length] = '</tr>';
    info[info.length] = '<tr>';
    if(dsResultData != null)
        info[info.length] = "<td align=\"left\" valign=\"top\"><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"FromHere("+order+","+lat+","+lng+",'"+name+", "+address+"')\">Từ đây</a> <span style=\"color:#cc6600;\">|</span> <a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"ToHere("+order+","+lat+","+lng+",'"+name+", "+address+"')\">Đến đây</a> <br/> <span style=\"color:#cc6600;\"> « </span><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"ViewDetailCurrentLevel("+order+","+lat+","+lng+")\">Quay lại</a><img src=\"images/spacer.gif\" width=\"10\" height=\"20\" align=\"absmiddle\" /></td>";
    else
        info[info.length] = "<td align=\"left\" valign=\"top\"><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"FromHere("+order+","+lat+","+lng+",'"+name+", "+address+"')\">Từ đây</a> <span style=\"color:#cc6600;\">|</span> <a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"ToHere("+order+","+lat+","+lng+",'"+name+", "+address+"')\">Đến đây</a> </td>";
    //info[info.length] = "<td align=\"left\" valign=\"top\"><br/> <span style=\"color:#cc6600;\"> « </span><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"ViewDetailCurrentLevel("+order+","+lat+","+lng+")\">Quay lại</a><img src=\"images/spacer.gif\" width=\"10\" height=\"20\" align=\"absmiddle\" /></td>";
    info[info.length] = '</tr>';
    info[info.length] = '</table></td>';
    info[info.length] = '<td align="right" valign="bottom" style="width:273px; height:175px;"><div id="InfoMap" style="width:265px; height:155px; border:1px #cccccc solid; margin-bottom:5px;position:relative; left:0px; top:0px;"></div></td>';
    info[info.length] = '</tr>';
    info[info.length] = '<tr>';
    info[info.length] = '<td valign="bottom" colspan="2" style="height:25px;">';
    info[info.length] = '<div class="tab_over">';
	info[info.length] = '<table align="left" cellspacing="0" cellpadding="0" class="table_over">';
	info[info.length] = '<tr>';
	info[info.length] = '<td align="center" valign="middle" class="bg_tab" style="background-image:url(images/btgreen.gif);">';
	info[info.length] = '<a href="#" class="tablink">Tổng quan </a></td>';
	info[info.length] = '<td style="width:3px;"></td>';
	info[info.length] = '<td align="center" valign="middle" class="bg_tab" style="background-image:url(images/btwhite.gif);">';
	info[info.length] = '<a href="#" class="tablink">Hình ảnh </a></td>';
	info[info.length] = '</tr>';
	info[info.length] = '</table>';
	info[info.length] = '</div>';
	info[info.length] = '</td>';
	info[info.length] = '</tr>';
	info[info.length] = '<tr>';
	info[info.length] = '<td colspan="2" style="height:175px;">';
	info[info.length] = '<div id="tongquat" align="justify" class="overview">';
	info[info.length] = '</div></td>';
	info[info.length] = '</tr>';
	info[info.length] = '</table>';*/	        
		//<!-- START DIV INFOWINDOWN MAX -->
	info[info.length] = '<div id="popup_max" style="width:475px; height:200px;">';
	info[info.length] = '<div style="width:475px; height:200px;">';
	info[info.length] = '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
	info[info.length] = '<tr>';
	info[info.length] = '<td width="50%" align="left" valign="top"><table cellspacing="0" cellpadding="0">';
    info[info.length] = '<tr>';
    info[info.length] = '<td align="left" valign="top"><span style="color:#0000FF; font-weight:bold; font-size:10pt;"><img src="images/spacer.gif" width="1" height="25" align="absmiddle" />'+name+'</span><br />';
    if(tinhly != "")
        info[info.length] = '<B>Tỉnh lỵ</B>: '+tinhly+' <br />';
    if(area != "")
        info[info.length] = '<B>Diện tích</B>: '+area+' km<sup>2</sup><br />';
    if(popu != "")
        info[info.length] = '<B>Dân số</B>: '+popu+'<br />';
  if(LayerNameInfo.indexOf('district') >= 0)
    {
        if(dantoc != "")
            info[info.length] = '<B>Tỉnh/Thành</B>: '+dantoc+'<br />';
    }
    if(comment != "")
        info[info.length] = '<I>( '+comment+' )</I><br /></td>';
    info[info.length] = '</tr>';
    info[info.length] = '<tr>';
    info[info.length] = "<td align=\"left\" valign=\"top\"><img src=\"images/spacer.gif\" width=\"10\" height=\"20\" align=\"absmiddle\" /><br /><a style=\" font-size:9pt;color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,\'#ff0000\')\" onmouseout=\"ChangeTextColor(this,\'#cc6600\')\" onclick=\"ViewDetailCurrentLevelInfo("+order+",'"+name+"',"+lat+","+lng+","+dolgisId+",'"+table+"')\"><< Quay lại</a></td>";
    info[info.length] = '</tr>';
    info[info.length] = '</table></td>';
	info[info.length] = '<td width="50%" align="left" valign="top"><div id=InfoMap style="width:225px; height:170px; margin-left:5px;margin-top:15px;border:1px #999999 solid;position:relative;left:0px;top:0px;">Bản đồ nhỏ</div></td>';
	info[info.length] = '</tr>';
	info[info.length] = '</table>';
	info[info.length] = '</div>';
	info[info.length] = '</div>';
		//<!-- END DIV INFOWINDOWN MAX -->
    return info.join("");
}
function MoreDetailWithSearchNearBy(order,lat,lng,name,address,comment,logo,pic,tel)
{
    var info = new Array();
    info[info.length] = '<table cellpadding="0" cellspacing="0" class="infowindow_max">';
    info[info.length] = '<tr>';
    info[info.length] = '<td align="left" valign="top" style="width:250px; height:175px;">';
    info[info.length] = '<table cellspacing="0" cellpadding="0" class="thongtinchitiet">';
    info[info.length] = '<tr>';
    info[info.length] = '<td align="left" valign="top"><span style="color:#0066cc;"><strong>'+name+'</strong></span><br />';
    info[info.length] = '<img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/spacer.gif" width="10" height="24" align="absmiddle" /><br />';
    info[info.length] = '<img src="images/diachi.gif" width="20" height="20" align="absmiddle"/>'+address+'<br />';
    info[info.length] = '<img src="images/dienthoai.gif" width="20" height="20" align="absmiddle"/>'+tel+'<br /></td>';
    info[info.length] = '</tr>';
    info[info.length] = '<tr>';
    info[info.length] = "<td align=\"left\" valign=\"top\">";// <span style=\"color:#cc6600;\"> | </span><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"MoreDetailWithSearchNearBy("+order+","+lat+","+lng+",'"+name+"','"+address+"','"+comment+"','"+logo+"','"+pic+"','"+tel+"')\">Tìm xung quanh</a><img src=\"images/spacer.gif\" width=\"10\" height=\"20\" align=\"absmiddle\" /></td>";
    info[info.length] = '</tr>';
    info[info.length] = '</table></td>';
    info[info.length] = '<td align="right" valign="bottom" style="width:273px; height:175px;"><div id="InfoMap" style="width:265px; height:155px; border:1px #cccccc solid; margin-bottom:5px;position:relative; left:0px; top:0px;"></div></td>';
    info[info.length] = '</tr>';
    info[info.length] = '<tr>';
    info[info.length] = '<td valign="bottom" colspan="2" style="height:25px;">';
    info[info.length] = '<div class="tab_over">';
	info[info.length] = '<table align="left" cellspacing="0" cellpadding="0" class="table_over">';
	info[info.length] = '<tr>';
	info[info.length] = '<td align="center" valign="middle" class="bg_tab" style="background-image:url(images/btgreen.gif);">';
	info[info.length] = '<a href="#" class="tablink">Tổng quan </a></td>';
	info[info.length] = '<td style="width:3px;"></td>';
	info[info.length] = '<td align="center" valign="middle" class="bg_tab" style="background-image:url(images/btwhite.gif);">';
	info[info.length] = '<a href="#" class="tablink">Hình ảnh </a></td>';
	info[info.length] = '</tr>';
	info[info.length] = '</table>';
	info[info.length] = '</div>';
	info[info.length] = '</td>';
	info[info.length] = '</tr>';
	info[info.length] = '<tr>';
	info[info.length] = '<td colspan="2" style="height:175px;">';
	info[info.length] = '<div id="tongquat" align="justify" class="overview">';
	info[info.length] = '</div></td>';
	info[info.length] = '</tr>';
	info[info.length] = '</table>';	        
    return info.join("");
}
function InfoWindowWithSearchNearByInfo(order, lat, lng, text,dolgisId,table)
{        
    if (order==null)
        return;
    var name;
    var address;
    var comment;
    var logo;
    var pic;
    var tel;
    name = text
    address = "";
    comment = "";
    logo = "";
    pic = "";
    tel = "";        
    if (pic!="")
    {
        pic = "tourist"+"\\"+pic;
    }

    var info = new Array();
    info[info.length] = '<table cellpadding="0" cellspacing="0" style="width:270px; height:auto; background-color:#FFFFFF; margin-left:6px; margin-right:8px; margin-top:8px; margin-bottom:8px;">';
    info[info.length] = '<tr>';
    if (pic!="")
    {
        info[info.length] = "<td><img src=\""+pic+"\" style=\"border:1px #cccccc solid; margin-right:3px; width:85px; height:100px;\" /></td>";        
        pic = pic.replace(/\\/g,"\\\\");
    }
    info[info.length] = '<td align="left" valign="top" colspan="2"><span style="color:#0066cc;"><strong>'+name+'</strong></span><br />';
    //info[info.length] = '<img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/spacer.gif" width="10" height="24" align="absmiddle" /><br />';
    if (address!="")
        info[info.length] = '<img src="images/diachi.gif" width="20" height="20" align="absmiddle"/>'+address+'<br />';
    if (tel!="")
        info[info.length] = '<img src="images/dienthoai.gif" width="20" height="20" align="absmiddle"/>'+tel+'<br />';
    if (comment!="")
        info[info.length] = '<img src="images/ghichu.gif" width="20" height="20" align="absmiddle"/>\"'+comment+'...\"<br />';
    info[info.length] = '</td>';
    info[info.length] = '</tr>';
    info[info.length] = '<tr>';
    info[info.length] = "<td align=\"left\" colspan=\"2\">Tìm địa điểm ở gần vị trí này.<br/> <span style=\"color:#999999;\">VD: ủy ban.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bán kính (m)</span></td></tr>";
    info[info.length] = "<tr><td align=\"left\" colspan=\"2\"><input id=searchnearbypoint  onkeydown=\"SearchNearByPointEnter(event,'"+ name+"','"+address+"','"+ lng+"','"+ lat+"', null,null)\" type=text style=\"font-size:11px; width:155px; height:16px; border:1px #999999 solid; margin-top:7px; margin-bottom:7px; margin-right:5px;\" /><input id=searchnearbypoint_radius value='2000'  onkeydown=\"SearchNearByPointEnter(event,'"+ name+"','"+address+"','"+ lng+"','"+ lat+"', null,null)\" type=text style=\"font-size:11px; width:50px; height:16px; border:1px #999999 solid; margin-top:7px; margin-bottom:7px; margin-right:5px;\" /><img src=images/tim.gif  width=45px height=19px align=absbottom style=\"cursor:pointer; border:1px #83c327 solid; margin-bottom:7px;\" onclick=\"SearchNearByPointExt('"+name+"','"+address+"','"+ lng+"','"+ lat+"', null,'', 1,null)\" onmouseover=\"ChangeBorderColor(this,'#f4c201')\" onmouseout=\"ChangeBorderColor(this,'#83c327')\" />";
    info[info.length] = '</td></tr>';
    info[info.length] = "<tr><td align=\"left\" style=\"width:65px\"><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#ff0000')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"ViewDetailCurrentLevelInfo("+order+",'"+name+"',"+lat+","+lng+","+dolgisId+",'"+table+"')\">« Quay lại</a></td>";
    info[info.length] = "<td>";//<a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"\">Xem chi tiết </a><img src=\"images/spacer.gif\" width=\"10\" height=\"20\" align=\"absmiddle\" /><br />";
    //info[info.length] = "<a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"SearchNearByPoint()\">Tìm xung quanh</a></td>";// <span style=\"color:#cc6600;\"> | </span> <a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"\">Lưu vào bản đồ của tôi </a> </td>";
    info[info.length] = '</tr>';
    info[info.length] = '</table>';   
    return info.join("");
}
function InfoWindowWithSearchNearBy(order, lat, lng, text)
{        
    if (order==null)
        return;
    var name;
    var address;
    var comment;
    var logo;
    var pic;
    var tel;
    name = dsResultData.Tables[0].Rows[order-1].Name;
    address = dsResultData.Tables[0].Rows[order-1].Address;
    comment = dsResultData.Tables[0].Rows[order-1].Comment;
    logo = dsResultData.Tables[0].Rows[order-1].Logo;
    pic = dsResultData.Tables[0].Rows[order-1].Picture;
    tel = dsResultData.Tables[0].Rows[order-1].Tel;        
    if (pic!="")
    {
        pic = "tourist"+"\\"+pic;
    }

    var info = new Array();
    info[info.length] = '<table cellpadding="0" cellspacing="0" style="width:270px; height:auto; background-color:#FFFFFF; margin-left:6px; margin-right:8px; margin-top:8px; margin-bottom:8px;">';
    info[info.length] = '<tr>';
    if (pic!="")
    {
        info[info.length] = "<td><img src=\""+pic+"\" style=\"border:1px #cccccc solid; margin-right:3px; width:85px; height:100px;\" /></td>";        
        pic = pic.replace(/\\/g,"\\\\");
    }
    info[info.length] = '<td align="left" valign="top" colspan="2"><span style="color:#0066cc;"><strong>'+name+'</strong></span><br />';
    //info[info.length] = '<img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/spacer.gif" width="10" height="24" align="absmiddle" /><br />';
    if (address!="")
        info[info.length] = '<img src="images/diachi.gif" width="20" height="20" align="absmiddle"/>'+address+'<br />';
    if (tel!="")
        info[info.length] = '<img src="images/dienthoai.gif" width="20" height="20" align="absmiddle"/>'+tel+'<br />';
    if (comment!="")
        info[info.length] = '<img src="images/ghichu.gif" width="20" height="20" align="absmiddle"/>\"'+comment+'...\"<br />';
    info[info.length] = '</td>';
    info[info.length] = '</tr>';
    info[info.length] = '<tr>';
    info[info.length] = "<td align=\"left\" colspan=\"2\">Tìm địa điểm ở gần vị trí này.<br/> <span style=\"color:#999999;\">VD: ủy ban.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bán kính (m)</span></td></tr>";
    info[info.length] = "<tr><td align=\"left\" colspan=\"2\"><input id=searchnearbypoint  onkeydown=\"SearchNearByPointEnter(event,'"+ name+"','"+address+"','"+ lng+"','"+ lat+"', null,null)\" type=text style=\"font-size:11px; width:155px; height:16px; border:1px #999999 solid; margin-top:7px; margin-bottom:7px; margin-right:5px;\" /><input id=searchnearbypoint_radius value='2000'  onkeydown=\"SearchNearByPointEnter(event,'"+ name+"','"+address+"','"+ lng+"','"+ lat+"', null,null)\" type=text style=\"font-size:11px; width:50px; height:16px; border:1px #999999 solid; margin-top:7px; margin-bottom:7px; margin-right:5px;\" /><img src=images/tim.gif  width=45px height=19px align=absbottom style=\"cursor:pointer; border:1px #83c327 solid; margin-bottom:7px;\" onclick=\"SearchNearByPointExt('"+name+"','"+address+"','"+ lng+"','"+ lat+"', null,'', 1,null)\" onmouseover=\"ChangeBorderColor(this,'#f4c201')\" onmouseout=\"ChangeBorderColor(this,'#83c327')\" />";
    info[info.length] = '</td></tr>';
    info[info.length] = "<tr><td align=\"left\" style=\"width:65px\"><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#ff0000')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"ViewDetailCurrentLevel("+order+","+lat+","+lng+")\">« Quay lại</a></td>";
    info[info.length] = "<td>";//<a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"\">Xem chi tiết </a><img src=\"images/spacer.gif\" width=\"10\" height=\"20\" align=\"absmiddle\" /><br />";
    //info[info.length] = "<a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"SearchNearByPoint()\">Tìm xung quanh</a></td>";// <span style=\"color:#cc6600;\"> | </span> <a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"\">Lưu vào bản đồ của tôi </a> </td>";
    info[info.length] = '</tr>';
    info[info.length] = '</table>';   
    return info.join("");
}
function ViewDetailCurrentLevelWithSearchNearBy_Tree(order,lat,lng)
{
    var info = new Array();
    name = NameInfo;
    address = "";
    comment = "";
    logo = "";
    pic = "";
    tel = "";        

    info[info.length] = '<table cellpadding="0" cellspacing="0" style="width:270px; height:auto; background-color:#FFFFFF; margin-left:6px; margin-right:8px; margin-top:8px; margin-bottom:8px;">';
    info[info.length] = '<tr>';
    if (pic!="")
    {
        info[info.length] = "<td><img src=\""+pic+"\" style=\"border:1px #cccccc solid; margin-right:3px; width:85px; height:100px;\" /></td>";        
        pic = pic.replace(/\\/g,"\\\\");
    }
    info[info.length] = '<td align="left" valign="top"><span style="color:#0066cc;"><strong>'+name+'</strong></span><br />';
    //info[info.length] = '<img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/start_yellow.gif" /><img src="images/spacer.gif" width="10" height="24" align="absmiddle" /><br />';
    if (address!="")
        info[info.length] = '<img src="images/diachi.gif" width="20" height="20" align="absmiddle"/>'+address+'<br />';
    if (tel!="")
        info[info.length] = '<img src="images/dienthoai.gif" width="20" height="20" align="absmiddle"/>'+tel+'<br />';
    if (comment!="")
        info[info.length] = '<img src="images/ghichu.gif" width="20" height="20" align="absmiddle"/>\"'+comment+'...\"<br />';
    info[info.length] = '</td>';
    info[info.length] = '</tr>';
    info[info.length] = '<tr>';
    info[info.length] = "<td align=\"left\" colspan=\"2\">Tìm địa điểm ở gần vị trí này.<br/> <span style=\"color:#999999;\">VD: ủy ban.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bán kính (m)</span></td></tr>";
    info[info.length] = "<tr><td align=\"left\" colspan=\"2\"><input id=searchnearbypoint  onkeydown=\"SearchNearByPointEnter(event,'"+ name+"','"+address+"','"+ lng+"','"+ lat+"', null,null)\" type=text style=\"font-size:11px; width:155px; height:16px; border:1px #999999 solid; margin-top:7px; margin-bottom:7px; margin-right:5px;\" /><input id=searchnearbypoint_radius value='2000'  onkeydown=\"SearchNearByPointEnter(event,'"+ name+"','"+address+"','"+ lng+"','"+ lat+"', null,null)\" type=text style=\"font-size:11px; width:50px; height:16px; border:1px #999999 solid; margin-top:7px; margin-bottom:7px; margin-right:5px;\" /><img src=images/tim.gif  width=45px height=19px align=absbottom style=\"cursor:pointer; border:1px #83c327 solid; margin-bottom:7px;\" onclick=\"SearchNearByPointExt('"+name+"','"+address+"','"+ lng+"','"+ lat+"', null,'', 1,null)\" onmouseover=\"ChangeBorderColor(this,'#f4c201')\" onmouseout=\"ChangeBorderColor(this,'#83c327')\" />";
    info[info.length] = '</td></tr>';
    /*info[info.length] = "<tr><td align=\"left\"><a style=\"font-size:9pt; color:#333333;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#ff0000')\" onmouseout=\"ChangeTextColor(this,'#333333')\" onclick=\"ViewDetailCurrentLevel("+order+","+lat+","+lng+")\">« Quay lại</a></td>";
    info[info.length] = "<td colspan=\"2\"><a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"FromHere("+order+","+lat+","+lng+",'"+text+"')\">Từ đây</a> <span style=\"color:#cc6600;\">|</span> <a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"ToHere("+order+","+lat+","+lng+",'"+text+"')\">Đến đây</a> <span style=\"color:#cc6600;\"> | </span>";//<a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"\">Xem chi tiết </a><img src=\"images/spacer.gif\" width=\"10\" height=\"20\" align=\"absmiddle\" /><br />";
    info[info.length] = "<a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"SearchNearByPoint()\">Tìm xung quanh</a></td>";// <span style=\"color:#cc6600;\"> | </span> <a style=\"color:#cc6600;cursor:pointer;\" onmouseover=\"ChangeTextColor(this,'#558800')\" onmouseout=\"ChangeTextColor(this,'#cc6600')\" onclick=\"\">Lưu vào bản đồ của tôi </a> </td>";
    info[info.length] = '</tr>';*/
    info[info.length] = '</table>';   
    var windowOpt = new VInfoWindowOptions();
    windowOpt.autoPan = true;
    arrSearchMapResult[0].openInfoWindow(info.join(""),windowOpt);    
    
}
function ViewDetailCurrentLevelWithSearchNearBy(order,lat,lng)
{
    if (order == null)
        return;

    var text;
    if (dsResultData.Tables[0].Rows[order - 1].Address != dsResultData.Tables[0].Rows[order - 1].Name && dsResultData.Tables[0].Rows[order - 1].Address!="")
        text = dsResultData.Tables[0].Rows[order - 1].Name+', '+dsResultData.Tables[0].Rows[order - 1].Address;
    else
        text = dsResultData.Tables[0].Rows[order - 1].Name;
    var div = "<div align=\"center\" style=\"width:280px; overflow:hidden\">";
    var shtml = InfoWindowWithSearchNearBy(order, lat, lng, text);
    var windowOpt = new VInfoWindowOptions();
    windowOpt.autoPan = true;
    div += shtml + "</div>";
    arrSearchMapResult[order-1].openInfoWindow(div,windowOpt);    
    // Highlight Active Item
    if (dsResultData.Tables[0].Rows[order-1].DolGisId != -1)// not center point
    {
        var element;
        if (resultActive != -1)
        {
            element = document.getElementById('resultItem_'+resultActive);
            ResultEntryInActive(element);
        }
        resultActive = order;
        var element = document.getElementById('resultItem_'+resultActive);
        ResultEntryActive(element);
    }
    else
    {
        var element;
        if (resultActive != -1)
        {
            element = document.getElementById('resultItem_'+resultActive);
            ResultEntryInActive(element);
        }
    }
}
function ViewDetailCurrentLevelWithSearchNearByInfo(order,lat,lng,text,dolgisId,table)
{
    if (order == null)
        return;

    var div = "<div align=\"center\" style=\"width:280px; overflow:hidden\">";
    var shtml = InfoWindowWithSearchNearByInfo(order, lat, lng, text,dolgisId,table);
    var windowOpt = new VInfoWindowOptions();
    windowOpt.autoPan = true;
    div += shtml + "</div>";
    arrSearchMapResult[order-1].openInfoWindow(div,windowOpt);    
}

function ViewDetailCurrentLevelInfo(order,text ,lat,lng,dolgisId,table)
{   
    if (order == null)
        return;        
    map.showControls();
    var text;
    var div = "<div align=\"center\" style=\"width:280px; overflow:hidden\">";
    var shtml = ResultItemHTML_InfoWindowInfo(order, lat, lng, text,dolgisId,table);
    var windowOpt = new VInfoWindowOptions();
    windowOpt.autoPan = true;
    div += shtml + "</div>";
    arrSearchMapResult[order-1].openInfoWindow(div,windowOpt);
}
function ViewDetailCurrentLevel(order,lat,lng)
{   
    if (order == null)
        return;        
    if(dsResultData == null) return;
    map.showControls();
    var text;
    if (dsResultData.Tables[0].Rows[order - 1].Address != dsResultData.Tables[0].Rows[order - 1].Name && dsResultData.Tables[0].Rows[order - 1].Address!="")
        text = dsResultData.Tables[0].Rows[order - 1].Name+', '+dsResultData.Tables[0].Rows[order - 1].Address;
    else
        text = dsResultData.Tables[0].Rows[order - 1].Name;

    var div = "<div align=\"center\" style=\"width:280px; overflow:hidden\">";
    var shtml = ResultItemHTML_InfoWindow(order, lat, lng, text);
    var windowOpt = new VInfoWindowOptions();
    windowOpt.autoPan = true;
    div += shtml + "</div>";
    arrSearchMapResult[order-1].openInfoWindow(div,windowOpt);
    // Highlight Active Item
    if (dsResultData.Tables[0].Rows[order-1].DolGisId != -1)// not center point
    {
        var element;
        if (resultActive != -1)
        {
            element = document.getElementById('resultItem_'+resultActive);
            ResultEntryInActive(element);
        }
        resultActive = order;
        var element = document.getElementById('resultItem_'+resultActive);
        ResultEntryActive(element);
    }
    else
    {        
        var element;
        if (resultActive != -1)
        {
            element = document.getElementById('resultItem_'+resultActive);
            ResultEntryInActive(element);
        }
    }
    
}
function ViewDetail(order,lat,lng,text)
{
    
    if (order == null)
        return;
    /*if(text.indexOf("<B>Quốc</B> <B>lộ</B>") >= 0 )
        map.setCenter(new VLatLng(lat,lng),0);
    else*/
        //map.setCenter(new VLatLng(lat,lng),map.numLevels-1);
    //map.setCenter(new VLatLng(lat,lng),2);
    var PointObjectTable = "vn_cultural_society_dat";
    var div = "<div align=\"center\" style=\"width:280px; overflow:hidden\">";
    var text;
    if (dsResultData.Tables[0].Rows[order - 1].Address != dsResultData.Tables[0].Rows[order - 1].Name && dsResultData.Tables[0].Rows[order - 1].Address!="")
        text = dsResultData.Tables[0].Rows[order - 1].Name+', '+dsResultData.Tables[0].Rows[order - 1].Address;
    else
        text = dsResultData.Tables[0].Rows[order - 1].Name;
    var shtml = ResultItemHTML_InfoWindow(order, lat, lng, text);
    var windowOpt = new VInfoWindowOptions();
    if(dsResultData.Tables[0].Rows[order - 1].Table != "vn_cultural_society_dat" && dsResultData.Tables[0].Rows[order - 1].Table != "vnam_dancu_dat")//-- neu doi tuong khac Point thi ve ra
        windowOpt.autoPan = false;
    else        
        windowOpt.autoPan = true;
    div += shtml + "</div>";
    arrSearchMapResult[order-1].openInfoWindow(div,windowOpt);
    //map.panTo(new VLatLng(lat,lng));
    if(dsResultData.Tables[0].Rows[order - 1].Table != "vn_cultural_society_dat" && dsResultData.Tables[0].Rows[order - 1].Table != "vnam_dancu_dat")//-- neu doi tuong khac Point thi ve ra
        map.setCenter(new VLatLng(lat,lng),2);
        //map.panTo(new VLatLng(lat,lng));
    // Highlight Active Item
    var element;
    if (resultActive != -1)
    {
        element = document.getElementById('resultItem_'+resultActive);
        ResultEntryInActive(element);
    }
    resultActive = order;
    var element = document.getElementById('resultItem_'+resultActive);
    ResultEntryActive(element);
    //vbdmap.GetGeometry( parseInt(dsResultData.Tables[0].Rows[order - 1].DolGisId), dsResultData.Tables[0].Rows[order - 1].Table, GetGeometryChange);
    OrderID = order;
    LatInfo = dsResultData.Tables[0].Rows[order - 1].Latitude;
    LngInfo = dsResultData.Tables[0].Rows[order - 1].Longitude;
    NameInfo = dsResultData.Tables[0].Rows[order - 1].Name;
    LayerNameInfo = dsResultData.Tables[0].Rows[order - 1].Table;
    //AddressInfo = dsResultData.Tables[0].Rows[order - 1].Address;
    DolgisIdInfo = dsResultData.Tables[0].Rows[order - 1].DolGisId;
    //alert(dsResultData.Tables[0].Rows[order - 1].Table);
    
    var level = map.getLevel();
    var bound = map.getDirectionBounds();
    var  layer = dsResultData.Tables[0].Rows[order - 1].Table;
    if(layer == "vn_province_dat" || layer == "vnisland_province_dat")
        layer = 0;
    else if(layer == "vn_district_dat" || layer == "vnisland_district_dat")        
        layer = 1;
    else if(layer == "vn_ward_dat")        
        layer = 2;
    else if(layer == "vn_road_dat")        
        layer = 3;
    else if(layer == "vn_river_dat")        
        layer = 4;
    else if(layer == "vn_island_dat")        
        layer = 5;
    else if(layer == "vnsea_road_dat")        
        layer = 6;
    if(dsResultData.Tables[0].Rows[order - 1].Table != PointObjectTable && dsResultData.Tables[0].Rows[order - 1].Table != "vnam_dancu_dat")//-- neu doi tuong khac Point thi ve ra
    {
        preLoading(true);
        //vbdmap.GetGeometry(parseInt(dsResultData.Tables[0].Rows[order - 1].DolGisId), layer,level, bound.getNorthWest().longitude,  bound.getNorthWest().latitude, bound.getSouthEast().longitude,  bound.getSouthEast().latitude, GetGeometryChange);
        var dID = parseInt(dsResultData.Tables[0].Rows[order - 1].DolGisId);
        var strResult = vbdmap.GetFitLevel(dID,layer,map.getSize().width, map.getSize().height);
        if(strResult.value != null && strResult.error == null)
        {
            arr = strResult.value;
            lat = parseFloat(arr[1]);
            lng = parseFloat(arr[2]);
            level = parseInt(arr[0]);
            var bound = map.getBoundsAtCenterLevel(new VLatLng(lat,lng),level);
            //map.redrawOverlay();
            //map.setCenter(centerPoint,nLevel)
            isRegionSelected = true;
            vbdmap.GetGeometry(dID,layer,level, bound.getNorthWest().longitude,  bound.getNorthWest().latitude, bound.getSouthEast().longitude,  bound.getSouthEast().latitude, GetGeometryChange);
        }
        else
        {
            map.setCenter(new VLatLng(LatInfo,LngInfo),map.numLevels - 1)
        }
        preLoading(false);

    }
    else
    {
        if (plHighlight != null)
        {
            for(var j= 0 ; j< plHighlight.length;j++)
            {
                map.removeOverlay(plHighlight[j]);
            }
            plHighlight = null;
        }
        map.setCenter(new VLatLng(lat,lng),map.numLevels-1);
    }
    /*if(dsResultData.TablesClrea[0].Rows[order - 1].Table == "vn_province_dat")   
        map.setCenter(new VLatLng(lat,lng),4);
    else
        map.setCenter(new VLatLng(lat,lng),map.numLevels-1);*/
}
var isRegionSelected = false;
function GetGeometryChange(str)
{
    var strCoor = str.value;
    if (strCoor == '')
    {
        isRegionSelected = false;
        preLoading(false);
        return;
    }    
    if(strCoor == null)
    {
        isRegionSelected = false;
        preLoading(false);
        return;
    }
    if (plHighlight != null)
    {
        for(var j= 0 ; j< plHighlight.length;j++)
        {
            map.removeOverlay(plHighlight[j]);
        }
        plHighlight = null;
    }
    
    plHighlight =  new Array()
    isRegionSelected = true;
    var arrHightLight = new Array();
    for(var i = 0; i< strCoor.length; i++)
    {
        /*if(PathPolylineArray[currentIndex][i] != 0 && PathPolylineArray[currentIndex][i] != null)
        {
            map.removeOverlay(PathPolylineArray[currentIndex][i]);
            PathPolylineArray[currentIndex][i] = pl;
        }    
        else
            PathPolylineArray[currentIndex].push(pl)
        pl.sid = currentIndex+","+(i);*/
        plHighlight[i] = new VPolyline(strCoor[i],"blue",3,"",0.5);
        map.addOverlay(plHighlight[i]);
        arrHightLight.push(plHighlight[i]);
    }
    if(cur != -1)
    {
        if(cur.indexOf('span_') >= 0) // province
        {
            map.fitMultiOverlays(arrHightLight);
            /*var windowOpt = new VInfoWindowOptions();
            windowOpt.autoPan = true;
            var str = "<table width=150px border=0 cellspacing=0 cellpadding=0 style=\"margin-left:3px; margin-top:3px;\">";
              str += "<tr align=left><td>"+NameInfo;
            str +=" </tr></table>";    
            arrSearchMapResult[0].openInfoWindow(str,windowOpt);*/
            //map.panTo(new VLatLng(LatInfo,LngInfo));
        }
        else
        {
            preIndex = pre.substring(0,pre.lastIndexOf('_'));
            curIndex = cur.substring(0,cur.lastIndexOf('_'));
            if(preIndex == curIndex || pre.indexOf('span_') >= 0)
            {
                /*var windowOpt = new VInfoWindowOptions();
                windowOpt.autoPan = true;*/
                //var level = map.getLevelMultiOverlays(arrHightLight);
                //map.zoomToLevel(level);
                //map.fitMultiOverlays(arrHightLight);
                /*var str = "<table width=150px border=0 cellspacing=0 cellpadding=0 style=\"margin-left:3px; margin-top:3px;\">";
                  str += "<tr align=left><td>"+NameInfo;
                str +=" </tr></table>";    
                arrSearchMapResult[0].openInfoWindow(str,windowOpt);*/
                //map.setCenter(new VLatLng(LatInfo,LngInfo),level);
                
            }
            /*else
                map.fitMultiOverlays(arrHightLight);*/
        }
    }
    else
    {
        //if(dsResultData.Tables[0].Rows[OrderID - 1].Table != "vn_cultural_society_dat" && dsResultData.Tables[0].Rows[OrderID - 1].Table != "vnam_dancu_dat")//-- neu doi tuong khac Point thi ve ra
            map.fitMultiOverlays(arrHightLight);
    }       
    preLoading(false);
    
}
var OrderID = -1;
var NameInfo = "";
var LatInfo = 0;
var LngInfo = 0;
var LayerNameInfo = "";
var AddressInfo = "";
var TinhLyInfo = "";
var DolgisIdInfo = "";
function ViewDetailInfo(order,lat,lng,name,dolgisId,layerName,address,tinhly)
{
    OrderID = order;
    NameInfo = name;
    LatInfo = lat;
    LngInfo = lng;
    LayerNameInfo = layerName;
    AddressInfo = address;
    TinhLyInfo = tinhly;
    DolgisIdInfo = dolgisId;
    if(layerName == "vnisland_province_dat")
        layerName = "vn_province_dat"
    vbdmap.getMoreInfoGov(dolgisId,layerName,ViewDetailInfo_CallBack)
}
function ViewDetailInfo_CallBack(dss)
{
    var ds = dss.value;
    var area = "";
    var popu = "";
    var dantoc = "";
    var comment = "";
    var tinhly = "";
    if(ds == "" || ds == null)
    {
        var div = "<div align=\"center\" style=\"width:497px; overflow:hidden\">";
        if(isTreeClick)
            var shtml = MoreDetailInfo(OrderID,DolgisIdInfo,LayerNameInfo,LatInfo,LngInfo,NameInfo,area,popu,dantoc,comment,AddressInfo,tinhly);
        else
            var shtml = MoreDetail(OrderID,LatInfo,LngInfo,NameInfo,area,popu,dantoc,comment,AddressInfo,tinhly);
        div += shtml + "</div>";    
        var windowOpt = new VInfoWindowOptions();
        windowOpt.autoPan = true;
        arrSearchMapResult[OrderID-1].openInfoWindow(div,windowOpt);
        loadMapMoreInfo(LatInfo,LngInfo);
        map.hideControls();
        return;
    }
    //map.setCenter(new VLatLng(LatInfo,LngInfo),map.numLevels-1);
    var div = "<div align=\"center\" style=\"width:497px; overflow:hidden\">";
    area = ds.Tables[0].Rows[0].DIENTICH;
    popu = ds.Tables[0].Rows[0].DANSO;
    if(LayerNameInfo.indexOf('province') >= 0 )
        dantoc = ds.Tables[0].Rows[0].TPDANTOC;
    else if (LayerNameInfo.indexOf('district') >= 0)    
        dantoc = ds.Tables[0].Rows[0].NAME;
    comment = ds.Tables[0].Rows[0].COMMENT;
    tinhly = ds.Tables[0].Rows[0].TINHLY;
    if(isTreeClick)
        var shtml = MoreDetailInfo(OrderID,DolgisIdInfo,LayerNameInfo,LatInfo,LngInfo,NameInfo,area,popu,dantoc,comment,AddressInfo,tinhly);
    else
        var shtml = MoreDetail(OrderID,LatInfo,LngInfo,NameInfo,area,popu,dantoc,comment,AddressInfo,tinhly);
    div += shtml + "</div>";    
    var windowOpt = new VInfoWindowOptions();
    windowOpt.autoPan = true;
    arrSearchMapResult[OrderID-1].openInfoWindow(div,windowOpt);
    loadMapMoreInfo(LatInfo,LngInfo);
    map.hideControls();
}
function RegionSelect()
{
    vbdmap.getMoreInfoGov(DolgisIdInfo,LayerNameInfo,ViewDetailInfo_CallBack)
}
/*
function ViewDetailInfo(order,lat,lng,name,address,comment,logo,pic,tel)
{
    if (order == null)
        return;    
    map.setCenter(new VLatLng(lat,lng),map.numLevels-1);
    var div = "<div align=\"center\" style=\"width:530px; overflow:hidden\">";
    var text;
    if (dsResultData.Tables[0].Rows[order - 1].Address != dsResultData.Tables[0].Rows[order - 1].Name && dsResultData.Tables[0].Rows[order - 1].Address!="")
        text = dsResultData.Tables[0].Rows[order - 1].Name+', '+dsResultData.Tables[0].Rows[order - 1].Address;
    else
        text = dsResultData.Tables[0].Rows[order - 1].Name;
    var shtml = MoreDetail(order,lat,lng,name,address,comment,logo,pic,tel);
    var windowOpt = new VInfoWindowOptions();
    windowOpt.autoPan = true;
    div += shtml + "</div>";    
    arrSearchMapResult[order-1].openInfoWindow(div,windowOpt);
    loadMapMoreInfo(lat,lng);
    // Highlight Active Item
//    var element;
//    if (resultActive != -1)
//    {
//        element = document.getElementById('resultItem_'+resultActive);
//        ResultEntryInActive(element);
//    }
//    resultActive = order;
//    var element = document.getElementById('resultItem_'+resultActive);
//    ResultEntryActive(element);
}
*/
function ShowSearchNearByLngLat(pt)
{    
    var lnglat = pt.toString();
    var fidx = lnglat.indexOf(',');
    var lat = lnglat.substring(0,fidx);
    var lng = lnglat.substring(fidx+1);
    var str = "<table width=270px border=0 cellspacing=0 cellpadding=0 style=\"margin-left:3px; margin-top:3px;\">";
      str += "<tr align=left><td>";
      str += " Tìm địa điểm ở gần vị trí này.<br/> <span style=\"color:#999999;\">VD: ủy ban.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bán kính (m)</span></td></tr>";
      str += "<tr><td><input id=searchnearbypoint onkeydown=\"SearchNearByPointEnter(event,'"+lnglat+"','','"+lng+"','"+ lat+"', null,null)\" type=text style=\"font-size:11px; width:155px; height:16px; border:1px #999999 solid; margin-top:7px; margin-bottom:7px; margin-right:5px;\" /><input id=searchnearbypoint_radius value='2000' onkeydown=\"SearchNearByPointEnter(event,'"+lnglat+"','','"+lng+"','"+ lat+"', null,null)\" type=text style=\"font-size:11px; width:50px; height:16px; border:1px #999999 solid; margin-top:7px; margin-bottom:7px; margin-right:5px;\" /><img src=images/tim.gif  width=45px height=19px align=absbottom style=\"cursor:pointer; border:1px #83c327 solid; margin-bottom:7px;\" onclick=\"SearchNearByPointExt('"+lnglat+"','','"+lng+"','"+lat+"',null,'',1,null)\" onmouseover=\"ChangeBorderColor(this,'#f4c201')\" onmouseout=\"ChangeBorderColor(this,'#83c327')\" /></td>";
        str +=" </tr></table>";    
    map.openInfoWindow(pt, str);
    
};  

function SearchPlace(index,value)
{			
	var key;
	key = value;
	current_index = index;
	if (value!="")
	    showBusyDiv("");
	if (key != null)
	{
		key	= key.replace("&", "!");
		key	= key.replace("'", "`");
	}
	if (key.length > 0)
	{
        /*nX = -parseInt(document.getElementById('box').style.left) + 256*nYImage;
        nY = -parseInt(document.getElementById('box').style.top) + 256*nXImage;
        dbLX = nX*parseFloat(MatrixV2R[nCurrentLevel][0].toString()) + nY*parseFloat(MatrixV2R[nCurrentLevel][2].toString()) + parseFloat(MatrixV2R[nCurrentLevel][4].toString());
        dbRY = nX*parseFloat(MatrixV2R[nCurrentLevel][1].toString()) + nY*parseFloat(MatrixV2R[nCurrentLevel][3].toString()) + parseFloat(MatrixV2R[nCurrentLevel][5].toString());
        nX = MainMap_Width - parseInt(document.getElementById('box').style.left) + 256*nYImage;
        nY = MainMap_Height - parseInt(document.getElementById('box').style.top) + 256*nXImage;
        dbRX = nX*parseFloat(MatrixV2R[nCurrentLevel][0].toString()) + nY*parseFloat(MatrixV2R[nCurrentLevel][2].toString()) + parseFloat(MatrixV2R[nCurrentLevel][4].toString());
        dbLY = nX*parseFloat(MatrixV2R[nCurrentLevel][1].toString()) + nY*parseFloat(MatrixV2R[nCurrentLevel][3].toString()) + parseFloat(MatrixV2R[nCurrentLevel][5].toString());
		*/
        var bound = map.getBounds();
        dbLX = bound.getNorthWest().longitude;
        dbLY = bound.getNorthWest().latitude;
        dbRX = bound.getSouthEast().longitude;
        dbRY = bound.getSouthEast().latitude;
        var nCurrentLevel = map.getLevel();
        var current_searchtype = GLOBAL_SEARCH_MAP;
		vbdmap.SearchResult(key, "", "", 1, nCurrentLevel, dbLX, dbLY, dbRX, dbRY, current_searchtype, FindPathSearch_CallBack)
	}
}

function FindPathSearch_CallBack(dss)
{
	hideBusyDiv();
	var dsResultData = dss.value;
	var info = new Array();
	if ((null != dsResultData)  && ("object" == typeof(dsResultData)))
	{   
        var length = dsResultData.Tables[0].Rows.length;
        var nHitSize = dsResultData.Tables[1].Rows[0].HitSize;        
        if (nHitSize == 1)
        {
            if (dsResultData.Tables[0].Rows[0].Address!="")
                AddPlaceAB(current_index, dsResultData.Tables[0].Rows[0].Latitude, dsResultData.Tables[0].Rows[0].Longitude, dsResultData.Tables[0].Rows[0].Name+", "+dsResultData.Tables[0].Rows[0].Address);                        
            else
                AddPlaceAB(current_index, dsResultData.Tables[0].Rows[0].Latitude, dsResultData.Tables[0].Rows[0].Longitude, dsResultData.Tables[0].Rows[0].Name);
            map.setCenter(new VLatLng(dsResultData.Tables[1].Rows[0].CenterLat,dsResultData.Tables[1].Rows[0].CenterLng),dsResultData.Tables[1].Rows[0].Level);    
            //hideBusyDiv();
            return;
        }
        info[info.length] = "<table id=TablePlace width=100% border=0 cellspacing=0 cellpadding=0 style=overflow:auto;>";
        if (nHitSize > 0)
        {
            info[info.length] = "<tr><td></td></tr>";
        }
        else
        {
            var suggestedKey = dsResultData.Tables[1].Rows[0].SuggestedKey; 
            var key = dsResultData.Tables[1].Rows[0].Key;     
            var isLonLat = dsResultData.Tables[1].Rows[0].IsLonLat;
            var isAddress = dsResultData.Tables[1].Rows[0].IsAddress;    
            info[info.length] = "<tr>";
            if (suggestedKey!="" && !isLonLat && !isAddress)
            {
                if (current_searchtype == GLOBAL_SEARCH_MAP)
                    info[info.length] = "<td height=20px align=left valign=middle style=\"font-size:11px;\"><span style=\"color:#FF0000; font-size:12px;\">Có phải bạn muốn tìm: </span><b><span style=\"color:#006699\"><a style=\"text-decoration:underline; cursor:pointer; font-size:12px;\" id=\"dym\" onclick=\"FindPlaceSpellCheckerClick("+ current_index+",'"+ suggestedKey +"')\">"+suggestedKey+"</a></span>?</b><br/><br/><br/>";                
                info[info.length] = '</td>';
            }
            else
            {
                if (isLonLat)
                info[info.length] = "<tr><td height=20px align=left valign=middle>Không xác định được tọa độ: <b>"+dsResultData.Tables[1].Rows[0].Key+"</b></td></tr>";
            else if (isAddress)
                info[info.length] = "<tr><td height=20px align=left valign=middle>Không tìm thấy địa chỉ: <b>"+dsResultData.Tables[1].Rows[0].Key+"</b><br /><br />&nbspĐề xuất:<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"vbd_images/dot.gif\" width=\"8\" height=\"8\"/> Xin bạn chắc chắn đã viết đúng địa chỉ.<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"vbd_images/dot.gif\" width=\"8\" height=\"8\"/> Nếu bạn viết tắt, hãy thử không viết tắt.</td></tr>";
            else
                info[info.length] = "<td height=20px align=left valign=middle style=\"font-size:11px;\">Không tìm thấy dữ liệu liên quan đến <b>"+key+"</b><br /><br />&nbspĐề xuất:<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"vbd_images/dot.gif\" width=\"8\" height=\"8\"/> Xin bạn chắc chắn đã viết đúng chính tả.<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"vbd_images/dot.gif\" width=\"8\" height=\"8\"/> Nếu bạn viết tắt, hãy thử không viết tắt.<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"vbd_images/dot.gif\" width=\"8\" height=\"8\" /> Hãy thử dùng các từ khóa khác có nghĩa tương tự.<br /></td>";
            }
            info[info.length] = "</tr>";             
        }                                    
        for(var i=0; i<length; i++)
        {
            info[info.length] = "<tr><td align=\"center\" valign=\"middle\">";
            if (dsResultData.Tables[0].Rows[i].Address!="")
                info[info.length] = "<table width=\"99%\" border=\"0\" align=\"left\" cellpadding=\"0\" cellspacing=\"0\" onmouseover=\"ResultEntryPlaceABMouseOver(this)\" onmouseout=\"ResultEntryPlaceABMouseOut(this)\" style=\"border:1px #ffffff solid; border-bottom:1px #efefef solid; margin-left:2px; margin-right:2px;cursor:pointer\" onclick=\"AddPlaceAB("+current_index+","+dsResultData.Tables[0].Rows[i].Latitude+","+dsResultData.Tables[0].Rows[i].Longitude+",'"+dsResultData.Tables[0].Rows[i].Name+", "+dsResultData.Tables[0].Rows[i].Address+"')\">";
            else
                info[info.length] = "<table width=\"99%\" border=\"0\" align=\"left\" cellpadding=\"0\" cellspacing=\"0\" onmouseover=\"ResultEntryPlaceABMouseOver(this)\" onmouseout=\"ResultEntryPlaceABMouseOut(this)\" style=\"border:1px #ffffff solid; border-bottom:1px #efefef solid; margin-left:2px; margin-right:2px;cursor:pointer\" onclick=\"AddPlaceAB("+current_index+","+dsResultData.Tables[0].Rows[i].Latitude+","+dsResultData.Tables[0].Rows[i].Longitude+",'"+dsResultData.Tables[0].Rows[i].Name+"')\">";
            info[info.length] = "<tr><td colspan=\"2\" style=\"height:5px;\"></td></tr>";
            info[info.length] = "<tr>";
            info[info.length] = "<td align=\"center\" valign=\"middle\" style=\"width:40px;\">";
            info[info.length] = "<img  id=resultimage_placeAB"+(i+1)+" src=images/"+(i+1)+".gif alt=\"\" /></td>";
            info[info.length] = "<td align=\"left\">";
            if (dsResultData.Tables[0].Rows[i].Address!="")
                info[info.length] = "<a style=\"color:#0066cc; cursor:pointer;\" onmouseover=\"ChangeTextColor(this,\'#558800\')\" onmouseout=\"ChangeTextColor(this,\'#0066cc\')\" onclick=\"SelectPlaceAB("+current_index+","+dsResultData.Tables[0].Rows[i].Latitude+","+dsResultData.Tables[0].Rows[i].Longitude+",'"+dsResultData.Tables[0].Rows[i].Name+", "+dsResultData.Tables[0].Rows[i].Address+"')\">"+dsResultData.Tables[0].Rows[i].Name+"</a><br />"+dsResultData.Tables[0].Rows[i].Address+"<br />";
            else
                info[info.length] = "<a style=\"color:#0066cc; cursor:pointer;\" onmouseover=\"ChangeTextColor(this,\'#558800\')\" onmouseout=\"ChangeTextColor(this,\'#0066cc\')\" onclick=\"SelectPlaceAB("+current_index+","+dsResultData.Tables[0].Rows[i].Latitude+","+dsResultData.Tables[0].Rows[i].Longitude+",'"+dsResultData.Tables[0].Rows[i].Name+"')\">"+dsResultData.Tables[0].Rows[i].Name+"</a><br />"+dsResultData.Tables[0].Rows[i].Address+"<br />";
            info[info.length] = "</td>";
            info[info.length] = "</tr>";
	        info[info.length] = "<tr>";
	        info[info.length] = "<td colspan=\"2\" style=\"height:5px;\"></td>";
	        info[info.length] = "</tr>";
            info[info.length] = "</table>";
            info[info.length] = "</td></tr>";
//            var latlng = new VLatLng(dsResultData.Tables[0].Rows[i].Latitude,dsResultData.Tables[0].Rows[i].Longitude);
//            var icon = new VIcon(dsResultData.Tables[0].Rows[i].Logo);
//            var mopt = new VMarkerOptions(icon);
//            var marker = new VMarker(latlng,mopt);
//            map.addOverlay(marker);
//            arrSearchMapResult.push(marker);
        }
        info[info.length] = "</table>";
      	var resultContent = info.join("");
      	//hideBusyDiv();
      	//Tao table ket qua
      	var curTextboxOffsetTop = document.getElementById('direction'+current_index).offsetTop;
		var divScrollTop = document.getElementById('findpath_div').scrollTop;
		var findPathDivHeight = document.getElementById('findpath_div').clientHeight;		
		var valign = "top";
		var Top = curTextboxOffsetTop - divScrollTop;
		if (Top + 280 < findPathDivHeight)
		    Top = Top + 122 + 25;
		else
	    {
	        Top = Top + 122 - 261 + 45;	  
	        valign = "bottom";
	    }
      	info = new Array();
      	info[info.length] = '<table width="100%" height="280" border="0" cellspacing="0" cellpadding="0" >';
        info[info.length] = '<tr>';
        info[info.length] = '<td class="p_topL"></td>';
        info[info.length] = '<td class="p_topM"></td>';
        info[info.length] = '<td class="p_topR"></td>';
        info[info.length] = '</tr>';
        info[info.length] = '<tr>';
        info[info.length] = '<td class="p_middleL" align="right" valign='+valign+'><img src="images/selectplace_tamgiac.gif" /></td>';
        info[info.length] = '<td class="p_middle">';
        info[info.length] = '<div class="yellow" id="title_selectplace" style="float:none; width:260px; height:24px;background-Color:#ffffff;"><strong>Chọn một vị trí cho điểm <img src="images/place_'+current_index+'.gif" align="absmiddle" /></strong></div>';
        info[info.length] = '<div id="info_selectplace" style="float:none; width:260px; height:208px; overflow:auto;background-Color:#ffffff;">';
		info[info.length] = resultContent;
		info[info.length] = '</div>';
		info[info.length] = '<div id="close_selectplace" style="float:none; width:260px; height:26px;background-Color:#ffffff;">';	    
	    //info[info.length] = "<img src=\"images/chon.gif\" onmouseover=\"ChangeBorderColor(this,'#f4c201')\" onmouseout=\"ChangeBorderColor(this,'#83c327')\" style=\"cursor:pointer; border:1px #83c327 solid; margin-left:145px; margin-top:4px\" alt=\"\" onclick=\"AddPlaceAB(null,null,null,null)\"/><img src=\"images/dong1.gif\" onmouseover=\"ChangeBorderColor(this,'#f4c201')\" onmouseout=\"ChangeBorderColor(this,'#83c327')\" style=\"cursor:pointer; border:1px #83c327 solid; margin-left:5px;margin-top:4px\" alt=\"\" onclick=\"DeletePlaceTable(true)\" /></div>";
	    info[info.length] = "</div>";
	    info[info.length] = '</td>';
		info[info.length] = '<td class="p_middleR"></td>';
		info[info.length] = '</tr>';
		info[info.length] = '<tr>';
		info[info.length] = '<td class="p_bottomL"></td>';
		info[info.length] = '<td class="p_bottomM"></td>';
		info[info.length] = '<td class="p_bottomR"></td>';
		info[info.length] = '</tr>';
		info[info.length] = '</table>';
		myrect = document.getElementById('SelectPlace');				
		if (myrect==null)
		{    //DeletePlaceTable(true);
		    myrect	=	document.createElement('div');											
		    myrect.id	=	'SelectPlace';							
		    document.body.appendChild(myrect);
		    myrect.style.left = 345 + "px";
		    myrect.style.top = Top + "px";
		    myrect.style.position	=	'absolute';
		    myrect.style.overflow = 'hidden';
		    myrect.style.width	=	290 + "px";
		    myrect.style.height	=	280 + "px";            
		    myrect.style.zIndex = 400;
		}
		else
		    myrect.style.top = Top + "px";
		myrect.innerHTML = info.join("");
		//hideBusyDiv();
      	// end Tao Table Ket qua
//     	if (nHitSize > 0)
//	        map.setCenter(new VLatLng(dsResultData.Tables[1].Rows[0].CenterLat,dsResultData.Tables[1].Rows[0].CenterLng),dsResultData.Tables[1].Rows[0].Level);    
	}
	//hideBusyDiv();
}

function SelectPlaceAB(index, lat, lng, text)
{
    var direction = document.getElementById("direction"+index);
    // Remove <B>, </B>
    var literal = "<B>";
	var replacement = "";
	var re = new RegExp(literal,"g");
    text = text.replace(re, replacement);
    
    literal = "</B>";
	re = new RegExp(literal,"g");
    text = text.replace(re, replacement);
    // End remove
    direction.childNodes[0].rows[0].cells[1].childNodes[0].value = text;
    currentSelectedResAB_Id = index;
    currentSelectedResAB_Lat = lat;
    currentSelectedResAB_Lng = lng;
    currentSelectedResAB_Text = text;
}
/*function AddPlaceAB(index, lat, lng, text)
{
    if (index==null)
        index = currentSelectedResAB_Id;
    if (lat == null)
        lat = currentSelectedResAB_Lat;
    if (lng == null)
        lng = currentSelectedResAB_Lng;
    if (text == null)
        text = currentSelectedResAB_Text;
    if (index == -1)
    {
        DeletePlaceTable(); 
        return;
    }
    PlaceStatusArray[index] = 1;
    var direction = document.getElementById("direction"+index);
    // Remove <B>, </B>
    var literal = "<B>";
	var replacement = "";
	var re = new RegExp(literal,"g");
    text = text.replace(re, replacement);
    
    literal = "</B>";
	re = new RegExp(literal,"g");
    text = text.replace(re, replacement);
    // End remove
    direction.childNodes[0].rows[0].cells[1].childNodes[0].value = text;
    if (index >= PlaceToFindPathArray.length)
    {
        if(index > PlaceToFindPathArray.length)
            direction.childNodes[0].rows[0].cells[1].childNodes[0].value = "";
        AddPlaceToFind(new VLatLng(lat,lng),text);
    }
    else
    {
        PlaceToFindPathArray[index][0].setPoint(new VLatLng(lat,lng));
        FindShortestPath(index+",0",0,0,0);
    }
    DeletePlaceTable();    
}*/
function AddPlaceAB(index, lat, lng, text)
{
    if (index == null) index = currentSelectedResAB_Id;
    if (lat == null) lat = currentSelectedResAB_Lat;
    if (lng == null) lng = currentSelectedResAB_Lng;
    if (text == null) text = currentSelectedResAB_Text;
    
    if (index == -1)
    {
        HideSelectPlaceBox(); 
        return;
    }
    var direction = document.getElementById("direction"+index);
    text = RemoveHTMLTag(text);
    
    var placecount = PlaceToFindPathArray.length;
    
    PlaceStatusArray[index] = 1;
    if (index + 1 >= placecount)
    {
        RemovePlace(index + ",0");
        if(toFirstFlag == false)
        {
            if(index == 0)
                AddPlaceFromFind(new VLatLng(lat,lng),text);
            else
                AddPlaceToFind(new VLatLng(lat,lng),text);
        }
        else
            AddPlaceFromFind(new VLatLng(lat,lng),text); 
    }
    else //Old place, find again but only find in changed section.
    {
        direction.childNodes[0].rows[0].cells[1].childNodes[0].value = text;
        PlaceToFindPathArray[index][0].setPoint(new VLatLng(lat,lng));
        FindShortestPath(index+",0",0,0,0);
    }
    changeContentFlag = false;    
    HideSelectPlaceBox();    
}
function HideSelectPlaceBox()
{
	myrect = document.getElementById('SelectPlace');
	if(myrect != null) document.body.removeChild(myrect);
}
function RemoveHTMLTag(text)
{
    text = text.replace(/<[a-zA-Z]*?[0-9]*>|<[/][a-zA-Z]*?[0-9]*>/g, "");
    
	return text;
}

function DeletePlaceTable(erase)
{
	myrect = document.getElementById('SelectPlace');
	if(myrect != null)
	{	document.body.removeChild(myrect);
	    if (erase)// fill lai text cu trong TH bo chon
	    {
	        PlaceStatusArray[current_index] = 1;
            var direction = document.getElementById('direction'+current_index);
            direction.childNodes[0].rows[0].cells[1].childNodes[0].value = selectedResAB_Text;	
            selectedResAB_Text = "";
        }
    }        
}
function FromHere(order, lat, lng, text)
{
    // Remove <B>, </B>
    var literal = "<B>";
	var replacement = "";
	var re = new RegExp(literal,"g");
    text = text.replace(re, replacement);
    
    literal = "</B>";
	re = new RegExp(literal,"g");
    text = text.replace(re, replacement);
    // End remove
    AddPlaceFromFind(new VLatLng(lat,lng), text);
}
function ToHere(order, lat, lng, text)
{
    // Remove <B>, </B>
    var literal = "<B>";
	var replacement = "";
	var re = new RegExp(literal,"g");
    text = text.replace(re, replacement);
    
    literal = "</B>";
	re = new RegExp(literal,"g");
    text = text.replace(re, replacement);
    // End remove
    AddPlaceToFind(new VLatLng(lat,lng), text);
}
function Toggle(node)
{
	// Unfold the branch if it isn't visible
	if (node.nextSibling.style.display == 'none')
	{
		// Change the image (if there is an image)
		if (node.children.length > 0)
		{
			if (node.children.item(0).tagName == "IMG")
			{
				node.children.item(0).src = "treechapters/minus.gif";
			}
		}

		node.nextSibling.style.display = '';
	}
	// Collapse the branch if it IS visible
	else
	{
		// Change the image (if there is an image)
		if (node.children.length > 0)
		{
			if (node.children.item(0).tagName == "IMG")
			{
				node.children.item(0).src = "treechapters/plus.gif";
			}
		}

		node.nextSibling.style.display = 'none';
	}

}

function Show_Map_Help()
{
    if (arrSearchMapResult.length == 0)
    {
        var content = new Array();
        var height = document.getElementById('leftpanel').style.height;
        if(document.all)
            content[content.length] = '<div id="divTree" style="position:absolute; color:#333333; height:'+(height)+'px; overflow:auto; SCROLLBAR-HIGHLIGHT-COLOR: #999999; SCROLLBAR-ARROW-COLOR: #999999; SCROLLBAR-TRACK-COLOR: #ffffff; SCROLLBAR-DARKSHADOW-COLOR: #ffffff; SCROLLBAR-BASE-COLOR: #ffffff; Scrollbar-Face-Color: #ffffff; Scrollbar-Shadow-Color: #999999; width: 347px;">';
        else
            content[content.length] = '<div id="divTree" style="position:absolute; color:#333333; height:'+(height)+'px; overflow:auto; SCROLLBAR-HIGHLIGHT-COLOR: #999999; SCROLLBAR-ARROW-COLOR: #999999; SCROLLBAR-TRACK-COLOR: #ffffff; SCROLLBAR-DARKSHADOW-COLOR: #ffffff; SCROLLBAR-BASE-COLOR: #ffffff; Scrollbar-Face-Color: #ffffff; Scrollbar-Shadow-Color: #999999; width: 347px;">';
        /*content[content.length] = '<table border="0" cellpadding="0" cellspacing="0" style=" width:310px; margin-top:5px; margin-left:10px;">';
        content[content.length] = '<tr>';
        content[content.length] = '<td width="10" height="20" align="center"><img src="vbd_images/images/icobando_help.gif" width="32" height="32" /></td>';
        content[content.length] = '<td height="20" colspan="2"><strong>Bản đồ</strong></td>';
        content[content.length] = '</tr>';
        content[content.length] = '<tr><td>';
        content[content.length] = '<div id="divTree" style=" color:#333333; height:370px; overflow:auto; SCROLLBAR-HIGHLIGHT-COLOR: #999999; SCROLLBAR-ARROW-COLOR: #999999; SCROLLBAR-TRACK-COLOR: #ffffff; SCROLLBAR-DARKSHADOW-COLOR: #ffffff; SCROLLBAR-BASE-COLOR: #ffffff; Scrollbar-Face-Color: #ffffff; Scrollbar-Shadow-Color: #999999; width: 347px;">';
        content[content.length] = '</td></tr>';
        content[content.length] = '<tr>';
        content[content.length] = '<td height="65" colspan="3" align="left" valign="top"><div align="left"><br/>';
        content[content.length] = '<img src="vbd_images/dot.gif" width="8" height="8" /> Tìm tỉnh/thành, quận/huyện, phường/xã:<br/>';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="a" onclick="MapExampleClick(this.id)">Hà Nội</a></span><br/>';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="b" onclick="MapExampleClick(this.id)">Quận 1, TPHCM</a></span><br/><br/>';
        content[content.length] = '<img src="vbd_images/dot.gif" width="8" height="8" /> Tìm địa danh du lịch:<br/>';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="c" onclick="MapExampleClick(this.id)">Vịnh Hạ Long</a></span><br/>';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="d" onclick="MapExampleClick(this.id)">Đảo Phú Quốc</a></span><br/><br/>';
        content[content.length] = '<img src="vbd_images/dot.gif" width="8" height="8" /> Tìm điểm dịch vụ:<br/>';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="e" onclick="MapExampleClick(this.id)">Khách sạn</a></span><br/>';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="f" onclick="MapExampleClick(this.id)">Nhà hàng, TPHCM</a></span><br/><br/>';
        content[content.length] = '<img src="vbd_images/dot.gif" width="8" height="8" /> Tìm địa chỉ ở TP.HCM:<br/>';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="g" onclick="MapExampleClick(this.id)">31A Huỳnh Văn Bánh, Quận Phú Nhuận</a></span><br/><br/>';
        content[content.length] = '<img src="vbd_images/dot.gif" width="8" height="8" /> Tìm đường, giao lộ:<br/>';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="h" onclick="MapExampleClick(this.id)">Đường Nguyễn Văn Cừ, TPHCM</a></span><br/>';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="i" onclick="MapExampleClick(this.id)">Giao lộ Nguyễn Trãi & Nguyễn Văn Cừ</a></span><br/><br/>';
    	content[content.length] = '<strong><div id="MMOnlineSupport" onclick="showOnlineSupport(this)" style="cursor:pointer;">Hỗ trợ kỹ thuật</div></strong>';
        content[content.length] = '</div></td>';
        content[content.length] = '</tr>';
        content[content.length] = '</table>';*/
        /*preLoading(true);
        var ds = vbdmap.GetTreeChapter("",0);
        dsTreeChapter = ds.value;
        var layerDistrictName = 1;
        
        content[content.length] = '<table id=tblProvince border="0" cellpadding="0" cellspacing="0" style=" width:310px; margin-top:5px; margin-left:10px;">';
        content[content.length] = '<tr id=dist_0><td><img src=treeview/folderOpen.gif >&nbsp;Bản đồ</td></tr>';
        content[content.length] = '<tr id=dist_1><td><img src="vbd_images/spacer.gif" width="24" height=1><img src=treeview/folderOpen.gif >&nbsp;<span  onmouseover = OverProvince(this,false) onmouseout = OverProvince(this,true) onclick=ZoomToCountry(1589602.17,956136.16,0) style=cursor:pointer> Việt Nam </span></td></tr>';
        var tableName = 'tblProvince';
        for(var i = 0 ; i<dsTreeChapter.Tables[0].Rows.length;i++)
        {
              j= i*2;
              var mapid = dsTreeChapter.Tables[0].Rows[i].MapId;
              content[content.length] = "<tr id=dist_"+(j+2)+"  onclick=\"ZoomToProvince('"+tableName+"',this,"+i+",'"+mapid+"',"+layerDistrictName+","+dsTreeChapter.Tables[0].Rows[i].Dolgis_GraphicId+","+dsTreeChapter.Tables[0].Rows[i].Y+","+dsTreeChapter.Tables[0].Rows[i].X+",4)\">";
              content[content.length] = "<td style=cursor:pointer><img src=\"vbd_images/spacer.gif\" width=\"48\" height=1><img id=img_"+(j+2)+" src=treeview/folderClosed.gif align=top/>&nbsp;<span id=span_"+(j+2)+" onmouseover = OverProvince(this,false) onmouseout = OverProvince(this,true)>"+dsTreeChapter.Tables[0].Rows[i].NAME+"</span></td>";
              content[content.length] = '</tr>';
              content[content.length] = '<tr id=dist_'+(j+3)+'>';
              content[content.length] = '<td>&nbsp;</td>';
              content[content.length] = '</tr>';

        }
        content[content.length] = '</table>';
        document.getElementById('searchresult_div').innerHTML = content.join("");
        preLoading(false);
        HideProvince('tblProvince');*/
        //init();
        //t.expandAll();
        TreeBinding.BindTree();
    }
}
function HideProvince(table)
{
	var mytable = document.getElementById(table);
	var length = mytable.rows.length;
	for(var i = 1 ; i < (length/2); i++)
	{
		j = i*2;
		var myrow = mytable.rows[j+1];
		var mycell = myrow.cells[0];
		mycell.style.width = 0;
 		mycell.style.height = 0;
		mycell.innerHTML = "";
	} 
    
}
function HideProvinceSelected(table,id)
{
	var mytable = document.getElementById(table);
	var myrow = mytable.rows[id+1];
	var mycell = myrow.cells[0];
	mycell.style.width = 0;
	mycell.style.height = 0;
	mycell.innerHTML = "";
}
function ZoomToCountry(x,y,level)
{
    map.setCenter(new VLatLng(x,y),level);
}
var pre = -1;
var cur = -1;
function ZoomToProvince(table,row,order,mapid,layername,dolgisId , x,y,level)
{
	var mytable = document.getElementById(table);
	var id= row.id;
	id = parseInt(id.substring(id.indexOf('_')+1,id.length));
  	var myrow = mytable.rows[id+1];
	var mycell = myrow.cells[0];
    if(row.value != 1)
    {
	    firstClick = true;
	    pre = cur;
	    cur = "span_"+id;
        if(document.getElementById(pre) != null)
            document.getElementById(pre).style.backgroundColor = "#ffffff";
        if(document.getElementById(cur) != null)
        {
                document.getElementById(cur).style.backgroundColor = "#C0C0C0";
        }
        row.value = 1;
        document.getElementById('img_'+id).src = "treeview/folderOpen.gif";
        OrderID = 1;
        NameInfo = dsTreeChapter.Tables[0].Rows[order].NAME;
        LatInfo = x;
        LngInfo = y;
        DolgisIdInfo = dolgisId;
        LayerNameInfo = 'vn_province_dat';
        if(arrSearchMapResult != null)
        {
            if(arrSearchMapResult.length == 1)
                map.removeOverlay(arrSearchMapResult[0]);
        }
        arrSearchMapResult = new Array();
        var latlng = new VLatLng(x,y);
        var icon = new VIcon("images/1.gif");
        icon.iconSize = new VSize(26,29);
        var mopt = new VMarkerOptions(icon);
        var marker = new VMarker(latlng,mopt);
        marker.order = i + 1;
        marker.type = MARKER_POI;
        marker.obj = 'object';
        map.addOverlay(marker);
        
        arrSearchMapResult.push(marker);
        preLoading(true);
        map.setCenter(new VLatLng(x,y),level);
        //map.panTo(latlng);
        //if(level == 0) return;
        //var nLevel = map.getLevel();
        var bound = map.getDirectionBounds();
        vbdmap.GetGeometry(parseInt(dolgisId), 'vn_province_dat',level, bound.getNorthWest().longitude,  bound.getNorthWest().latitude, bound.getSouthEast().longitude,  bound.getSouthEast().latitude, GetGeometryChange);
        var ds = vbdmap.GetTreeChapter(mapid,layername);
        dsDistrict_Ward = ds.value;
        var layerWardName = 2;
        var str = new Array();
        str[str.length] =  '<table id=tblWard width="100%" border="0" cellspacing="0" cellpadding="0" >';
        for(var i=0;i<dsDistrict_Ward.Tables[0].Rows.length;i++)
        {
            var mapid = dsDistrict_Ward.Tables[0].Rows[i].MapId;
            var name = dsDistrict_Ward.Tables[0].Rows[i].NAME.toString();
            str[str.length] =  "<tr ><td><img src=\"vbd_images/spacer.gif\" width=\"80\" height=1><img src=treeview/leaf.gif align=top/>&nbsp;<span id=spanward_"+id+"_"+i+" onmouseover = OverProvince(this,false) onmouseout = OverProvince(this,true)  onclick=\"ZoomToDistrict("+id+","+i+",'"+mapid+"',"+layerWardName+",'"+name+"',"+dsDistrict_Ward.Tables[0].Rows[i].Dolgis_GraphicId+","+dsDistrict_Ward.Tables[0].Rows[i].Y+","+dsDistrict_Ward.Tables[0].Rows[i].X+",4)\" style=cursor:pointer>"+name+"</span></td></tr>";
        }
        str[str.length] =  '</table>';
        mycell.innerHTML = str.join("");
        preLoading(false);
    }
    else
    {
        row.value = 0;
        mycell.innerHTML="";
        document.getElementById('img_'+id).src = "treeview/folderClosed.gif";
        document.getElementById("span_"+id).style.backgroundColor = "#ffffff";
        /*preLoading(true);
        map.setCenter(new VLatLng(x,y),level);
        //if(level == 0) return;
        var bound = map.getDirectionBounds();
        vbdmap.GetGeometry(parseInt(dolgisId), 'vn_province_dat',level, bound.getNorthWest().longitude,  bound.getNorthWest().latitude, bound.getSouthEast().longitude,  bound.getSouthEast().latitude, GetGeometryChange);
        preLoading(false);*/
    }
}
var preBound = null;
var curBound = null;
var firstClick = true;
function ZoomToDistrict(parentorder,order,mapid,layername,name,dolgisId , x,y,level)
{
    OrderID = 1;
    NameInfo = name;
    LatInfo = x;
    LngInfo = y;
    DolgisIdInfo = dolgisId;
    LayerNameInfo = 'vn_district_dat';
    if(arrSearchMapResult != null)
    {
        if(arrSearchMapResult.length == 1)
            map.removeOverlay(arrSearchMapResult[0]);
    }
    pre = cur;
    cur = 'spanward_'+parentorder+'_'+order;
    if(document.getElementById(pre) != null)
        document.getElementById(pre).style.backgroundColor = "#ffffff";
    if(document.getElementById(cur) != null)
    {
            document.getElementById(cur).style.backgroundColor = "#C0C0C0";
    }
    arrSearchMapResult = new Array();
    var latlng = new VLatLng(x,y);
    var icon = new VIcon("images/1.gif");
    icon.iconSize = new VSize(26,29);
    var mopt = new VMarkerOptions(icon);
    var marker = new VMarker(latlng,mopt);
    marker.order = i + 1;
    marker.type = MARKER_POI;
    marker.obj = 'object';
    map.addOverlay(marker);
    arrSearchMapResult.push(marker);
    /*var windowOpt = new VInfoWindowOptions();
    windowOpt.autoPan = true;
    var str = "<table width=150px border=0 cellspacing=0 cellpadding=0 style=\"margin-left:3px; margin-top:3px;\">";
      str += "<tr align=left><td>"+NameInfo;
    str +=" </tr></table>";    
    arrSearchMapResult[0].openInfoWindow(str,windowOpt);*/
    

    //map.N_setCenter(new VLatLng(x,y),level);
    if(firstClick == true)
    {
        
        map.setCenter(new VLatLng(x,y),map.numLevels-1);
        firstClick = false;
    }
    else
        map.panTo(latlng);   
    //if(level == 0) return;
    var nLevel = map.getLevel();
    var bound = map.getDirectionBounds();
    vbdmap.GetGeometry(parseInt(dolgisId), 'vn_district_dat',nLevel, bound.getNorthWest().longitude,  bound.getNorthWest().latitude, bound.getSouthEast().longitude,  bound.getSouthEast().latitude, GetGeometryChange);

}

function Show_Business_Help()
{
    if (arrSearchMapResult.length == 0)
    {
        var content = new Array();
        content[content.length] = '<table border="0" cellpadding="0" cellspacing="0" style=" width:310px; margin-top:5px; margin-left:10px;">';
        content[content.length] = '<tr>';
        content[content.length] = '<td width="10" height="20" align="center" valign="middle"><img src="vbd_images/images/icodichvu_help.gif" width="32" height="32" /></td>';
        content[content.length] = '<td height="20" colspan="2" align="left" ><strong>Điểm dịch vụ</strong></td>';
        content[content.length] = '</tr><tr>';
        content[content.length] = '<td height="65" colspan="3" align="left" valign="top"><div align="justify">';
        content[content.length] = 'Ví dụ:<br/>';
    //    content[content.length] = 'Tìm gì: <span style="color:#006699"><a style=cursor:pointer id="g" onclick="BusinessExampleClick(this.id)">Khách sạn Novotel</a></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ở đâu: <span style="color:#006699">Đà Lạt</span><br/>';
    //    content[content.length] = '(có thể gõ tiếng Việt không dấu) <br/>';
        content[content.length] = '<br/>';
        content[content.length] = '<img src="vbd_images/dot.gif" width="8" height="8" /> ';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="a1" onclick="BusinessExampleClick(this.id)">Công ty</a></span>, ';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="b1" onclick="BusinessExampleClick(this.id)">Văn phòng</a></span>,...<br/>';
        content[content.length] = '<img src="vbd_images/dot.gif" width="8" height="8" /> ';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="c1" onclick="BusinessExampleClick(this.id)">Nhà hàng</a></span>, ';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="d1" onclick="BusinessExampleClick(this.id)">Quán ăn</a></span>,...<br/>';
        content[content.length] = '<img src="vbd_images/dot.gif" width="8" height="8" /> ';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="e1" onclick="BusinessExampleClick(this.id)">Quán cà phê</a></span>, ';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="f1" onclick="BusinessExampleClick(this.id)">Phòng trà</a></span>, ';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="g1" onclick="BusinessExampleClick(this.id)">Bar</a></span>, ';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="h1" onclick="BusinessExampleClick(this.id)">Karaoke</a></span>,...<br/> ';
        content[content.length] = '<img src="vbd_images/dot.gif" width="8" height="8" /> ';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="i1" onclick="BusinessExampleClick(this.id)">Khu du lịch</a></span>, ';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="j1" onclick="BusinessExampleClick(this.id)">Khách sạn</a></span>, ';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="k1" onclick="BusinessExampleClick(this.id)">Resort</a></span>, ';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="l1" onclick="BusinessExampleClick(this.id)">Nhà nghỉ</a></span>,...<br/>';
        content[content.length] = '<img src="vbd_images/dot.gif" width="8" height="8" /> ';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="m1" onclick="BusinessExampleClick(this.id)">Cửa hàng</a></span>, ';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="n1" onclick="BusinessExampleClick(this.id)">Siêu thị</a></span>, ';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="o1" onclick="BusinessExampleClick(this.id)">Nhà sách</a></span>,...<br/>';
        content[content.length] = '<img src="vbd_images/dot.gif" width="8" height="8" /> ';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="s1" onclick="BusinessExampleClick(this.id)">Lãnh sự quán</a></span>, ';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="t1" onclick="BusinessExampleClick(this.id)">Đại sứ quán</a></span>,...<br/>';
        content[content.length] = '<img src="vbd_images/dot.gif" width="8" height="8" /> ';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="u1" onclick="BusinessExampleClick(this.id)">Trường đại học</a></span>, ';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="v1" onclick="BusinessExampleClick(this.id)">Trung tâm đào tạo</a></span>, ';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="w1" onclick="BusinessExampleClick(this.id)">Học viện</a></span>,...<br/>';
        content[content.length] = '<img src="vbd_images/dot.gif" width="8" height="8" /> ';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="x1" onclick="BusinessExampleClick(this.id)">Ngân hàng</a></span>, ';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="y1" onclick="BusinessExampleClick(this.id)">ATM</a></span>,...<br/><br/>';
        content[content.length] = '<strong><div id="MMOnlineSupport" onclick="showOnlineSupport(this)" style="cursor:pointer;">Hỗ trợ kỹ thuật</div></strong>';
        content[content.length] = '</div></td>';
        content[content.length] = '</tr>';
        content[content.length] = '</table>';
        document.getElementById('searchresult_div').innerHTML = content.join("");
    }
}
function Show_Address_Help()
{
    if (arrSearchMapResult.length == 0)
    {
        var content = new Array();
        content[content.length] = '<table border="0" cellpadding="0" cellspacing="0" style=" width:310px; margin-top:5px; margin-left:10px;">';
        content[content.length] = '<tr>';
        content[content.length] = '<td width="10" height="20" align="center" valign="middle"><img src="vbd_images/images/icobando_help.gif" width="32" height="32" /></td>';
        content[content.length] = '<td height="20" colspan="2" align="left"><strong>Địa chỉ</strong></td>';
        content[content.length] = '</tr>';
        
        /*content[content.length] = '<tr>';
        content[content.length] = '<td height="65" colspan="3" align="left" valign="top"><div align="left"><br/>';
        content[content.length] = '<img src="vbd_images/dot.gif" width="8" height="8" /> Tìm tỉnh/thành, quận/huyện, phường/xã:<br/>';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="a2" onclick="AddressExampleClick(this.id)">Hà Nội</a></span><br/>';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="b2" onclick="AddressExampleClick(this.id)">Quận 1, TPHCM</a></span><br/><br/>';
        content[content.length] = '<img src="vbd_images/dot.gif" width="8" height="8" /> Tìm địa danh du lịch:<br/>';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="c2" onclick="AddressExampleClick(this.id)">Vịnh Hạ Long</a></span><br/>';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="d2" onclick="AddressExampleClick(this.id)">Đảo Phú Quốc</a></span><br/><br/>';
        content[content.length] = '<img src="vbd_images/dot.gif" width="8" height="8" /> Tìm điểm dịch vụ:<br/>';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="e2" onclick="AddressExampleClick(this.id)">Khách sạn</a></span><br/>';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="f2" onclick="AddressExampleClick(this.id)">Nhà hàng, TPHCM</a></span><br/><br/>';
        content[content.length] = '<img src="vbd_images/dot.gif" width="8" height="8" /> Tìm địa chỉ ở TP.HCM:<br/>';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="g2" onclick="AddressExampleClick(this.id)">31A Huỳnh Văn Bánh, Quận Phú Nhuận</a></span><br/><br/>';
        content[content.length] = '<img src="vbd_images/dot.gif" width="8" height="8" /> Tìm đường, giao lộ:<br/>';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="h2" onclick="AddressExampleClick(this.id)">Đường Nguyễn Văn Cừ, TPHCM</a></span><br/>';
        content[content.length] = '<span style="color:#006699"><a style=cursor:pointer id="i2" onclick="AddressExampleClick(this.id)">Giao lộ Nguyễn Trãi & Nguyễn Văn Cừ</a></span><br/><br/>';
        content[content.length] = '<strong><div id="MMOnlineSupport" onclick="showOnlineSupport(this)" style="cursor:pointer;">Hỗ trợ kỹ thuật</div></strong>';
        content[content.length] = '</div></td>';
        content[content.length] = '</tr>';*/
        content[content.length] = '</table>';
        document.getElementById('searchresult_div').innerHTML = content.join("");
    }
}
function MapExampleClick(id)
{
    document.getElementById('mapinput').style.background = '#ffffff';
	var tmp = document.getElementById(id).innerHTML;
	tmp = tmp.replace('amp;','');
	document.getElementById('mapinput').value = tmp;
	FindPlace(1);
}
function FindPlaceSpellCheckerClick(idx,value)
{
    var direction = document.getElementById('direction'+idx);
    direction.childNodes[0].rows[0].cells[1].childNodes[0].value = value;
    SearchPlace(idx, value);
}
function BusinessExampleClick(id)
{
    document.getElementById('businesswhat').style.background = '#ffffff';
	var tmp = document.getElementById(id).innerHTML;
	tmp = tmp.replace('amp;','');
	document.getElementById('businesswhat').value = tmp;
	FindPlace(1);
}
function AddressExampleClick(id)
{
    document.getElementById('addressinput').style.background = '#ffffff';
	var tmp = document.getElementById(id).innerHTML;
	tmp = tmp.replace('amp;','');
	document.getElementById('addressinput').value = tmp;
	FindPlace(1);
}
/*function OnforcusTextBoxAB(tb)
{
	DeletePlaceTable();
	//if (tb.value != "")
	{
	    prev_selectedResAB_Text = tb.value;
	    selectedResAB_Text = tb.value;	    
	}
	tb.style.background = '#ffffff';
};

function OnblurTextBoxAB(tb)
{		
	if(tb.value == '')
	{
		if(nLanguage ==0)
			tb.style.background = "#FFFFFF url(images/helptimduong.gif) left no-repeat";
		else
			tb.style.background = "#FFFFFF url(images/diachi_e.gif) left no-repeat";
	}
	var did = tb.parentNode.parentNode.parentNode.parentNode.parentNode.id;
    var index = parseInt(did.substring(9,did.length));
    if(PlaceStatusArray[index] == 0 && document.getElementById('SelectPlace') == null)
        if(CheckInputDatatype(tb.value) != 'coor')
            SearchPlace(index, tb.value);
    //else
        //tb.value = prev_selectedResAB_Text;
    //prev_selectedResAB_Text = "";     
    //hideBusyDiv();      
};
*/
function OnforcusTextBoxAB(tb)
{
	HideSelectPlaceBox();
	prev_selectedResAB_Text = tb.value;
	selectedResAB_Text = tb.value;	    
	tb.style.background = '#ffffff';
};

function OnblurTextBoxAB(tb)
{		
	if(tb.value == '')
	{
		if(nLanguage ==0)
			tb.style.background = "#FFFFFF url(images/helptimduong.gif) left no-repeat";
		else
			tb.style.background = "#FFFFFF url(images/helptimduongE.gif) left no-repeat";
	}
	
	var did = tb.parentNode.parentNode.parentNode.parentNode.parentNode.id;
    var index = parseInt(did.substring(9,did.length));
    
    if(selectedResAB_Text != tb.value && document.getElementById('SelectPlace') == null)
    {
        
        if(CheckInputDatatype(tb.value) != 'coor')
            SearchPlace(index, tb.value,1);
    }
};

function preLoading(Loading)
{
    var divLeftPanel = document.getElementById('container');
    var divBusyLP = document.getElementById('divBusyLP');
    if(Loading == true)
    {
        if (divBusyLP == null)
        {
            divBusyLP = document.createElement('div');
            divBusyLP.id = 'divBusyLP';
            divBusyLP.style.position = 'absolute';
            divBusyLP.style.zIndex = 3000;
            divBusyLP.style.left = '0px';
            divBusyLP.style.top = '0px';
            divBusyLP.style.width = divLeftPanel.style.width;
            divBusyLP.style.height = divLeftPanel.style.height;
            divBusyLP.style.backgroundColor = '#ffffff';
            divBusyLP.style.filter = 'alpha(opacity = 80)';
            divBusyLP.style.opacity = 0.8;
            divBusyLP.innerHTML = "<img width='64px' height='64px' id='loadingImg' src='images/loading.gif' />";
            divLeftPanel.appendChild(divBusyLP);
            var loadingImg = document.getElementById('loadingImg');
            var imgLeft = (parseInt(divLeftPanel.offsetWidth) - parseInt(loadingImg.offsetWidth)) / 2;
            var imgTop = (parseInt(divLeftPanel.offsetHeight) - parseInt(loadingImg.offsetHeight)) / 2;
            loadingImg.style.position = 'absolute';
            loadingImg.style.left = imgLeft + 'px';
            loadingImg.style.top = imgTop + 'px';
        }
    }
    else
    {
        if (divBusyLP != null)
            divLeftPanel.removeChild(divBusyLP);
            //document.body.removeChild(divBusyLP);
    }
}