﻿//Global variables
var GLOBAL_SEARCH_MAP               =   0;
var GLOBAL_SEARCH_BUSINESS          =   1;
var GLOBAL_SEARCH_ADDRESS           =   2;
var GLOBAL_SEARCH_FUNCTION          =   3;
var GLOBAL_FINDPATH_FUNCTION        =   4;
var GLOBAL_MYMAP_FUNCTION           =   5;
var GLOBAL_ACTIVE_ZINDEX            =   2;
var GLOBAL_HIDDEN_ZINDEX            =   1;

var map;
var cMnu = null;
var nLanguage = 0;
var expandMapTmr = null;
var shrinkMapTmr = null;
var bFirstTmr = true;
var myWidth = 0, myHeight = 0;
var current_searchtype;
var current_functype;
var MARKER_POI = 0;
var MARKER_AB = 1;
var MYMAPOBJ = 2;
var MMCONTROLOBJ = 3;
var MMAPCONTROLOBJ = 4;
var FPMARKEROBJ = 5;
var FPPOLYLINEOBJ = 6;
var mkD = null;
var directionLatLng = null;
var directionLevel = null;
var onlineSupportShow = false;
var busyDivTmr = null;
var isTreeClick = false;
function ChangeBorderColor(element,color)
{
    element.style.borderColor = color;
};

function ChangeTextColor(element,color)
{   
    element.style.color = color;
};

function ChangeFontWeight(element,weight)
{
    element.style.fontWeight = weight;
};

function ChangeImageSrc(image, src)
{
    image.src = src;
};

function ChangeBgColor(element, color)
{
    if(element != null)
        element.style.backgroundColor = color;
};

function ChangeSearchType(type)
{
    onlineSupportShow = false;
    ChangeFontWeight(document.getElementById('search_map_tab'), 'normal');
    ChangeFontWeight(document.getElementById('search_business_tab'), 'normal');
//    ChangeFontWeight(document.getElementById('search_address_tab'), 'normal');
    current_searchtype = type;
    var text;
    if(type == GLOBAL_SEARCH_MAP)
    {
        ChangeFontWeight(document.getElementById('search_map_tab'), 'bold');
        document.getElementById('searchmap_input').style.zIndex = GLOBAL_ACTIVE_ZINDEX;
        //document.getElementById('searchbusiness_input').style.zIndex = GLOBAL_HIDDEN_ZINDEX;
        //document.getElementById('searchaddress_input').style.zIndex = GLOBAL_HIDDEN_ZINDEX;
        Show_Map_Help();
        
    }
    else if(type == GLOBAL_SEARCH_BUSINESS)
    {
        
        ChangeFontWeight(document.getElementById('search_business_tab'), 'bold');
        document.getElementById('searchmap_input').style.zIndex = GLOBAL_HIDDEN_ZINDEX;
        //document.getElementById('searchbusiness_input').style.zIndex = GLOBAL_ACTIVE_ZINDEX;
        //document.getElementById('searchaddress_input').style.zIndex = GLOBAL_HIDDEN_ZINDEX;
        //Show_Business_Help();
    }
    else if(type == GLOBAL_SEARCH_ADDRESS)
    {
        
//        ChangeFontWeight(document.getElementById('search_address_tab'), 'bold');
        document.getElementById('searchmap_input').style.zIndex = GLOBAL_HIDDEN_ZINDEX;
        //document.getElementById('searchbusiness_input').style.zIndex = GLOBAL_HIDDEN_ZINDEX;
        //document.getElementById('searchaddress_input').style.zIndex = GLOBAL_ACTIVE_ZINDEX;
        //Show_Address_Help();
    }
};

function ChangeFunctionType(type)
{
    var imgCenterPanel = document.getElementById('expand_map');
    if (imgCenterPanel.src.indexOf("images/expand_map.gif") == -1)
        shrinkMap();
    
    ChangeBgColor(document.getElementById('search_function_tab'), '#ffeac3');
    ChangeBgColor(document.getElementById('search_findpath_tab'), '#ffeac3');
    ChangeBgColor(document.getElementById('search_mymap_tab'), '#ffeac3');
    ChangeImageSrc(document.getElementById('search_function_tab').nextSibling.childNodes[0], "images/rightwhite.gif");
    ChangeImageSrc(document.getElementById('search_function_tab').previousSibling.childNodes[0], "images/leftwhite.gif");
    ChangeImageSrc(document.getElementById('search_findpath_tab').nextSibling.childNodes[0], "images/rightwhite.gif");
    ChangeImageSrc(document.getElementById('search_findpath_tab').previousSibling.childNodes[0], "images/leftwhite.gif");
    ChangeImageSrc(document.getElementById('search_mymap_tab').nextSibling.childNodes[0], "images/rightwhite.gif");
    ChangeImageSrc(document.getElementById('search_mymap_tab').previousSibling.childNodes[0], "images/leftwhite.gif");
    
    var element;
    current_functype = type;
    if(type == GLOBAL_SEARCH_FUNCTION)
    {
        element = document.getElementById('search_function_tab');
        document.getElementById('searchresult_div').style.zIndex = GLOBAL_ACTIVE_ZINDEX;
        document.getElementById('findpath_div').style.zIndex = GLOBAL_HIDDEN_ZINDEX;
        document.getElementById('mymap_div').style.zIndex = GLOBAL_HIDDEN_ZINDEX;
        if (browserName == 'msie')
            document.getElementById('clearResultText').innerText = 'Xóa kết quả';
        else
            document.getElementById('clearResultText').firstChild.nodeValue = 'Xóa kết quả';
        document.getElementById('clearResultText').style.display = 'none';
        document.getElementById('clearResultText').onclick = ClearResult;        
        document.getElementById('tdvehicle').style.display = 'none';
        document.getElementById('tdreverse').style.display = 'none';
    }
    else if(type == GLOBAL_FINDPATH_FUNCTION)
    {
        element = document.getElementById('search_findpath_tab');
        document.getElementById('searchresult_div').style.zIndex = GLOBAL_HIDDEN_ZINDEX;
        document.getElementById('findpath_div').style.zIndex = GLOBAL_ACTIVE_ZINDEX;
        document.getElementById('mymap_div').style.zIndex = GLOBAL_HIDDEN_ZINDEX;
        if (browserName == 'msie')
            document.getElementById('clearResultText').innerText = 'Xóa kết quả';
        else
            document.getElementById('clearResultText').firstChild.nodeValue = 'Xóa kết quả';
        document.getElementById('clearResultText').onclick = ClearResult;
        document.getElementById('tdvehicle').style.display = '';
        if(PlaceToFindPathArray.length == 2)
            document.getElementById('tdreverse').style.display = '';
        else
            document.getElementById('tdreverse').style.display = 'none';
    }
    else if(type == GLOBAL_MYMAP_FUNCTION)
    {
        element = document.getElementById('search_mymap_tab');
        document.getElementById('searchresult_div').style.zIndex = GLOBAL_HIDDEN_ZINDEX;
        document.getElementById('findpath_div').style.zIndex = GLOBAL_HIDDEN_ZINDEX;
        document.getElementById('mymap_div').style.zIndex = GLOBAL_ACTIVE_ZINDEX;
        if (browserName == 'msie')
            document.getElementById('clearResultText').innerText = 'Tạo bản đồ mới';
        else
            document.getElementById('clearResultText').firstChild.nodeValue = 'Tạo bản đồ mới';
        document.getElementById('clearResultText').onclick = createNewMap;
        document.getElementById('tdvehicle').style.display = 'none';
        document.getElementById('tdreverse').style.display = 'none';
        loadMyMap();
        if (!checkLogin())
	    {
		    window.location =  "login.aspx?tab=5";
		    return;
	    }
    }
    ChangeImageSrc(element.nextSibling.childNodes[0], "images/rightgreen.gif");
    ChangeImageSrc(element.previousSibling.childNodes[0], "images/leftgreen.gif");
    ChangeBgColor(element, '#FFFFFF');
    DeletePlaceTable();
};

