﻿//======================================
//Author:guoqiaobin 090420

//document.write('');

//首页交通模块

//自驾起始城市
var g_StartCityId = g_cityId;
var g_StartCityName = g_cityName;

//自驾终点城市
var g_EndCityId = g_cityId;
var g_EndCityName = g_cityName;

var select = "bus";
$("startSpan").innerHTML = "[<a href='javascript:setCity(1);'>" + g_StartCityName + "</a>]";
$("endSpan").innerHTML = "[" + g_EndCityName + "]";
if($("endP") != null){
    $("endP").value = g_companyName;
}

//公交
function Traffic_Bus_Tab(){
    select = "bus";
    $("traTool").innerHTML = "公交 | <a href='javascript:Traffic_Self_Tab();'><u>自驾</u></a>";
    $("startSpan").style.display = "none";
    $("endSpan").style.display = "none";
}
//自驾
function Traffic_Self_Tab(){
    select = "self";
    $("traTool").innerHTML = "<a href='javascript:Traffic_Bus_Tab();'><u>公交</u></a> | 自驾";
    $("startSpan").style.display = "inline";
    $("endSpan").style.display = "inline";
}
var g_rdo_flag = "arrive";
//"到达这里"按钮
function arrive(){
    if(g_rdo_flag == "startAt"){
        g_rdo_flag = "arrive";
        g_StartCityId = g_EndCityId;
        g_StartCityName = g_EndCityName;
        g_EndCityId = g_cityId;
        g_EndCityName = g_cityName;
        if($("startP") != null){
            $("startP").value = $("endP").value;
        }
        if($("endP") != null){
            $("endP").value = g_companyName;
            $("startP").disabled = null;
            $("endP").disabled = "disabled";
        }
        $("startSpan").innerHTML = "[<a href='javascript:setCity(1);'>" + g_StartCityName + "</a>]";
        $("endSpan").innerHTML = "[" + g_EndCityName + "]";
    }
    
}
//"从这里出发"按钮
function startAt(){
    if(g_rdo_flag == "arrive"){
        g_rdo_flag = "startAt";
        g_EndCityId = g_StartCityId;
        g_EndCityName = g_StartCityName;
        g_StartCityId = g_cityId;
        g_StartCityName = g_cityName;
        if($("endP") != null){
            $("endP").value = $("startP").value;
        }
        if($("startP") != null){
            $("startP").value = g_companyName;
            $("startP").disabled = "disabled";
            $("endP").disabled = null;
        }
        $("startSpan").innerHTML = "[" + g_StartCityName + "]";
        $("endSpan").innerHTML = "[<a href='javascript:setCity(2);'>" + g_EndCityName + "</a>]";
    }
}
//交通查询按钮
function btnTraffic(){
    var start = $("startP").value;
    var end = $("endP").value;
    if(start != "" & end != ""){
        var strUrl = "http://traffic.365ditu.com/";
        if(select == "bus"){    //公交
            strUrl += "bus_start_end.aspx";
            strUrl += "?act=bus";
            strUrl += "&startkw=" + escape(start);
            strUrl += "&endkw=" + escape(end);
            strUrl += "&startcityid=" + g_cityId;
            strUrl += "&endcityid=" + g_cityId;
            strUrl += "&startcityname=" + escape(g_cityName);
            strUrl += "&endcityname=" + escape(g_cityName);
        }
        else if(select == "self"){   //自驾
            strUrl += "self_start_end.aspx";
            strUrl += "?act=self";
            strUrl += "&startkw=" + escape(start);
            strUrl += "&endkw=" + escape(end);
            strUrl += "&startcityid=" + g_StartCityId;
            strUrl += "&endcityid=" + g_EndCityId;
            strUrl += "&startcityname=" + escape(g_StartCityName);
            strUrl += "&endcityname=" + escape(g_EndCityName);
        }
        //交通频道加参数090520
        var gpsid = codeLatLng(g_lat, g_lng);
        if(start == g_companyName){
            strUrl += "&startpoiname=" + escape(start);
            strUrl += "&startgpsid=" + gpsid;
        }
        else if(end == g_companyName){
            strUrl += "&endpoiname=" + escape(end);
            strUrl += "&endgpsid=" + gpsid;
        }
        window.open(strUrl, "_blank");
    }
}

/*===================切换城市====================*/
//var g_currentCityId = g_cityId;
//var g_currentCityName = g_cityName;

var g_switchCityBox = new MapSwitchCityBox();
var g_CityType = 0;

function setCity(type){
    g_CityType = type;
    showSwitchCityBox();
}

//页面弹出层对象
var pageAlert = null;

function showSwitchCityBox(){
    var divSwitchCity = $("divSwitchCity");
    if(divSwitchCity){
        if(divSwitchCity.innerHTML == ""){
            divSwitchCity.innerHTML = g_switchCityBox.get();
        }
        pageAlert = new PageAlert(divSwitchCity);
        pageAlert.setCenter(800, 517);    //SwitchCityBox
        pageAlert.open();
//        divSwitchCity.style.display = 'block';
    }
}
function closeSwitchCityBox(){
    var divSwitchCity = $("divSwitchCity");
    if(divSwitchCity){
        pageAlert.close();
//        divSwitchCity.style.display='none';
    }
}

