﻿
function MensagemAlerta(strMsg){
    alert(strMsg);
    return false;
}

/////////////////////////////////////////////////////////////////////////////////

function ModalPopUp(Destino , Nome , Altura , Largura , CtrlRetorno){ 
    var vRetorno; 
    vRetorno = window.showModalDialog(Destino ,  Nome  ,"dialogHeight:" +Altura+ "px;dialogWidth:"+Largura+"px; center: Yes; resizable: No; scroll: Yes; status: No;");                    
    document.getElementById(CtrlRetorno).value = vRetorno; 
    return false;
} 

/////////////////////////////////////////////////////////////////////////////////

function ModalPopUpEdit(Destino , Nome , Altura , Largura, CtrlRetorno){ 
    var vRetorno; 
    vRetorno = window.showModalDialog(Destino ,  Nome  ,"dialogHeight:" +Altura+ "px;dialogWidth:"+Largura+"px; center: Yes; resizable: No; status: No;");                    
    document.getElementById(CtrlRetorno).value = vRetorno; 
    return false;
} 

/////////////////////////////////////////////////////////////////////////////////

function ModalPopUpError(Destino , Nome , Altura , Largura , CtrlRetorno){ 
//    window.showModalDialog(Destino ,  Nome  ,"dialogHeight:" +Altura+ "px;dialogWidth:"+Largura+"px; center: Yes; resizable: No; scroll:No; status: No;");
//    return false;   

    winwidth    = Largura; 
    winheight   = Altura;  
    winleft     = 200; 
    wintop      = 200; 
  
    if(parseInt(navigator.appVersion)>=4){
        winleft = (screen.width / 2) - (winwidth / 2);  
        wintop = (screen.height / 2) - (winheight / 2) - 9;  
    }
    
    window.open(Destino, Nome , 'top=' + wintop + ',left=' + winleft + ',status=yes,resizable=no,toolbar=no,menubar=no,location=no,scrollbars=no, height=' + winheight + ',width=' + winwidth); 
                  
} 

/////////////////////////////////////////////////////////////////////////////////

function ModalPopUpSucesso(Destino , Nome , Altura , Largura , CtrlRetorno){ 
//    window.showModalDialog(Destino ,  Nome  ,"dialogHeight:" +Altura+ "px;dialogWidth:"+Largura+"px; center: Yes; resizable: No; scroll:No; status: No;");
//    return false; 
    winwidth    = Largura; 
    winheight   = Altura;  
    winleft     = 200; 
    wintop      = 200; 
  
    if(parseInt(navigator.appVersion)>=4){
        winleft = (screen.width / 2) - (winwidth / 2);  
        wintop = (screen.height / 2) - (winheight / 2) - 9;  
    }
    
    window.open(Destino, Nome , 'top=' + wintop + ',left=' + winleft + ',status=yes,resizable=no,toolbar=no,menubar=no,location=no,scrollbars=no, height=' + winheight + ',width=' + winwidth); 
                      
} 

/////////////////////////////////////////////////////////////////////////////////

function FecharJanelaValor(CtrlRetorno) 
{ 
    window.returnValue = document.getElementById(CtrlRetorno).value; 
    window.close(); 
} 

/////////////////////////////////////////////////////////////////////////////////

function FecharJanela() 
{ 
    window.close();
} 

/////////////////////////////////////////////////////////////////////////////////

function MM_formtCep(e,src,mask) {
    if(window.event) { _TXT = e.keyCode; } 
    else if(e.which) { _TXT = e.which; }
    if(_TXT > 47 && _TXT < 58) { 
     var i = src.value.length; var saida = mask.substring(0,1); var texto = mask.substring(i)
     if (texto.substring(0,1) != saida) { src.value += texto.substring(0,1); } 
        return true; } else { if (_TXT != 8) { return false; } 
     else { return true; }
   }
}

/////////////////////////////////////////////////////////////////////////////////

