/*! Module Name : car_Search.js
      version : 1.0
    Developer : daniel Park
    Description
    : 자동차 길찾기 검색 알고리즘 수행.
*/
CarSearchModule = function(opt, _parent){
    this.map = opt.map;
    this.$inputStartTxt = $('#' + opt.inputStartTxtId);
    this.$inputEndTxt = $('#' + opt.inputEndTxtId);
    this.$pageNum = $('#' + opt.pageNumId);
    this.$language = $('#' + opt.languageId);
    this.searchName = null;
    this.resultPos = null;
    this.resultName = null;
    this.parentObj = _parent;
};

CarSearchModule.prototype = {
    init: function(){
        $("#pageNum").attr('value', 1);
    },
    search: function(_gubun){
        var searchTxt = '';

        if (_gubun == LocalTextBox.START_TARGET) {
            searchTxt = this.$inputStartTxt.val();
        }
        else {
            searchTxt = this.$inputEndTxt.val();
        }

        this.searchName = searchTxt;
        this.searchExecute();
    },
    searchExecute: function(){
        // [Loading...] Start
        this.poiSearchLoadingAjax(true);

        var varRq = 'poi';
        var varF = 'json';
        var varLang = this.$language.val();
        var varPage = this.$pageNum.val() + ',' + ViewCount;

        var varParameter = 'f=' + varF + '&rq=' + varRq + '&lang=' +
                                varLang + '&page=' + varPage + '&name=' + this.searchName;
        executeAjaxArgument(false, varParameter, this.rtnSearchPoi, this);
    },
    rtnSearchPoi: function(data){
        var resultCode = 0;
        var address;

        // [Loading...] Stop
        this.poiSearchLoadingAjax(false);

        if(data.Mapot.Response.Status.code!="200" || !data.Mapot.Response.Poi.Placemark){
            this.viewResultTotalCount(0);
            this.noData();
            return;
        }

        var totalCnt = data.Mapot.Response.Poi.Page.totalCnt;
        // Total Count view
        this.viewResultTotalCount(totalCnt);

        // Content View <div><ul>
        $("#resultInfo").append("<div id='sch_place' class='sch_map'></div>");
        $("#sch_place").append("<ul id='sch_place_sub' class='pathSearch'></ul");

        // Content Loop <ul><li><dl><a>
        if (data.Mapot.Response.Poi.Placemark.length > 0) {
            var thisObj = this;
            $.each(data.Mapot.Response.Poi.Placemark, function(index, value){
                if (!value.address) {
                    tempAddress = '-';
                }
                else {
                    var tempAddress = value.address.substring(value.address.indexOf(",") + 1);
                    if(mapLang=="china_g" || mapLang=="china_b")
                        tempAddress = ReplaceAll(tempAddress, ',', '');
                    else
                        tempAddress = ReplaceAll(tempAddress, ',', ' ');

                    tempAddress = ReplaceAll(tempAddress, 'null', ' ');
                }
                thisObj.viewPoiResultDetail(index, value.name, tempAddress, new SPoint(value.Point.coordinate[0], value.Point.coordinate[1], 'WGS84_Degree'));
            });
        }

        // Page Display
        this.viewPaging($('#pageNum').val(), totalCnt);
    },
    viewPoiResultDetail: function(_idx, _poiName, _poiAddress, _poiPoint){
        var thisObj = this;
        $link = $("#sch_place_sub");

        $link.append("<div id='sublist_" + _idx + "'>" + "<a>" + _poiName +
        "</a><br>" +
        "</div>");

        $("#sublist_" + _idx).wrap("<li></li>").append("<span id='searchResult_" + _idx + "'  class='addr'>" +
        _poiAddress +
        "</span>");

        $("#sublist_" + _idx).attr('coordX', _poiPoint.x).attr('coordY', _poiPoint.y).attr('address', _poiAddress).attr('poiName', _poiName);

        $clickInfo = $("#sublist_" + _idx);
        $clickInfo.css('cursor', 'pointer');
        $clickInfo.bind('click', function(){
            thisObj.map.setCenterAndZoom(new SPoint($(this).attr('coordX'), $(this).attr('coordY')), 2);
            thisObj.parentObj.cbPoiSearchResultClick($(this).attr('poiName'), $(this).attr('address'), $(this).attr('coordX'), $(this).attr('coordY'));

            return false;
        });

        var displayTitle = '';
        if (!_poiName || _poiName == '')
            displayTitle = _poiAddress;
        else
            displayTitle = _poiName;
    },
    viewResultTotalCount: function(_totalCount){
        this.deletePoiSearchHtml();
        var searchTxt = '';
        var tempTxt = '';

        searchTxt = this.searchName;

        $link = $("#resultInfo");
        $link.append("<div class='sch_title'>" + "<strong>'" + searchTxt + "' " +
        i18NObj.getTextValue('searchResultTitle') +
        " (" +
        i18NObj.getTextValue('searchResultCountHead') +
        _totalCount +
        ' ' +
        i18NObj.getTextValue('searchResultCount') +
        ")</strong></div>");
    },
    noData : function() {
        $link = $("#resultInfo");
        $link.append("<div class='search_result'><ul><li>" + i18NObj.getTextValue('searchNotResult') + "</li></ul></div>");
    },
    deletePoiSearchHtml: function(){
        // Guide창 hide 시키기
        this.parentObj.parentObj.showSearch();
        this.parentObj.parentObj.hideGuide();
        this.parentObj.parentObj.hideResult();

        $("#resultInfo").empty();
        $("#pageNavigation").empty();
    },
    viewPaging: function(_currentPage, _totalItemCount){
        var totalPage = Math.ceil(_totalItemCount / ViewCount); // 총
        // 페이징
        // 갯수

        var currentStep = Math.ceil(_currentPage / ViewPageCount); // 현 위치
        // Step
        var totalStep = Math.ceil(totalPage / ViewPageCount); // 총
        // Step

        var prevPageMax = (currentStep - 1) * ViewPageCount;
        var currPageMin = prevPageMax + 1;
        var nextPageMin = (currentStep * ViewPageCount) + 1;
        $link = $("#pageNavigation");
        $link.empty();

        // Prev Action
        if (currentStep > 1) {
            $('<a></a>').attr({
                'class': 'arrow_pre',
                'onfocus': 'this.blur()',
                'href': 'javascript:goCarSearchResultPage(' + prevPageMax + ')'
            }).append("<img src='/images/index2/n_local_btn_32.gif' border='0' />").appendTo($link);
        }

        // Real Item Display
        for (var index = 0; index < ViewPageCount &&
        currPageMin + index <= totalPage; index++) {
            if (_currentPage == (currPageMin + index)) {
                $('<span></span>').addClass('current').html(currPageMin + index).appendTo($link).html((currPageMin + index));
            }
            else {
                $('<a></a>').attr({
                    'onfocus': 'this.blur()',
                    'href': 'javascript:goCarSearchResultPage(' + (currPageMin + index) + ')'
                }).html(currPageMin + index).appendTo($link);
            }
        }

        // Next Action.
        if (currentStep < totalStep) {
            $('<a></a>').attr({
                'class': 'arrow_next',
                'onfocus': 'this.blur()',
                'href': 'javascript:goCarSearchResultPage(' + nextPageMin + ')'
            }).append("<img src='/images/index2/n_local_btn_33.gif' border='0' />").appendTo($link);
        }
    },
    poiSearchLoadingAjax: function(flag){
        if (flag)
            $('#ajaxLoading').show();
        else
            $('#ajaxLoading').hide();
    }
};

