function mostraBusca(){
	if (document.getElementById('buscaBaixo').style.display == 'none') {		
		$('#buscaBaixo').slideDown('fast');
	} else {
		$('#buscaBaixo').slideUp('fast');
	}	
}	

function obterIndiceProximoElemento(campo) {
  var nObj, i;
  for (var i = 0; i < campo.form.elements.length; i++)
    if (campo == campo.form.elements[i]) {
      nObj = i;
    }
  for (var i = nObj + 1; i < campo.form.elements.length; i++)
    if (campo.form.elements[i].type != 'hidden' && !campo.form.elements[i].disabled && campo.form.elements[i].style.visibility != 'hidden') {
      return i;
    }
  return -1;
}

function editarCampo(evento, campo, tipo, mascara, prox, funcao) {
  var t, msk, virgula;
  if (campo.onblur == null)
    campo.onblur = campo.onfocus;
  if (campo.onkeyup == null)
    campo.onkeyup = campo.onfocus;
  if (campo.onkeypress == null)
    campo.onkeypress = campo.onfocus;
  if (evento.type == "focus") {
    campo.onfocus = null;
    return;
  }
  t = evento.keyCode;
  if (t == 9 || t == 16) {
    campo.focus();
    return;
  }
  if (funcao != null && evento.type == "keypress" && t == 13) {
    eval(funcao);
    return;
  }
  if (evento.type == "keypress") {
    return;
  }
  if (evento.type == "keypress" || evento.type == "keyup" || evento.type == "blur") {
    campo.value = eliminarCaracteresInvalidos(campo.value, tipo);
    campo.value = inserirMascara(campo.value, mascara);
    if (campo.value.length > campo.maxLength)
      campo.value = campo.value.substr(0, campo.maxLength);
    if (campo.value.length == campo.maxLength)
      if (prox != null){
      
        prox.focus();
      }  
      else {
        nOrd = obterIndiceProximoElemento(campo);
        if (nOrd > -1 && event.type != "blur") 
          campo.form.elements[nOrd].focus();
      }
  }
  if ((t>=16&&t<=20) || (t>=33&&t<=39) || (t>=44&&t<=45) || (t>=112&&t<=123) || (t>=144&&t<=145) || t==12)
    return true; 
  if ('ALNX'.indexOf(tipo, 0) != -1)
    campo.value = campo.value.toUpperCase();
  if (mascara != null && mascara != "" )
    if (campo.style.textAlign == "right") {
      msk = right(mascara, campo.value.length);
      campo.value = eliminarCaracteresInvalidos(campo.value, tipo);
      campo.value = eliminarZerosEsquerda(campo.value);
      mascara = inverter(mascara);
      virgula = mascara.indexOf(",")
      if (virgula > -1 && campo.value.length > 0)
        campo.value = preencheZeros(campo.value, virgula + 1);
      valor = inverter(campo.value);
      valor = inserirMascara(valor, mascara);
      campo.value = inverter(valor);
    }
    else {
      campo.value = eliminarCaracteresInvalidos(campo.value, tipo);
      campo.value = inserirMascara(campo.value, mascara);
      if (campo.value.length > campo.maxLength)
        campo.value = campo.value.substr(0, campo.maxLength);
    }
  return true;
}

function editarCampo2(evento, campo, tipo, mascara, prox, funcao) {
  var t, msk, virgula;
  if (campo.onblur == null)
    campo.onblur = campo.onfocus;
  if (campo.onkeyup == null)
    campo.onkeyup = campo.onfocus;
  if (campo.onkeypress == null)
    campo.onkeypress = campo.onfocus;
  if (evento.type == "focus") {
    campo.onfocus = null;
    return;
  }
  t = evento.keyCode;
  if (t == 9 || t == 16) {
    campo.focus();
    return;
  }
  if (funcao != null && evento.type == "keypress" && t == 13) {
    eval(funcao);
    return;
  }
  if (evento.type == "keypress") {
    return;
  }
  if (evento.type == "keypress" || evento.type == "keyup" || evento.type == "blur") {
    if (campo.value.length == campo.maxLength)
      if (prox != null){
      
        prox.focus();
      }  
      else {
        nOrd = obterIndiceProximoElemento(campo);
        if (nOrd > -1 && event.type != "blur") 
          campo.form.elements[nOrd].focus();
      }
  }
  if ((t>=16&&t<=20) || (t>=33&&t<=39) || (t>=44&&t<=45) || (t>=112&&t<=123) || (t>=144&&t<=145) || t==12)
    return true; 
  return true;
}