function MM_formtCPF(formato, objeto)
{
    campo = eval (objeto);
    if (formato=='CPF')
    {
        caracteres = '01234567890';
        separacoes = 3;
        separacao1 = '.';
        separacao2 = '-';
        conjuntos = 4;
        conjunto1 = 3;
        conjunto2 = 7;
        conjunto3 = 11;
        conjunto4 = 14;
        if ((caracteres.search(String.fromCharCode (window.event.keyCode))!=-1) && campo.value.length < 
        (conjunto4))
        {
        if (campo.value.length == conjunto1) 
        campo.value = campo.value + separacao1;
        else if (campo.value.length == conjunto2) 
        campo.value = campo.value + separacao1;
        else if (campo.value.length == conjunto3) 
        campo.value = campo.value + separacao2;
    }
    else 
    event.returnValue = false;
  } 
}

/////////////////////////////////////////////////////////////////////////////////

function MM_formtCNPJ(Campo, teclapres){

   if(window.event){
    var tecla = teclapres.keyCode;
   }else  tecla = teclapres.which;

   var vr = new String(Campo.value);
   vr = vr.replace(".", "");
   vr = vr.replace(".", "");
   vr = vr.replace("/", "");
   vr = vr.replace("-", "");

   tam = vr.length + 1;
   if (tecla > 47 && tecla < 58){
      if (tam > 2 && tam < 6)
         Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
      if (tam >= 6 && tam < 9)
         Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
      if (tam >= 9 && tam < 13)
         Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
      if (tam >= 13 && tam < 15)
         Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
    }
    else
        return false;
}

/////////////////////////////////////////////////////////////////////////////////

function Numero(e)
{
    navegador = /msie/i.test(navigator.userAgent);
    if (navegador)
        var tecla = event.keyCode;
    else
        var tecla = e.which;

    if(tecla > 43 && tecla < 58){
       if(tecla != 45 && tecla != 46)
          return true;
        else
          return false;
     }
    else
    {
    if (tecla != 8) // backspace
        return false;
    else
        return true;
  }
}

/////////////////////////////////////////////////////////////////////////////////

function setfocus(t) {
    document.getElementById(t).focus();
    return;
}

//////////////////////////////////////////////////////////////////////////////////

function TABEnter(oEvent){
  var oEvent = (oEvent)? oEvent : event;
  if(oEvent.keyCode==13)
        oEvent.keyCode = 9;
}

function LimitCaractFocus(obj, obj2, limit) {
    if (document.getElementById(obj).value.length == limit) {
        document.getElementById(obj2).focus();
    }
}

///////////////////////////////////////////////////////////////////////////////////

function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
        if (whichCode == 13 || whichCode == 8) return true;
        key = String.fromCharCode(whichCode); // Valor para o código da Chave
        if (strCheck.indexOf(key) == -1) return false; // Chave inválida
        len = objTextBox.value.length;
        //alert(len);
        for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
        aux = '';
        for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
        aux += key;
        len = aux.length;
        // alert(len);
        if (len == 9999){
        return false;
        }
            if (len == 0) objTextBox.value = '';
            if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + '0' + aux;
            if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
            if (len == 3) objTextBox.value = '0'+ SeparadorDecimal + aux;
        //if (len == 4) objTextBox.value = '0'+ SeparadorDecimal + aux;
        //alert(len);
        if (len > 3) {
        aux2 = '';
        for (j = 0, i = len - 4; i >= 0; i--) {
        if (j == 3) {
        aux2 += '.';
        j = 0;
        }
        aux2 += aux.charAt(i);
        //alert(aux2);
        j++;
        }
        objTextBox.value = '';
        //alert('1');
        len2 = aux2.length;
        //alert('2');
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 3, len);
        //alert(aux.substr(len - 4, len));
        //alert(objTextBox.value)
    }
 return false;
}

///////////////////////////////////////////////////////////////////////////////////