/**
 * 입력 박스 컨트롤 = 자동차 길찾기
 */
LocalTextBox = function(obj, _parentObj){
    this.map = obj.map;
    this.$inputStartTxt = $('#' + obj.inputStartTxtId);
    this.$searchStartBtn = $('#' + obj.searchStartBtnId);
    this.$inputEndTxt = $('#' + obj.inputEndTxtId);
    this.$searchEndBtn = $('#' + obj.searchEndBtnId);
    this.$routeSearchBtn = $('#' + obj.routeBtnId);
    this.$carResetBtn = $('#' + obj.carResetBtnId);

    this.searchModule = new CarSearchModule(obj, this);
    this.statusStart;
    this.statusEnd;
    this.currentSearchPoiStatus;
    this.parentObj = _parentObj;

    this.init();
};

LocalTextBox.START_TARGET = "START_POINT";
LocalTextBox.END_TARGET = "END_POINT";

LocalTextBox.INIT = "INIT";
LocalTextBox.INPUTOK = "INPUTOK";
LocalTextBox.COMPLETE = "COMPLETE";

LocalTextBox.prototype = {
    init: function(){
        this.status = LocalTextBox.INIT;
        var thisObject = this;

        this.$inputStartTxt.bind('click', function(){
            thisObject._inputStartClick.call(thisObject);
        });
        this.$inputStartTxt.bind('keydown', function(e){
            thisObject.textKeyDown.apply(thisObject, new Array(e, LocalTextBox.START_TARGET));
        });
        this.$searchStartBtn.bind('click', function(){
            thisObject._searchPoi.apply(thisObject, new Array(thisObject.$inputStartTxt, LocalTextBox.START_TARGET));
        });
        this.$inputEndTxt.bind('click', function(){
            thisObject._inputEndClick.call(thisObject);
        });
        this.$inputEndTxt.bind('keydown', function(e){
            thisObject.textKeyDown.apply(thisObject, new Array(e, LocalTextBox.END_TARGET));
        });
        this.$searchEndBtn.bind('click', function(){
            thisObject._searchPoi.apply(thisObject, new Array(thisObject.$inputEndTxt, LocalTextBox.END_TARGET));
        });
        this.$routeSearchBtn.bind('click', function(e){
            thisObject._searchRouteBtnExecute.call(thisObject, e);
        });
        this.$carResetBtn.bind('click', function(){
            thisObject._searchRouteReset.call(thisObject);
        });
    },
    _inputStartClick: function(){
        if (this._isEmpty(this.$inputStartTxt)) {
            this.$inputStartTxt.attr('value', '');
        }
        this.$inputStartTxt.focus();
    },
    _inputEndClick: function(){
        if (this._isEmpty(this.$inputEndTxt)) {
            this.$inputEndTxt.attr('value', '');
        }
        this.$inputEndTxt.focus();
    },
    textKeyDown: function(e, target){
        if (e.keyCode == 13 || e.keyCode == 9) {
            var $targetPoint = '';

            if (target == LocalTextBox.START_TARGET) {
                this.currentSearchPoiStatus = LocalTextBox.START_TARGET;
                $targetPoint = this.$inputStartTxt;
            }
            else {
                this.currentSearchPoiStatus = LocalTextBox.END_TARGET;
                $targetPoint = this.$inputEndTxt;
            }
            this._searchPoi($targetPoint);
            e.preventDefault();
        }
        else {
            if (target == LocalTextBox.START_TARGET) {
                this._inputStartClick();
            }
            else {
                this._inputEndClick();
            }
        }
    },
    _isEmpty: function($objTarget){
        return $objTarget.val() == '' ||
                $objTarget.val() == i18NObj.getTextValue('searchStartInput') ||
                $objTarget.val() == i18NObj.getTextValue('searchEndInput');
    },
    _searchPoi: function($target, targetPosition){
        if (targetPosition != null)
            this.currentSearchPoiStatus = targetPosition;

        if (this._isEmpty($target)) {
            if (this.currentSearchPoiStatus == LocalTextBox.START_TARGET)
                alert(i18NObj.getTextValue('searchStartRequire'));
            else
                alert(i18NObj.getTextValue('searchEndRequire'));

            return false;
        }


        if ($target.val().length<2){
            alert(i18NObj.getTextValue('twoWordLengthRequire'));		// 2자 이상 입력 요청.
            return false;
        }

        this._searchPoiInnerExecute();
    },
    _searchPoiInnerExecute: function(){
        var poiSearchValue = '';

        if (this.currentSearchPoiStatus == LocalTextBox.START_TARGET)
            poiSearchValue = this.$inputStartTxt.val();
        else
            poiSearchValue = this.$inputEndTxt.val();

        this.searchModule.init();
        this.searchModule.search(this.currentSearchPoiStatus);
    },
    _searchRouteBtnExecute: function(e){
        if (this._isEmpty(this.$inputStartTxt)) {
            alert(i18NObj.getTextValue('searchStartRequire'));
            return false;
        }

        if (this._isEmpty(this.$inputEndTxt)) {
            alert(i18NObj.getTextValue('searchEndRequire'));
            return false;
        }

        eventOverlap(e);
        e.stopPropagation();
        e.preventDefault();

        this.parentObj.carRoutingExecute();
    },
    searchRouteExecute: function(){

    },
    searchPagingPoiExecute: function(){
        this.searchModule.searchExecute();
    },
    cbPoiSearchResultClick: function(_paramName, _paramAddress, _paramX, _paramY){
        var inputValue = '';
        if (!_paramName)
            inputValue = _paramAddress;
        else
            inputValue = _paramName;

        this.inputBox(inputValue);
        this.parentObj.cbPoiSearchClick(inputValue, _paramX, _paramY, this.currentSearchPoiStatus);
    },
    inputBox: function(_paramValue){
        if (this.currentSearchPoiStatus == LocalTextBox.START_TARGET)
            this.$inputStartTxt.attr('value', _paramValue);
        else
            this.$inputEndTxt.attr('value', _paramValue);
    },
    clearTextBox: function(_id){
        if (_id == LocalTextBox.START_TARGET)
            this.$inputStartTxt.attr('value', '');
        else
            this.$inputEndTxt.attr('value', '');
    },
    clearTextBoxAll: function(){
        this.$inputStartTxt.attr('value', i18NObj.getTextValue('searchStartRequire'));
        this.$inputEndTxt.attr('value', i18NObj.getTextValue('searchEndRequire'));
    },
    returnStartPointName: function(){
        return this.$inputStartTxt.val();
    },
    returnEndPointName: function(){
        return this.$inputEndTxt.val();
    },
    setStartBoxValue: function(_paramValue){
        this.$inputStartTxt.attr('value', _paramValue);
    },
    setEndBoxValue: function(_paramValue){
        this.$inputEndTxt.attr('value', _paramValue);
    },
    getStartBoxValue: function(){
        return this.$inputStartTxt.val();
    },
    getEndBoxValue: function(){
        return this.$inputEndTxt.val();
    },
    _searchRouteReset: function(){
        this.parentObj.clearAll();
    }
};

