// ARQUIVO DE SCRIPT -- VANDERLEI 13-04-2009

var divConteudo = "conteudo_pagina";
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);
}

// funcao que cria objeto do 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;
}
//----------------------------------------------

// recebe a pagina a ser inserida no corpo do site (localizacao/contato)
function getPagina(pag){
	xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange=function()
    	{
    		if(xmlHttp.readyState==4)
      			{
      				document.getElementById(divConteudo).innerHTML = xmlHttp.responseText;
					document.location = "#capistrano";
      			}
			else
				document.getElementById(divConteudo).innerHTML = '<img src="imagens/load.gif" />';
    	}
	
	xmlHttp.open("GET",pag + ".asp",true);
	xmlHttp.send(null);			
}

function getPrincipal(){
	xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange=function()
    	{
    		if(xmlHttp.readyState==4)
      			{
      				document.getElementById(divConteudo).innerHTML = xmlHttp.responseText;					
      			}
			else
				document.getElementById(divConteudo).innerHTML = '<img src="imagens/load.gif" />';
    	}
	
	xmlHttp.open("GET","home.asp",true);
	xmlHttp.send(null);			
}

/* ATUALIZAÇÃO DE NEWSLETTER */

function AtualizaNews()
{	
	var nome = document.getElementById("nomeNews");
	var email = document.getElementById("emailNews");
	var icIncluir = document.getElementById("incluirNews");

	if(ValidarCampo(nome,"Informe seu nome"))
		if (!checkMail(email)){
		  alert('email incorreto!');
		  email.focus();
		}
		else{
			xmlHttp=GetXmlHttpObject();
			xmlHttp.onreadystatechange=function()
				{
					if(xmlHttp.readyState==4)
						{
							if (xmlHttp.responseText == ""){
								email.value = "";
								nome.value = "";
								if(icIncluir.checked)
									alert("Cadastro realizado com sucesso");
								else
									alert("Registro exclu\u00eddo com sucesso");
							}
							else
								alert(xmlHttp.responseText)
						}
				}
			url = "insere_exclui_newsletter.asp?email="+email.value+"&nome="+nome.value+"&icIncluir="+icIncluir.checked;
		
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			
		}
}

// envia a mensagem da 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{
						form.submit();
				}		
			}
		}	
	}   
}

//envio de senha para email do cliente
function pega_senha(idEmail){
	var email = document.getElementById(idEmail);
	
	xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange=function()
    	{
    		if(xmlHttp.readyState==4)
      			{
					if (xmlHttp.responseText == 'Foi' )
					{
						alert('Um Email foi enviado contendo sua senha de acesso!');
					}
					else
					{
						alert('O Email informado n\u00e3o est\u00e1 cadastrado!');
					}
      			}
    	}
	
	url = "pega_senha.asp?email"+email.value;

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

//valida email ------------
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 ValidarCampo(campo,msg_erro){
	if(campo.value == ""){
		alert(msg_erro);
		campo.focus();
		return false;
	}	
	else
		return true;
}

/* TABELAS */

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.');
							}
						}
				}
			
			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 getPaginaEscolha(divEmail,divSenha){
	var email = document.getElementById(divEmail);
	var senha = document.getElementById(divSenha);
	
	if(ValidarCampo(email,' Informe o email cadastrado.'))
	  if(ValidarCampo(senha,'Informe sua senha'))
	  {
		xmlHttp=GetXmlHttpObject();
		xmlHttp.onreadystatechange=function()
			{
				if(xmlHttp.readyState==4)
					{      				
						if (xmlHttp.responseText == 'Nada encontrado!' )
						{
							alert('Login ou senha inv\u00e1lido!');
						}
						else{
							document.getElementById(divConteudo).innerHTML = xmlHttp.responseText;
							document.location = "#capistrano";	
						}
					}
			}
		url = "escolha_tabela.asp?email="+email.value+"&senha="+senha.value;
	
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);	
	  }
}

function lembra_senha(){
	var area = document.getElementById('esq_senha');
	area.style.display = 'block';
}

function setOpcao(vl){
	opcao = vl;
	if (opcao == 'venda')
	{
		document.getElementById("combolanc").style.display = "block";
	}
	else
	{
		document.getElementById("combolanc").style.display = "none";		
	}
}

