vendaTerreno = {
	map : null,
	geocoder : null,
	enderecoMapa : '',
	
	inicia : function(){
		if (GBrowserIsCompatible()) {
			vendaTerreno.map = new GMap2(document.getElementById("divMapa"));
			vendaTerreno.geocoder = new GClientGeocoder();
			vendaTerreno.map.addControl(new GSmallMapControl());
			vendaTerreno.map.addControl(new GMapTypeControl());
			vendaTerreno.map.setCenter(new GLatLng(-23.553948,-46.696359), 15);
		}
	},
	
	carregaDropCidade : function(uf){
		if(uf==''){
			FG.E('divVendaEndereco').style.display='none';
			FG.E('cmbCidade').lenght=0;
		}else{
			FG.E('cmbCidade').lenght=0;
			venda_seu_terreno.carregaCidades(uf,vendaTerreno.carregaDropCidadeRetorno);
		}
	},
	
	carregaDropCidadeRetorno : function(retorno){
		var dt = retorno.value;
		if(dt!=null && typeof(dt) == "object"){
			var drop = FG.E('cmbCidade');
			
			var padrao = document.createElement("option");
			padrao.setAttribute("id", "opcoes");
			padrao.value = '';
			padrao.text  = 'Selecione';
			padrao.select = true;
			drop.options.add(padrao);
			
			for(i=0;i<dt.Rows.length;i++){
				var row = dt.Rows[i];
				var novo = document.createElement("option");
			    novo.setAttribute("id", "opcoes");
			    novo.value = row.id_cidade;
			    novo.text  = row.cidade;
				drop.options.add(novo);
			}			
		}
	},
	
	abreDivEndereco : function(){
		if(FG.E('cmbCidade').value!=''){
			FG.E('divVendaEndereco').style.display='';
		}else
			FG.E('divVendaEndereco').style.display='none';
	},
	
	idCidade :0,
	nome :'',
	email :'',
	endereco :'',
	latitude :'',
	longitude :'',
	telefone :'',
	telefone2 :'',
	telefoneComercial :'',
	ramal :'',
	tipo :'proprietario',
	corretora :'',
	pontoDeReferencia :'',
	areaDoTerreno :'',
	nContribuiente :'',
	linkComFotos :'',
	preco  :'',
	
	carregaMapa : function(){
		if (GBrowserIsCompatible()) {
			FG.E('cmbEstadoBox').value=FG.E('ctl00_ContentPlaceHolder1_cmbEstado').value;
			FG.E('cmbCidadeBox').value=FG.E('cmbCidade').options[FG.E('cmbCidade').selectedIndex].text;
			var endereco = FG.E('txtNome').value + ' ' + FG.E('cmbCidade').options[FG.E('cmbCidade').selectedIndex].text + '-' + FG.E('ctl00_ContentPlaceHolder1_cmbEstado').value;
			vendaTerreno.enderecoMapa = endereco;
			if (vendaTerreno.geocoder) {
				vendaTerreno.geocoder.getLatLng(
				endereco,
					function(point) {
						if (!point) {
							alert(endereco + " não encontrado");
							FG.E('aVendaProseguir').style.display='none';
							FG.E('aVendaProseguir2').style.display='none';
						} else {
							vendaTerreno.latitude = point.lat();
							vendaTerreno.longitude = point.lng();
							vendaTerreno.map.setCenter(point, 16);
							var marker = new GMarker(point);
							vendaTerreno.map.addOverlay(marker);
							FG.E('aVendaProseguir').style.display='';
							FG.E('aVendaProseguir2').style.display='';
					}				   
				});				
			}
		}
	},
	
	trocaTipo : function(valor){
		FG.E('imgVendaCorretor').style.display='none';
		FG.E('imgVendaProprietario').style.display='none';
		FG.E('imgVendaIndicacao').style.display='none';
		vendaTerreno.tipo = valor;
		if(vendaTerreno.tipo=='proprietario'){
			FG.E('liCorretor').style.visibility='hidden';
			FG.E('imgVendaProprietario').style.display='';
		}else if(vendaTerreno.tipo=='indicacao'){
			FG.E('liCorretor').style.visibility='hidden';
			FG.E('imgVendaIndicacao').style.display='';
		}else{
			FG.E('liCorretor').style.visibility='';
			FG.E('imgVendaCorretor').style.display='';
		}
	},
	
	valida : function(){
		vendaTerreno.idCidade = FG.E('cmbCidade').value;
		vendaTerreno.nome = FG.E('txtNomeBox').value;
		vendaTerreno.email = FG.E('txtEmailBox').value;
		vendaTerreno.endereco = FG.E('txtNome').value;
		vendaTerreno.telefone = FG.E('txtTelefone1Box').value;
		vendaTerreno.telefone2 = FG.E('txtTelefone2Box').value;
		vendaTerreno.telefoneComercial = FG.E('txtTelefoneComercialBox').value;
		vendaTerreno.ramal = FG.E('txtRamalBox').value;
		vendaTerreno.corretora = FG.E('txtCorretoraBox').value;
		vendaTerreno.pontoDeReferencia = FG.E('txtPontoReferenciaBox').value;
		vendaTerreno.areaDoTerreno = FG.E('txtAreaTerrenoBox').value;
		vendaTerreno.nContribuiente = FG.E('txtCadastroPrefeituraBox').value;
		vendaTerreno.linkComFotos = FG.E('txtLinkBox').value;
		vendaTerreno.preco = FG.E('txtPrecoBox').value;
		
		var validado='ok';
		
		if(vendaTerreno.nome==''){
			validado = 'erro';
			document.getElementById('txtNomeBox').style.backgroundColor = '#ffe2e2';
		}else
			document.getElementById('txtNomeBox').style.backgroundColor = 'white';
			
		if(FuncoesGerais.ValidaEmail(vendaTerreno.email)==0){
			validado = 'erro';
			document.getElementById('txtEmailBox').style.backgroundColor = '#ffe2e2';
		}else
			document.getElementById('txtEmailBox').style.backgroundColor = 'white';
			
		if(vendaTerreno.telefone==''){
			validado = 'erro';
			document.getElementById('txtTelefone1Box').style.backgroundColor = '#ffe2e2';
		}else
			document.getElementById('txtTelefone1Box').style.backgroundColor = 'white';
			
		if(vendaTerreno.nContribuiente==''){
			validado = 'erro';
			document.getElementById('txtCadastroPrefeituraBox').style.backgroundColor = '#ffe2e2';
		}else
			document.getElementById('txtCadastroPrefeituraBox').style.backgroundColor = 'white';
			
		
			
		return validado;
	},
	
	envia : function(){
		var validado = vendaTerreno.valida();
		if(validado=='ok'){
			classTerrenos.inseri(vendaTerreno.idCidade, vendaTerreno.nome, vendaTerreno.email, vendaTerreno.endereco, vendaTerreno.latitude, vendaTerreno.longitude,vendaTerreno.telefone, vendaTerreno.telefone2,vendaTerreno.telefoneComercial, vendaTerreno.ramal, vendaTerreno.tipo, vendaTerreno.corretora,vendaTerreno.pontoDeReferencia, vendaTerreno.areaDoTerreno, vendaTerreno.nContribuiente, vendaTerreno.linkComFotos, vendaTerreno.preco).value;
			var conteudo='Estado: ' + FG.E('cmbEstadoBox').value + '<br>';
			conteudo+='Cidade: ' + FG.E('cmbCidadeBox').value + '<br>';
			conteudo+='Endereço: ' + FG.E('txtNome').value + '<br>';
			conteudo+='Nome: ' + vendaTerreno.nome + '<br>';
			conteudo+='E-mail: ' + vendaTerreno.email + '<br>';
			conteudo+='Telefone: ' + vendaTerreno.telefone + '<br>';
			conteudo+='Telefone 2: ' + vendaTerreno.telefone2 + '<br>';
			conteudo+='Telefone Comercial: ' + vendaTerreno.telefoneComercial + '<br>';
			conteudo+='Ramal: ' + vendaTerreno.ramal + '<br>';
			conteudo+='Relação com o terreno: ' + vendaTerreno.tipo + '<br>';
			conteudo+='Corretora: ' + vendaTerreno.corretora + '<br>';
			conteudo+='Ponte de referência: ' + vendaTerreno.pontoDeReferencia + '<br>';
			conteudo+='Area do terreno: ' + vendaTerreno.areaDoTerreno + '<br>';
			conteudo+='N contribuiente: ' + vendaTerreno.nContribuiente + '<br>';
			conteudo+='link fotos: ' + vendaTerreno.linkComFotos + '<br>';
			conteudo+='Preço: ' + vendaTerreno.preco + '<br>';
			var cord = vendaTerreno.latitude + ',' + vendaTerreno.longitude;
			conteudo+='<a href="http://www.even.com.br/mapa.htm?lat=' + vendaTerreno.latitude + '&lon=' + vendaTerreno.longitude + '">Mapa</a>';

			if(FG.E('cmbEstadoBox').value=='MG')
				funcoes.sendmail('gcarvalho@even.com.br', vendaTerreno.email, 'EVEN - OFERTA DE TERRENO', conteudo, '');
			funcoes.sendmail('arondini@even.com.br', vendaTerreno.email, 'EVEN - OFERTA DE TERRENO', conteudo, '');
			funcoes.sendmail('bruno@playercom.net', vendaTerreno.email, 'EVEN - OFERTA DE TERRENO', conteudo, '');

			
			FG.E('divVendaMain').style.height='200px';
			FG.E('divVendaForm').style.display = 'none';
			FG.E('divVendaSucesso').style.display = '';
		}else{
			FG.E('pVendaSeuImovelValidacao').innerHTML = 'Preencha corretamente os campos em vermelho.<br>';
			FG.E('pVendaSeuImovelValidacao').style.color = 'red';
		}
	}
	

	
}