CarRouteServiceModule = function(_param){
    this.map = _param.map;
    this.mapLayerId = _param.mapLayerId;
    this.$mapLayerObject = $('#' + _param.mapLayerId);
    this.RouteStartPlag = _param.startPlag;
    this.RouteEndPlag = _param.endPlag;
    this.currentRoutePlag = null;
    this.TextBoxModule = new LocalTextBox({
        map: this.map,
        inputStartTxtId: _param.inputStartTxtId,
        searchStartBtnId: _param.searchStartBtnId,
        inputEndTxtId: _param.inputEndTxtId,
        searchEndBtnId: _param.searchEndBtnId,
        routeBtnId: _param.routeBtnId,
        pageNumId: _param.pageNumId,
        languageId: _param.languageId,
        carResetBtnId: _param.carResetBtnId
    }, this);
    this.carRoutingSearchModule = new CarRoutingSearchModule(this.map, this);
    this.startPointCursor;
    this.endPointCursor;
    this.startPointPlag;
    this.endPointPlag;

    this.init();
    this.startMark;
    this.endMark;

    this.startPointCoord = null;
    this.endPointCoord = null;
};

CarRouteServiceModule.ADD_POINT_X = 21;
CarRouteServiceModule.ADD_POINT_Y = -36;

CarRouteServiceModule.prototype = {
    init: function(){
        this.startPointCursor = '/images/cursor/point_start.cur';
        this.endPointCursor = '/images/cursor/point_end.cur';
        this.startPointPlag = '/images/index2/n_local_click_start.png';
        this.endPointPlag = '/images/index2/n_local_click_arrive.png';
        var thisSearchModule = this;
        var $mapObject = this.$mapLayerObject;

        this.RouteStartPlag.prevMapClick = function(){
            this.mapSetCursor(thisSearchModule.startPointCursor);
            this.$topDivId.css("cursor", "default");
            thisSearchModule.resetAllInfo();

            thisSearchModule.clearMark(thisSearchModule.startMark, CarRouteSearchControl.CAR_SEARCH_MARK_START_ID);
            thisSearchModule.showGuide();
            thisSearchModule.hideSearch();
            thisSearchModule.hideResult();
            thisSearchModule.carRoutingSearchModule.unloadPolyLine();
        };
        this.RouteEndPlag.prevMapClick = function(){
            this.mapSetCursor(thisSearchModule.endPointCursor);
            this.$topDivId.css("cursor", "default");
            thisSearchModule.resetAllInfo();

            thisSearchModule.clearMark(thisSearchModule.endMark, CarRouteSearchControl.CAR_SEARCH_MARK_END_ID);
            thisSearchModule.showGuide();
            thisSearchModule.hideSearch();
            thisSearchModule.hideResult();
            thisSearchModule.carRoutingSearchModule.unloadPolyLine();
        };
        this.RouteStartPlag.onFix = function(_areaName, _pos){
            thisSearchModule.onFixStart(_areaName, _pos);
        };
        this.RouteEndPlag.onFix = function(_areaName, _pos){
            thisSearchModule.onFixEnd(_areaName, _pos);
        };
    },
    unLoadModule: function(){
        this.TextBoxModule = null;

        this.map.clearOverlay(CarRouteSearchControl.CAR_SEARCH_MARK_START_ID);
        this.map.clearOverlay(CarRouteSearchControl.CAR_SEARCH_MARK_END_ID);

        this.RouteStartPlag = null;
        this.RouteEndPlag = null;

        this.carRoutingSearchModule.unLoadModule();
    },
    initExecute: function(_sX, _sY, _eX, _eY, _sName, _eName){
        this.onFixEnd(null, new SPoint(_eX, _eY, 'WGS84_Degree'));

        this.TextBoxModule.setStartBoxValue(_sName);
        if(_sName != null && !_sX ){
            alert(i18NObj.getTextValue('searchStartRequire'));
            this.TextBoxModule.$searchStartBtn.click();
        }

        this.TextBoxModule.setEndBoxValue(_eName);

        if(_sX!=null && _sY!=null){
            this.onFixStart(null, new SPoint(_sX, _sY, 'WGS84_Degree'));
            this.carRoutingExecute();
        }
    },
    initStartParam: function(_sX, _sY, _sName){
        this.onFixStart(null, new SPoint(_sX, _sY), null, true);
        this.TextBoxModule.setStartBoxValue(_sName);
    },
    initEndParam: function(_eX, _eY, _eName){
        this.onFixEnd(null, new SPoint(_eX, _eY), null, true);
        this.TextBoxModule.setEndBoxValue(_eName);
    },
    onFixStart: function(_areaName, _pos, _poiSearchPath, _notAddFlag){
        if (this.startMark == null) {
            // Image Point 보정하기
            var imagePoint = null;
            if(_notAddFlag!=null){
                imagePoint = new SPoint(0, 0);
            }
            else{
                imagePoint = new SPoint(MapPixelPerPoint(CarRouteServiceModule.ADD_POINT_X),
                                                MapPixelPerPoint(CarRouteServiceModule.ADD_POINT_Y));
            }
            var markPoint = new SPoint(_pos.x, _pos.y);
            markPoint.add(imagePoint.x, imagePoint.y);

            var markSize = new SSize(44, 47);
            this.startMark = new SContent(this.startPointPlag, 'image', markPoint, markSize, true, 'top', false);
//            this.startMark.SMark.setContent("<table border='0' cellspacing='0' cellpadding='0'>" +
//            "<tr>" +
//            "<td width='4'><img src='/images/index/popup_left.gif' width='4' height='24'></td>" +
//            "<td background='/images/index/popup_side.gif'><div align='center'><font color='#FFFFFF' size='-1'>" +
//            _areaName +
//            "</font></div></td>" +
//            "<td width='4'><img src='/images/index/popup_right.gif' width='4' height='24'></td>" +
//            "</tr>" +
//            "</table>");
            this.map.addOverlay(this.startMark, true, false, CarRouteSearchControl.CAR_SEARCH_MARK_START_ID);
            this.startMark.setDraggable(true, this._startMarkEndDrag, this);
           // this.startMark.SMark.showInfoWin();
        }
        else {
            var imagePoint;
            // Image Point 보정하기
            if(this.RouteStartPlag.mapEndDragFlag){
                imagePoint = new SPoint(MapPixelPerPoint(0), MapPixelPerPoint(0));
                this.RouteStartPlag.mapEndDragFlag = false;
            }
            else{
                imagePoint = new SPoint(MapPixelPerPoint(CarRouteServiceModule.ADD_POINT_X),
                                            MapPixelPerPoint(CarRouteServiceModule.ADD_POINT_Y));
            }
            var markPoint = new SPoint(_pos.x, _pos.y);
            markPoint.add(imagePoint.x, imagePoint.y);

            this.startMark.SMark.setPoint(markPoint);
//            this.startMark.SMark.setContent("<table border='0' cellspacing='0' cellpadding='0'>" +
//            "<tr>" +
//            "<td width='4'><img src='/images/index/popup_left.gif' width='4' height='24'></td>" +
//            "<td background='/images/index/popup_side.gif'><div align='center'><font color='#FFFFFF' size='-1'>" +
//            _areaName +
//            "</font></div></td>" +
//            "<td width='4'><img src='/images/index/popup_right.gif' width='4' height='24'></td>" +
//            "</tr>" +
//            "</table>");
//
//            this.startMark.SMark.showInfoWin();
            this.startMark.SMark.redraw();
        }

        this.cbPlagEndDrag(markPoint.x, markPoint.y, LocalTextBox.START_TARGET, _poiSearchPath);
    },
    clearMark: function(_paramObj, _id){
        if(!_paramObj) return;

        this.map.clearOverlay(_id);
        this.clearTextBox(_id);

        if(_id==CarRouteSearchControl.CAR_SEARCH_MARK_START_ID){
            this.startPointCoord = null;
        }
        else{
            this.endPointCoord = null;
        }
    },
    clearTextBox: function(_id){
        if(_id==CarRouteSearchControl.CAR_SEARCH_MARK_START_ID){
            this.startMark = null;
            this.TextBoxModule.clearTextBox(LocalTextBox.START_TARGET);
        }
        else{
            this.endMark = null;
            this.TextBoxModule.clearTextBox(LocalTextBox.END_TARGET);
        }
    },
    onFixEnd: function(_areaName, _pos, _poiSearchPath, _notAddFlag){
        if (this.endMark == null) {
            // Image Point 보정하기
            var imagePoint = null;
            if(_notAddFlag!=null){
                imagePoint = new SPoint(0, 0);
            }
            else{
                imagePoint = new SPoint(MapPixelPerPoint(CarRouteServiceModule.ADD_POINT_X),
                                                MapPixelPerPoint(CarRouteServiceModule.ADD_POINT_Y));
            }

            var markPoint = new SPoint(_pos.x, _pos.y);
            markPoint.add(imagePoint.x, imagePoint.y);

            var markSize = new SSize(44, 47);
            this.endMark = new SContent(this.endPointPlag, 'image', markPoint, markSize, true, 'top', false);
//            this.endMark.SMark.setContent("<table border='0' cellspacing='0' cellpadding='0'>" +
//            "<tr>" +
//            "<td width='4'><img src='/images/index/popup_left.gif' width='4' height='24'></td>" +
//            "<td background='/images/index/popup_side.gif'><div align='center'><font color='#FFFFFF' size='-1'>" +
//            _areaName +
//            "</font></div></td>" +
//            "<td width='4'><img src='/images/index/popup_right.gif' width='4' height='24'></td>" +
//            "</tr>" +
//            "</table>");
            this.map.addOverlay(this.endMark, true, false, CarRouteSearchControl.CAR_SEARCH_MARK_END_ID);
            //this.endMark.SMark.showInfoWin();
            this.endMark.setDraggable(true, this._endMarkEndDrag, this);
        }
        else {
            var imagePoint;

            // Image Point 보정하기
            if(this.RouteEndPlag.mapEndDragFlag){
                imagePoint = new SPoint(MapPixelPerPoint(0), MapPixelPerPoint(0));
                this.RouteEndPlag.mapEndDragFlag = false;
            }
            else{
                imagePoint = new SPoint(MapPixelPerPoint(21), MapPixelPerPoint(-36));
            }

            var markPoint = new SPoint(_pos.x, _pos.y);
            markPoint.add(imagePoint.x, imagePoint.y);

            this.endMark.SMark.setPoint(markPoint);
//            this.endMark.SMark.setContent("<table border='0' cellspacing='0' cellpadding='0'>" +
//            "<tr>" +
//            "<td width='4'><img src='/images/index/popup_left.gif' width='4' height='24'></td>" +
//            "<td background='/images/index/popup_side.gif'><div align='center'><font color='#FFFFFF' size='-1'>" +
//            _areaName +
//            "</font></div></td>" +
//            "<td width='4'><img src='/images/index/popup_right.gif' width='4' height='24'></td>" +
//            "</tr>" +
//            "</table>");
//            this.endMark.SMark.showInfoWin();
            this.endMark.SMark.redraw();
        }

        this.cbPlagEndDrag(markPoint.x, markPoint.y, LocalTextBox.END_TARGET, _poiSearchPath);
    },
    resetAllInfo: function(){
        this.RouteStartPlag.removeMapClickEvent();
        this.RouteStartPlag.setStyle();
        this.RouteEndPlag.removeMapClickEvent();
        this.RouteEndPlag.setStyle();
    },
    onMapClickActivation: function(info){
    },
    _getInfoWindowContent: function(_nodeType, info){
        if (!this._nodeTe) {
            this._nodeTe = TrimPath.parseTemplate(route__node_infowindow_template);
        }
        info.nodeType = _nodeType;
        return this._nodeTe.process(info);
    },
    _startMarkEndDrag: function(e){
        this.RouteStartPlag.mapEndDragFlag = true;
        this.RouteStartPlag.mapClickEvent(null, e);
    },
    _endMarkEndDrag: function(e){
        this.RouteEndPlag.mapEndDragFlag = true;
        this.RouteEndPlag.mapClickEvent(null, e);
    },
    searchPagingPoiExecute: function(){
        this.TextBoxModule.searchPagingPoiExecute();
    },
    cbPoiSearchClick: function(_paramValue, _paramX, _paramY, _paramFlag){
        if (_paramFlag == LocalTextBox.START_TARGET) {
            this.RouteStartPlag.mapEndDragFlag = true;
            this.onFixStart(_paramValue, new SPoint(Math.floor(_paramX), Math.floor(_paramY)), true);
        }
        else {
            this.RouteEndPlag.mapEndDragFlag = true;
            this.onFixEnd(_paramValue, new SPoint(Math.floor(_paramX), Math.floor(_paramY)), true);
        }
    },
    cbPlagEndDrag: function(_paramX, _paramY, _paramFlag, _poiSearchPath){
        if (_paramFlag == LocalTextBox.START_TARGET) {
            this.setStartPoint(Math.floor(_paramX), Math.floor(_paramY));
        }
        else {
            this.setEndPoint(Math.floor(_paramX), Math.floor(_paramY));
        }

        if (this.carRoutingSearchModule.getExecuteFlag()){
            this.carRoutingSearchModule.unloadPolyLine();
            this.hideResult();

            if(!_poiSearchPath){
                this.hideSearch();
                this.showGuide();
            }
        }
    },
    setStartPoint: function(_paramX, _paramY){
        var tempPos = new SPoint(_paramX, _paramY);
        var tempPosWGS84 = TMtoWGS84(_paramX, _paramY);

        if (!this.startPointCoord)
            this.startPointCoord = tempPos;
        else
            this.startPointCoord.set(_paramX, _paramY);

        this.carRoutingSearchModule.setStartPoint(tempPosWGS84, this.startPointCoord)
        //this.carRoutingExecute();
    },
    setEndPoint: function(_paramX, _paramY){
        var tempPos = new SPoint(_paramX, _paramY);
        var tempPosWGS84 = TMtoWGS84(_paramX, _paramY);

        if (!this.endPointCoord)
            this.endPointCoord = tempPos;
        else
            this.endPointCoord.set(_paramX, _paramY);

        this.carRoutingSearchModule.setEndPoint(tempPosWGS84, this.endPointCoord)
        //this.carRoutingExecute();
    },
    carRoutingExecute: function(){
        if(!this.startPointCoord || !this.endPointCoord) return;
        this.carRoutingSearchModule.execute();
    },
    showSearch: function(){
        $("#ifr_sch_result").show();
    },
    showGuide: function(){
        $("#carleftinfo").show();
    },
    showResult: function(){
        $("#car_result").show();
    },
    hideSearch: function(){
        $("#ifr_sch_result").hide();
    },
    hideGuide: function(){
        $("#carleftinfo").hide();
    },
    hideResult: function(){
        $("#car_result").hide();
    },
    hideSearchAndGuide: function(){
        this.hideGuide();
        this.hideSearch();
    },
    showSearchAndGuide: function(){
        this.showGuide();
        this.showSearch();
    },
    clearAll: function(){
        this.startPointCoord = null;
        this.endPointCoord = null;

        this.resetAllInfo();

        this.clearMark(this.RouteStartPlag, CarRouteSearchControl.CAR_SEARCH_MARK_START_ID);
        this.clearMark(this.RouteEndPlag, CarRouteSearchControl.CAR_SEARCH_MARK_END_ID);

        this.carRoutingSearchModule.unloadPolyLine();

        this.TextBoxModule.clearTextBoxAll();

        this.hideResult();
        this.showGuide();
    }
};