function leftTrim(cTexto) {
  var cNovoTexto = "";
  for (var i=0; i < cTexto.length; i++) {
    if (cTexto.substr(i, 1) != " ") { 
      cNovoTexto = cTexto.substr(i);
      break;
    }
  }
  return cNovoTexto;
}

function rightTrim(cTexto) {
  var cNovoTexto = "";
  for (var i = (cTexto.length - 1); i > -1 ; i--) {
    if (cTexto.substr(i, 1) != " ") { 
      cNovoTexto = cTexto.substr(0, i + 1);
      break;
    }
  }
  return cNovoTexto;
}

function allTrim(cTexto) {
  return leftTrim(rightTrim(cTexto));
}
function preencheZeros(Numero, Tamanho) {

  var Diferenca

  Numero = allTrim(Numero)
  Diferenca = Tamanho - Numero.length
  for (var i=0; i < Diferenca; i++)
    {
    Numero = "0" + Numero
    }

  return Numero

}
function inverter(s) {
  var i, ret;
  ret = "";
  i = s.length - 1;
  while (i >= 0) {
    ret += s.substr(i, 1);
    i--;
  }
  return ret;
}
function eliminarZerosEsquerda(valor) {
  var ret = "";
  var status = 0;
  for (var i = 0; i < valor.length; i++) {
    if (valor.substr(i, 1) != "0")
      status = 1;
    if (status == 1)
      ret += valor.substr(i, 1);
  }
  return ret;
}
function right(s, n) {
  return s.substr(s.length - n, n);
}
function inserirMascara(valor, mascara) {
  var fimValor, fimMascara, posV, posM, ret;
  ret = "";
  posV = 0;
  posM = 0;
  fimValor = false;
  fimMascara = (mascara.length == 0) ? true : false;
  while (posV < valor.length) {
    if (!fimMascara && mascara.substr(posM, 1) != "X") {
      ret += mascara.substr(posM, 1);
      posM++;
      if (posM == mascara.length)
        fimMascara = true;
      }
    else {
      ret += valor.substr(posV, 1);
      posV++;
      posM++;
    }
  }
  return ret;
}
function eliminarCaracteresInvalidos(valor, tipo) {
  var i, ret;
  if (tipo == "9")
    caracteres = "0123456789";
  else if (tipo == "A" || tipo == "a" )
    caracteres = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
  else if (tipo == "L" || tipo == "l" )
    caracteres = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  else if (tipo == "N" || tipo == "n" )
    caracteres = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  else if (tipo == "T" || tipo == "t" )
    caracteres = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ÁáÉéÍíÓóÚúÀàÇçÃãÕõ-=*&#+\/,.;:";
  ret = "";
  for (i = 0; i < valor.length; i++)
    if (tipo == 'x' || tipo == 'X')
      ret += valor.substr(i, 1);
    else
      if (caracteres.indexOf(valor.substr(i, 1), 0) != -1)
        ret += valor.substr(i, 1);
  return ret; 
}
function identBrowser() {
  if (document.all)
	return "ie";
  if (document.layers)
	return "ns4";
  if (document.getElementById)
	return "ns6";
}
function procurarObjetoPorTipo(nome, tipo) {
  var  xx, ii, obj;
  obj = null;
  if (identBrowser() == "ns6") {
    var vetor = document.getElementsByTagName(tipo);
    for (ii = 0; vetor.item(ii) != null; ii++) {
      if (nome == vetor.item(ii).getAttribute("name"))
        return vetor.item(ii);
    }
  }
  else {
    xx = (!document.all);
    if (!xx) 
      for (ii = 0; ii < document.all.length; ii++)
        if (document.all[ii].nodeName == tipo)
            if (document.all[ii].name == nome || document.all[ii].id == nome)
              return document.all[ii];
  }
  return obj;
}

function tiraPonto(str,numDecimais) 
//Tira ponto e define o número de casas decimais
{
  for (i = 0; i < str.length; i++) 
  {
    if (str.charAt(i) == ".")
    {
		return str.substring(0,i)+str.substring(i+1,i+numDecimais+1);
	}
  }
  return str;
}