function closeContextMenu()
{
    if (cMnu != null)
    {
        map.removeControl(cMnu);
        cMnu = null;
    }
}
var dsTreeChapter;
function StartApp()
{
    var query = window.location.href.split('?');
    var query_name = new Array();
	var query_value = new Array();
	if(query.length > 1)
	{
	    var t1 = query[1].split('&');
	    for(var i=0; i < t1.length; i++)
	    {
		    var t2 = t1[i].split('=');
		    query_name.push(t2[0]);
		    query_value.push(t2[1]);
	    }
	}
	document.getElementById('mapinput').value = "";
    /*document.getElementById('businesswhat').value = "";
    document.getElementById('businesswhere').value = "";
    document.getElementById('addressinput').value = "";*/
    map = new VMap(document.getElementById('container'));
    ResizeWindow();
    var level = 0;
    var latlng = new VLatLng(1589602.17,956136.160);
    var pa = null;
    var pb = null;
    var sk = 0;
    for(var i=0; i< query_name.length; i++)
    {
        if(query_name[i] == "l")
            level = parseInt(query_value[i]);
        else if(query_name[i] == "kv")
        {
            var temp = query_value[i].split(",");
            latlng = new VLatLng(parseFloat(temp[0]), parseFloat(temp[1]));
            LatInfo = parseFloat(temp[0]);
            LngInfo = parseFloat(temp[1]);
        }
        else if (query_name[i] == "draw")
        {
            var temp = query_value[i].split(",");
            if(temp[0] == 'true')
            {
                LevelInfo = level;
                Dolgis = parseInt(temp[1]);
                LayerSelect = temp[2];
                vbdmap.GetGeometry(parseInt(temp[1]), temp[2],level, parseFloat(temp[3]),  parseFloat(temp[4]),  parseFloat(temp[5]),   parseFloat(temp[6]), GetGeometryChange);
                /*if(temp.length > 7)
                {
                    var latlng = new VLatLng(temp[7],temp[8]);
                    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 = temp[9];
                    marker.type = MARKER_POI;
                    marker.obj = 'object';
                    map.addOverlay(marker);
                }*/
            }
        }
        else if(query_name[i] == "fp")
        {
            var temp = query_value[i].split(",");
            pa = new VLatLng(parseFloat(temp[0]),parseFloat(temp[1]));
            if(temp.length > 3)
                pb = new VLatLng(parseFloat(temp[2]),parseFloat(temp[3]));
        }
        else if(query_name[i] == "sk")
        {
            var temp = query_value[i].split(";");
            current_searchtype = parseInt(temp[0]);
            if(current_searchtype == GLOBAL_SEARCH_MAP)
            {
                document.getElementById('mapinput').value = temp[1];
            }
            /*else if(current_searchtype == GLOBAL_SEARCH_BUSINESS)
            {
                
                document.getElementById('businesswhat').value = temp[1];
                document.getElementById('businesswhere').value = temp[2];
            }
            else if(current_searchtype == GLOBAL_SEARCH_ADDRESS)
            {
                document.getElementById('addressinput').value = temp[1];
            }*/
            ChangeSearchType(current_searchtype);
            sk = 1;
        }
        else if(query_name[i] == "mi")
        {
            if (checkLogin())
            {
                bSendMyMap = parseInt(query_value[i]);
                loadMyMap();
            }
            else
            {
                bSendMyMap = true;
                loadMyMapCoor(parseInt(query_value[i]));
            }
        }
    }
    map.addControl(new VLargeMapControl());
    map.addControl(new VScaleControl());
    map.addControl(new VOverviewMapControl());
    map.setCenter(latlng, level);
    var direction = document.getElementById('direction0');
    if (direction != null)
    {
        direction.childNodes[0].rows[0].cells[1].childNodes[0].value = "";
    }
    direction = document.getElementById('direction1');
    if (direction != null)
    {
        direction.childNodes[0].rows[0].cells[1].childNodes[0].value = "";
    }
    
    if(pa != null)
        AddPlaceFromFind(pa);
    if(pb != null)
        AddPlaceToFind(pb);
    if(sk == 1)
        FindPlace(1);
    
    var hdTab = document.getElementById('hdTab');
    ChangeFunctionType(parseInt(hdTab.value));
    VEvent.addListener(map, "singlerightclick", function(overlay, rp){
            if (rp != null)
            {
                if (mkD != null)
	            {
	                map.removeOverlay(mkD);
	                mkD = null;
	            }
	            
                map.closeInfoWindow();
                closeContextMenu();
                //if(isRegionSelected)
                    var arrContent = ['Tâm bản đồ', 'Tìm xung quanh', 'Đo khoảng cách', '-', 'Thu nhỏ', 'Phóng to','-', 'Xem chi tiết'];
               //else
                   //var arrContent = ['Xem chi tiết','-','Tâm bản đồ', 'Tìm xung quanh', 'Đo khoảng cách', '-', 'Thu nhỏ', 'Phóng to'];
                
                //var arrContent = ['Tâm bản đồ', 'Tìm xung quanh', 'Đo khoảng cách', '-', 'Thu nhỏ', 'Phóng to'];
                var arrHandler = new Array();
                arrHandler[0] = panToCenter;//Tam ban do
                arrHandler[1] = searchNearBy;//Tim xung quanh
                arrHandler[2] = measureDistance;//Do khoang cach
                arrHandler[4] = zoomOut;//Thu nho
                arrHandler[5] = zoomIn;//Phong to
                //arrHandler[7] = ToHereClick;//Den day
                //arrHandler[8] = FromHereClick;//Tu day
                /*if(isRegionSelected)*/
                //arrHandler[7] = RegionSelect;//Chitiet
                arrHandler[7] = XemChiTiet;
                if (overlay != null)
                {
                    if (overlay.type == MYMAPOBJ || overlay.type == MMCONTROLOBJ || overlay.type == MMAPCONTROLOBJ)//mymap
                    {
                        if (!bReadOnly)
                        {
                            arrContent[arrContent.length] = '-';
                            arrContent[arrContent.length] = 'Xóa địa điểm';
                            arrContent[arrContent.length] = 'Cập nhật địa điểm';
                            
                            arrHandler[10] = function(){
                                    closeContextMenu();
                                    if (overlay.type == MYMAPOBJ)
                                        deleteMyMapCoor(overlay.mmIndex);
                                    else
                                        deleteMyMapCoor(overlay.editObjectIndex);
                                };
                            
                            arrHandler[11] = function(){
                                    closeContextMenu();
                                    clickedPoint = rp;
                                    if (overlay.type == MYMAPOBJ)
                                        showMyMapInfoWindow(overlay.mmIndex, 1);
                                    else
                                        showMyMapInfoWindow(overlay.editObjectIndex, 1);
                                };
                            
                            if (overlay.type == MMAPCONTROLOBJ)
                            {
                                arrContent[arrContent.length] = 'Thêm điểm';
                                
                                arrHandler[12] = function(){
                                    closeContextMenu();
                                    var np = overlay.getLatLng().copy();
                                    arrMyMapCoorObj[overlay.editObjectIndex].insertPoint(overlay.addPointIndex, np);
                                    if (arrMyMapCoorObj[overlay.editObjectIndex].actionType != 'New')
                                        arrMyMapCoorObj[overlay.editObjectIndex].actionType = 'Edit';
                                    enableSaveBtn();
                                    clearControlPoint();
                                    showControlPoint(arrMyMapCoorObj[overlay.editObjectIndex]);
                                };
                            }
                            else if (overlay.type == MMCONTROLOBJ)
                            {
                                var nMinV = (arrMyMapCoorObj[overlay.editObjectIndex].vType() == 'VPolyline') ? 2 : 4;
                                if (arrMyMapCoorObj[overlay.editObjectIndex].getVertexCount() > nMinV)
                                {
                                    arrContent[arrContent.length] = 'Xóa điểm';
                                    
                                    arrHandler[12] = function(){
                                        closeContextMenu();
                                        arrMyMapCoorObj[overlay.editObjectIndex].deletePoint(overlay.editPointIndex);
                                        if (arrMyMapCoorObj[overlay.editObjectIndex].actionType != 'New')
                                            arrMyMapCoorObj[overlay.editObjectIndex].actionType = 'Edit';
                                        enableSaveBtn();
                                        clearControlPoint();
                                        showControlPoint(arrMyMapCoorObj[overlay.editObjectIndex]);
                                    };
                                }
                            }
                        }
                    }
                    else if (overlay.type == FPMARKEROBJ)
                    {
                        arrContent[arrContent.length] = '-';
                        arrContent[arrContent.length] = 'Xóa điểm này';
                        
                        arrHandler[10] = function(){
                                closeContextMenu();
                                RemovePlace(overlay.sid);
                            };
                    }
                }
                cMnu = new ContextMenu(rp, arrContent, arrHandler);
                map.addControl(cMnu);
            }
        });
      
    VEvent.addListener(map, "movestart", function(){
            closeContextMenu();
            enableSaveBtn();
        });
    VEvent.addListener(map, "zoomstart", function(){
            closeContextMenu();
            enableSaveBtn();
        });
    VEvent.addListener(map, "click", function(overlay, pt){
            if (selTbrButton != null && selTbrButton.id != 'btnMove' && pt != null)//create new object in mymap
            {
                if (selTbrButton.id == 'btnAddPoint' || selTbrButton.id == 'btnAddText')
                {
                    var divMyMapCoorList = document.getElementById('MyMapCoorList');
			        var table = document.createElement('TABLE');
                    table.setAttribute('width', '95%');
                    table.setAttribute('border', 0);
                    table.setAttribute('cellPadding', 0);
                    table.setAttribute('cellSpacing', 0);
                    table.style.marginTop = '5px';
                    if (browserName == 'msie')
                    {
                        table.style.marginBottom = '5px';
                        table.style.marginLeft = '5px';
                    }
                    table.style.cursor = 'pointer';
                    table.setAttribute('id', 'MyMapCoorList_' + nMyMapCoorObj);
                    table.onclick = function(){
                            clickedPoint=null;
                            showMyMapInfoWindow(this.id.substring(this.id.indexOf('_') + 1, this.id.length), 0);
                        };
                    table.onmouseover = function(){
                            changeCoorTextStyle(this.id.substring(this.id.indexOf('_') + 1, this.id.length));
                        };
                    table.onmouseout = function(){
                            changeCoorTextStyle(this.id.substring(this.id.indexOf('_') + 1, this.id.length));
                        };
                    
                    var tBody = document.createElement('TBODY');
                    var row = document.createElement('TR');
                    var cell = document.createElement('TD');
                    cell.setAttribute('width', '13%');
                    cell.setAttribute('rowspan', 2);
                    cell.setAttribute('align', 'center');
                    cell.setAttribute('valign', 'middle');
                    var strHTML = '';
                    if (selTbrButton.id == 'btnAddPoint')
                        strHTML = "<img id='MyMapCoorListImg_" + nMyMapCoorObj + "' src='images/MyMap_icon/point-1.gif' width='32px' height='32px' />";
                    else if (selTbrButton.id == 'btnAddText')
                        strHTML += "<img src='images/icon_text.gif' />";
                    cell.innerHTML = strHTML;
                    row.appendChild(cell);
                    
                    cell = document.createElement('TD');
                    cell.setAttribute('width', '87%');
                    cell.setAttribute('height', '20px');
                    cell.setAttribute('align', 'left');
                    cell.setAttribute('valign', 'middle');
                    
                    strHTML = "<span id='MyMapCoorListTitle_" + nMyMapCoorObj + "' style='color:#0066cc; font-weight:bold;' >";
                    strHTML += 'Chưa đặt tên' + "</span><br /><span id='MyMapCoorListDesc_" + nMyMapCoorObj + "' >";
                    strHTML += '&nbsp;&nbsp;&nbsp;';
                    strHTML += "</span>";
                    cell.innerHTML = strHTML;
                    row.appendChild(cell);
                    
                    tBody.appendChild(row);
                    table.appendChild(tBody);
                    
                    divMyMapCoorList.appendChild(table);
                }
                
                if (selTbrButton.id == 'btnAddPoint')
                {
                    selectToolbarBtn(document.getElementById('btnMove'));
	                var marker = new VMarker(pt, new VIcon('images/mymap_icon/point-1.gif', new VSize(32, 32)));
                    marker.type = MYMAPOBJ;
				    marker.mmIndex = nMyMapCoorObj;
				    marker.actionType = 'New';
                    map.addOverlay(marker);
                    arrMyMapCoorObj[nMyMapCoorObj] = marker;
				    nMyMapCoorObj++;
				    marker.enableDragging();
				    var dtRow = new Object();
				    dtRow.MyMapCoorID = '';
				    dtRow.MyMapID = '';
				    dtRow.ObjectTitle = 'Chưa đặt tên';
				    dtRow.ObjectDesc = '';
				    dtRow.Coor = 'POINT(' + pt.longitude + ' ' + pt.latitude + ')';
				    dtRow.Style = ';;;;point-1;';
				    dsMyMapCoor.Tables[0].Rows[dsMyMapCoor.Tables[0].Rows.length] = dtRow;
	                
				    bCreateNewMMObj = true;
                    showMyMapInfoWindow(marker.mmIndex, 0);
                }
                else if (selTbrButton.id == 'btnAddText')
                {
                    selectToolbarBtn(document.getElementById('btnMove'));
                    
                    var text = new VText(pt, 'vietbando');
                    text.type = MYMAPOBJ;
                    text.mmIndex = nMyMapCoorObj;
                    text.actionType = 'New';
                    map.addOverlay(text);
				    arrMyMapCoorObj[nMyMapCoorObj] = text;
				    nMyMapCoorObj++;
				    text.enableDragging();
				    var dtRow = new Object();
				    dtRow.MyMapCoorID = '';
				    dtRow.MyMapID = '';
				    dtRow.ObjectTitle = 'Chưa đặt tên';
				    dtRow.ObjectDesc = '';
				    dtRow.Coor = 'POINT(' + pt.longitude + ' ' + pt.latitude + ')';
				    dtRow.Style = 'normal;#ff0000;20;Arial;;vietbando';
				    dsMyMapCoor.Tables[0].Rows[dsMyMapCoor.Tables[0].Rows.length] = dtRow;
	                
				    bCreateNewMMObj = true;
                    showMyMapInfoWindow(text.mmIndex, 0);
                }
                else if (selTbrButton.id == 'btnAddPolyline')
                {
                    map.disableDoubleClickZoom();
                    bDrawingPolyline = true;
                    if (tempPolyline != null)
                    {
                        map.removeOverlay(tempPolyline);
                        tempPolyline = null;
                    }
                    if (arrDrawingPts == null)
                        arrDrawingPts = new Array();
                    arrDrawingPts[nDrawingPts] = pt.copy();
                    nDrawingPts++;
                    if (nDrawingPts == 2)
                    {
                        var drawingPolyline = new VPolyline(arrDrawingPts);
                        drawingPolyline.type = MYMAPOBJ;
                        drawingPolyline.mmIndex = nMyMapCoorObj;
                        drawingPolyline.actionType = 'New';
                        map.addOverlay(drawingPolyline);
                        arrMyMapCoorObj[nMyMapCoorObj] = drawingPolyline;
				        nMyMapCoorObj++;
				        VEvent.addListener(drawingPolyline, 'mouseover', showControlPoint);
                    }
                    else if (nDrawingPts > 2)
                    {
                        arrMyMapCoorObj[nMyMapCoorObj - 1].setLatLngs(arrDrawingPts);
                    }
                }
                else if (selTbrButton.id == 'btnAddPolygon')
                {
                    map.disableDoubleClickZoom();
                    bDrawingPolyline = true;
                    if (tempPolyline != null)
                    {
                        map.removeOverlay(tempPolyline);
                        tempPolyline = null;
                    }
                    if (arrDrawingPts == null)
                        arrDrawingPts = new Array();
                    arrDrawingPts[nDrawingPts] = pt.copy();
                    nDrawingPts++;
                    if (nDrawingPts == 2)
                    {
                        var drawingPolygon = new VPolygon(arrDrawingPts);
                        drawingPolygon.type = MYMAPOBJ;
                        drawingPolygon.mmIndex = nMyMapCoorObj;
                        drawingPolygon.reductionTol = 0;
                        drawingPolygon.actionType = 'New';
                        map.addOverlay(drawingPolygon);
                        arrMyMapCoorObj[nMyMapCoorObj] = drawingPolygon;
				        nMyMapCoorObj++;
				        VEvent.addListener(drawingPolygon, 'mouseover', showControlPoint);
                    }
                    else if (nDrawingPts > 2)
                    {
                        arrMyMapCoorObj[nMyMapCoorObj - 1].setLatLngs(arrDrawingPts);
                    }
                }
                return;
            }
            
            if(isMeasureDistance)
            {
                //map.disableDoubleClickZoom();
                bMeasureLine = true;
                if (tempPolyline != null)
                {
                    map.removeOverlay(tempPolyline);
                    tempPolyline = null;
                }
                if (arrDrawingPtsML == null)
                    arrDrawingPtsML = new Array();
                arrDrawingPtsML[nDrawingPtsML] = pt.copy();
                nDrawingPtsML++;
                if (nDrawingPtsML == 2)
                {
                    var drawingPolyline = new VPolyline(arrDrawingPtsML,'green');
                    map.addOverlay(drawingPolyline);
                    arrMLObj[nMLObj] = drawingPolyline;
                    nMLObj++;
                }
                else if (nDrawingPtsML > 2)
                {
                    arrMLObj[nMLObj - 1].setLatLngs(arrDrawingPtsML);
                }
                if(arrDrawingPtsML.length > 1)
                {
                    CurrentDistance = CalculateDistance(arrDrawingPtsML[arrDrawingPtsML.length-2],arrDrawingPtsML[arrDrawingPtsML.length-1]);
                }
                else
                {
                    CurrentDistance = CalculateDistance(arrDrawingPtsML[arrDrawingPtsML.length-1],pt);
       	        }
       	        if(CurrentDistance >= 1000)
                    document.getElementById('lblCurDistance').innerHTML = '<FONT style="color:#FF3300">'+(CurrentDistance / 1000)  +' km</FONT>';
                else
                    document.getElementById('lblCurDistance').innerHTML = '<FONT style="color:#FF3300">'+CurrentDistance +' m</FONT>';
                TotalDistance += CurrentDistance;
       		    if(TotalDistance >= 1000)
                    document.getElementById('lblTotalDistance').innerHTML ='<FONT style="color:#FF3300;font-weight:bold">'+ (TotalDistance / 1000) + ' km</FONT>';
                else
                    document.getElementById('lblTotalDistance').innerHTML ='<FONT style="color:#FF3300;font-weight:bold">'+ TotalDistance + ' m</FONT>';
            }
            else
            {
                if (overlay != null)
                {
                    if (overlay.vType() == 'VMarker' && overlay.type == MARKER_POI)//search
                    {
                        if(overlay.obj == 'object')
                        {
                            var latlng = overlay.getPoint();
                            ViewDetailInfo(OrderID,latlng.latitude, latlng.longitude,NameInfo,DolgisIdInfo,LayerNameInfo,AddressInfo,TinhLyInfo);
                        }
                        else
                        {
                            var latlng = overlay.getPoint();
                            ViewDetailCurrentLevel(overlay.order, latlng.latitude, latlng.longitude);                                                            
                        }
                        return;
                    }
                    if (overlay.type == MYMAPOBJ || overlay.type == MMCONTROLOBJ || overlay.type == MMAPCONTROLOBJ)//mymap
                    {
                        clickedPoint = pt;
                        if (overlay.mmIndex != undefined)
                            showMyMapInfoWindow(overlay.mmIndex, 1);
                        else
                            showMyMapInfoWindow(overlay.editObjectIndex, 1);
                    }
                }
            }
        }); 
    VEvent.addListener(map, 'mousemove', function(pt){
                if (selTbrButton != null && selTbrButton.id != 'btnMove')
                {
                    if (pt != null && bDrawingPolyline)
                    {
                        if (tempPolyline == null)
                        {
                            var plOpts = new VPolylineOptions(true, false, 'Dot');
                            tempPolyline = new VPolyline([arrDrawingPts[arrDrawingPts.length - 1], pt]);
                            tempPolyline.opts = plOpts;
                            map.addOverlay(tempPolyline);
                        }
                        else
                        {
                            tempPolyline.setLatLngs([arrDrawingPts[arrDrawingPts.length - 1], pt]);
                        }
                    }
                    return;
                }
                
                if (pt != null && bMeasureLine)
                {
                    if (tempPolyline == null)
                    {
                        
                        var plOpts = new VPolylineOptions(true, false, 'Dot');
                        tempPolyline = new VPolyline([arrDrawingPtsML[arrDrawingPtsML.length - 1], pt],'green');
                        tempPolyline.opts = plOpts;
                        map.addOverlay(tempPolyline);
                    }
                    else
                    {
                    
                        tempPolyline.setLatLngs([arrDrawingPtsML[arrDrawingPtsML.length - 1], pt]);
                    }
                    if(arrDrawingPtsML.length > 1)
                    {
                        if(arrDrawingPtsML[arrDrawingPtsML.length-1].latitude == pt.latitude)
                            CurrentDistance = CalculateDistance(arrDrawingPtsML[arrDrawingPtsML.length-2],pt);
                        else
                            CurrentDistance = CalculateDistance(arrDrawingPtsML[arrDrawingPtsML.length-1],pt);
                    }
                    else
                        CurrentDistance = CalculateDistance(arrDrawingPtsML[arrDrawingPtsML.length-1],pt);
               	    window.status = CurrentDistance+"aa";
               	    if(CurrentDistance >= 1000)
	                    document.getElementById('lblCurDistance').innerHTML = '<FONT style="color:#FF3300">'+(CurrentDistance / 1000)  +' km</FONT>';
	                else
                        document.getElementById('lblCurDistance').innerHTML = '<FONT style="color:#FF3300">'+CurrentDistance +' m</FONT>';
                    return false;
                }
                
    	        if (mkD != null && selectedPoly != null && !isFPObjDragging && !bCPDragging)//find path
    	        {
    	            var tarr = selectedPoly.split(",");
                    var index  = parseInt(tarr[0]);
                    var sub  = parseInt(tarr[1]);
    	            var arrPts = PathPolylineArray[index][sub].latlngs;
				    var arrRet = new Array();
				    VUtil.ClosestPointPolylines(pt.longitude, pt.latitude, arrPts, arrRet);
				    var ptCl = arrRet[0];
				    var ptV = map.fromLatLngToDivPixel(pt);
				    var ptClV = map.fromLatLngToDivPixel(ptCl);
				    var ptStartV = map.fromLatLngToDivPixel(arrPts[0][0]);
			        var nLines = arrPts.length;
			        var nPoints = arrPts[nLines - 1].length;
			        var ptEndV = map.fromLatLngToDivPixel(arrPts[nLines - 1][nPoints - 1]);
				    
				    if (VUtil.Distance(ptV.x, ptV.y, ptClV.x, ptClV.y) > 300 || VUtil.Distance(ptClV.x, ptClV.y, ptStartV.x, ptStartV.y) < 150 || VUtil.Distance(ptClV.x, ptClV.y, ptEndV.x, ptEndV.y) < 150)
				    {
				        map.removeOverlay(mkD);
    	                mkD = null;
    	                selectedPoly = null;
				    }
				    else
				    {
				    	mkD.setPoint(ptCl);
				    }
    	        }
    	        
    	        if (iMyMapCoorOver != -1 && !bCPDragging && !isFPObjDragging)//my map
    	        {
    	            var arrPts = arrMyMapCoorObj[iMyMapCoorOver].latlngs;
				    var arrRet = new Array();
				    VUtil.ClosestPointPolyline(pt.longitude, pt.latitude, arrPts, arrRet);
				    var ptCl = arrRet[0];
				    var ptV = map.fromLatLngToDivPixel(pt);
				    var ptClV = map.fromLatLngToDivPixel(ptCl);
				    if (VUtil.Distance(ptV.x, ptV.y, ptClV.x, ptClV.y) > 300)
				    {
				        clearControlPoint();
				        iMyMapCoorOver = -1;
				    }
    	        }
    	        
    	    });
    	    
    VEvent.addListener(map, 'dblclick', function(overlay, pt){
            if (nDrawingPts > 1  && bDrawingPolyline)
                {
                    var divMyMapCoorList = document.getElementById('MyMapCoorList');
			        var table = document.createElement('TABLE');
                    table.setAttribute('width', '95%');
                    table.setAttribute('border', 0);
                    table.setAttribute('cellPadding', 0);
                    table.setAttribute('cellSpacing', 0);
                    table.style.marginTop = '5px';
                    if (browserName == 'msie')
                    {
                        table.style.marginBottom = '5px';
                        table.style.marginLeft = '5px';
                    }
                    table.style.cursor = 'pointer';
                    table.setAttribute('id', 'MyMapCoorList_' + (nMyMapCoorObj - 1));
                    table.onclick = function(){
                            clickedPoint=null;
                            showMyMapInfoWindow(this.id.substring(this.id.indexOf('_') + 1, this.id.length), 0);
                        };
                    table.onmouseover = function(){
                            changeCoorTextStyle(this.id.substring(this.id.indexOf('_') + 1, this.id.length));
                        };
                    table.onmouseout = function(){
                            changeCoorTextStyle(this.id.substring(this.id.indexOf('_') + 1, this.id.length));
                        };
                    
                    var tBody = document.createElement('TBODY');
                    var row = document.createElement('TR');
                    var cell = document.createElement('TD');
                    cell.setAttribute('width', '13%');
                    cell.setAttribute('rowspan', 2);
                    cell.setAttribute('align', 'center');
                    cell.setAttribute('valign', 'middle');
                    var strHTML = '';
                    if (selTbrButton.id == 'btnAddPolyline')
                        strHTML += "<img src='images/icon_polyline.gif' />";
                    else if (selTbrButton.id == 'btnAddPolygon')
                        strHTML += "<img src='images/icon_polygon.gif' />";
                    cell.innerHTML = strHTML;
                    row.appendChild(cell);
                    
                    cell = document.createElement('TD');
                    cell.setAttribute('width', '87%');
                    cell.setAttribute('height', '20px');
                    cell.setAttribute('align', 'left');
                    cell.setAttribute('valign', 'middle');
                    
                    strHTML = "<span id='MyMapCoorListTitle_" + (nMyMapCoorObj - 1) + "' style='color:#0066cc; font-weight:bold;' >";
                    strHTML += 'Chưa đặt tên' + "</span><br /><span id='MyMapCoorListDesc_" + (nMyMapCoorObj - 1) + "' >";
                    strHTML += '&nbsp;&nbsp;&nbsp;';
                    strHTML += "</span>";
                    cell.innerHTML = strHTML;
                    row.appendChild(cell);
                    
                    tBody.appendChild(row);
                    table.appendChild(tBody);
                    divMyMapCoorList.appendChild(table);
                    
                    bDrawingPolyline = false;
                    if (tempPolyline != null)
                    {
                        map.removeOverlay(tempPolyline);
                        tempPolyline = null;
                    }
                    if (browserName != 'msie')
                    {
                        arrDrawingPts.pop();
                        nDrawingPts--;
                    }
                    
                    if (selTbrButton.id == 'btnAddPolygon')
                    {
	                    arrDrawingPts[nDrawingPts] = arrDrawingPts[0].copy();
	                    nDrawingPts++;
                    }
                    
                    arrMyMapCoorObj[nMyMapCoorObj - 1].setLatLngs(arrDrawingPts);
                    
                    var dtRow = new Object();
				    dtRow.MyMapCoorID = '';
				    dtRow.MyMapID = '';
				    dtRow.ObjectTitle = 'Chưa đặt tên';
				    dtRow.ObjectDesc = '';
				    
				    var strLatLngs = '';
                    if (selTbrButton.id == 'btnAddPolyline')
                        strLatLngs = 'LINESTRING(';
                    else if (selTbrButton.id == 'btnAddPolygon')
                        strLatLngs = 'POLYGON((';
                    
                    for (var i = 0; i < nDrawingPts; i++)
                    {
                        strLatLngs += arrDrawingPts[i].longitude + ' ' + arrDrawingPts[i].latitude;
                        if (i < nDrawingPts - 1)
                            strLatLngs += ',';
                    }
                    
                    if (selTbrButton.id == 'btnAddPolyline')
                        strLatLngs += ')';
                    else if (selTbrButton.id == 'btnAddPolygon')
                        strLatLngs += '))';
                    
				    dtRow.Coor = strLatLngs;
				    
				    if (selTbrButton.id == 'btnAddPolyline')
				        dtRow.Style = '3;#ff0000;#ff0000;0.5;;';
				    else if (selTbrButton.id == 'btnAddPolygon')
				        dtRow.Style = '3;#ff0000;#00ff00;0.3;0.5;';
				    
				    dsMyMapCoor.Tables[0].Rows[dsMyMapCoor.Tables[0].Rows.length] = dtRow;
	                
	                arrDrawingPts = null;
                    nDrawingPts = 0;
				    bCreateNewMMObj = true;
				    selectToolbarBtn(document.getElementById('btnMove'));
                    showMyMapInfoWindow(arrMyMapCoorObj[nMyMapCoorObj - 1].mmIndex, 0);
                    return;
                }
            
            if (nDrawingPtsML > 1  && bMeasureLine)
            {
                bMeasureLine = false;
                if (tempPolyline != null)
                {
                    map.removeOverlay(tempPolyline);
                    tempPolyline = null;
                }
                if (browserName != 'msie')
                {
                    arrDrawingPtsML.pop();
                    nDrawingPtsML--;
                }
                if(arrDrawingPtsML.length > 1)
                {
                    CurrentDistance = CalculateDistance(arrDrawingPtsML[arrDrawingPtsML.length-2],arrDrawingPtsML[arrDrawingPtsML.length-1]);
                }
                else
                {
                    CurrentDistance = CalculateDistance(arrDrawingPtsML[arrDrawingPtsML.length-1],pt);
       	        }
       	        if(CurrentDistance >= 1000)
                    document.getElementById('lblCurDistance').innerHTML = '<FONT style="color:#FF3300">'+(CurrentDistance / 1000)  +' km</FONT>';
                else
                    document.getElementById('lblCurDistance').innerHTML = '<FONT style="color:#FF3300">'+CurrentDistance +' m</FONT>';
                arrDrawingPtsML = null;
                nDrawingPtsML = 0;
                isMeasureDistance = false;
                //alert('Tổng khoảng cách: '+ TotalDistance);
                //map.enableDoubleClickZoom();
                return false;
            }                    
        });
    
    VEvent.addListener(map, 'infowindowclose', function(){ 
            if (bCreateNewMMObj)
                map.enableDoubleClickZoom();
            if (resultActive != -1)
            {
                var element = document.getElementById('resultItem_'+resultActive);
                ResultEntryInActive(element);    
                resultActive = -1;              
            }
            
            if (iMyMapCoorSel != -1)
            {
                changeCoorBkColor(iMyMapCoorSel, false);
                iMyMapCoorSel = -1;
            }   
            if(markerXemChiTiet != undefined)
            {
            
                 map.removeOverlay(markerXemChiTiet); 
                 markerXemChiTiet = undefined;
            }
            curTitle = '';
            curDesc = '';
            curIcon = '';
            curText = '';
            curFontFamily = '';
            curFontWeight = '';
            curFontSize = '';
            curFontColor = '';
            curLineColor = '';
            curLineWidth = '';
            curLineOpacity = '';
            curFillColor = '';
            curFillOpacity = '';
            bCreateNewMMObj = false;
            map.showControls();
        });
    VEvent.addListener(map, 'zoomend', function(){
        /*if(isSetGetCookies)
            document.getElementById('defaultLocation').innerHTML = 'Quay lại khu vực quan tâm';*/
        GetDirectionLatLngs();
        });
        
    VEvent.addListener(map, 'moveend', function(){ 
        /*if(isSetGetCookies)
            document.getElementById('defaultLocation').innerHTML = 'Quay lại khu vực quan tâm';*/
        if(directionLatLng != null && PlaceToFindPathArray.length > 1)
        {
            var last = map.fromLatLngToDivPixel(directionLatLng);
            var now = map.fromLatLngToDivPixel(map.getCenter());
            if(Math.sqrt(VUtil.Distance(last.x, last.y, now.x, now.y)) > map.getSize().width || Math.sqrt(VUtil.Distance(last.x, last.y, now.x, now.y)) > map.getSize().height )
            {
            GetDirectionLatLngs();}
        }
        });
    ChangeSearchType(GLOBAL_SEARCH_MAP);
};
function calculateWindowSize()
{
    if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.						documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
}

