var _mZoom=9;
var _mTool=1;

var blnMovimentar = false;
var blnGoogle = false;

function mapMapa(pMapa)
{
    var m_MapObj, m_widthMap, m_heightMap;
    
    m_MapObj = document.getElementById(pMapa);
    
    m_widthMap  = m_MapObj.style.width;
    m_heightMap = m_MapObj.style.height;
    
    if (m_widthMap.indexOf('px')) m_widthMap =  m_widthMap.substring(0,m_widthMap.indexOf('px'));
    if (m_heightMap.indexOf('px')) m_heightMap =  m_heightMap.substring(0,m_heightMap.indexOf('px'));
    var tTemp;
    
    m_MapObj.style.position = 'relative';
    m_MapObj.style.overflow = 'hidden';
    
    tTemp = "<iframe name='frameMapa' id='frameMapa' src='' width=" + m_widthMap + " height=" + m_heightMap + " frameborder='0' scrolling='no'></iframe>" + 
            "<div id='cmdCarregando' style='Z-INDEX: 1; LEFT: " + ( (m_widthMap/2)-(mLoadingWidth/2) ) + "px;  TOP: " + ( (m_heightMap/2)-(mLoadingHeight/2) ) + "px; VISIBILITY:hidden; WIDTH:" + mLoadingWidth + "px; HEIGHT: " + mLoadingHeight + "px; POSITION: absolute;'>" + 
            "<img src='http://" + mServer + "/" + mSite + "/" + mImgs + "/" + mLoadingImg + "' border='0'></div>";

    lf_Texto(pMapa,tTemp);
}

// Controle sobre carregamento do Mapa
function lf_Movimentar() {
	if (blnMovimentar == false){
		alert('Por favor, aguarde o carregamento do Mapa.');
		return false;
	}
	if (blnGoogle == true){
		alert('Funcionalidade só para o modo "Mapa". Clique no botão "Mapa"');
		return false;
	}
	return true;
}
// Movimentação norte, sul, leste ...
function lf_AtualizaDirecao(ldirecao) {
    if (lf_Movimentar()==false) return;
	lf_Load();
	window.frames['frameMapa'].lf_AtualizaDirecao(ldirecao);
}
// Ir direto para a imagem do Mapa
function lf_IrMapa() {
	var cNode = document.getElementById("frameMapa");
	window.scrollTo(0,findPosition(cNode));
}	
// centraliza o mapa em um ponto X Y de coordenadas
function lf_MudaCentroRota(x,y){
    if (lf_Movimentar()==false) return;
	lf_Load();
	lf_IrMapa();
    window.frames['frameMapa'].lf_MudaCentroRota(x,y);
}
// Abrir o frame de rota
function lf_AbrirRota(xmlRota) 
{
    document.getElementById('xmlrota').value = xmlRota;
    frameRota.location = "rota_detalhada.asp?xmlrota=" + xmlRota;
}
// Zoom In
function lf_AtualizaZoomIN() {	
	if (parseInt(_mZoom) + 1 == 11) 
	    alert('Limite de Zoom Atingido!');
    else {
	    lf_Load();
	    _mZoom = parseInt(_mZoom) + 1;
	    window.frames['frameMapa'].lf_AtualizaZoom(_mZoom);
	}
}
// Zoom Out
function lf_AtualizaZoomOUT() {	
	if (parseInt(_mZoom) - 1 == 0) 
	    alert('Limite de Zoom Atingido!');
    else {
        lf_Load();	
        _mZoom = parseInt(_mZoom) - 1;
        window.frames['frameMapa'].lf_AtualizaZoom(_mZoom);
    }
}
// Atualiza Zoom
function lf_AtualizaZoom(lzoom) {
    if (lf_Movimentar()==false) return;
	lf_Load();
	_mZoom = lzoom;
	window.frames['frameMapa'].lf_AtualizaZoom(lzoom);
}

// Por geocode atualiza os X Y atuais
function lf_AtualizarPontosXpYp(x,y) {
    var endereco;
    if (document.getElementById('x').value==''){
	    document.getElementById('x').value = x;
	    document.getElementById('y').value = y;
        endereco = document.getElementById('endereco').value;
        document.getElementById('endereco').value = endereco.substring(endereco.indexOf('-')+1);
	}
}
// Mover para a posicao inicial do mapa
function lf_PosicaoIni() {
    if (lf_Movimentar()==false) return;
	lf_Load();
	window.frames['frameMapa'].lf_PosicaoIni();
}
function lf_Load(){
	MM_showHideLayers('cmdCarregando','','show');
}
function lf_UnLoad(){
	MM_showHideLayers('cmdCarregando','','hide');
}