﻿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;

var whichCode = e.keyCode;
if (whichCode == 13 || whichCode == 8) return true;
key = String.fromCharCode(whichCode); // Valor para o cdigo da Chave
if (strCheck.indexOf(key) == -1) return false; // Chave invlida
//if (strCheck.indexOf(key) == -1) return false; // Chave invlida
len = objTextBox.value.length;

if(len >= 12) return false;

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;

if (len == 0) objTextBox.value = '';

if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;

if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;

if (len > 2) {

aux2 = '';

for (j = 0, i = len - 3; i >= 0; i--) {

if (j == 3) {

aux2 += SeparadorMilesimo;

j = 0;

}

aux2 += aux.charAt(i);

j++;

}

objTextBox.value = '';

len2 = aux2.length;

for (i = len2 - 1; i >= 0; i--)

objTextBox.value += aux2.charAt(i);

objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);

}

return false;

}


function IluminaPnl(obj)
{
    obj.style.backgroundColor = "#FFFAF0";
}

function EscurecePnl(obj)
{
    obj.style.backgroundColor = "#fff";
}

function EscurecePnlPar(obj)
{
    obj.style.backgroundColor = "#efffee";
}

function Dir(direcao)
{
    if(direcao == "")
        return;

    window.location = "ImovelDetalhe.aspx?imovelid=" + direcao;
}

function Carrega()
{
        
  var map = new GMap2(document.getElementById("map"));
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
        
        
  var center = new GLatLng(-23.17620, -45.82467);
    map.setCenter(center, 15);
    geocoder = new GClientGeocoder();
  
  
  var marker = new GMarker(center, {draggable: true});  
    map.addOverlay(marker);
    
    
    
    GEvent.addListener(marker, "mouseover", function() {
                 map.openInfoWindowHtml(center, "<center><b>Narezzi Imóveis</b></center><br>Rua Cidade de La Paz, 13 - SJCampos Vista Verde - Cep: 12223.690<br><br><center>narezzi@narezziimoveis.com.br <br> Tel Fax: (12) 3912-8001</center>");
                 setTimeout(
                     function() {
                       map.closeInfoWindow();
                    }, 50000);
            });
            GEvent.addListener(map, "mouseout", function() {
                map.closeInfoWindow();
            });
}




function AbreTelaIndicacao(id)
{
winwidth = 768;
winheight = 171;
winleft  = 200;
wintop    = 400;
 
if(parseInt(navigator.appVersion)>=4)
{
winleft = (screen.width / 2) - (winwidth / 2); 
wintop = (screen.height / 2) - (winheight / 2); 

}

	janela1 = null

    janela1=window.open('IndicaImovel.aspx?id=' + id, 'Indicação', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=507,height=364, left='+ winleft + ', top=150', '_self');
    
    return false;
}


function AbreEmailImovel(Cod, location)
{
winwidth = 768;
winheight = 171;
winleft  = 200;
wintop    = 400;
 
if(parseInt(navigator.appVersion)>=4)
{
winleft = (screen.width / 2) - (winwidth / 2); 
wintop = (screen.height / 2) - (winheight / 2); 

}

	janela1 = null

    if(location == "chat")
    janela1=window.open('../EmailImovel.aspx?cod=' + Cod, 'Indicação', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=507,height=364, left='+ winleft + ', top=150', '_self');
    else
    janela1=window.open('EmailImovel.aspx?cod=' + Cod, 'Indicação', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=507,height=364, left='+ winleft + ', top=150', '_self');    
    return false;
}

function AbreChat(ref)
{
    winwidth = 768;
    winheight = 171;
    winleft  = 200;
    wintop    = 400;
     
    if(parseInt(navigator.appVersion)>=4)
    {
        winleft = (screen.width / 2) - (winwidth / 2); 
        wintop = (screen.height / 2) - (winheight / 2); 

    }

	janela1 = null
    
    if(ref == "")
        //janela1=window.open('Chat/LoginChat.aspx', 'ChatNarezzi', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=508,height=370, left='+ winleft + ', top=150', '_self');
        janela1=window.open('Chat/ChatLogin.aspx', 'ChatNarezzi', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=490,height=570, left='+ winleft + ', top=150', '_self');
     else
        janela1=window.open('Chat/ChatLogin.aspx?ref=' + ref, 'ChatNarezzi', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=490,height=570, left='+ winleft + ', top=150', '_self');   
    
    return false;
}

function teste2()
{
    alert('PATO BRANCO');
}

function AbreChatServer(SessionID, cliente)
{
    winwidth = 768;
    winheight = 171;
    winleft  = 200;
    wintop    = 400;
     
    if(parseInt(navigator.appVersion)>=4)
    {
        winleft = (screen.width / 2) - (winwidth / 2); 
        wintop = (screen.height / 2) - (winheight / 2); 

    }

	janela1 = null
		

    //janela1=window.open('../Chat/ChatRoom2.aspx?User=' + cliente + '&UserMode=Server&MetaServer=18mt&Token=a567a89lakjhagaggajkj2828ahshsgs4567&SessionID=' + SessionID, 'ChatNarezzi', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=508,height=370, left='+ winleft + ', top=150', '_self');    
    janela1=window.open('../Chat/ChatSala.aspx?User=' + cliente + '&UserMode=Server&MetaServer=18mt&Token=a567a89lakjhagaggajkj2828ahshsgs4567&SessionID=' + SessionID, 'ChatNarezzi', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=490,height=570, left='+ winleft + ', top=150', '_self');    
    
    
    location = "admChat.aspx";
    
    return false;
}

function SairChat()
{
    //18mt.Logoff(LogoffResult);
    
    alert(sSessionID);
    
    var param =
       {
         SessionID: sSessionID
       };
    
   // _18mt.Logoff(sSessionID, LogoffResult);
}

function LogoffResult(result)
{
    alert('Conversa Encerrada');
    window.close();
}

function SaiDahSala()
{         

    PageMethods.SaiDahSala(sSessionID);
}


function VerificaFila()
{    
    i = 1;   
        
    
    bverificaFila = true;    
    
    setInterval(VerificaFilaFunction, 10000);
}

function VerificaFilaFunction()
{
    //alert(lblInfo.innerHtml);
    
    
    
    lblTime.innerHTML = "<font color=blue>Verificando Fila...</font>";
    
    
    
    if(bverificaFila)
        PageMethods.VerificaFila(sEspera, VerificaFilaReturn);  
    
    i++;
    
    setInterval(VerificaFilaFunction, 10000);
}

function VerificaFilaReturn(result)
{
    lblTime.innerHTML = "";   
          
    
    if(!result.bDireciona)    
        lblInfo.innerHTML = result.sFila;        
    else
    {
        bverificaFila = false;
        window.location = "ChatRoom2.aspx?User=" + result.sSolicitante + "&UserMode=Client&MetaServer=18mt&Token=a567a89lakjhagaggajkj2828ahshsgs4567&SessionID=" + result.sSessionID;     
    }
}