function ResizeWindow()
{
	calculateWindowSize();
	var container = document.getElementById('container');
	var leftpanel = document.getElementById('leftpanel');
	var centerpanel = document.getElementById('centerpanel');
	var copyright = document.getElementById('copyright');
	
	container.style.width = myWidth - container.offsetLeft - 5 + "px";
	container.style.height = myHeight - container.offsetTop - 25 + "px";
	centerpanel.style.height = myHeight - container.offsetTop - 25 +"px";
	
	document.getElementById('expand_map').style.marginTop =  (myHeight - container.offsetTop - 35)/2 - 6 + "px";
	leftpanel.style.height = myHeight - container.offsetTop - 45 - 5 +"px";
	//copyright.style.top = myHeight - 35 + "px";
	resizeMyMapDiv();
    if(map != null)
       map.checkResize();
};

function ResultEntryMouseOver(element)
{        
      var index = element.parentNode.parentNode.rowIndex;
      var img = document.getElementById('resultimage_'+index);
      var logo = document.getElementById('resultlogo_'+index);
      if (logo==null && arrSearchMapResult.length>0)
      {
          var icon = new VIcon("images/"+index+"over.gif");
          arrSearchMapResult[index-1].setIcon(icon); 
          
                   
          arrSearchMapResult[index-1].active();
      }
      ChangeImageSrc(img, "images/"+index+"over.gif");
      ChangeBorderColor(element,'#ff9933');          
      //Tam thoi InActive selected result item neu move chuot vào result item khac     
      if (resultActive!=-1 && resultActive!=index)
      {
          index = resultActive;
          logo = document.getElementById('resultlogo_'+index);
          img = document.getElementById('resultimage_'+index);
          if (logo==null && arrSearchMapResult.length>0)
          {
              var icon = new VIcon("images/"+index+".gif");
              arrSearchMapResult[index-1].setIcon(icon); 
              arrSearchMapResult[index-1].unactive();
          }          
      }
};