function calculaTotal(campo){

  var a = 0;
  
  if (campo.name == "dependente")
	mascara = "XX";
  else
    mascara = "X.XXX.XXX.XXX.XXX.XXX.XXX.XXX.XXX.XXX,XX";
  msk = right(mascara, campo.value.length);
  campo.value = eliminarCaracteresInvalidos(campo.value, '9');
  campo.value = eliminarZerosEsquerda(campo.value);
  mascara = inverter(mascara);
  virgula = mascara.indexOf(",")
  if (virgula > -1 && campo.value.length > 0)
    campo.value = preencheZeros(campo.value, virgula + 1);
  valor = inverter(campo.value);
  valor = inserirMascara(valor, mascara);
  campo.value = inverter(valor);
  if (campo.value == "")
    {
	campo.value = "";
	}

  a = parseFloat(eliminarCaracteresInvalidos(document.form.valor.value, '9'));
  if ((document.form.valor.value == "") || (document.form.valor.value == null))
	document.form.valor.value= "";
}

function BuscaSubTipo(cod_tipo){
//	var ter = document.frmBusca.subtipo; 
//	alert(cod_tipo);
//	if (cod_tipo == '1'){
//		ter.options[0].style.display = 'none';
//		ter.options[1].style.display = 'none';
//		ter.options[2].style.display = 'none';
//		ter.options[3].style.display = 'none';
//		ter.options[4].style.display = 'none';
//		ter.options[5].style.display = 'none';
//	}	
	   $.get("./buscaSubTipo.asp",
	   { tipo: $("#tipo").val() },
	    function(data){
	     //$("#subtipo").html(data);
		 $("#lblSubTipo .jqTransformSelectWrapper ul").html(data);
	    }
		);
	   $.get("./buscaSubTipo2.asp",
	   { tipo: $("#tipo").val() },
	    function(data){
	     $("#subtipo").html(data);
		 //$("#lblSubTipo .jqTransformSelectWrapper ul").html(data);
	    }
		);

}

jQuery(document).ready(function() {
	
	//Ajax Subtipo
//	 $("#tipo").change(function(){
//	   $.get("./buscaSubTipo.asp",
//	   { tipo: $("#tipo").val() },
//	    function(data){
//	     $("#lblSubTipo").html(data);
//	    }
//	   );
//	 });	
	
	$("#frmContato input[type=text], #frmContato textarea, #frmContato select, #frmContato input[type=password]").blur(function() {
		if ($(this).val()=="") {
			$("#error_"+$(this).attr("id")).fadeIn("fast");
			$(this).addClass("input-error");				 
		} else {
			$("#error_"+$(this).attr("id")).hide();
			$(this).removeClass("input-error");
		}
		
		if ($(this).attr("id")=="email") {
			if (!(/^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$/.test($("#email").val()))) {
				$("#error_email").fadeIn("fast");
				$("#email").addClass("input-error");
			}
		}		
	});	
	
	$("#frmContato").submit(function() {
		$("input[type=text], textarea").removeClass("input-error");
//		$("#error_contato").hide("fast");
		if ($("#nome").val()=="") {
			$("#error_nome").fadeIn("fast");
			$("#nome").addClass("input-error");
			return false;
		} else if (!(/^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$/.test($("#email").val()))) {
			$("#error_email").fadeIn("fast");
			$("#email").addClass("input-error");
			return false;
		} else if ($("#comochegou").val()=="") {
			$("#error_comochegou").fadeIn("fast");
			$("#comochegou").addClass("input-error");
			return false;
		} else if ($("#mensagem").val()=="") {
			$("#error_mensagem").fadeIn("fast");
			$("#mensagem").addClass("input-error");
			return false;
		} else {
			return true;
		}
	});		


	$("#frmAvalie input[type=text], #frmAvalie textarea, #frmAvalie select, #frmAvalie input[type=password]").blur(function() {
		if ($(this).val()=="") {
			$("#error_"+$(this).attr("id")).fadeIn("fast");
			$(this).addClass("input-error");				 
		} else {
			$("#error_"+$(this).attr("id")).hide();
			$(this).removeClass("input-error");
		}
		
		if ($(this).attr("id")=="email") {
			if (!(/^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$/.test($("#email").val()))) {
				$("#error_email").fadeIn("fast");
				$("#email").addClass("input-error");
			}
		}		
	});	
	
	$("#frmAvalie").submit(function() {
		$("input[type=text], textarea").removeClass("input-error");
//		$("#error_contato").hide("fast");
		if ($("#nome").val()=="") {
			$("#error_nome").fadeIn("fast");
			$("#nome").addClass("input-error");
			return false;
		} else if (!(/^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$/.test($("#email").val()))) {
			$("#error_email").fadeIn("fast");
			$("#email").addClass("input-error");
			return false;
		} else if ($("#tel").val()=="") {
			$("#error_tel").fadeIn("fast");
			$("#tel").addClass("input-error");
			return false;
		} else if ($("#tipoimovel").val()=="") {
			$("#error_tipoimovel").fadeIn("fast");
			$("#tipoimovel").addClass("input-error");
			return false;
		} else if ($("#rua").val()=="") {
			$("#error_rua").fadeIn("fast");
			$("#rua").addClass("input-error");
			return false;
		} else if ($("#fase").val()=="") {
			$("#error_fase").fadeIn("fast");
			$("#fase").addClass("input-error");
			return false;
		}else if ($("#mensagem").val()=="") {
			$("#error_mensagem").fadeIn("fast");
			$("#mensagem").addClass("input-error");
			return false;
		} else {
			return true;
		}
	});		
	
	
	$("#frmTrabalhe input[type=text], #frmTrabalhe textarea, #frmTrabalhe select, #frmTrabalhe input[type=password]").blur(function() {
		if ($(this).val()=="") {
			$("#error_"+$(this).attr("id")).fadeIn("fast");
			$(this).addClass("input-error");				 
		} else {
			$("#error_"+$(this).attr("id")).hide();
			$(this).removeClass("input-error");
		}
		
		if ($(this).attr("id")=="email") {
			if (!(/^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$/.test($("#email").val()))) {
				$("#error_email").fadeIn("fast");
				$("#email").addClass("input-error");
			}
		}		
	});	
	
	$("#frmTrabalhe").submit(function() {
		$("input[type=text], textarea").removeClass("input-error");
//		$("#error_contato").hide("fast");
		if ($("#nome").val()=="") {
			$("#error_nome").fadeIn("fast");
			$("#nome").addClass("input-error");
			return false;
		} else if ($("#cpf").val()=="") {
			$("#error_cpf").fadeIn("fast");
			$("#cpf").addClass("input-error");
			return false;
		} else if ($("#endereco").val()=="") {
			$("#error_endereco").fadeIn("fast");
			$("#endereco").addClass("input-error");
			return false;
		} else if ($("#tel").val()=="") {
			$("#error_tel").fadeIn("fast");
			$("#tel").addClass("input-error");
			return false;
		} else if ($("#celular").val()=="") {
			$("#error_celular").fadeIn("fast");
			$("#celular").addClass("input-error");
			return false;
		} else if (!(/^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$/.test($("#email").val()))) {
			$("#error_email").fadeIn("fast");
			$("#email").addClass("input-error");
			return false;
		} else if ($("#cargo").val()=="") {
			$("#error_cargo").fadeIn("fast");
			$("#cargo").addClass("input-error");
			return false;
		} else {
			return true;
		}
	});		
	
});