function AcessarTabelas(icAcessar){
	xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange=function()
    	{
    		if(xmlHttp.readyState==4)
      			{
					if(xmlHttp.responseText == "logado")
						getPagina('escolha_tabela');
					else{
      					document.getElementById(divConteudo).innerHTML = xmlHttp.responseText;
						document.location = "#capistrano";	
					}
      			}
			else
				document.getElementById(divConteudo).innerHTML = '<img src="imagens/load.gif" />';
    	}
	
	xmlHttp.open("GET","venda_login.asp?acessar=" + icAcessar,true);
	xmlHttp.send(null);	
}

function getEscolha(){
	var id_edif = document.getElementById("combolancamento").value;
	
	if (opcao == "revenda")
	{
		window.open("admin/tabela_revenda.asp");
	}
	else
	{
		if (opcao == "venda")
			if (id_edif != 0)
				window.open("admin/venda_print.asp?idEdificio="+id_edif);
			else
				alert('Selecione um edifício!');
		else
			alert('Selecione um tipo de tabela!');
	}		
}

/* FINAL DE TABELAS */

function showCampoSenha(icShow){
	var mostrar = "none";
	
	if (icShow)
		icShow = "block";		
		
	document.getElementById("informeEmail").style.display = icShow;	
	
	if(icShow){
		document.getElementById("infoEmail").value = "Informe seu email";
		document.getElementById("infoEmail").focus();	
	}
}

function getEmpreendimentos(querystring){
	xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange=function()
    	{
    		if(xmlHttp.readyState==4)
      			{
      				document.getElementById(divConteudo).innerHTML = xmlHttp.responseText;
					document.location = "#conteudo_pagina";
      			}
    	}
	
	url = "obras.asp"+querystring;
	
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

/* ACOMPANHAMENTO DE OBRAS */

function MostrarObra(querystring){
	xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange=function()
    	{
    		if(xmlHttp.readyState==4)
      			{
      				document.getElementById(divConteudo).innerHTML = xmlHttp.responseText;
					document.location = "#conteudo_pagina";
      			}
    	}
	
	url = "visuEdificio.asp"+querystring;

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

function setImg(img,desc,altura,largura){	
	document.getElementById("imagem").style.height = altura + "px";
	document.getElementById("imagem").style.width = largura+"px";
	document.getElementById("ds").innerHTML = desc;	
	document.getElementById("imagem").src = img;
}

function muda_data(obj,id){
	var query = obj.value;
	MostrarObra('?id='+id+'&'+query);
}

/* FINAL DE ACOMPANHAMENTO */

/* BUSCA POR EMPREENDIMENTO */

function PesEmpreendimento(){
	obj = document.getElementById('pesEmpreendimento');
	if(ValidarCampo(obj,'Selecione o empreendimento')){
		vl = obj.value.split("#")
		if (vl[1] == "1")
			MostrarObra('?id=' + vl[0]);
		else
			window.open('lancamentos/index.asp?id='+vl[0]);			
	}
}

/* SAC */

function SetSac(icCasa){
	var nmE = document.getElementById("nomeEdificio") 
	var nmA = document.getElementById("apto")
	if(icCasa){
		//nmE.style.display = "none";		
		nmE.style.visibility = "hidden";	
		nmA.style.display = "none";	
		nmA.value = "";
		nmE.value = "";
	}	
	else{
		//nmE.style.display = "block";
		nmA.style.display = "block";
		nmE.style.visibility = "visible";
	}
}

// SAC - FORMULARIO ---------------
function sendSAC(form){
	var validacao = true;
	with(form){
		if(!document.getElementById("icCasa").checked){
			if(!ValidarCampo(v_nome_edificio,"Informe o nome do edif\u00edcio"))
				validacao = false
			else
				if(!ValidarCampo(v_apto,"Informe o numero do apartamento"))
					validacao = false;					
		}
		
		if(validacao){	
			if(ValidarCampo(v_end_imovel,"Informe o endereço do im\u00f3vel"))
				if(ValidarCampo(v_nome,"Informe seu nome"))
					if((v_telefone.value == "")&&(v_cel.value == "")&&(v_nextel.value == "")){
						alert('Informe ao menos um numero para contato (Tel/Cel/Nextel)');
						v_telefone.focus();
						return false
					}
					else{
						if (!checkMail(v_email)){
						  alert('email incorreto!');
					  	  v_email.focus();
				  		}
						else
							if(ValidarCampo(v_assunto,"Informe o assunto"))
								if(ValidarCampo(v_texto,"Informe o texto")){
									submit();
									reset();
								}
					}
			 
		}
		
		
	}//FINAL WITH   
}//FINAL FUNCTION

window.setTimeout(function () {
			getPrincipal();
}, 200)	
