faleConosco = {
	
	nome : '',
	email : '',
	empresa : '',
	estado : '',
	cidade : '',
	telefone : '',
	cmbAssunto : '',
	mensagem : '',
	
	
	procuraParametro : function() {
		if(FuncoesGerais.BuscaParametro('produto')!=''){
			document.getElementById('cmbAssunto').value = 'Orçamento'
			this.subAssuntoCombo('Orçamento');
			this.carregaSubAssunto();
			document.getElementById('cmbSubAssunto').value = FuncoesGerais.BuscaParametro('produto');
		}
	
	},
	
	
	enviar : function(){
		this.limpaValidacao();
		msg = this.valida();
		if (msg == ''){
			classFaleConosco.inserir(this.nome, this.email,this.empresa,this.estado, this.cidade,this.telefone,this.cmbAssunto, this.mensagem).value;
			document.divForm.reset();
			document.getElementById('msgErro').style.display = 'none';
			document.getElementById('divForm').style.display = 'none';
			document.getElementById('msgSucesso').style.display = '';
		}else{
			document.getElementById('msgSucesso').style.display = 'none';
			document.getElementById('msgErro').style.display = '';
		}
	},
	
	
	valida : function(){
		this.nome = document.getElementById('txtNome').value;
		this.email = document.getElementById('txtEmail').value;
		this.estado = document.getElementById('cmbEstado').value;
		this.empresa = document.getElementById('txtEmpresa').value;
		this.cidade = document.getElementById('cmbCidade').value;
		this.telefone = document.getElementById('txtTelDDD').value + '-' + document.getElementById('txtTel').value;
		this.cmbAssunto = document.getElementById('cmbAssunto').value;
		this.subAssunto = document.getElementById('cmbSubAssunto').value;
		this.mensagem = document.getElementById('txtMensagem').value;
		
		msg = '';
		if (this.nome == ''){
			document.getElementById('txtNome').style.backgroundColor="#ecb2b1"
			msg = 'Nome';
		}
		if (FuncoesGerais.ValidaEmail(this.email) == 0){
			document.getElementById('txtEmail').style.backgroundColor="#ecb2b1"
			msg = 'E-mail';
		}
		if (this.empresa == ''){
			document.getElementById('txtEmpresa').style.backgroundColor="#ecb2b1"
			msg = 'Empresa';
		}
		if (this.estado == ''){
			document.getElementById('cmbEstado').style.backgroundColor="#ecb2b1"
			msg = 'Estado';
		}
		if (this.cidade == ''){
			document.getElementById('cmbCidade').style.backgroundColor="#ecb2b1"
			msg = 'Cidade';
		}
		
		if (this.telefone == '-'){
			document.getElementById('txtTelDDD').style.backgroundColor="#ecb2b1"
			document.getElementById('txtTel').style.backgroundColor="#ecb2b1"
			msg = 'Telefone';
		}
		if (this.cmbAssunto == ''){
			document.getElementById('cmbAssunto').style.backgroundColor="#ecb2b1"
			msg = 'Assunto';
		}
		
		if (this.cmbAssunto == 'Orçamento'){
			if (this.subAssunto == ''){
				document.getElementById('cmbSubAssunto').style.backgroundColor="#ecb2b1"
				msg = 'Assunto';
			}else{
				this.cmbAssunto = this.cmbAssunto + ' - ' + this.subAssunto; 
			}
		}

		if (this.mensagem == ''){
			document.getElementById('txtMensagem').style.backgroundColor="#ecb2b1"
			msg = 'Mensagem';
		}
		
		return msg;
	},
	
	limpaValidacao : function(){
		document.getElementById('txtNome').style.backgroundColor="#ffffff";
		document.getElementById('txtEmail').style.backgroundColor="#ffffff";
		document.getElementById('cmbEstado').style.backgroundColor="#ffffff";
		document.getElementById('txtEmpresa').style.backgroundColor="#ffffff";
		document.getElementById('cmbCidade').style.backgroundColor="#ffffff";
		document.getElementById('txtTelDDD').style.backgroundColor="#ffffff";
		document.getElementById('txtTel').style.backgroundColor="#ffffff";
		document.getElementById('cmbAssunto').style.backgroundColor="#ffffff";
		document.getElementById('cmbSubAssunto').style.backgroundColor="#ffffff";
		document.getElementById('txtMensagem').style.backgroundColor="#ffffff";
	},
	
	
	limpaFormulario : function() {
		this.limpaValidacao();
		document.getElementById('msgSucesso').style.display = 'none';
		document.getElementById('msgErro').style.display = 'none';
		document.divForm.reset();
		
	},
	
	carregaCidade : function(estado){
		document.getElementById('cmbCidade').disabled = ''
		response = classCidades.seleciona(estado, '', 2);
		
		
		if(response.error == null){
			var retorno = response.value;
			var ds = retorno;
			if(ds!=null && typeof(ds) == "object" && ds.Tables!=null){
				//define a quantidade de itens do dropdown(1 a mais da quantidade de itens do dataset)
				document.getElementById('cmbCidade').length =ds.Tables[0].Rows.length+1;
				
				//adiciona um item no dropdown
				document.getElementById('cmbCidade').options[0].text= 'Cidade';
				document.getElementById('cmbCidade').options[0].value= '';
				
				//adiciona os itens do dataset no dropdown
				for(var i=0; i<ds.Tables[0].Rows.length; i++){
					var row = ds.Tables[0].Rows[i];
					document.getElementById('cmbCidade').options[i+1].text= row.cidade;
					document.getElementById('cmbCidade').options[i+1].value= row.cidade;
				}
			} 
		}else{
			document.getElementById('cmbCidade').length = 1;
		}
	},
	
	subAssuntoCombo : function(assunto){
		if ((assunto != '') && (assunto == 'Orçamento')){
			document.getElementById('divSubAssunto').style.display = '';
			this.carregaSubAssunto();			
		}else{
			document.getElementById('divSubAssunto').style.display = 'none';
		}
	},
	
	
	
	carregaSubAssunto : function(){
		var tmpi;
		response = classProdutos.seleciona(0, '', 1);
		
		if(response.error == null){
			var retorno = response.value;
			var ds = retorno;
			if(ds!=null && typeof(ds) == "object" && ds.Tables!=null){
				//define a quantidade de itens do dropdown(1 a mais da quantidade de itens do dataset)
				document.getElementById('cmbSubAssunto').length =ds.Tables[0].Rows.length+2;
				
				//adiciona um item no dropdown
				document.getElementById('cmbSubAssunto').options[0].text= 'Produtos';
				document.getElementById('cmbSubAssunto').options[0].value= '';
				
				//adiciona os itens do dataset no dropdown
				for(var i=0; i<ds.Tables[0].Rows.length; i++){
					var row = ds.Tables[0].Rows[i];
					document.getElementById('cmbSubAssunto').options[i+1].text= row.nome;
					document.getElementById('cmbSubAssunto').options[i+1].value= row.nome;
					tmpi = i+1
				}
				
				document.getElementById('cmbSubAssunto').options[tmpi+1].text= 'Outros';
				document.getElementById('cmbSubAssunto').options[tmpi+1].value= 'Outros';

				
				
			} 
		}else{
			document.getElementById('cmbSubAssunto').length = 1;
		}
	}
	

}