var opcao = "";
var AcaoNews = "inclui";

function AbreJanela(url, width, height, nome, scrollbars) {
	var top; var left;
	top = ( (screen.height/2) - (height/1.55) )
	left = ( (screen.width/2) - (width/2) )
	window.open(url, nome,'width='+width+',height='+height+',scrollbars='+scrollbars+',toolbar=no,location=no,status=no,menubar=no,resizable=no,left='+left+',top='+top);
}

function navegacao(pag){
	var ind = location.href.indexOf("&pag=");
	var url;
	
	if(ind > -1)	
		url = location.href.substring(0,ind);
	else
		url = location.href;
				
	url = url.replace("#conteudo","");
	location.href = url + "&pag=" + pag + "#conteudo";	
}

/*PAGINA DE CONTATO*/
function sendMSG(form){
	with(form){
		if (v_nome.value == ""){
			alert('Informe o nome!');
			v_nome.focus();
		}
		else{
			if (! checkMail(v_email)){
				alert('email incorreto!');
				v_email.focus();
			}
			else{
				if (v_mensagem.value == ""){
					alert('Informe a mensagem!');
					v_mensagem.focus();
				}else{
						document.form.submit();
				}		
			}
		}	
	}   
}

function checkMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string"){
        if(er.test(mail)){ return true; }
    }else if(typeof(mail) == "object"){
        if(er.test(mail.value)){ 
                    return true; 
                }
    }else{
        return false;
        }
}

function vEmail(campo){
	if(checkMail(campo.value))
		return true;
	else{
		alert('Email inválido');
		campo.focus();
		return false;	
	}	
}

function vField(campo,msgErro){
	if(campo.value != "")
		return true;
	else{
		alert(msgErro);
		campo.focus();
		return false;	
	}	
}

/*---OBJETOS DE MANIPULACAO VIA AJAX--*/
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function getNewsletter(email_obj, nome_obj)
{
	var email = document.getElementById(email_obj);
	var nome = document.getElementById(nome_obj);
	if ((email.value != "")&&(nome.value != ""))
	{
	xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange=function()
    	{
    		if(xmlHttp.readyState==4)
      			{
					if(xmlHttp.responseText == ""){
						alert('Cadastro realizado com sucesso');
						email.value = "";
      					nome.value = "";
					}
				}
    	}
	url = "insere_exclui_newsletter.asp?email="+email.value+"&icIncluir=true&nome="+nome.value;

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}
	else
	{
		alert('Informe o seu nome e seu email!');
		nome.focus();
	}
}

function AcessoRestrito(email,senha){
	var email = document.getElementById(email);
	var senha = document.getElementById(senha);
		
	if(vEmail(email))
		if(vField(senha,'Informe sua senha')){
			xmlHttp=GetXmlHttpObject();
			xmlHttp.onreadystatechange=function()
				{
					if(xmlHttp.readyState==4){
						if(xmlHttp.responseText == "false")
							alert('Login ou senha inválidos');
						else{
							if(location.href.indexOf("sair") > -1)
								location.href = "index.asp";
							else
								window.location.reload();	
						}					
					}					
				}
			url = "acessarSistema.asp?email="+email.value+"&senha="+senha.value;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		}
}

function EnviarCadRestrito(form){
	var flag = false;
	with(form){
		if(vField(cad_nome,'Informe seu nome'))
			if(vEmail(cad_email))
				if(vField(cad_senha,'Informe sua senha'))
					flag = true;	
	}	
	return flag;
}

function getPaginaEscolha(objEmail,objSenha){
	if (validaForm_login(objEmail,objSenha))
	{
		var ind = location.href.indexOf("?pagina=");
		var url = location.href.substring(ind+8,location.href.length);
			
		xmlHttp=GetXmlHttpObject();
		xmlHttp.onreadystatechange=function()
			{
				if(xmlHttp.readyState==4)
					{    
						
						if (xmlHttp.responseText == 'Nada encontrado!' )
						{
							alert('Login ou senha inválido!');
						}
						else
							if((ind == -1)||(url == "home"))
								location.href = "index.asp?pagina=tabela";
							else
								document.getElementById('conteudo').innerHTML = xmlHttp.responseText;
					}
			}
		url = "escolha_tabela.asp?email="+objEmail.value+"&senha="+objSenha.value;
	
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);	
	}
}

