// JavaScript Document
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' deve conter um endereço de e-mail válido.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' deve conter um número.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' deve conter um número entre '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' é obrigatório.\n'; }
  } if (errors) alert('O(s) seguinte(s) erro(s) ocorreu(ram):\n'+errors);
  document.MM_returnValue = (errors == '');
}

function janela(htm){
window.open(htm,"janela","width=450,height=350,scrollbars=yes");
}

function seleciona(url) {
document.location.href=url;
}

function centraliza(id,w){
	var alinha = (document.documentElement.clientWidth - w) / 2;
	if(alinha < 0){document.getElementById(id).style.left = 0}
	else{document.getElementById(id).style.left = alinha + "px"}
/*	alert(document.documentElement.clientWidth);
	return;
	*/
}

function habilita()
  {  
  if(document.form.nome_dest.value.length == 0 | document.form.email_dest.value.length == 0 | document.form.nome_envio.value.length == 0)
    {
    document.form.Submit.disabled = true
	}
	else
	{
    document.form.Submit.disabled = false
	}
  }
  
function verifica_busca(n){
	if (n == 1){
	document.busca2.condterrenos.disabled = true;
	document.busca2.condcasas.disabled = false;
//	alert(document.busca2.condcasas.options[0].value);
	}
	else if (n == 2){
	document.busca2.condcasas.disabled = true;
	document.busca2.condterrenos.disabled = false;
//	alert(document.busca2.condterrenos.options[0].value)
	}
}


function escolhe(){
for (i=arguments.length-1;i>=0; i--){

if (arguments[i].disabled == false){
//alert(arguments[i].disabled);
if (arguments[i].selectedIndex != -1){
var selectedOptionvalue = arguments[i].options[arguments[i].selectedIndex].value;

if (selectedOptionvalue != "#"){
document.busca2.submit;
break
}
else{
alert("Selecione um Condomínio para efetuar a busca!");
}
}
}
}
}


//------------------------------------------- Minha Lista -------------------------------------------------

//function Selecao( nome, valor, expira, excluir, path, domain, secure )
function Selecao(nome, valor, expira, excluir)
{
var data = new Date();
var val = valor;
var msg = "";
var msg1;
data.setTime(data.getTime());

//alert(document.cookie);

if (document.cookie.match(eval("/" + escape(nome) + "=/"))) {
	var o_cookie = document.cookie;
	var o_cookie = unescape(o_cookie);
	var vl = o_cookie.split(nome+"=");

	var vl = vl[1].replace(/ASPSESSIONID\w.*/gi,"");
	var vl = vl.replace(/saveit\w.*/gi,"");

	if(excluir == "e"){
	
	valor = vl.replace(valor," ");
	valor = valor.replace("; ","");
	valor = valor.replace(" ;","");
	valor = valor.replace(/[:-@].$/,"");
	valor = valor.replace(/[ ]/gi,"");

	msg1 = "excluído";
	alert(valor);
	
	}else{
	
	if(vl != ""){
	valor = vl.replace("; ","") + ";" + valor;
	}else{
	valor = vl.replace(" ","") + valor;
	valor = valor.replace("; ","");
	}
	
	msg1 = "adicionado";
	msg = "                          OK!\nO imóvel foi " + msg1 + " com sucesso!";
//	alert(valor);
	}


	if (vl.indexOf(val) == -1){
		msg = "                          OK!\nO imóvel foi " + msg1 + " com sucesso!";
	}else{
		msg = "            JÁ CADASTRADO!\nO imóvel já se encontra cadastrado!";
	}

}

/*
set time, it's in milliseconds
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expira ){
expira = expira * 1000 * 60 * 60 * 24;
}

var expira_data = new Date( data.getTime() + (expira) );

if (excluir == "e" || msg == "" || msg.indexOf("OK!") != -1){
document.cookie = nome + "=" + escape( valor ) +
( ( expira ) ? ";expires=" + expira_data.toGMTString() : "" ) 
/*+
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
*/

if(expira < 0){
msg = "Todos os imóveis foram excluídos da Minha Seleção.";
}else if(excluir == "e"){
msg = "                     OK!\nO imóvel foi " + msg1 + " com sucesso!";
}else{
msg = "                       OK!\nO imóvel foi adicionado com sucesso!";
}


var total = valor.split(";");

if(total.length <= 1){
document.getElementById("minha_selecao").innerHTML = "<b>" + total.length + "</b>" + " imóvel";
}else{
document.getElementById("minha_selecao").innerHTML = "<b>" + total.length + "</b>" + " imóveis";
}

//document.getElementById(nome).href = "selecao_granja_viana.asp"
document.getElementById(nome).disabled = false;
}



if(msg1 == "excluído"){
		document.location = "selecao_imoveis_granja_viana.asp"
}

alert(msg);

}
//---------------------------------------------------------------------------------------------------------------------


//-->