function ResultEntryPlaceABMouseOver(element)
{
      var index = element.parentNode.parentNode.rowIndex;
      var img = document.getElementById('resultimage_placeAB'+index);
      ChangeImageSrc(img, "images/"+index+"over.gif");
      ChangeBorderColor(element,'#ff9933');      
};
function ResultEntryPlaceABMouseOut(element)
{
      var index = element.parentNode.parentNode.rowIndex;
      var img = document.getElementById('resultimage_placeAB'+index);
      ChangeImageSrc(img, "images/"+index+".gif");
      ChangeBorderColor(element,'#ffffff');
      element.style.borderBottom = '1px #efefef solid';      
};

function ResultEntryMouseOut(element)
{
      var index = element.parentNode.parentNode.rowIndex;
      var img = document.getElementById('resultimage_'+index);
      var logo = document.getElementById('resultlogo_'+index);
      if (logo == null && arrSearchMapResult.length > 0)
      {
          var icon = new VIcon("images/"+index+".gif");
          arrSearchMapResult[index-1].setIcon(icon); 
          arrSearchMapResult[index-1].unactive();
      }
      ChangeImageSrc(img, "images/"+index+".gif");
      ChangeBorderColor(element,'#ffffff');
      element.style.borderBottom = '1px #efefef solid'; 
      //Active selected result item     
      if (resultActive!=-1)
      {
          index = resultActive;
          logo = document.getElementById('resultlogo_'+index);
          img = document.getElementById('resultimage_'+index);
          if (logo==null && arrSearchMapResult.length>0)
          {
              var icon = new VIcon("images/"+index+"over.gif");
              arrSearchMapResult[index-1].setIcon(icon); 
              arrSearchMapResult[index-1].active();
          }
          ChangeImageSrc(img, "images/"+index+"over.gif");          
      }
};

