﻿var BackGroundDiv = null;
var ShowDiv = null;
var _ZoomBar = null;            //缩放工具条

function fnLoadInit()
{    
    //加载对象
    if (typeof vEdushiMap == 'undefined' || typeof vEdushiMap.Body.NewMapLayer != 'function' || (vEdushiMap.Body.MapState.Map != 0 && vEdushiMap.Body.GoogleMap == null)) {
        setTimeout("fnLoadInit()", 50);
        return;
    }
    if(GlobalConfig.PageType=='1')
    {
        document.getElementById('CompassNav').style.display = 'block';
    }
    vM  = vEdushiMap;
    _MarkLayer = vM.NewMapLayer('Mark', 265, true);//标记图层
    _BusLayer = vM.NewMapLayer('Bus', 264, true);
    var MarkCss=vM.$C('link');
    MarkCss.rel='stylesheet';
    MarkCss.type = 'text/css';
    MarkCss.href=GlobalConfig.SkinPath+'Css/Mark.css';
    vM.Body.document.getElementsByTagName('head')[0].appendChild(MarkCss);
    if(ShowDiv)
    {
        ShowDiv.style.display = 'none';
    }
    //滑竿缩放
    vM.attachEvent(EGIS.KeyWord.EventName.Switch3D, function() {
        if (vM.$('RoadPicLayer')) {
            vM.ViewSystemMapLayer(false, 'RoadPicLayer');
        }
        vM.ViewSigns(true, 'park');
        vM.ViewPlots(true, 'ad');
        document.getElementById('CompassNav').innerHTML = '<img src="' + GlobalConfig.SkinPath + 'Images/CompassIco.gif" alt="指针" />';
    });
    vM.attachEvent(EGIS.KeyWord.EventName.Switch2D, function() {
        vM.ViewSigns(false, 'park');
        vM.ViewPlots(false, 'ad');
        document.getElementById('CompassNav').innerHTML = '<img src="' + GlobalConfig.SkinPath + 'Images/CompassIco1.gif" alt="指针" />';
    });
    vM.attachEvent(EGIS.KeyWord.EventName.SwitchWX, function() {
        vM.ViewSigns(false, 'park');
        vM.ViewPlots(false, 'ad');
        document.getElementById('CompassNav').innerHTML = '<img src="' + GlobalConfig.SkinPath + 'Images/CompassIco1.gif" alt="指针" />';
    });
    vM.attachEvent(EGIS.KeyWord.EventName.SignClick, function(sign) {
        switch (sign.Group) {
            case 'bus':
            case 'bus3d':
                fnShowBusStation(sign.ID, sign.Name, vM.PointerX(), vM.PointerY());
                break;
        }
    });
    fnShowMarkData(EAddressData.id,EAddressData.name,EAddressData.x,EAddressData.y,EAddressData.title,EAddressData.content);
}
function $(id) {
    return document.getElementById(id);
}
function ShowHiddenCityList() {
    if ($('divCityList').style.display != 'none') {
        $('divCityList').style.display = 'none';
    }
    else {
        $('divCityList').style.display = 'block';
    }
}
function StopPropagation(e) {
    if (!e) {
        e = window.event;
    }
    //停止事件冒泡
    if (e.stopPropagation) {
        e.stopPropagation();
    }
    else {
        e.cancelBubble = true;
    }
}
function SetCity(name, domain, l) {
    $('txtCityName').value = name;
    $('txtDomain').value = domain;
    $('txtLanguage').value = l;
}
function RedirectCity(domain, eaddress)
{
    document.location.href = domain + '?EAddressRegister=1&EAddressName=' + eaddress;
}
function fnShowBusStation(id,title,x,y)
{
    var url = GlobalConfig.CityCode + 'CommMap5.0/bus.aspx?domain=' + GlobalConfig.CityCode + '.' + GlobalConfig.WebDomain + '&l=' + GlobalConfig.Language + '&req=8&stationid=' + id;
     var busStationPopID = "busStationPop";
     
     if(!vM.$(busStationPopID))
     {
        var showpop = vM.$C('div');
        showpop.id = busStationPopID;
        showpop.style.display = 'none';
        showpop.innerHTML='<div class="BusPlatformNav"><div class="PinIco"></div><div class="PlatformCon"><div class="PlatformConBg" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+GlobalConfig.SkinPath+'Images/PlatformConBg.png\',sizingMethod=\'image\') !important;"></div><div class="PlatformDetCon"><h3 id="divStationName">Loading...</h3><div class="AutoText"><ul id="divBusList"></ul></div></div><div class="CloseWin" onmouseover="this.className=\'CloseBtnOver\'" onmouseout="this.className=\'CloseBtnOut\'" onclick="parent.Delete(\''+busStationPopID+'\')" title="关闭窗口"></div></div></div>';
        vM.AppendEntity(showpop, _BusLayer, false, x,y,303, 170,0,38, false);
     }
     else
     {
        vM.MoveEntity(busStationPopID,x,y)
     }
    ENetwork.DownloadScript(url,function(){
            if(typeof _BusLineList =='undefined' || _BusLineList.length < 1){
                vM.$('divStationName').innerHTML =title;
                vM.$('divBusList').innerHTML = '<li style="width:100%">很抱歉，该站点公交数据正在完善中</li>';
                Show(busStationPopID);
            }
            else{
                vM.$('divStationName').innerHTML = title;
                //append bus list
                var sHtml = '';
                for (var k=0; k<_BusLineList.length; k++){
                    sHtml += '<li>' + _BusLineList[k].VehicleName + '</li>';
                }
                vM.$('divBusList').innerHTML = sHtml;
                Show(busStationPopID);
            }
        });
    vM.MoveTo(x*1+170,y,true);    
}
function LoadMap(citycode, x, y, is3d) {
    GlobalConfig.CityCode = citycode;
    var w, h;
    if (GlobalConfig.PageType == '1') {
        w = 946;
        h = 456;
    }
    else {
        w = 596;
        h = 400;
    }
    var jsDom = document.createElement('script');
    jsDom.type = 'text/javascript';

    var src = GlobalConfig.Api3Url+'?City=' + citycode + '&L=' + GlobalConfig.Language + '&MapID=EdushiMap&x=' + x + '&y=' + y + '&w=' + w + '&h=' + h + '&eye=0&e=utf-8&m=false';
    if (citycode == 'hz') {
        src += '&z=4&v=0';
    }
    else if (is3d == 1) {
        src += '&z=1&v=1';
    }
    else {
        src += '&z=0&v=2';
    }
    jsDom.src = src;
    document.body.appendChild(jsDom);
}
function fnShowMarkData(id,name,x,y,title,content)
{
    var markId = "mark"+id;
    if(!vM.$(markId))
    {
    
        var dingwei = vM.$C('div');
        dingwei.id = 'dingwei'+markId;
        dingwei.innerHTML='<div style="cursor:pointer" class="PinIco" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+GlobalConfig.SkinPath+'Images/PinIco.png\',sizingMethod=\'image\') !important;"></div>';
        vM.AppendEntity(dingwei, _MarkLayer, false, x,y,35,34,-2,34, false);
        
        
        var showmark = vM.$C('div');
        showmark.id = markId;
        showmark.style.display = 'none';
        showmark.innerHTML='<div class="InTagCon"><div class="InTagConBg" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+GlobalConfig.SkinPath+'Images/ViewTagBg.png\',sizingMethod=\'image\') !important;"></div><div class="InTagDetCon"><h3 title="标题"></h3><div class="AutoText" id="MarkContent"></div><div class="DeAdr"><span>E地址：</span><input type="text" value="'+GlobalConfig.EdizhiUrl+name+'" onfocus="this.select()" class="InFieldSty" /></div><div class="WkButton"><img id="btnMarkCopy" style="cursor:pointer" src="Images/ToFriend.gif" alt="复制给好友" /></div></div><div class="CloseWin" id="btnMarkDelete" onmouseover="this.className=\'CloseBtnOver\'" onmouseout="this.className=\'CloseBtnOut\'" title="关闭窗口"></div></div>';
        vM.AppendEntity(showmark, _MarkLayer, false, x,y,305,158,-6,100, false);
        
        var divList = showmark.getElementsByTagName('DIV');
        for(var i=0;i<divList.length;i++)
        {
            switch(divList[i].id)
            {
                case "btnMarkDelete":
                    divList[i].onclick = function(){ Delete(markId)};
                    break;
                case "MarkContent":
                    var isEventDown = false;
                    //被海忠骗了，这个属性根本没用
                    divList[i].onmousedown = function(e) {
                        isEventDown = true;
                        if (e) 
                            e.stopPropagation();
                        else
                           vM.Body.event.cancelBubble = true;

                    };
                    divList[i].onmousemove = function(e) {
                        if (isEventDown) {
                            if (e) 
                            {
                                e.stopPropagation();
                            }
                            else {
                                vM.Body.event.cancelBubble = true;
                            }
                        }

                    };
                    divList[i].onmouseup = function() {
                        isEventDown = false;
                    };
                    divList[i].innerHTML = content;
                    break;
            }
        }
        var h3 = showmark.getElementsByTagName('H3');
        h3[0].innerHTML = title;
        
        
        var imgList = showmark.getElementsByTagName('IMG');
        
        for(var i=0;i<imgList.length;i++)
        {
            switch(imgList[i].id)
            {
                
                case "btnMarkCopy":
                    imgList[i].onclick = function() { clipboardData.setData('text', GlobalConfig.EdizhiUrl + name); alert('复制URL成功,您可以将该网址发送给您的好友.') }; //需要创建标记的Url
                    break;
            }
        }
        showmark.style.display = 'block';
    }
    
    dingwei.onclick = function(){
            Show(markId)
        }
    vM.MoveTo(x*1+170,y,true);
}
function Delete(id)
{
    if(vM.$(id))
    {
        vM.$(id).style.display = "none";
    }
}
function Show(id)
{
    if(vM.$(id))
    {
        vM.$(id).style.display = "block";
    }
}
function Copy(url)
{
    fnCopyToClipboard(url,"复制好了，发给我的QQ/MSN好友分享吧！");
}