CarRouteSearchControl = function(_param){
    this.$topDivId = $('#' + _param.divId);
    this.$flagId = $('#' + _param.buttonId);
    this.$inputBoxId = $('#' + _param.inputBoxId);
    this.initProgress();
    this.status;
    this.clickInfo;
    this.areaName;
    this.mapEndDragFlag=false;
};

CarRouteSearchControl.INIT = 'INIT';
CarRouteSearchControl.MAP_CLICK_WAIT = 'MAP_CLICK_WAIT';
CarRouteSearchControl.CLICKED = 'MAP_CLICK_OK';
CarRouteSearchControl.SETUP = 'SETUP';
CarRouteSearchControl.CAR_SEARCH_MARK_START_ID = 'MARK_START_ID';
CarRouteSearchControl.CAR_SEARCH_MARK_END_ID = 'MARK_END_ID';

CarRouteSearchControl.prototype = {
    initProgress: function(){
        this.status = CarRouteSearchControl.INIT;
        this.nullEventFunc(this.$topDivId);
        this.addPlagEvent();
    },
    onclickFlagButton: function(event){
        var tempClass = this.$flagId.attr('class');

        if (tempClass.indexOf('on') != -1) {
            this._cleanMapClickInfo();
        }
        else {
            this.prevMapClick(this);
            this.removeMapClickEvent();
            this.addMapClickEvent();
            this.status = CarRouteSearchControl.MAP_CLICK_WAIT;
            this.setStyle("on");
        }

        return false;
    },
    nullEventFunc: function(_id){
        $link = _id;
        $.each(eventTypes, function(index, eventType){
            $link.bind(eventType, function(event){
                return false;
            });
        });
    },
    _cleanMapClickInfo: function(){
        this.mapSetCursor();
        this.removeMapClickEvent();
        this.setStyle();
    },
    mapSetCursor: function(type){
        var $mapObj = $('#mapContainer');
        if (!type) {
            $mapObj.children('div').css("cursor", "default");
        }
        else {
            $mapObj.children('div').css("cursor", "url('" + type + "'),default");
        }
    },
    prevMapClick: function(){
    },
    setMapClickInfo: function(){
        this.prevMapClick();
    },
    mapClickEvent: function(event, eventCoord){
        this.setStyle();
        var clickPositionCoord = new SPoint(eventCoord.x, eventCoord.y);
        var areaName = this.getOpenApiAreaName(clickPositionCoord);
        this.fixMap(areaName, clickPositionCoord);
    },
    fixMap: function(_areaName, _pos){
        if (!this.areaName)
            this.areaName = _areaName;
        this.areaName = _areaName;
        this.status = CarRouteSearchControl.SETUP;
        this.$inputBoxId.attr('value', this.areaName);
        this._cleanMapClickInfo();
        this.onFix(_areaName, _pos);
    },
    onFix: function(_areaName, _pos){
    },
    addPlagEvent: function(){
        mapObserverEvent.addEvent(this.$flagId, 'click', this.onclickFlagButton, this);
    },
    removePlagEvent: function(){
        mapObserverEvent.addEvent(this.$flagId, 'click');
    },
    removeMapClickEvent: function(){
        SEvent.mapEventRemoveById('click', this.mapClickEvent);
    },
    addMapClickEvent: function(){
        SEvent.mapEventHandler('click', this.mapClickEvent, this);
    },
    setStyle: function(_flag){
        if (enum_BrowserType.IE) {
            if (!_flag)
                this.$flagId.removeClass().addClass(this.$flagId.attr('tag')+'IE');
            else
                this.$flagId.removeClass().addClass(this.$flagId.attr('tag') + '_' + _flag +'IE');
        }
        else{
            if (!_flag)
                this.$flagId.removeClass().addClass(this.$flagId.attr('tag'));
            else
                this.$flagId.removeClass().addClass(this.$flagId.attr('tag') + '_' + _flag);
        }
    },
    getOpenApiAreaName: function(_coord){
        var coordWGS84 = TMtoWGS84(_coord.x, _coord.y);
        var areaName = makeReverseGeocodingParemeter(coordWGS84.x, coordWGS84.y);
        return areaName;
    }
};

