function subBackWindow() {
  history.back();
}
function subPrintWindow() {
  window.print();
}
function subImagem(image, width, height) {
  parent.document.getElementById("imagemPrincipal").src = image;
  parent.document.getElementById("imagemPrincipal").width = width;
  parent.document.getElementById("imagemPrincipal").height = height;
}
function trim(string) {
  var re= /^\s*|\s*$/g;
  return string.replace(re,"");
}
function validateEmail(e) {
  if (e != "") {
    var objRegExp = /^.+@.+\..{2,3}$/;
    return objRegExp.test(e);
  } else {
    return true;
  }
}
function frmContactos_Validate() {
  if(trim(document.getElementById("Contactos1_tfNome").value) == "" || trim(document.getElementById("Contactos1_tfEmail").value) == "" || trim(document.getElementById("Contactos1_tfTelefone").value) == "" || trim(document.getElementById("Contactos1_tfAssunto").value) == "") {
    alert ("Não é possível concluír o processo.\nTodos os campos de preenchimento obrigatório.");
    return false;
  }
  if(!validateEmail(document.getElementById("Contactos1_tfEmail").value)) {
    alert("Não é possível enviar o formulário.\nIntroduza um endereço de e-mail válido.");
    return false;
  }
  return true;
}
function frmPesquisaRapida_Validate() {
  if(document.getElementById("PesquisaRapida1_tfReferencia").value.length == 0) {
    if(document.getElementById("PesquisaRapida1_ddlFinalidade").value == "") {
      alert("Não é possível realizar a pesquisa.\nSeleccione a finalidade.");
      return false;
    } 
    if(document.getElementById("PesquisaRapida1_ddlTipoImovel").value == "") {
      alert("Não é possível realizar a pesquisa.\nSeleccione o tipo de imóvel.");
      return false;
    }
	return true;
  }
}
function frmComprarVender_Validate() {
  if(trim(document.getElementById("QueroVender1_tfNome").value) == "" || trim(document.getElementById("QueroVender1_tfMorada").value) == "" || trim(document.getElementById("QueroVender1_tfTelefone").value) == "" || 
     trim(document.getElementById("QueroVender1_tfEmail").value) == "" || trim(document.getElementById("QueroVender1_tfHorario").value) == "" || trim(document.getElementById("QueroVender1_tfPreco").value) == "" ||
	 trim(document.getElementById("QueroVender1_tfCaracteristicas").value) == "") {
	alert ("Não é possível concluír o processo.\nTodos os campos de preenchimento obrigatório.");
	return false;
  }
  if(!validateEmail(document.getElementById("QueroVender1_tfEmail").value)) {
    alert("Não é possível enviar o formulário.\nIntroduza um endereço de e-mail válido.");
	return false;
  }
  return true;
}
function frmPesquisaAvancada_Validate() {
  var pL, pH;
  if(document.getElementById("PesquisaAvancada1_ddlTipologiaL").selectedIndex != 0 && document.getElementById("PesquisaAvancada1_ddlTipologiaH").selectedIndex != 0) {
    if(document.getElementById("PesquisaAvancada1_ddlTipologiaL").selectedIndex > document.getElementById("PesquisaAvancada1_ddlTipologiaH").selectedIndex){
      alert("Não é possível iniciar o processo.\nIntroduza por favor um intervalo de tipologias válido.");
	  return false;
    }
  }
  if(document.getElementById("PesquisaAvancada1_tfPrecoL").value.length > 0) {
    if(isNaN(document.getElementById("PesquisaAvancada1_tfPrecoL").value * 2)) {
      alert("Não é possível iniciar o processo.\nIntroduza por favor um intervalo de preços válido.");
	  return false;
	} else { 
	  pL = document.getElementById("PesquisaAvancada1_tfPrecoL").value;
	}
  } else { 
    pL = 0;
  }
  if(document.getElementById("PesquisaAvancada1_tfPrecoH").value.length > 0) {
    if(isNaN(document.getElementById("PesquisaAvancada1_tfPrecoH").value * 2)) {
	  alert("Não é possível iniciar o processo.\nIntroduza por favor um intervalo de preços válido.");
	  return false;
	} else {
	  pH = document.getElementById("PesquisaAvancada1_tfPrecoH").value;
	}
  } else {
    pH = 0;
  }
  if(pH > 0) {
    if(pL > pH) {
	  alert("Não é possível iniciar o processo.\nIntroduza por favor um intervalo de preços válido.");
	  return false;
    }
  }
  return true;
}
function subCenterWindow(url, width, height, scr) {
  window.open(url, "", "status=1,scrollbars="+scr+",width="+width+",height="+height+",left="+(screen.width - width) / 2+",top="+(screen.height - height) / 2);
}
function subOpenWindow(url) {
  window.open(url, '', 'location=yes,toolbar=yes,menubar=yes,directories=yes,status=yes,resizable=yes,scrollbars=yes,height='+screen.height+',width='+screen.width, false);
}
function frmWebFormImovel_Validate(f) {
  if(trim(document.getElementById("tfNome").value) == "" || trim(document.getElementById("tfTelefone").value) == "" || trim(document.getElementById("tfEmail").value) == "") {
	alert ("Não é possível concluír o processo.\nIntroduza os campos de preenchimento obrigatório.");
	return false;
  }
  if(!validateEmail(document.getElementById("tfEmail").value)) {
    alert("Não é possível enviar o formulário.\nIntroduza um endereço de e-mail válido.");
	return false;
  }
  return true;
}

/* Método que permite visualizar a imagem de um imóvel*/
function viewThumb(_clientID, _src, _width, _height) {
    // Obtém o objecto da imagem principal
    with (document.getElementById("imagemPrincipal")) {
        if (document.all) {
            style.filter = "blendTrans(duration=2)";
            style.filter = "blendTrans(duration=crossFadeDuration)";
            filters.blendTrans.Apply();
        }
        // Atribui as propriedades da imagem
        src = _src;
        style.width = _width
        style.height = height

        // Aplica a transformação da imagem
        if (document.all) {
            filters.blendTrans.Play();
        }
    }
}