function fnGetWindowWidth(){
	var vw = 0;
	var _dEt = document.documentElement;
	var _dBy = document.body;
	if(typeof window.innerWidth=='number'){
	    vw = window.innerWidth;
	}
	else{
		if(_dEt&&_dEt.clientWidth){
		    vw = _dEt.clientWidth;
		}
		else{
			if(_dBy&&_dBy.clientWidth)vw = _dBy.clientWidth;
		}
	}
	if(!vw||vw<100){
	    vw = 100;
	}
	return vw;
}
function fnGetWindowHeight(){
	var vh = 0;
	var _dEt = document.documentElement;
	var _dBy = document.body;
	if(typeof window.innerHeight=='number'){
	    vh = window.innerHeight;
	}
	else{
		if(_dEt&&_dEt.clientHeight){
		    vh = _dEt.clientHeight;
		}
		else{
			if(_dBy&&_dBy.clientHeight)vh = _dBy.clientHeight;
		}
	}
	if(!vh||vh<100){
	    vh = 100;
	}
	return vh;
}

function CreateViewBg(w,h)
{
    if(!BackGroundDiv)
	{
        BackGroundDiv = document.createElement('div');
        BackGroundDiv.id = 'divDialogBg';
        BackGroundDiv.style.backgroundColor = 'black';
        BackGroundDiv.style.position = 'absolute';
        BackGroundDiv.style.filter = 'alpha(opacity=50)';
        BackGroundDiv.style.opacity = '.50';
        BackGroundDiv.style.zIndex = 100001;
        BackGroundDiv.style.left = 0;
        BackGroundDiv.style.top = 0;
        BackGroundDiv.style.width = w+'px';
        BackGroundDiv.style.height= h+'px';
        document.body.appendChild(BackGroundDiv);
	}
	BackGroundDiv.style.display = 'block';

}
function ShowFriendView()
{
    var h=fnGetWindowHeight();
	var w=fnGetWindowWidth();
//	
    w = w>946?w:document.body.scrollWidth;
    h = h>document.body.scrollHeight?h:document.body.scrollHeight;
    //CreateViewBg(w,h);
    ShowDiv = document.getElementById('divFriendView');
    ShowDiv.style.display = 'block';
//    ShowDiv.style.left = (w/2 -150)+'px';
//    ShowDiv.style.top = (h/2 -60)+'px';
    ShowDiv.style.left = (w/2 -180)+'px';
    ShowDiv.style.top = '271px';
    ShowDiv.style.position = 'absolute';
    ShowDiv.style.zIndex = 100002;	
}