function ResultEntryActive(element)
{
      var index = resultActive;
      var img = document.getElementById('resultimage_'+index);
      var logo = document.getElementById('resultlogo_'+index);
      if (logo==null)
      {
          var icon = new VIcon("images/"+index+"over.gif");
          arrSearchMapResult[index-1].setIcon(icon); 
      }
      arrSearchMapResult[index-1].active();
      ChangeImageSrc(img, "images/"+index+"over.gif");
      ChangeBorderColor(element,'#ff9933');
      ChangeBgColor(element,'#ffffcc');        
};

function ResultEntryInActive(element)
{
      var index = resultActive;
      var img = document.getElementById('resultimage_'+index);
      var logo = document.getElementById('resultlogo_'+index);
      if (logo == null)
      {
          var icon = new VIcon("images/"+index+".gif");
          arrSearchMapResult[index-1].setIcon(icon); 
      }
      arrSearchMapResult[index-1].unactive();
      ChangeImageSrc(img, "images/"+index+".gif");
      ChangeBorderColor(element,'#ffffff');
      element.style.borderBottom = '1px #efefef solid';
      ChangeBgColor(element,'#FFFFFF');        
};

function OnforcusMap(tb)
{
	tb.style.background = '#ffffff';
	//ChangeSearchType(GLOBAL_SEARCH_MAP);
};

