cadastro = {
	nome : '',
	sexo : '',
	nascimento : '',
	cpf : '',
	cep : '',
	estado : '',
	cidade : '',
	endereco : '',
	numero : '',
	complemento : '',
	bairro : '',
	telefone : '',
	celular : '',
	comercial : '',
	ramal : '',
	email : '',
	carro : 0,
	marca : '',
	modelo : '',
	ano : '',
	senha : '',
	confirmaSenha : '',
	termo : 0,
	receberNews : 0,
		
	enviar : function(){
		this.limpaValidacao();
		msg = this.valida();
		if (msg == ''){
			classCadastro.inserir(this.nome, this.sexo, this.nascimento, this.cpf, this.cep, this.estado, this.cidade, this.endereco, this.numero, this.complemento, this.bairro, this.telefone, this.celular, this.comercial, this.ramal, this.email, this.carro, this.marca, this.modelo, this.ano, this.senha, this.receberNews).value;
			document.divForm.reset();
			document.getElementById('msgErro').style.visibility = 'hidden';
			//document.getElementById('divForm').style.display = 'none';
			document.getElementById('msgSucesso').style.display = '';
		}else{
			document.getElementById('msgSucesso').style.display = 'none';
			document.getElementById('msgErro').style.visibility = 'visible';
		}
	},
	
	valida : function(){
		this.nome = document.getElementById('txtNome').value;
		if (document.getElementById('radioSexoM').checked){
			this.sexo = 'M';
		}else if (document.getElementById('radioSexoF').checked){
			this.sexo = 'F';
		}
		this.nascimento = document.getElementById('txtAno').value + '-' + document.getElementById('txtMes').value + '-' + document.getElementById('txtDia').value;
		this.cpf = document.getElementById('txtCpf').value;
		this.cep = document.getElementById('txtCep1').value + '-' + document.getElementById('txtCep2').value;
		this.estado = document.getElementById('cmbEstado').value;
		this.cidade = document.getElementById('cmbCidade').value;
		this.endereco = document.getElementById('txtEndereco').value;
		this.numero = document.getElementById('txtNumero').value;
		this.complemento = document.getElementById('txtComplemento').value;
		this.bairro = document.getElementById('txtBairro').value;
		this.telefone1 = document.getElementById('txtTel1DDD').value + '-' + document.getElementById('txtTel1').value;
		this.telefone2 = document.getElementById('txtTel2DDD').value + '-' + document.getElementById('txtTel2').value;
		this.telefoneComercial = document.getElementById('txtTelComercialDDD').value + '-' + document.getElementById('txtTelComercial').value;
		this.ramal = document.getElementById('txtRamal').value;
		this.email = document.getElementById('txtEmail').value;
		if (document.getElementById('radioCarroS').checked){
			this.carro = 1;
		}else if (document.getElementById('radioCarroN').checked){
			this.carro = 2;
		}
		this.marca = document.getElementById('txtMarca').value;
		this.modelo = document.getElementById('txtModelo').value;
		this.ano = document.getElementById('txtAnoCarro').value;
		this.senha = document.getElementById('txtSenha').value;
		this.confirmaSenha = document.getElementById('txtConfirmaSenha').value;
		this.termos = FuncoesGerais.RetornaValorCheckUnico(document.getElementById('chkTermos'));
		this.receberNews = FuncoesGerais.RetornaValorCheckUnico(document.getElementById('chkReceberNews'));
				
		msg = '';
		if (this.nome == ''){
			document.getElementById('txtNome').style.backgroundColor="#ecb2b1"
			msg = 'Nome';
		}
		if (this.sexo == ''){
			document.getElementById('divSexo').style.backgroundColor="#ecb2b1"
			msg = 'Sexo';
		}
		if (FuncoesGerais.ValidaDataSeparada(document.getElementById('txtDia').value, document.getElementById('txtMes').value, document.getElementById('txtAno').value) == 0){
			document.getElementById('txtDia').style.backgroundColor="#ecb2b1"
			document.getElementById('txtMes').style.backgroundColor="#ecb2b1"
			document.getElementById('txtAno').style.backgroundColor="#ecb2b1"
			msg = 'Nascimento';
		}
		if (FuncoesGerais.checaCPF(this.cpf) == false){
			document.getElementById('txtCpf').style.backgroundColor="#ecb2b1"
			msg = 'CPF';
		}
		if (this.cep == '-'){
			document.getElementById('txtCep1').style.backgroundColor="#ecb2b1"
			document.getElementById('txtCep2').style.backgroundColor="#ecb2b1"
			msg = 'CEP';
		}
		if (this.estado == ''){
			document.getElementById('cmbEstado').style.backgroundColor="#ecb2b1"
			msg = 'Estado';
		}
		if (this.cidade == ''){
			document.getElementById('cmbCidade').style.backgroundColor="#ecb2b1"
			msg = 'Cidade';
		}
		if (this.endereco == ''){
			document.getElementById('txtEndereco').style.backgroundColor="#ecb2b1"
			msg = 'Endereco';
		}
		if (this.numero == ''){
			document.getElementById('txtNumero').style.backgroundColor="#ecb2b1"
			msg = 'Numero';
		}
		if (this.bairro == ''){
			document.getElementById('txtBairro').style.backgroundColor="#ecb2b1"
			msg = 'Bairro';
		}
		/*if (this.telefone == '-'){
			document.getElementById('txtTel1DDD').style.backgroundColor="#ecb2b1"
			document.getElementById('txtTel1').style.backgroundColor="#ecb2b1"
			msg = 'Telefone1';
		}
		if (this.celular == '-'){
			document.getElementById('txtTel2DDD').style.backgroundColor="#ecb2b1"
			document.getElementById('txtTel2').style.backgroundColor="#ecb2b1"
			msg = 'Telefone2';
		}
		if (this.comercial == '-'){
			document.getElementById('txtTelComercialDDD').style.backgroundColor="#ecb2b1"
			document.getElementById('txtTelComercial').style.backgroundColor="#ecb2b1"
			msg = 'Telefone Comercial';
		}
		if (this.ramal == ''){
			document.getElementById('txtRamal').style.backgroundColor="#ecb2b1"
			msg = 'Ramal';
		}*/
		if (FuncoesGerais.ValidaEmail(this.email) == 0){
			document.getElementById('txtEmail').style.backgroundColor="#ecb2b1"
			msg = 'E-mail';
		}
		/*if (this.carro == 0){
			document.getElementById('txtCarro').style.backgroundColor="#ecb2b1"
			msg = 'Carro';
		}
		if ((this.marca == '') && (this.carro != 0)){
			document.getElementById('txtMarca').style.backgroundColor="#ecb2b1"
			msg = 'Marca';
		}
		if ((this.modelo == '') && (this.carro != 0)){
			document.getElementById('txtModelo').style.backgroundColor="#ecb2b1"
			msg = 'Modelo';
		}
		if ((this.ano == '') && (this.carro != 0)){
			document.getElementById('txtAnoCarro').style.backgroundColor="#ecb2b1"
			msg = 'Ano';
		}*/
		if (this.senha == ''){
			document.getElementById('txtSenha').style.backgroundColor="#ecb2b1"
			msg = 'Senha';
		}
		if (this.confirmaSenha != this.senha){
			document.getElementById('txtSenha').style.backgroundColor="#ecb2b1"
			document.getElementById('txtConfirmaSenha').style.backgroundColor="#ecb2b1"
			msg = 'Confirma Senha';
		}
		/*if (this.termos == 0){
			document.getElementById('divTermos').style.backgroundColor="#ecb2b1"
			msg = 'Termos';
		}*/
		
		return msg;
	},
	
	limpaCampo : function(campo){
		campo.value = '';
	},
	
	limpaValidacao : function(){
		document.getElementById('txtNome').style.backgroundColor="#ffffff";
		document.getElementById('divSexo').style.backgroundColor="";
		document.getElementById('txtDia').style.backgroundColor="#ffffff";
		document.getElementById('txtMes').style.backgroundColor="#ffffff";
		document.getElementById('txtAno').style.backgroundColor="#ffffff";
		document.getElementById('txtCpf').style.backgroundColor="#ffffff";
		document.getElementById('txtCep1').style.backgroundColor="#ffffff";
		document.getElementById('txtCep2').style.backgroundColor="#ffffff";
		document.getElementById('cmbEstado').style.backgroundColor="#ffffff";
		document.getElementById('cmbCidade').style.backgroundColor="#ffffff";
		document.getElementById('txtEndereco').style.backgroundColor="#ffffff";
		document.getElementById('txtNumero').style.backgroundColor="#ffffff";
		document.getElementById('txtComplemento').style.backgroundColor="#ffffff";
		document.getElementById('txtBairro').style.backgroundColor="#ffffff";
		document.getElementById('txtTel1DDD').style.backgroundColor="#ffffff";
		document.getElementById('txtTel1').style.backgroundColor="#ffffff";
		document.getElementById('txtTel2DDD').style.backgroundColor="#ffffff";
		document.getElementById('txtTel2').style.backgroundColor="#ffffff";
		document.getElementById('txtTelComercialDDD').style.backgroundColor="#ffffff";
		document.getElementById('txtTelComercial').style.backgroundColor="#ffffff";
		document.getElementById('txtRamal').style.backgroundColor="#ffffff";
		document.getElementById('txtEmail').style.backgroundColor="#ffffff";
		document.getElementById('txtCarro').style.backgroundColor="";
		document.getElementById('txtMarca').style.backgroundColor="#ffffff";
		document.getElementById('txtModelo').style.backgroundColor="#ffffff";
		document.getElementById('txtAnoCarro').style.backgroundColor="#ffffff";
		document.getElementById('txtSenha').style.backgroundColor="#ffffff";
		document.getElementById('txtConfirmaSenha').style.backgroundColor="#ffffff";
		document.getElementById('divTermos').style.backgroundColor="";
	},
	
	carregaCidade : function(estado){
		document.getElementById('cmbCidade').disabled = '';
		
		response = classCidades.seleciona(estado, '', 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('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;
		}
	}
}