function lembra_senha(){
	var area = document.getElementById('esq_senha');
	area.style.display = 'block';
}

function solicita_cadastro(form){
	with(form){
		if((creci.value == "")||(imobiliaria.value == "")||(telefone.value == "")||(responsavel.value == "")||(email_imobiliaria.value == "")||(senha.value == ""))
			alert('\xc9 necess\xe1rio o preenchimento de todos os campos!');
		else{
			xmlHttp=GetXmlHttpObject();
			xmlHttp.onreadystatechange=function()
				{
					if(xmlHttp.readyState==4)
						{
							if (xmlHttp.responseText == 'Foi' )
							{
								alert('Solicita\xe7\xe3o enviada! Aguarde nosso contato.');
								email_imobiliaria.value = "";
								imobiliaria.value = "";
								creci.value = "";
								telefone.value = "";
								senha.value = "";
								responsavel.value = "";
							}
						}
				}
			url = "solicita_cadastro.asp?email="+email_imobiliaria.value+"&imobiliaria="+imobiliaria.value+"&creci="+creci.value+"&telefone="+telefone.value;
			url += "&senha="+senha.value+"&responsavel="+responsavel.value;
					
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);				
		}					
	}
}

function validaForm_login(email,senha){
		if ((email != undefined) && ( senha != undefined))
			{
				if(email.value == ""){alert("Por favor, digite o email cadastrado."); email.focus();  return false;}
				if(senha.value == ""){alert("Por favor, digite sua senha."); senha.focus(); return false;}
			}
		return true;
}

function getEscolha(){
	var id_edif = document.getElementById("combolancamento").value;
	xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange=function()
    	{
    		if(xmlHttp.readyState==4)
      			{
      				document.getElementById(divConteudo).innerHTML = xmlHttp.responseText;
      			}
    	}
	
	if (opcao == "revenda")
	{
		imprimir("admin/tabela_revenda.asp");
	}
	else
	{
		if (opcao == "venda")
			if (id_edif != 0)
				imprimir("admin/venda_print.asp?idEdificio="+id_edif);
			else
				alert('Selecione um empreendimento!');
		else
			alert('Selecione um tipo de tabela!');
	}
	

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);			
}

function imprimir(pagina){
	location.href=pagina;
}


function setOpcao(vl){
	opcao = vl;
	if (opcao == 'venda')
	{
		document.getElementById("combolanc").style.display = "block";
	}
	else
	{
		document.getElementById("combolanc").style.display = "none";		
	}
}

function seleciona_obra(){
	id = document.getElementById('obras').value;
	location.href = "index.asp?pagina=acompanheObra&id="+id;	
}

function LigamoVoce(nm,tel){
	var nome = document.getElementById(nm);
	var telefone = document.getElementById(tel);
	if(vField(nome,'Informe seu nome'))
		if(vField(telefone,'Informe seu telefone')){
			xmlHttp=GetXmlHttpObject();
			xmlHttp.onreadystatechange=function()
				{
					if(xmlHttp.readyState==4)
						{
							if (xmlHttp.responseText == 'true' )
							{
								alert('Solicitação de telefonema realizada com sucesso, em  breve entraremos em contato');
								telefone.value = "";
								nome.value = "";
							}
						}
				}
			
			url = "ligamos_enviar.asp?nome_tel="+nome.value+"&tel="+telefone.value;		
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		}	
}

function SetPhoto(img){
	document.getElementById("imgVisualizada").src = img.src.replace("/m/","/g/");	
	document.getElementById("imgVisualizada").title = img.title;
	document.getElementById("descImg").innerHTML = img.title;	
}