function OnblurMap(tb)
{
	if(tb.value == '')
	{ 
		if(nLanguage ==0)
			tb.style.background = "#FFFFFF url(images/help_bando.gif) left no-repeat";
		else
			tb.style.background = "#FFFFFF url(images/help_bando.gif) left no-repeat";
	}
};

function OnforcusBusinessWhat(tb)
{
    ChangeSearchType(GLOBAL_SEARCH_BUSINESS);
	tb.style.background = '#ffffff';
};

function OnblurBusinessWhat(tb)
{
	if(tb.value == '')
	{
		if(nLanguage ==0)
			tb.style.background = "#FFFFFF url(images/help_diemdv1.gif) left no-repeat";
		else
			tb.style.background = "#FFFFFF url(images/help_diemdv1.gif) left no-repeat";
	}
};

function OnforcusBusinessWhere(tb)
{
	tb.style.background = '#ffffff';
};

function OnblurBusinessWhere(tb)
{
	if(tb.value == '')
	{
		if(nLanguage ==0)
			tb.style.background = "#FFFFFF url(images/help_diemdv2.gif) left no-repeat";
		else
			tb.style.background = "#FFFFFF url(images/help_diemdv2.gif) left no-repeat";
	}
};

function OnforcusAddress(tb)
{
    ChangeSearchType(GLOBAL_SEARCH_ADDRESS);
	tb.style.background = '#ffffff';
};

