﻿var _PopLayer;
var _MapFinished = false;
function AppendIcon(iconPath,x,y,title)
{
    if (!title) title = '我在这里'; 
    //加载对象
    if(typeof vEdushiMap =='undefined' || typeof vEdushiMap.Body.NewMapLayer !='function' )
    {
        setTimeout('AppendIcon("' + iconPath + '",' + x + ',' + y + ', "' + title + '")',50);
        return;
    }
    _PopLayer = vEdushiMap.NewMapLayer('Pop',269, 0);   
    var div = vEdushiMap.$C('div');
    div.innerHTML = '<div class=\"header\"><div style=\"height:19px;width:10px; padding-top:2px; padding-left:5px; padding-right:5px; white-space:nowrap;border:1px #FC9A1E solid;background-color:#ffffff;color:#1A70C7; font-size:12px;\">' + title + '</div><div style=\"float:left; margin-left:10px; font-size:10px; width:13px; height:10px;background-repeat: no-repeat; text-align:center;  position:relative; margin-top:-1px;background:none;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src=\'' + iconPath + '\');\" ></div></div>';
    vEdushiMap.appendEntity(div, _PopLayer, false, x, y, 20,28,25,15, false);
}

function InitCompanyPop(rootPath)
{
    //加载对象
    if(typeof vEdushiMap =='undefined' || typeof vEdushiMap.Body.NewMapLayer !='function' )
    {
        setTimeout('InitCompanyPop("' + rootPath + '")',50);
        return;
    }
    _MapFinished = true;
    var css=vEdushiMap.$C('link');
    css.rel='stylesheet';
    css.type = 'text/css';
    css.href=rootPath+'css/pop.css';
    vEdushiMap.Body.document.getElementsByTagName('head')[0].appendChild(css);
    
    _PopLayer = vEdushiMap.NewMapLayer('Pop',269, 0);  
}

function ShowCompanyPop(id,rootPath,cityPath,mapUrl)
{
    if (!_MapFinished)
    {
        //alert('地图未加载完成,请稍候再点击.');
        return;
    }
    var o = null;
    for (var i=0; i<_CompanyList.length; i++)
    {
        if (_CompanyList[i].ID == id)
        {
            o = _CompanyList[i];
            break;
        }
    }
    
    if (o != null)
    {
        if (o.X == '' || o.Y=='')
        {
            return;
        }
        _PopLayer.innerHTML = '';
        var pop = vEdushiMap.$C('div');
        
        pop.innerHTML = '' +
'<div id="Pop">' +
  '<div class="Top">' +
    '<div class="Title">' + o.Title.substr(0, 18) + '</div>' +
	'<div class="Close"><a href="javascript:;" onclick="parent._PopLayer.innerHTML=\'\';"><img src="' + rootPath + 'img/Close.gif" /></a></div>' +
  '</div>' +
  '<div class="Content">' +
    '<div class="Detail">' +
      '电话：' + o.Tel + '<br />' +
      '地址：' + o.Address + '<br />' +
	  '简介：' + o.Info.substr(0, 45) +
    '</div>' +
    '<div class="Infor">' +
      '级别：' + o.Level + '&nbsp;&nbsp;&nbsp;&nbsp;' +
	  '<!--点评：<span class="Orange">' + o.Comment + '</span>&nbsp;&nbsp;&nbsp;&nbsp;-->' +
    '</div>' +
    '<div class="Btn"><a href="/shopvip.aspx?id=' + o.ID + '" target="_blank"><img src="' + rootPath + 'img/BtnDetail.gif" /></a>&nbsp;<a href="' + mapUrl + '?cid=' + o.ID + '" target="_blank"><img src="' + rootPath + 'img/BtnCome.gif" /></a></div>' +
    '<div class="Ad"><script type="text/javascript" src="' + _sLocalSearchAD + '"></script></div>' +
  '</div>' +
'</div><div id="foot"><img src="' + rootPath + 'img/Foot.gif" /></div>';

        vEdushiMap.appendEntity(pop, _PopLayer, false, o.X, o.Y, 320,220,120,260, false);
        vEdushiMap.MoveTo(o.X, o.Y-120, true);
    }
}

//创建一个背景
function CreatBackground()
{
    if(!document.getElementById('Map_BG'))
    {
        var BG = document.createElement('div');
        BG.id = 'Map_BG';
        if(document.all)
        {
            BG.style.cssText = 'top:0px; left:0px; position:absolute; z-index:10000; background-color:#000000;filter:alpha(opacity=60); opacity:.6;';
        }
        else
        {
            BG.setAttribute('style', 'top:0px; left:0px; position:absolute; z-index:10000; background-color:#000000;filter:alpha(opacity=60); opacity:.6;');
        }
        BG.style.width= document.body.scrollWidth + 'px';
        BG.style.height= document.body.scrollHeight + 'px';
        document.body.appendChild(BG);
    }
    else
    {
        document.getElementById('Map_BG').style.display = '';
    }
}
//隐藏背景
function CloseBackground()
{
    if(document.getElementById('Map_BG'))
    {
        document.getElementById('Map_BG').style.display = 'none';
    }
}