/**
 * 자동차 길찾기 라우팅 모듈
 */
CarRoutingSearchModule = function(map, _parent){
    this.parentObj = _parent;
    this.map = map;

    this.routeStartPoint = null;
    this.routeEndPoint = null;
    this.tempStartPoint = null;
    this.tempEndPoint = null;
    this.executeFlag = false;

    this.firstResultHtml = $('#summary_01_detail');
    this.secondResultHtml = $('#summary_02_detail');

    this.firstLink = null;
    this.secondLink = null;
    this.firstPolyLine = null;
    this.secondPolyLine = null;
}

CarRoutingSearchModule.NORMAL = "1"; 	// 최단 거리
CarRoutingSearchModule.SHORT = "4";		// 최적 거리

CarRoutingSearchModule.EXPIRE_DISTANCE = 10;

CarRoutingSearchModule.S_POLYLINE_COLOR = 'blue';
CarRoutingSearchModule.E_POLYLINE_COLOR = 'red';
CarRoutingSearchModule.POLYLINE_OPACITY = 0.5;
CarRoutingSearchModule.POLYLINE_WEIGHT = 5;

CarRoutingSearchModule.FIRST_SEARCH_RESULT = "FIRST_RESULT";
CarRoutingSearchModule.SECOND_SEARCH_RESULT = "SECOND_RESULT";