function OnblurAddress(tb)
{
	if(tb.value == '')
	{
		if(nLanguage ==0)
			tb.style.background = "#FFFFFF url(images/help_diachi.gif) left no-repeat";
		else
			tb.style.background = "#FFFFFF url(images/help_diachi.gif) left no-repeat";
	}
};

function OnforcusTextBox(tb)
{
	tb.style.background = '#ffffff';
};

function OnblurTextBox(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);
};

function fullscreen()
{
    var imgCenterPanel = document.getElementById('expand_map');
    if (imgCenterPanel.src.indexOf("images/expand_map.gif") != -1)
        expandMap();
    else
        shrinkMap();
};

function expandMap()
{
    var divLeftPanel = document.getElementById('leftpanel');
    var divClearResult = document.getElementById('clearresult_div');
    var divCenterPanel = document.getElementById('centerpanel');
    var imgCenterPanel = document.getElementById('expand_map');
    var divContainer = document.getElementById('container');
    if (parseInt(divLeftPanel.style.width) > 150)
    {
        divLeftPanel.style.width = parseInt(divLeftPanel.style.width) - 150 + 'px';
        divClearResult.style.width = divLeftPanel.style.width;
        divCenterPanel.style.left = parseInt(divCenterPanel.style.left) - 150 + 'px';
        if (bFirstTmr)
        {
            bFirstTmr = false;
            divContainer.style.left = '6px';
	        divContainer.style.width = myWidth - divContainer.offsetLeft - 5 + "px";
            map.checkResize();
        }
        if (expandMapTmr != null)
            clearTimeout(expandMapTmr);
        expandMapTmr = setTimeout(expandMap, 1);
    }
    else
    {
        bFirstTmr = true;
        divLeftPanel.style.width = '0px';
        divLeftPanel.style.borderWidth = '0px';
        divClearResult.style.width = '0px';
        divClearResult.style.borderWidth = '0px';
        divCenterPanel.style.left = '0px';
        imgCenterPanel.src = "images/shrink_map.gif";
        clearTimeout(expandMapTmr);
    }
};