function addFav(){
var url      = "http://www.singullare.com.br";
var title    = "Singullare Imóveis";
if (window.sidebar) window.sidebar.addPanel(title, url,"");
else if(window.opera && window.print){
	var mbm = document.createElement('a');
	mbm.setAttribute('rel','sidebar');
	mbm.setAttribute('href',url);
	mbm.setAttribute('title',title);
	mbm.click();
}
else if(document.all){window.external.AddFavorite(url, title);}
}

//desabilita menu de opções após clicar no botão direito
function desabilitaMenu(e)
{
if (window.Event)
{
if (e.which == 2 || e.which == 3)
return false;
}
else
{
event.cancelBubble = true
event.returnValue = false;
return false;
}
}

//desabilita botão direito
function desabilitaBotaoDireito(e)
{
if (window.Event)
{
if (e.which == 2 || e.which == 3)
return false;
}
else
if (event.button == 2 || event.button == 3)
{
event.cancelBubble = true
event.returnValue = false;
return false;
}
}

//desabilita botão direito do mouse
if ( window.Event )
document.captureEvents(Event.MOUSEUP);
if ( document.layers )
document.captureEvents(Event.MOUSEDOWN);

document.oncontextmenu = desabilitaMenu;
document.onmousedown = desabilitaBotaoDireito;
document.onmouseup = desabilitaBotaoDireito; 


// Bloqueia o copy
function copy(text2copy) {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
}

function mouseDown(e) {
 if (parseInt(navigator.appVersion)>3) {
  var clickType=1;
  if (navigator.appName=="Netscape") clickType=e.which;
  else clickType=event.button;
  if (clickType!=1) return false;
 }
}
if (parseInt(navigator.appVersion)>3) {
 document.onmousedown = mouseDown;
 if (navigator.appName=="Netscape") 
  document.captureEvents(Event.MOUSEDOWN);
}


function keypresed() {
copy("Singullare Imoveis");
}
document.onkeydown=keypresed;
document.oncontextmenu = new Function("return false;")
