// JavaScript Document
matriculas = {
	inicia : function(){
		this.carregaCursos();
	},
	
	carregaCursos : function(){
		var ds = classCursos.seleciona(0,'',1).value;
		var drop = document.getElementById('cmbCurso')
		if(ds!=null && typeof(ds) == "object" && ds.Tables!=null){
			drop.length =ds.Tables[0].Rows.length;
			var linha=0;
			for(var i=0; i<ds.Tables[0].Rows.length; i++){
				var row = ds.Tables[0].Rows[i];

				drop.options[i].text= row.titulo;
				drop.options[i].value= row.titulo;
			}
			

		}
	},
	curso : '',
	nome : '',
	sexo : '',
	dtNasc : '',
	cep : '',
	uf : '',
	cidade : '',
	endereco : '',
	numero : '',
	complemento : '',
	bairro : '',
	telContato1 : '',
	telContato2 : '',
	telComercial : '',
	ramal : '',
	email : '',
	news : '',
	
	valida : function(){
		this.curso = document.getElementById('cmbCurso').value;
		this.nome = document.getElementById('txtNome').value;
		if(document.getElementById('radioSexoM').checked)
			this.sexo='M';
		else if(document.getElementById('radioSexoF').checked)
			this.sexo='F';
		this.dtNasc = document.getElementById('txtNasciDD').value + '/' + document.getElementById('txtNasciMM').value + '/' + document.getElementById('txtNasciAAAA').value;
		this.cep = document.getElementById('txtCEP_pt1').value + '-' + document.getElementById('txtCEP_pt2').value;
		this.uf = document.getElementById('cmbEstado').value;
		this.cidade = document.getElementById('txtCidade').value;
		this.endereco = document.getElementById('txtEndereco').value;
		this.numero = document.getElementById('txtEndNumero').value;
		this.complemento = document.getElementById('txtEndComp').value;
		this.bairro = document.getElementById('txtBairro').value;
		this.telContato1 = document.getElementById('txtTelDDD_01').value + '-' + document.getElementById('txtTel_01').value;
		this.telContato2 = document.getElementById('txtTelDDD_02').value + '-' + document.getElementById('txtTel_02').value;
		this.telComercial = document.getElementById('txtTelDDD_03').value + '-' + document.getElementById('txtTel_03').value;
		this.ramal = document.getElementById('txtTelRamal').value;
		this.email = document.getElementById('txtEmail').value;
		if(document.getElementById('news').checked)
			this.news = 'SIM';
		else
			this.news = 'NÃO';
			
		
		if(this.nome=='')
			return 'Preencha corretamente o campo nome';
		if(this.sexo=='')
			return 'Preencha corretamente o campo sexo';
		if(this.dtNasc.length<8)
			return 'Preencha corretamente o campo data de nascimento';
		if(this.cep.length<9)
			return 'Preencha corretamente o campo CEP';
		if(this.uf=='')
			return 'Preencha corretamente o campo estado';
		if(this.cidade=='')
			return 'Preencha corretamente o campo cidade';
		if(this.endereco=='')
			return 'Preencha corretamente o campo endereço';
		if(this.numero=='')
			return 'Preencha corretamente o campo numero';
		if(this.telContato1.length<11)
			return 'Preencha corretamente o campo Telefone de contato 1';
		/*if(this.telContato2.length<11)
			return 'Preencha corretamente o campo Telefone de contato 2';
		if(this.telComercial.length<11)
			return 'Preencha corretamente o campo Telefone comercial';*/
		if(!FuncoesGerais.ValidaEmail(this.email))
			return 'Preencha corretamente o campo e-mail';
			
		return 'ok';
			
	},
	
	envia : function(){
		var validacao = this.valida();
		if(validacao=='ok'){
			var corpoEmail = 'nome: ' + this.nome + '<br>';
			corpoEmail += 'curso: ' + this.curso + '<br>';
			corpoEmail += 'sexo: ' + this.sexo + '<br>';
			corpoEmail += 'dtNasc: ' + this.dtNasc + '<br>';
			corpoEmail += 'cep: ' + this.cep + '<br>';
			corpoEmail += 'estado: ' + this.uf + '<br>';
			corpoEmail += 'cidade: ' + this.cidade + '<br>';
			corpoEmail += 'endereco: ' + this.endereco + '<br>';
			corpoEmail += 'numero: ' + this.numero + '<br>';
			corpoEmail += 'complemento: ' + this.complemento + '<br>';
			corpoEmail += 'telContato1: ' + this.telContato1 + '<br>';
			corpoEmail += 'telContato2: ' + this.telContato2 + '<br>';
			corpoEmail += 'telComercial: ' + this.telComercial + '<br>';
			corpoEmail += 'ramal: ' + this.ramal + '<br>';
			corpoEmail += 'email: ' + this.email + '<br>';
			corpoEmail += 'news: ' + this.news + '<br>';
			//funcoes.sendmail('katia@escolaartemetal.com.br', this.email, 'Arte Metal - Matricula', corpoEmail, '');
			//funcoes.sendmail('escolaartemetal@uol.com.br', 'escolaartemetal@uol.com.br', 'Arte Metal - Matrícula', corpoEmail, '');
			funcoes.sendmail('escolaartemetal@uol.com.br', 'envios@escolaartemetal.com.br', 'Arte Metal - Matrícula', corpoEmail, 'html');
			if(this.news=='SIM')
				classCadastro.Inserir(this.nome , this.email, this.telContato1, 'Arte Metal - Contato', '', 1);
			alert('ok');

			document.getElementById('txtNome').value='';
			document.getElementById('txtNasciDD').value='';
			document.getElementById('txtNasciMM').value='';
			document.getElementById('txtNasciAAAA').value='';
			document.getElementById('txtCEP_pt1').value='';
			document.getElementById('txtCEP_pt2').value='';
			document.getElementById('txtCidade').value='';
			document.getElementById('txtEndereco').value='';
			document.getElementById('txtEndNumero').value='';
			document.getElementById('txtEndComp').value='';
			document.getElementById('txtBairro').value='';
			document.getElementById('txtTelDDD_01').value='';
			document.getElementById('txtTel_01').value='';
			document.getElementById('txtTelDDD_02').value='';
			document.getElementById('txtTel_02').value='';
			document.getElementById('txtTelDDD_03').value='';
			document.getElementById('txtTel_03').value='';
			document.getElementById('txtTelRamal').value='';
			document.getElementById('txtEmail').value='';
		}else{
			alert(validacao);	
		}
	}
}