CarRoutingSearchModule.prototype = {
    setStartPoint: function(startPos, tempPos){
        debugger;
        if(!this.tempStartPoint){
            this.routeStartPoint = new SPoint();
            this.tempStartPoint = new SPoint();

            this.routeStartPoint.set(startPos.x, startPos.y);
            this.tempStartPoint.set(tempPos.x, tempPos.y);

            this.executeFlag = true;
        }
        else{
            if(this.tempStartPoint.distance(tempPos)<CarRoutingSearchModule.EXPIRE_DISTANCE){
                this.executeFlag = false;
            }
            else{
                this.routeStartPoint.x = startPos.x;
                this.routeStartPoint.y = startPos.y;
                this.tempStartPoint.x = tempPos.x;
                this.tempStartPoint.y = tempPos.y;
                this.executeFlag = true;
            }
        }
    },
    setEndPoint: function(endPos, tempPos){
        debugger;
        if(!this.tempEndPoint){
            this.routeEndPoint = new SPoint();
            this.tempEndPoint = new SPoint();

            this.routeEndPoint.set(endPos.x, endPos.y);
            this.tempEndPoint.set(tempPos.x, tempPos.y);

            this.executeFlag = true;
        }
        else{
            if(this.tempEndPoint.distance(tempPos)<CarRoutingSearchModule.EXPIRE_DISTANCE){
                this.executeFlag = false;
            }
            else{
                this.routeEndPoint.x = endPos.x;
                this.routeEndPoint.y = endPos.y;
                this.tempEndPoint.x = tempPos.x;
                this.tempEndPoint.y = tempPos.y;
                this.executeFlag = true;
            }
        }
    },
    getExecuteFlag: function(){
        return this.executeFlag;
    },
    setOpt: function(opt){
        this.opt = opt;
    },
    execute:function(){
        if(!this.executeFlag)
            return false;

        this.executeFlag = false;
        this.cleanResult();
        this.executeFirst();
        this.executeSecond();
    },
    executeFirst: function(){
        this.loadingAjaxDetail1(true);
        var paramF = 'json';
        var paramRq = 'path';

        var varCoordStart = this.routeStartPoint.x + "," + this.routeStartPoint.y;
        var varCoordEnd = this.routeEndPoint.x + "," + this.routeEndPoint.y;


        var varParameter = 'f=' + paramF + '&rq=' + paramRq +
                        '&option=' + CarRoutingSearchModule.NORMAL +
                        '&sp=' + varCoordStart +
                        '&ep=' + varCoordEnd +
                        '&rp_crs=tmmid';

        executeAjaxArgument(true, varParameter, this.cbCarRouteResult, this, new Array(CarRoutingSearchModule.FIRST_SEARCH_RESULT), this.cbErrRoutResult);
    },
    executeSecond: function(){
        this.loadingAjaxDetail2(true);
        var paramF = 'json';
        var paramRq = 'path';

        var varCoordStart = this.routeStartPoint.x + "," + this.routeStartPoint.y;
        var varCoordEnd = this.routeEndPoint.x + "," + this.routeEndPoint.y;

        var varParameter = 'f=' + paramF + '&rq=' + paramRq +
                        '&option=' + CarRoutingSearchModule.SHORT +
                        '&sp=' + varCoordStart +
                        '&ep=' + varCoordEnd +
                        '&link=false';

        executeAjaxArgument(true, varParameter, this.cbCarRouteResultSecond, this, new Array(CarRoutingSearchModule.SECOND_SEARCH_RESULT), this.cbErrRoutResult);
    },
    executeSecond2: function(){
        if (!this.secondLink){
            var paramF = 'json';
            var paramRq = 'path';

            var varCoordStart = this.routeStartPoint.x + "," + this.routeStartPoint.y;
            var varCoordEnd = this.routeEndPoint.x + "," + this.routeEndPoint.y;

            var varParameter = 'f=' + paramF + '&rq=' + paramRq +
                            '&option=' + CarRoutingSearchModule.SHORT +
                            '&sp=' + varCoordStart +
                            '&ep=' + varCoordEnd +
                            '&rp_crs=tmmid';

            executeAjaxArgument(false, varParameter, this.cbCarRouteResultSecondLane, this, new Array(CarRoutingSearchModule.SECOND_SEARCH_RESULT), this.cbErrRoutResult);
        }
        else{
            this.executeSecondLane();
        }
    },
    cleanResult: function(){
        this.firstResultHtml.empty();
        this.secondResultHtml.empty();
        this.parentObj.hideSearchAndGuide();
        this.parentObj.showResult();
        this.unLoadModule();
        this.parentObj.showResult();
    },
    unLoadModule: function(){
        this.executeFlag = false;
        this.firstLink = null;
        this.secondLink = null;

        if(this.firstPolyLine!=null)
            this.firstPolyLine.unload();

        if(this.secondPolyLine!=null)
            this.secondPolyLine.unload();

        this.firstPolyLine = null;
        this.secondPolyLine = null;
    },
    cbCarRouteResult: function(data, nth){
        var tempLink = new Array();
        var totalTime = '';
        var totalPrice = '';
        var totalDistance = '';

        // 1. No Data
        if(data.Mapot.Response.Status.code!="200"){
            this.errorResult('검색된 결과가 없습니다', nth);
            this.loadingAjaxDetail1(false);
            return;
        }

        // 2. Base Information
        totalPrice = data.Mapot.Response.Path.PathInfo.PathCarPrice[0].amout;
        totalDistance = data.Mapot.Response.Path.PathInfo.totalDistance;
        totalTime = data.Mapot.Response.Path.PathInfo.totalTime;

        if(!totalPrice)
            totalPrice = 0;

        // 3. Route Link Data
        $.each(data.Mapot.Response.Path.Link, function(index, value){
            if (value.LineString.coordinate != null){
                tempLink.push(value.LineString.coordinate);
            };
        });

        this.firstLink = tempLink;

        // 5. Result View
        this.loadingAjaxDetail1(false);
        this.successResult(totalDistance, totalTime, totalPrice, nth);
    },
    cbCarRouteResultSecond: function(data, nth){
        var totalTime = '';
        var totalPrice = '';
        var totalDistance = '';

        // 1. No Data
        if(data.Mapot.Response.Status.code!="200"){
            this.errorResult('검색된 결과가 없습니다', nth);
            this.loadingAjaxDetail2(false);
            return;
        }

        // 2. Base Information
        totalPrice = data.Mapot.Response.Path.PathInfo.PathCarPrice[0].amout;
        totalDistance = data.Mapot.Response.Path.PathInfo.totalDistance;
        totalTime = data.Mapot.Response.Path.PathInfo.totalTime;

        if(!totalPrice)
            totalPrice = 0;

        // 5. Result View
        this.loadingAjaxDetail2(false);
        this.successResult(totalDistance, totalTime, totalPrice, nth);
    },
    cbCarRouteResultSecondLane: function(data, nth){
        var tempLink = new Array();

        // 1. No Data
        if(!data.Mapot.Response.Path.PathInfo){
            this.errorResult('검색된 결과가 없습니다', nth);
            return;
        }

        // 2. Route Link Data
        $.each(data.Mapot.Response.Path.Link, function(index, value){
            if (value.LineString.coordinate != null){
                tempLink.push(value.LineString.coordinate);
            };
        });

        this.secondLink = tempLink;
        this.executeSecondLane();
    },
    successResult: function(totalDistance, totalTime, totalPrice, nth){
        var hour = min = sec = 0;
        var timeText = '';

        if(totalTime>0){
            hour = parseInt(totalTime/3600);
            min = parseInt((totalTime%3600)/60);
            //sec = totalTime%60;
        }

        if(hour>0)
            timeText = hour + i18NObj.getTextValue('hour');
        if(min>0)
            timeText += min + i18NObj.getTextValue('min(s)');

           var thisObject = this;
        if(nth == CarRoutingSearchModule.FIRST_SEARCH_RESULT){
            this.firstResultHtml.append("<li>"+ i18NObj.getTextValue('resultStartName') + ": " +
                                            this.parentObj.TextBoxModule.returnStartPointName() + "</li>")
                                        .append("<li>"+ i18NObj.getTextValue('resultEndName') + ": " +
                                            this.parentObj.TextBoxModule.returnEndPointName() +"</li>")
                                        .append("<li>"+ i18NObj.getTextValue('resultDistance') + ": " +
                                                COMMIFYKM(totalDistance) +" km</li>")
                                        .append("<li>"+ i18NObj.getTextValue('resultTime') + ": " +
                                                timeText + "</li>")
                                        .append("<li>"+ i18NObj.getTextValue('resultPrice') + ": " +
                                                COMMIFY(totalPrice) + i18NObj.getTextValue('won') + "</li>")
                                        .append("<div id='firstResultLaneView' class='routeview_btn' style='cursor:pointer'><img src='/images/index2/" + mapLang
                                                + "/allrouteview_btn.gif'/></div>");

            $('#firstResultLaneView').bind('click', function(){
                thisObject.executeFirstLane.call(thisObject);
            });
            this.executeFirstLane();
        }
        else{
            this.secondResultHtml.append("<li>"+ i18NObj.getTextValue('resultStartName') + ": " +
                                        this.parentObj.TextBoxModule.returnStartPointName() + "</li>")
                                .append("<li>"+ i18NObj.getTextValue('resultEndName') + ": " +
                                        this.parentObj.TextBoxModule.returnEndPointName() +"</li>")
                                .append("<li>"+ i18NObj.getTextValue('resultDistance') + ": " +
                                        COMMIFYKM(totalDistance) +" km</li>")
                                .append("<li>"+ i18NObj.getTextValue('resultTime') + ": " +
                                        timeText + "</li>")
                                .append("<li>"+ i18NObj.getTextValue('resultPrice') + ": " +
                                        COMMIFY(totalPrice) + i18NObj.getTextValue('won') + "</li>")
                                .append("<div id='secondResultLaneView' class='routeview_btn' style='cursor:pointer'><img src='/images/index2/" + mapLang
                                        + "/allrouteview_btn.gif'/></div>");

            $('#secondResultLaneView').bind('click', function(){
                thisObject.executeSecond2();
            });
        }
    },
    errorResult: function(html, nth){
        if (nth==CarRoutingSearchModule.FIRST_SEARCH_RESULT){
            this.firstResultHtml.append("<li></li>")
                                .append(html);
        }
        else{
            this.secondResultHtml.append("<li></li>")
                                .append(html);
        }
    },
    loadingAjaxDetail1: function(flag){
        if (flag)
            $('#contentLoadingDetail1').show();
        else
            $('#contentLoadingDetail1').hide();
    },
    loadingAjaxDetail2: function(flag){
        if (flag)
            $('#contentLoadingDetail2').show();
        else
            $('#contentLoadingDetail2').hide();
    },
    cbErrRoutResult: function(){
        this.errorResult('검색된 결과가 없습니다', CarRoutingSearchModule.FIRST_SEARCH_RESULT);
        this.errorResult('검색된 결과가 없습니다', CarRoutingSearchModule.SECOND_SEARCH_RESULT);
    },
    executeFirstLane: function(){
        var LinkData;

        if(this.secondPolyLine!=null && this.secondPolyLine.enable){
            this.secondPolyLine.hide();
        }

        if(!this.firstPolyLine){
            this.firstPolyLine = new SPolyline();

            //debugger;
            for (var link_Index=0; link_Index< this.firstLink.length;link_Index++){
                for (var link_SubIndex=0; link_SubIndex< this.firstLink[link_Index].length/2;link_SubIndex++){

                    this.firstPolyLine.addPoints(
                                                new SPoint(
                                                        this.firstLink[link_Index][link_SubIndex*2],
                                                        this.firstLink[link_Index][link_SubIndex*2+1])
                                                );
                }
            }

            this.firstPolyLine.drawArrow();
            this.firstPolyLine.opacity=CarRoutingSearchModule.POLYLINE_OPACITY;
            this.firstPolyLine.color=CarRoutingSearchModule.S_POLYLINE_COLOR;
            this.firstPolyLine.setWeight(CarRoutingSearchModule.POLYLINE_WEIGHT);

            this.map.addOverlay(this.firstPolyLine);
        }
        else{
            if(!this.firstPolyLine.enable){
                this.firstPolyLine.show();
            }
        }

        this.setPoiLevelAndFitting(CarRoutingSearchModule.FIRST_SEARCH_RESULT);
    },
    executeSecondLane: function(){
        if(this.firstPolyLine!=null && this.firstPolyLine.enable){
            this.firstPolyLine.hide();
        }



        if(!this.secondPolyLine){
            this.secondPolyLine = new SPolyline();

            for (var link_Index=0; link_Index< this.secondLink.length;link_Index++){
                for (var link_SubIndex=0; link_SubIndex< this.secondLink[link_Index].length/2;link_SubIndex++){

                    this.secondPolyLine.addPoints(
                                                new SPoint(
                                                        this.secondLink[link_Index][link_SubIndex*2],
                                                        this.secondLink[link_Index][link_SubIndex*2+1])
                                                );
                }
            }


            this.secondPolyLine.drawArrow();
            this.secondPolyLine.opacity=CarRoutingSearchModule.POLYLINE_OPACITY;
            this.secondPolyLine.color=CarRoutingSearchModule.E_POLYLINE_COLOR;
            this.secondPolyLine.setWeight(CarRoutingSearchModule.POLYLINE_WEIGHT);

            this.map.addOverlay(this.secondPolyLine);
        }
        else{
            if(!this.secondLink.enable){
                this.secondPolyLine.show();
            }
        }

        this.setPoiLevelAndFitting(CarRoutingSearchModule.SECOND_SEARCH_RESULT);
    },
    unloadPolyLine: function(){
        if(this.firstPolyLine!=null){
            this.firstPolyLine.unload();
            this.firstPolyLine = null;
        }

        if(this.secondPolyLine!=null){
            this.secondPolyLine.unload();
            this.secondPolyLine = null;
        }
    },
    setPoiLevelAndFitting: function(type){
        var polyBound ;

        if (type == CarRoutingSearchModule.FIRST_SEARCH_RESULT){
            polyBound  = this.firstPolyLine.getBound();
        }
        else{
            polyBound = this.secondPolyLine.getBound();
        }

        debugger;
        setPoiLevelAndFitting(this.map.viewSize.width, this.map.viewSize.height,
                polyBound[0], polyBound[2], polyBound[3], polyBound[1]);
    }
};