//创建一个页面内嵌地图IFRAME
function CreateMapIframe(src)
{
    CreatBackground();
    if(!document.getElementById('Map_Loading'))
    {
        var Map_Loading = document.createElement('div');
        var LoadingLeft = (fnGetWindowWidth()-200)/2 + 'px';
        Map_Loading.id = 'Map_Loading';
        if(document.all)
        {
            Map_Loading.style.cssText = 'border-right: #82aad2; border-top: #82aad2 ; z-index: 10001; left:'+ LoadingLeft+'; border-left: #82aad2 ; width: 200px; border-bottom: #82aad2;position: absolute;top:250px;height: 50px; background-color: #ffffff;';
        }
        else
        {
            Map_Loading.setAttribute('style', 'border-right: #82aad2; border-top: #82aad2 ; z-index: 10001; left:'+ LoadingLeft+'; border-left: #82aad2 ; width: 200px; border-bottom: #82aad2;position: absolute;top:250px;height: 50px; background-color: #ffffff');
        }
        document.body.appendChild(Map_Loading);
        var sWaiting = '<table width="100%" height="100%" align="center" style="text-decoration: none;border:#82AAD2 solid;border-width:1 1 1 1;" cellpadding="0" cellspacing="0" border="0"><tr>';
        sWaiting += '<td align="center" style="border:#ffffff solid;border-width:0 1 1 0;text-decoration: none;padding: 2 5 2 5;background-color:F8F9FD;text-align: center;line-height:20px;font-size:12px;font-weight:bold;color: #666666;">地图加载中，请稍等.....';
        sWaiting += '<marquee id="LoadMarquee" style="border:1px solid #82AAD2" behavior="scroll" direction="right" width="200" scrollamount="3" scrolldelay="10" bgcolor="#ffffff">';
        sWaiting += '<table cellspacing="0" border="0">';
        sWaiting += '<tr height=8><td bgcolor=#D4DDEC width=8></td>';
        sWaiting += '<td></td><td bgcolor=#C1D1E0 width=8></td>';
        sWaiting += '<td></td><td bgcolor=#9AAFD3 width=8></td>';
        sWaiting += '<td></td><td bgcolor=#6F8DC0 width=8></td>';
        sWaiting += '<td></td><td bgcolor=#6F8DC0 width=8></td>';
        sWaiting += '<td></td><td bgcolor=#6F8DC0 width=8></td>';
        sWaiting += '<td></td><td bgcolor=#6F8DC0 width=8></td>';
        sWaiting += '<td></td><td bgcolor=#9AAFD3 width=8></td>';
        sWaiting += '<td></td><td bgcolor=#C1D1E0 width=8></td>';
        sWaiting += '<td></td><td bgcolor=#D4DDEC width=8></td>';
        sWaiting += '<td></td></tr></table></marquee></td></tr>';
        sWaiting += '</table>';
        Map_Loading.innerHTML = sWaiting;
    }
    else
    {
        document.getElementById('Map_Loading').style.display = '';
    }
    
    var id = 'MyEdushiHuiMap';
    realsrc = src +'w_'+fnGetWindowWidth()+'_h_'+fnGetWindowHeight();
    if(!document.getElementById(id))
    {
        setTimeout("appendMapIframe()",1000);
    }
    else
    {
        if(document.getElementById(id).src.indexOf(realsrc)< 0)
        {
            document.getElementById(id).src = realsrc;
            if(document.all)
            {
                document.getElementById(id).attachEvent("onload",function (){document.getElementById(id).style.display = ''});
            }
            else
            {
                document.getElementById(id).onload = function (){document.getElementById(id).style.display = '';}
            }
        }
        else
        {
            document.getElementById(id).style.display = '';
        }
    }
}
function appendMapIframe()
{
    var createIframe = document.createElement('iframe');
    createIframe.id = 'MyEdushiHuiMap';
    createIframe.frameBorder = '0';
    createIframe.scrolling = "no";
    createIframe.style.position = 'absolute';
    createIframe.style.overflow = 'hidden';
    createIframe.allowTransparency = 'true';
    createIframe.style.width = fnGetWindowWidth() + 'px';
    createIframe.style.height = fnGetWindowHeight() + 'px';
    createIframe.style.left ='0px';
    createIframe.style.top = '0px';
    createIframe.style.zIndex = '10002';
    createIframe.src = realsrc;
    document.body.appendChild(createIframe);
}
//隐藏内嵌的地图IFRAME
function CloseMapIframe()
{
    var id = 'MyEdushiHuiMap';
    if(document.getElementById(id))
    {
        document.getElementById(id).style.display = 'none';
        document.getElementById('Map_Loading').style.display = 'none';
    }
    CloseBackground();
}

function ChangeMapIframeSize()
{
    if(document.getElementById("MyEdushiHuiMap"))
    {
        var w = fnGetWindowWidth();
        var h = fnGetWindowHeight();
        document.getElementById("MyEdushiHuiMap").style.width = w + 'px';
        document.getElementById("MyEdushiHuiMap").style.height = h + 'px';
        if(document.getElementById("MyEdushiHuiMap").contentWindow.vM)
        {
            var vM = document.getElementById("MyEdushiHuiMap").contentWindow.vM;
            vM.MapHeight(h);
            vM.MapWidth(w);
        }
    }
}   
window.onresize=function(){
    ChangeMapIframeSize();
};