function getCurrentCityInfo(){
    closeSwitchCityBox();
    //调用方法视情况设置DIV宽度
    var cityLength = g_switchCityBox.getCurrentCityName().length;
    //setDivWidth(g_switchCityBox.getCurrentCityName(),cityLength,g_CityType);        
            
    switch (g_CityType){
        case 1:
            document.getElementById("startSpan").innerHTML="[<a href='javascript:setCity(1);'>" + g_switchCityBox.getCurrentCityName() + "</a>]";
            g_StartCityId=g_switchCityBox.getCurrentCityCode();
            g_StartCityName=g_switchCityBox.getCurrentCityName();

            break;
        case 2:
            document.getElementById("endSpan").innerHTML="[<a href='javascript:setCity(2);'>" + g_switchCityBox.getCurrentCityName() + "</a>]";
            g_EndCityId=g_switchCityBox.getCurrentCityCode();
            g_EndCityName=g_switchCityBox.getCurrentCityName();

            break;
        case 3:
            document.getElementById("passSpan").innerHTML=g_switchCityBox.getCurrentCityName();
            g_PassCityId=g_switchCityBox.getCurrentCityCode();
            g_PassCityName=g_switchCityBox.getCurrentCityName();
            break;
        case 4:             
            setDefaultCity();
            break;
        case 5:
            gotoMap();
            break;    
        case 6:
            setDivCity();
            break;
        case 7:
            document.getElementById("TravelStartSpan").innerHTML=g_switchCityBox.getCurrentCityName();
            d_CityId = g_switchCityBox.getCurrentCityCode();
            d_cityName = g_switchCityBox.getCurrentCityName();
            break;
        default:
            alert("非法的切换城市操作！");
            break;
    }
}

//                if($('endP') != null){
//                    $('endP').value = g_companyName;
//                }
//初始化公交信息模块
function showStationList(mbsl, mssl){
    //
    if($('gjxx') != null && $('gjz') != null){
        if( mbsl != null && mbsl != ''){
            $('gjxx').innerHTML = mbsl;
        }
        else{
            $('gjz').style.display = 'none';
            $('gjxx').style.display = 'none';
        }
    }
    if($('dtxx') != null && $('dtz') != null){
        if( mssl != null && mssl != ''){
            $('dtxx').innerHTML = mssl;
        }
        else{
            $('dtz').style.display = 'none';
            $('dtxx').style.display = 'none';
        }
    }
}
//显示更详细周边公交信息
function trafficInfoClick(on_off){
    if(on_off == 1){
        $('tra_link').innerHTML = '<a href=javascript:trafficInfoClick(0);>默认交通信息>></a>';
        showStationList(mBusStationsAll, mSubwayStationsAll);
    }
    else if(on_off == 0){
        $('tra_link').innerHTML = '<a href=javascript:trafficInfoClick(1);>周边交通详情>></a>';
        showStationList(mBusStationList, mSubwayStationList);
    }
}
//showStationList(mBusStationList, mSubwayStationList);

//                //交通查询按钮
//                function btnTraffic(select){
//                    var start = $('startP').value;
//                    var end = $('endP').value;
//                    if(start != '' & end != ''){
//                        var strUrl = 'http://traffic.365ditu.com/';
//                        if(select == 1){    //公交
//                            strUrl += 'bus_start_end.aspx';
//                            strUrl += '?act=bus';
//                            strUrl += '&startkw=' + escape(start);
//                            strUrl += '&endkw=' + escape(end);
//                            strUrl += '&startcityid=' + g_cityId;
//                            strUrl += '&endcityid=' + g_cityId;
//                            strUrl += '&startcityname=' + escape(g_cityName);
//                            strUrl += '&endcityname=' + escape(g_cityName);
//                        }
//                        else if(select == 2){   //自驾
//                            strUrl += 'self_start_end.aspx';
//                            strUrl += '?act=self';
//                            strUrl += '&startkw=' + escape(start);
//                            strUrl += '&endkw=' + escape(end);
//                            strUrl += '&startcityid=' + g_cityId;
//                            strUrl += '&endcityid=' + g_cityId;
//                            strUrl += '&startcityname=' + escape(g_cityName);
//                            strUrl += '&endcityname=' + escape(g_cityName);
//                        }
//                        window.open(strUrl, 'traffic');
//                    }
//                }
//                //到达这里按钮
//                function arrive(){
//                    if($('traTool') != null){
//                        $('traTool').innerHTML = 
//                            '到达这里 |&nbsp;<a href=javascript:void(0); onclick=startAt();><u>从这里出发</u></a>';
//                    }
//                    if($('startP') != null){
//                        $('startP').value = '';
//                    }
//                    if($('endP') != null){
//                        $('endP').value = g_companyName;
//                        $('startP').disabled = null;
//                        $('endP').disabled = 'disabled';
//                    }
//                }
//                //从这里出发按钮
//                function startAt(){
//                    if($('traTool') != null){
//                        $('traTool').innerHTML = 
//                            '<a href=javascript:void(0); onclick=arrive();><u>到达这里</u></a> |&nbsp;从这里出发';
//                    }
//                    if($('endP') != null){
//                        $('endP').value = '';
//                    }
//                    if($('startP') != null){
//                        $('startP').value = g_companyName;
//                        $('startP').disabled = 'disabled';
//                        $('endP').disabled = null;
//                    }
//                }