function ShowPasswordView()
{
    var h=fnGetWindowHeight();
	var w=fnGetWindowWidth();
	
	w = w>946?w:document.body.scrollWidth;
	h = h>document.body.scrollHeight?h:document.body.scrollHeight;
//    CreateViewBg(w,h);
    ShowDiv = document.getElementById('divPasswordView');
    ShowDiv.style.display = 'block';
//    ShowDiv.style.left = (w/2 -150)+'px';
//    ShowDiv.style.top = (h/2 -60)+'px';
    ShowDiv.style.left = (w/2 -180)+'px';
    ShowDiv.style.top = '271px';
    ShowDiv.style.position = 'absolute';
    ShowDiv.style.zIndex = 100002;	
}

function ShowNoRegView()
{
    var h=fnGetWindowHeight();
	var w=fnGetWindowWidth();
	
	w = w>946?w:document.body.scrollWidth;
	h = h>document.body.scrollHeight?h:document.body.scrollHeight;
//    CreateViewBg(w,h);
    ShowDiv = document.getElementById('divNoRegView');
    ShowDiv.style.display = 'block';
//    ShowDiv.style.left = (w/2 -150)+'px';
//    ShowDiv.style.top = (h/2 -60)+'px';
    ShowDiv.style.left = (w/2 -180)+'px';
    ShowDiv.style.top = '271px';
    ShowDiv.style.position = 'absolute';
    ShowDiv.style.zIndex = 100002;	
}
window.onresize = function()
{
    if(ShowDiv)
    {
        var h=fnGetWindowHeight();
	    var w=fnGetWindowWidth();
    	
	    w = w>946?w:document.body.scrollWidth;
	    h = h>document.body.scrollHeight?h:document.body.scrollHeight;

        ShowDiv.style.left = (w/2 -180)+'px';
    ShowDiv.style.top = '271px';
    }
}

