// JavaScript Document
SAC ={
	inicia : function(){
		SAC.carregaDropEstado();
		var a = FuncoesGerais.BuscaParametro('a');
		if(a=='')
			a=0;
		SAC.carregaDropSAC(a);
	},
	
	carregaDropSAC : function(selecionado){
				
		var drop  = document.getElementById('dropAssunto')		
		var dt = MasterPage.carregaAssuntos().value;
		var novo = document.createElement("option");
		novo.setAttribute("id", "opcoes");
		novo.value = '';
		novo.text  = 'Selecione';
		drop.options.add(novo);
		if(dt!=null && typeof(dt) == "object"){
			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.idAssunto;
				novo.text  = row.assunto;
				drop.options.add(novo);
			}			
		}
		if(selecionado!=0)
			drop.value=selecionado;
		else
			drop.value='';
	},
	
	carregaDropEstado : function(){
		var drop  = document.getElementById('dropEstadoFale')
		var dt = MasterPage.carregaEstados().value;
		var novo = document.createElement("option");
		novo.setAttribute("id", "opcoes");
		novo.value = '';
		novo.text  = 'Selecione';
		drop.options.add(novo);
		if(dt!=null && typeof(dt) == "object"){
			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.uf;
				novo.text  = row.uf;
				drop.options.add(novo);
			}			
		}
		drop.value='';
	},
	
	carregaDropCidade : function(uf){
		var drop  = document.getElementById('dropCidadeFale')
		var dt = MasterPage.carregaCidades(uf).value;
		var novo = document.createElement("option");
		novo.setAttribute("id", "cidade");
		novo.value = '';
		novo.text  = 'Selecione';
		drop.options.add(novo);
		if(dt!=null && typeof(dt) == "object"){
			for(i=0;i<dt.Rows.length;i++){
				var row = dt.Rows[i];
				var novo = document.createElement("option");
				novo.setAttribute("id", "cidade");
				novo.value = row.cidade;
				novo.text  = row.cidade;
				drop.options.add(novo);
			}			
		}
		drop.value='';
	},
	
	Assunto : '',
	NomeFale : '',
	EmailFale : '',
	EstadoFale : '',
	CidadeFale : '',
	Tel1Fale : '',
	Tel2Fale : '',
	Tel3Fale : '',
	Ramal : '',
	Mensagem : '',
	
	
	validaFale : function(){
		SAC.Assunto = document.getElementById('dropAssunto').options[document.getElementById('dropAssunto').selectedIndex].text;
		SAC.NomeFale = document.getElementById('txtNomeFaleIn').value;
		SAC.EmailFale = document.getElementById('txtEmailFaleIn').value;
		SAC.EstadoFale = document.getElementById('dropEstadoFale').value;
		SAC.CidadeFale = document.getElementById('dropCidadeFale').value;
		SAC.Tel1Fale = document.getElementById('txtDDDFale1').value + '-' + document.getElementById('txtTelFale1').value;
		SAC.Tel2Fale = document.getElementById('txtDDDFale2').value + '-' + document.getElementById('txtTelFale2').value;
		SAC.Tel3Fale = document.getElementById('txtDDDFale3').value + '-' + document.getElementById('txtTelFale3').value;
		SAC.Ramal = document.getElementById('txtRamalFale').value;
		SAC.Mensagem = document.getElementById('txtMensagemFaleIn').value;
		var validado = 'ok';
		if(SAC.Assunto=='Selecione' || SAC.Assunto=='Select'){
			validado = 'erro';
			document.getElementById('dropAssunto').style.backgroundColor = '#ffe2e2';
		}else
			document.getElementById('dropAssunto').style.backgroundColor = 'white';
		if(SAC.NomeFale==''){
			validado = 'erro';
			document.getElementById('txtNomeFaleIn').style.backgroundColor = '#ffe2e2';
		}else
			document.getElementById('txtNomeFaleIn').style.backgroundColor = 'white';
		if(FuncoesGerais.ValidaEmail(SAC.EmailFale)==0){
			validado = 'erro';
			document.getElementById('txtEmailFaleIn').style.backgroundColor = '#ffe2e2';
		}else
			document.getElementById('txtEmailFaleIn').style.backgroundColor = 'white';
		if(SAC.EstadoFale==''){
			validado = 'erro';
			document.getElementById('dropEstadoFale').style.backgroundColor = '#ffe2e2';
		}else
			document.getElementById('dropEstadoFale').style.backgroundColor = 'white';
		if(SAC.CidadeFale==''){
			validado = 'erro';
			document.getElementById('dropCidadeFale').style.backgroundColor = '#ffe2e2';
		}else
			document.getElementById('dropCidadeFale').style.backgroundColor = 'white';
		if(SAC.Tel1Fale.length<9){
			validado = 'erro';
			document.getElementById('txtDDDFale1').style.backgroundColor = '#ffe2e2';
			document.getElementById('txtTelFale1').style.backgroundColor = '#ffe2e2';
		}else{
			document.getElementById('txtDDDFale1').style.backgroundColor = 'white';
			document.getElementById('txtTelFale1').style.backgroundColor = 'white';
		}
		if(SAC.Mensagem==''){
			validado = 'erro';
			document.getElementById('txtMensagemFaleIn').style.backgroundColor = '#ffe2e2';
		}else
			document.getElementById('txtMensagemFaleIn').style.backgroundColor = 'white';
			
		return validado;
	},
	
	enviaFale : function(){
		var validado = SAC.validaFale();
		if(validado=='ok'){
			classSAC.inseri('F', SAC.Assunto, SAC.NomeFale, SAC.EmailFale, '', SAC.EstadoFale, SAC.CidadeFale,'', SAC.Tel1Fale, SAC.Tel2Fale, SAC.Tel3Fale, SAC.Ramal, '',SAC.Mensagem,'Institucional').value;
			var conteudoHTM ='';
			conteudoHTM+='Nome: ' + SAC.NomeFale + '<br>';
			conteudoHTM+='E-mail: ' + SAC.EmailFale + '<br>';
			conteudoHTM+='Estado: ' + SAC.EstadoFale + '<br>';
			conteudoHTM+='Cidade: ' + SAC.CidadeFale + '<br>';
			//conteudoHTM+='Empreendimento: ' + SAC.EmpreendimentoFale + '<br>';
			conteudoHTM+='Telefone 1: ' + SAC.Tel1Fale + '<br>';
			conteudoHTM+='Telefone 2: ' + SAC.Tel2Fale + '<br>';
			conteudoHTM+='Telefone Comercial: ' + SAC.Tel3Fale + '<br>';
			conteudoHTM+='Ramal: ' + SAC.Ramal + '<br>';
			conteudoHTM+='Assunto: ' + SAC.Assunto + '<br>';
			conteudoHTM+='Mensagen: ' + SAC.Mensagem + '<br>';
			//funcoes.sendmail('bruno@playercom.net', SAC.EmailFale, 'EVEN - FALE CONOSCO - ' + SAC.Assunto, conteudoHTM, '');
			
			var dt = MasterPage.carregaDestinatarios(document.getElementById('dropAssunto').value).value;
			if(dt!=null && typeof(dt) == "object"){
				for(i=0;i<dt.Rows.length;i++){
					var row = dt.Rows[i];
					funcoes.sendmail(row.email, SAC.EmailFale, 'EVEN - FALE CONOSCO - ' + SAC.Assunto, conteudoHTM, '');
				}
			}
			
			if(document.getElementById('chkNewsFale').checked)
				classCadastro.inseri(SAC.NomeFale,SAC.EmailFale);
				
			document.getElementById('divSacFormValidacao').style.display = '';
			document.getElementById('divSacForm').style.display = 'none';
			document.getElementById('txtNomeFale').value='';
			document.getElementById('txtEmailFale').value='';
			document.getElementById('dropEstadoFale').value='';
			document.getElementById('dropCidadeFale').length=0;
			document.getElementById('txtRamalFale').value='';
			document.getElementById('txtDDDFale1').value='';
			document.getElementById('txtTelFale1').value='';
			document.getElementById('txtDDDFale2').value='';
			document.getElementById('txtTelFale2').value='';
			document.getElementById('txtDDDFale3').value='';
			document.getElementById('txtTelFale3').value='';
			document.getElementById('txtMensagemFale').value='';
		}else{
			document.getElementById('divSacFormRed').style.display = '';
		}
	},
	
	voltarFale : function(){
		document.getElementById('divSacFormValidacao').style.display = 'none';
		document.getElementById('divSacForm').style.display = '';
		document.getElementById('divSacFormRed').style.display = 'none';
	},
	
	enviaFaleIng : function(){


		document.getElementById('errorFaleIng').style.display = 'none';
        var validado = SAC.validaFaleIng();
		
		
		if(validado=='ok'){
			
			classSAC.inseriIngles('F', SAC.NomeFale, SAC.Assunto, SAC.EmailFale, '', '',SAC.Mensagem,'Formulario Ingles').value;
			
			var conteudoHTM ='';
			conteudoHTM+='Assunto: ' + SAC.Assunto + '<br>';
			conteudoHTM+='Nome: ' + SAC.NomeFale + '<br>';
			conteudoHTM+='E-mail: ' + SAC.EmailFale + '<br>';
			conteudoHTM+='Mensagen: ' + SAC.Mensagem + '<br>';
			//funcoes.sendmail('amizrahi@even.com.br', SAC.EmailFale, 'EVEN - CONTACT US', conteudoHTM, '');
			funcoes.sendmail('nuzzi@playercom.net', SAC.EmailFale, 'EVEN CONTACT US - '+SAC.Assunto, conteudoHTM, '');
			
			
			document.getElementById('fIngles').style.display = "none"
			document.getElementById('sIngles').style.display = "block"
			
		}else{
			document.getElementById('errorFaleIng').style.display = '';
		}
	},
	
	validaFaleIng : function(){
		
		SAC.NomeFale = document.getElementById('txtNomeFale').value;
		SAC.EmailFale = document.getElementById('txtEmailFale').value;
		SAC.Assunto = document.getElementById('txtAssuntoFale').value;
		SAC.Mensagem = document.getElementById('txtMensagemFale').value;
	
		
		var validado = 'ok';
		
		if(SAC.NomeFale==''){
			validado = 'erro';
			document.getElementById('txtNomeFale').style.backgroundColor = "#ffe2e2"
		}else
			document.getElementById('txtNomeFale').style.backgroundColor = "white"
		
		
		if(FuncoesGerais.ValidaEmail(SAC.EmailFale)==0){
			validado = 'erro';
			document.getElementById('txtEmailFale').style.backgroundColor = '#ffe2e2';
		}else
			document.getElementById('txtEmailFale').style.backgroundColor = 'white';
			
		if(SAC.Assunto==''){
			validado = 'erro';
			document.getElementById('txtAssuntoFale').style.backgroundColor = '#ffe2e2';
		}else
			document.getElementById('txtAssuntoFale').style.backgroundColor = 'white';	
			
		
		if(SAC.Mensagem==''){
			validado = 'erro';
			document.getElementById('txtMensagemFale').style.backgroundColor = '#ffe2e2';
		}else
			document.getElementById('txtMensagemFale').style.backgroundColor = 'white';
			
		return validado;
	},
	
	limparFormularioIng : function(){
		document.getElementById('txtNomeFale').style.backgroundColor = "white";
		document.getElementById('txtEmailFale').style.backgroundColor = "white";
		document.getElementById('txtAssuntoFale').style.backgroundColor = "white";
		document.getElementById('txtMensagemFale').style.backgroundColor = 'white';
		document.getElementById('errorFaleIng').style.display = 'none';
		document.getElementById('fIngles').style.display = "block"
		document.getElementById('sIngles').style.display = "none"
		document.formIngles.reset();
	},
	
	enviaFaleConduta : function(){

	
        var validado = SAC.validaFaleConduta();
		
		
		if(validado=='ok'){
			
			classSAC.inseri('C', SAC.Assunto, SAC.NomeFale, SAC.EmailFale, '', '', '','', SAC.Tel1Fale, '', '', '', '',SAC.Mensagem,'Institucional').value;
			
			var conteudoHTM ='';
			conteudoHTM+='Assunto: ' + SAC.Assunto + '<br>';
			conteudoHTM+='Nome: ' + SAC.NomeFale + '<br>';
			conteudoHTM+='E-mail: ' + SAC.EmailFale + '<br>';
			conteudoHTM+='Telefone : ' + SAC.Tel1Fale + '<br>';
			conteudoHTM+='Mensagen: ' + SAC.Mensagem + '<br>';
			
			
            funcoes.sendmail('cferro@even.com.br', SAC.EmailFale, 'EVEN - '+SAC.Assunto, conteudoHTM, '');
			funcoes.sendmail('flafraia@even.com.br', SAC.EmailFale, 'EVEN - '+SAC.Assunto, conteudoHTM, '');
			funcoes.sendmail('dmuszkat@even.com.br', SAC.EmailFale, 'EVEN - '+SAC.Assunto, conteudoHTM, '');
			funcoes.sendmail('vfsilva@even.com.br ', SAC.EmailFale, 'EVEN - '+SAC.Assunto, conteudoHTM, '');
			funcoes.sendmail('psano@even.com.br', SAC.EmailFale, 'EVEN - '+SAC.Assunto, conteudoHTM, '');
            funcoes.sendmail('mbelo@even.com.br', SAC.EmailFale, 'EVEN - '+SAC.Assunto, conteudoHTM, '');
			funcoes.sendmail('mbelo@even.com.br', SAC.EmailFale, 'EVEN - '+SAC.Assunto, conteudoHTM, '');
			funcoes.sendmail('pomoura@even.com.br', SAC.EmailFale, 'EVEN - '+SAC.Assunto, conteudoHTM, '');
			funcoes.sendmail('nuzzi@playercom.net', SAC.EmailFale, 'EVEN - '+SAC.Assunto, conteudoHTM, '');
			
			
			
			document.getElementById('formConduta').style.display = "none"
			document.getElementById('fCSucesso').style.display = "block"
		}
	},
	
	validaFaleConduta : function(){
		
		SAC.NomeFale = document.getElementById('txtNomeFaleConduta').value;
		SAC.EmailFale = document.getElementById('txtEmailFaleConduta').value;
		SAC.Assunto = document.getElementById('assuntoConduta').value;
		SAC.Tel1Fale = document.getElementById('txtDDDFale1Conduta').value + '-' + document.getElementById('txtTelFale1Conduta').value;
		SAC.Mensagem = document.getElementById('txtMensagemFaleConduta').value;
	
		
		var validado = 'ok';
		
		if(SAC.NomeFale==''){
			validado = 'erro';
			document.getElementById('txtNomeFaleConduta').style.backgroundColor = "#ffe2e2"
		}else
			document.getElementById('txtNomeFaleConduta').style.backgroundColor = "white"
		
		if(FuncoesGerais.ValidaEmail(SAC.EmailFale)==0){
			validado = 'erro';
			document.getElementById('txtEmailFaleConduta').style.backgroundColor = '#ffe2e2';
		}else
			document.getElementById('txtEmailFaleConduta').style.backgroundColor = 'white';
			
		
		if(SAC.Tel1Fale.length<9){
			validado = 'erro';
			document.getElementById('txtDDDFale1Conduta').style.backgroundColor = '#ffe2e2';
			document.getElementById('txtTelFale1Conduta').style.backgroundColor = '#ffe2e2';
		}else{
			document.getElementById('txtDDDFale1Conduta').style.backgroundColor = 'white';
			document.getElementById('txtTelFale1Conduta').style.backgroundColor = 'white';
		}
			
			
		if(SAC.Mensagem==''){
			validado = 'erro';
			document.getElementById('txtMensagemFaleConduta').style.backgroundColor = '#ffe2e2';
		}else
			document.getElementById('txtMensagemFaleConduta').style.backgroundColor = 'white';
			
		return validado;
	},
	
	limparFormularioConduta : function(){
		document.getElementById('txtNomeFaleConduta').style.backgroundColor = "white";
		document.getElementById('txtEmailFaleConduta').style.backgroundColor = "white";
		document.getElementById('txtMensagemFaleConduta').style.backgroundColor = 'white';
		document.formConduta.reset();
	}
}