function makeReverseGeocodingParemeter(_x, _y){
    var paramF = 'json';
    var paramKey = '';
    var paramRq = 'reversegeocoding';
    var paramLang = mapLang;
    var paramPoint = _x + ',' + _y;

    this.AJAX_URL_PARAM = 'f=' + paramF // + '&key=' + paramKey
    +
    '&rq=' +
    paramRq +
    '&lang=' +
    paramLang +
    '&point=' +
    paramPoint;

    var resultAddressName = '';

    $.ajax({
        type: "POST",
        url: AJAX_MAP_OPEN_API,
        data: "svcCode=uTourOnion&" + this.AJAX_URL_PARAM,
        async: false,
        dataType: "json",
        success: function(data){
            resultAddressName = returnReverseGeocoding(data);
        }
    });

    return resultAddressName;
};

function returnReverseGeocoding(data){
    if (!data)
        return '-';

    if (!data.Mapot.Response.ReverseGeocoding.Placemark.name)
        return '-';

    var tempAddress = data.Mapot.Response.ReverseGeocoding.Placemark.name.substring(data.Mapot.Response.ReverseGeocoding.Placemark.name.indexOf(",") +
    1);
    tempAddress = ReplaceAll(tempAddress, ',', ' ');
    tempAddress = ReplaceAll(tempAddress, 'null', ' ');

    return tempAddress;
};

function goCarSearchResultPage(pageNum){
    $("#pageNum").attr('value', pageNum);
    carStartRouteControl.searchPagingPoiExecute.call(carStartRouteControl);
}

var CarRouteLineInfo = null;