function WindowOpen(Destino , Nome, Altura, Largura){

    winwidth    = Largura; 
    winheight   = Altura;  
    winleft     = 200; 
    wintop      = 200; 
  
    if(parseInt(navigator.appVersion)>=4){
        winleft = (screen.width / 2) - (winwidth / 2);  
        wintop = (screen.height / 2) - (winheight / 2) - 9;  
    }
    
    window.open(Destino, Nome , 'top=' + wintop + ',left=' + winleft + ',status=yes,resizable=yes,toolbar=no,menubar=no,location=no,scrollbars=yes, height=' + winheight + ',width=' + winwidth); 
}

function RedirPageJava(Destino){

    window.location=Destino;
}

/////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
//Mapa - Google Maps
//Danilo Brito
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////


var map = null;
	
//Evite erro no IE ao carregar Mapa
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

//Carregar Mapa
function initialize(coord, lat, log, MapZoom, AtuaMapa, vHtml) {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(lat, log), MapZoom);
    geocoder = new GClientGeocoder();
    
   
    //Inicializa como ponto central
    document.getElementById(coord).value = map.getCenter();  
	
	  //Controles zoom e botões no mapa
	  map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
	  
	   // bind a search control to the map, suppress result list
      map.addControl(new google.maps.LocalSearch(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,20)));
	  
	  map.enableContinuousZoom();
  	  map.disableScrollWheelZoom()
  	  map.enableDoubleClickZoom();
  	  		  
  	  if(AtuaMapa == 1){
  	    MapaAtualiza(MapZoom,vHtml);
  	   }
  	  		  
	  //Evento click para marcar posição no banco
	  GEvent.addListener(map,"click", function(overlay,latlng) {     
      var myHtml = "<strong><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>Definir como principal.</font></strong><br><font size='1' color='#FF0000' face='Verdana, Arial, Helvetica, sans-serif'>" + latlng + "</font>"
      if(latlng == null){
        map.openInfoWindow(map.getCenter(), vHtml);
        document.getElementById(coord).value = map.getCenter();  
      }
      else{
        document.getElementById(coord).value = latlng;  
        //map.openInfoWindow(latlng, myHtml);
      }
    });
  }
}

//Atualizar mapa quando usuário realizar pesquisa
function MapaAtualiza(MapZoom, MapHtml){
      map.setCenter(map.getCenter(), MapZoom);	  
	  var point = map.getCenter();
	  map.addOverlay(new GMarker(point));
	  map.openInfoWindowHtml(map.getCenter(),MapHtml); 
}

function fn_Redir(url) {
    var id = document.getElementById("hidIdAnuncio").value;
    var imovel = document.getElementById("hidTituloImovel").value;
    location.href = url + "?idAnuncio=" + id + "&Imovel=" + imovel;
}

function fn_RedirPorti() {
    var guid = document.getElementById("Uc_Menu1_hidGUID").value;

    if (guid == "AC50AB95-739C-DD11-BA06-0015C5E69DBD") {
        location.href = "http://www.ciaqualita.com.br/Busca.aspx?ima=4&imb=DF&imc=&imd=&imf=&g=AC50AB95-739C-DD11-BA06-0015C5E69DBD";
    }
    else if (guid == "D12B1ED7-1BF5-DD11-8AB2-005056B2242A") {
        location.href = "http://www.ciagoiania.com.br/Busca.aspx?ima=4&imb=GO&imc=&imd=&imf=&g=D12B1ED7-1BF5-DD11-8AB2-005056B2242A";
    }
    else if (guid == "420D4CA7-8A4C-DF11-9E5E-005056B2242A") {
        location.href = "http://www.ciasalvador.com.br/Busca.aspx?ima=4&imb=BA&imc=&imd=&imf=&g=420D4CA7-8A4C-DF11-9E5E-005056B2242A";
    }

}

function fn_RedirWeb() {
    var guid = document.getElementById("Uc_Menu1_hidGUID").value;

    if (guid == "D12B1ED7-1BF5-DD11-8AB2-005056B2242A") {
        location.href = "http://webmail.ciagoiania.com.br/";
    }
    else {
        location.href = "http://webmail.imovel-cia.com.br/";
    }

}