function shrinkMap()
{
    var divLeftPanel = document.getElementById('leftpanel');
    var divClearResult = document.getElementById('clearresult_div');
    var divCenterPanel = document.getElementById('centerpanel');
    var imgCenterPanel = document.getElementById('expand_map');
    var divContainer = document.getElementById('container');
    if (parseInt(divLeftPanel.style.width) < 300)
    {
        divLeftPanel.style.width = parseInt(divLeftPanel.style.width) + 150 + 'px';
        divClearResult.style.width = divLeftPanel.style.width;
        divCenterPanel.style.left = parseInt(divCenterPanel.style.left) + 150 + 'px';
        if (shrinkMapTmr != null)
            clearTimeout(shrinkMapTmr);
        shrinkMapTmr = setTimeout(shrinkMap, 1);
    }
    else
    {
        divLeftPanel.style.width = '347px';
        divLeftPanel.style.borderWidth = '1px';
        divClearResult.style.width = '347px';
        divClearResult.style.borderWidth = '1px';
        divCenterPanel.style.left = '355px';
        imgCenterPanel.src = "images/expand_map.gif";
        divContainer.style.left = '362px';
	    divContainer.style.width = myWidth - divContainer.offsetLeft - 5 + "px";
        map.checkResize();
        clearTimeout(shrinkMapTmr);
    }
};

function showOnlineSupport(obj)
{
    if (onlineSupportShow)
    {
        var strHTML = '';
        strHTML += "Hỗ trợ kỹ thuật";
        obj.innerHTML = strHTML;
        onlineSupportShow = false;
    }
    else
    {
        var strHTML = '';
        strHTML += "Hỗ trợ kỹ thuật<br/><br/>";
        strHTML += "<a href='ymsgr:sendIM?hotro_vietbando' class='nav2'><img border=0 src='http://opi.yahoo.com/online?u=hotro_vietbando&m=g&t=1' /></a>";
        strHTML += "<br /><br />";
        strHTML += "<a href='skype:hotro_vietbando?chat' class='nav2'><img src='http://download.skype.com/share/skypebuttons/buttons/chat_green_transparent_97x23.png' style='border: none;' width='97' height='23' alt='Ho tro Vietbando' /></a>";
        obj.innerHTML = strHTML;
        onlineSupportShow = true;
    }
};

function panToCenter(pt)
{
    map.panTo(pt);
};

function zoomIn(pt)
{
    closeContextMenu();
    map.setCenter(pt, map.getLevel() + 1);
};

function zoomOut(pt)
{
    closeContextMenu();
    map.setCenter(pt, map.getLevel() - 1);
};
isMeasureDistance = false;
function measureDistance(pt)
{
    closeContextMenu();
    //alert('Chúng tôi sẽ sớm hỗ trợ chức năng này');
    isMeasureDistance = true;    
    ShowPopUpMyMapDistance();
};
function searchNearBy(pt)
{
    closeContextMenu();
    ShowSearchNearByLngLat(pt);
};
function showBusyDiv(strMessage)
{
    var divClearResult = document.getElementById('clearresult_div');
    var divBusyCR = document.getElementById('divBusyCR');
    if (divBusyCR == null)
    {
        divBusyCR = document.createElement('div');
        divBusyCR.id = 'divBusyCR';
        divBusyCR.style.position = 'absolute';
        divBusyCR.style.zIndex = 5;
        divBusyCR.style.left = '0px';
        divBusyCR.style.top = '0px';
        divBusyCR.style.width = divClearResult.style.width;
        divBusyCR.style.height = divClearResult.style.height;
        divBusyCR.style.backgroundColor = '#ffffff';
        divBusyCR.style.filter = 'alpha(opacity = 50)';
        divBusyCR.style.opacity = 0.5;
        divClearResult.appendChild(divBusyCR);
    }
    
    var divLeftPanel = document.getElementById('leftpanel');
    var divBusyLP = document.getElementById('divBusyLP');
    if (divBusyLP == null)
    {
        divBusyLP = document.createElement('div');
        divBusyLP.id = 'divBusyLP';
        divBusyLP.style.position = 'absolute';
        divBusyLP.style.zIndex = 5;
        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' /><a class='a1' id='loadingText' style='font-family:Verdana; font-size:12px; font-weight:bold; color:#ff0000;'>" + strMessage + "</a>";
        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 - 50;
        loadingImg.style.position = 'absolute';
        loadingImg.style.left = imgLeft + 'px';
        loadingImg.style.top = imgTop + 'px';
        
        var loadingText = document.getElementById('loadingText');
        var textLeft = (parseInt(divLeftPanel.offsetWidth) - parseInt(loadingText.offsetWidth)) / 2;
        var textTop = (parseInt(divLeftPanel.offsetHeight) - parseInt(loadingText.offsetHeight)) / 2 - 10;
        loadingText.style.position = 'absolute';
        loadingText.style.left = textLeft + 'px';
        loadingText.style.top = textTop + 'px';
    }
};

function hideBusyDiv(strMessage)
{
    if (strMessage != undefined && strMessage != '')
    {
        var divLeftPanel = document.getElementById('leftpanel');
        var loadingText = document.getElementById('loadingText');
        loadingText.innerText = strMessage;
        var textLeft = (parseInt(divLeftPanel.offsetWidth) - parseInt(loadingText.offsetWidth)) / 2;
        var textTop = (parseInt(divLeftPanel.offsetHeight) - parseInt(loadingText.offsetHeight)) / 2 - 10;
        loadingText.style.left = textLeft + 'px';
        loadingText.style.top = textTop + 'px';
    }
    if (busyDivTmr != null)
        clearTimeout(busyDivTmr);
    busyDivTmr = setTimeout(removeBusyDiv, 100);
};

function removeBusyDiv()
{
    clearTimeout(busyDivTmr);
    var divClearResult = document.getElementById('clearresult_div');
    var divBusyCR = document.getElementById('divBusyCR');
    if (divBusyCR != null)
        divClearResult.removeChild(divBusyCR);
    
    var divLeftPanel = document.getElementById('leftpanel');
    var divBusyLP = document.getElementById('divBusyLP');
    if (divBusyLP != null)
        divLeftPanel.removeChild(divBusyLP);
};