function DisableImage(imageid)
{
    document.getElementById(imageid).disabled=true;
    return true;
}

function ShowSaveSuccess()
{
    document.getElementById('favoriteblk').style.display = '';
    document.getElementById('imgAddFav').disabled=false
}

//地图移动和鹰眼联动
function MoveTo(x,y)
{
    vM.MoveTo(x, y, true);
}

function ENetwork(){};
ENetwork.GetExecutionID = function()
{
    var a = new Date, b = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate(),a.getHours(), a.getMinutes(), a.getSeconds(), a.getMilliseconds());
    b += Math.round(Math.random() * 1000000);
    return b
};
ENetwork.DownloadScriptCallback = function(a)
{
    if (a){
        a();
    }
};
ENetwork.DownloadScript = function(a, b, c)
{
    try{        
        if (a == null || a == "undefined" || a.length == 0){
            throw new ENetworkException("ENetwork:DownloadScript", "err_noscripturl",l24ht);
        }
        var elScript = document.createElement("script");
        elScript.type = "text/javascript";
        elScript.language = "javascript";
        elScript.id = typeof(c) == "undefined" ? ENetwork.GetExecutionID() : c;
        elScript.src = a;        
        if(document.getElementById(c)){
            ENetwork.GetAttachTarget().removeChild(document.getElementById(c));
        }
        ENetwork.GetAttachTarget().appendChild(elScript);
        if (navigator.userAgent.indexOf("IE") >= 0){
            elScript.onreadystatechange = function(){
                if (elScript && ("loaded" == elScript.readyState || "complete" == elScript.readyState)){
                    elScript.onreadystatechange = null;
                    ENetwork.DownloadScriptCallback(b);                    
                }
            }
        }
        else{
            elScript.onload = function(){
                elScript.onload = null;
                ENetwork.DownloadScriptCallback(b);
            }
        }        
        return elScript.id;
    }
    catch (e){
        alert('加载失败！');
    }
};
ENetwork.GetAttachTarget = function()
{
    if (document.getElementsByTagName("head")[0] != null){
        return document.getElementsByTagName("head")[0];
    }
    else{
        throw new ENetworkException("ENetwork:cstr", "err_noheadelement", l611ft);
    }
};
function ENetworkException(b, c, a)
{
    this.source = b;
    this.name = c;
    this.message = a;
}
ENetworkException.prototype.Name = this.name;
ENetworkException.prototype.Source = this.source;
ENetworkException.prototype.Message = this.message;