cadastroUsuario = {
	
	 id_cadastro : 0,
	 nome: '',
	 email: '',
	 sexo: '',
	 dt_nascimento: '',
	 cpf: '',
	 cep: '',
	 endereco: '',
	 numero: '',
	 complemento: '',
	 estado: '',
	 cidade: '',
	 telefone: '',
	 senha: '',
	 confirmacaoSenha: '',
	 flg_possui_carro: '',
	 marca_carro: '',
	 modelo: '',
	 ano: '',
	 marca_pneu_carro: '',
	 flg_receber_news: '',
	 flg_validacao:'',

	
	
	limpaValidacao : function(){

		frm = document.form1;
		
		document.getElementById('msgErro').innerHTML='Preencha corretamente os campos em vermelho.';
		frm.nome.style.backgroundColor="#FFFFFF";
		frm.email.style.backgroundColor="#FFFFFF";
		document.getElementById('sexo').style.color="#4c4c4c";
		frm.data_dia.style.backgroundColor="#FFFFFF";
		frm.data_mes.style.backgroundColor="#FFFFFF";
		frm.data_ano.style.backgroundColor="#FFFFFF";
		frm.cpf1.style.backgroundColor="#FFFFFF";
		frm.cpf2.style.backgroundColor="#FFFFFF";
		frm.cep.style.backgroundColor="#FFFFFF";
		document.getElementById('possuiCarro').style.color="#4c4c4c";
		document.getElementById('Marca').style.color="#4c4c4c";
		document.getElementById('Modelo').style.color="#4c4c4c";
		frm.anoCarro.style.backgroundColor="#FFFFFF";
		frm.txtsenha.style.backgroundColor="#FFFFFF";
		frm.confirmacaoSenha.style.backgroundColor="#FFFFFF";	
	},
	
	
	ValidaCadastro : function(){
		 
		 frm = document.form1
		 this.flg_validacao =  "ok"
		 
		 this.erro = '';
		 if (document.form1.txtIdCadastro){
		 	this.id_cadastro = document.form1.txtIdCadastro.value;
		 }
		 this.nome = document.form1.nome.value;
		 this.email = document.form1.email.value;
		 this.sexo = FuncoesGerais.RetornaValorRadio(document.form1.sexo_m);
		 this.dt_nascimento = document.form1.data_ano.value + '-' + document.form1.data_mes.value + '-' + document.form1.data_dia.value;
		 this.cpf = document.form1.cpf1.value + document.form1.cpf2.value ;
		 this.cep = document.form1.cep.value;
		 this.endereco = document.form1.endereco.value;
		 this.numero = document.form1.numero.value;
		 this.complemento = document.form1.complemento.value;
		 this.estado = document.form1.estados.value;
		 this.cidade = document.form1.NomeCampoCidade.value; 
		 this.telefone = document.form1.tel_pre.value + '-' + document.form1.telefone.value ;
		 this.senha = document.form1.txtsenha.value;
		 this.confirmacaoSenha = document.form1.confirmacaoSenha.value; 
		 this.flg_possui_carro = FuncoesGerais.RetornaValorRadio(document.form1.PossuiCarro);
		 this.marca_carro = document.form1.combo_marca_veiculo.value;
		 this.modelo = document.form1.combo_modelo_veiculo.value;
		 this.ano = document.form1.anoCarro.value;
		 this.marca_pneu_carro = document.form1.marca_pneu_carro.value;
		 this.flg_receber_news = FuncoesGerais.RetornaValorCheckUnico(document.form1.news);

		if(this.nome==''){
		frm.nome.style.backgroundColor="#ecb2b1"
		this.flg_validacao =  "erro"
		}
		
		if(FuncoesGerais.ValidaEmail(this.email)==0){
		frm.email.style.backgroundColor="#ecb2b1"
		this.flg_validacao =  "erro"
		}
		
		if(this.sexo==''){
		document.getElementById('sexo').style.color="#ac1411"
		this.flg_validacao =  "erro"
		}
			
		if(FuncoesGerais.ValidaDataSeparada(document.form1.data_dia.value,document.form1.data_mes.value,document.form1.data_ano.value)==0){
		frm.data_dia.style.backgroundColor="#ecb2b1"
		frm.data_mes.style.backgroundColor="#ecb2b1"
		frm.data_ano.style.backgroundColor="#ecb2b1"
		this.flg_validacao =  "erro"
		}
			
		if(FuncoesGerais.checaCPF(this.cpf)==0){
		frm.cpf1.style.backgroundColor="#ecb2b1"
		frm.cpf2.style.backgroundColor="#ecb2b1"
		this.flg_validacao =  "erro"
		}
				
		if(this.cep == ""){
		frm.cep.style.backgroundColor="#ecb2b1"
		this.flg_validacao =  "erro"
		}
		
		
		if(this.flg_possui_carro==""){
		document.getElementById('possuiCarro').style.color="#ac1411"
		this.flg_validacao =  "erro"
		}
		
		
		if(this.flg_possui_carro=='1'){
			if((this.marca_carro=='') || (this.marca_carro=='0')) {
			document.getElementById('Marca').style.color="#ac1411"
			this.flg_validacao =  "erro"	
			}
			
			if((this.modelo=='') || (this.modelo=='0')){
			document.getElementById('Modelo').style.color="#ac1411"
			this.flg_validacao =  "erro"	
			}
			
			if(this.ano==''){
			frm.anoCarro.style.backgroundColor="#ecb2b1"
			this.flg_validacao =  "erro"	
			}
			
		}
		
		if(this.flg_receber_news==''){
			this.flg_receber_news = 0;
		}else{
			this.flg_receber_news = 1;
		}
	
		
		if(this.senha==""){
		frm.txtsenha.style.backgroundColor="#ecb2b1"
		this.flg_validacao =  "erro"
		}


		if ((this.senha != this.confirmacaoSenha) || (this.confirmacaoSenha=='')){
		frm.confirmacaoSenha.style.backgroundColor="#ecb2b1"
		this.flg_validacao =  "erro"
		}

	},
	
	
	
	validaLogin : function() {
		frm = document.form1
		this.flg_validacao =  "ok"
		 
		this.erro = '';
		this.email = document.form1.txtEmailLogin.value;
		this.senha = document.form1.txtSenhaLogin.value;
	
		if(FuncoesGerais.ValidaEmail(this.email)==0){
			this.flg_validacao =  "erro"
		}
		
		if(this.senha==''){
			this.flg_validacao =  "erro"
		}
	},
	

	EnviaCadastro : function () {	
	
		this.limpaValidacao();
	
			this.ValidaCadastro();
			
			if(this.flg_validacao=='ok'){
			
				
				if (cadastro.verificaEmail(this.email).value=='erro'){
					document.getElementById('msgErro').innerHTML=' &nbsp;E-mail j&aacute; cadastrado.'
					document.getElementById('msgErro').style.display='block';
					return
				}
				
			
				if(cadastro.verificaCpf(this.cpf).value=='erro'){
				   document.getElementById('msgErro').innerHTML=' &nbsp;CPF j&aacute; cadastrado.'
				   document.getElementById('msgErro').style.display='block';
				   return
				}
			
			retorno = Class_cadastroUsuarios.insere(this.nome,this.email,this.sexo,this.dt_nascimento,this.cpf,this.cep,this.endereco,this.numero,this.complemento,this.estado,this.cidade,this.telefone,this.senha,this.flg_possui_carro,this.marca_carro,this.modelo,this.ano,this.marca_pneu_carro,this.flg_receber_news).value;
			document.getElementById('sucesso').style.display='block';
			document.getElementById('completemsg').style.display='none';
			document.getElementById('cadastro_form').style.display='none';	
			
			}else{	
				document.getElementById('msgErro').style.display='block';
			}

		
	},
	
	AtualizaCadastro : function () {	
	
		this.limpaValidacao();
		this.ValidaCadastro();
			

				if(this.flg_validacao=='ok'){
			
				
				if (this.email != this.email_atual){
					if (cadastro_alteracao.verificaEmail(this.email).value=='erro'){
						document.getElementById('msgErro').innerHTML=' &nbsp;E-mail j&aacute; cadastrado.'
						document.getElementById('msgErro').style.display='block';
						return
					}
				}
				
				if (this.cpf != this.cpf_atual){
				   document.getElementById('msgErro').innerHTML=' &nbsp;CPF j&aacute; cadastrado.'
				   document.getElementById('msgErro').style.display='block';
				   return
				}
			
			retorno = Class_cadastroUsuarios.atualiza(this.id_cadastro,this.nome,this.email,this.sexo,this.dt_nascimento,this.cpf,this.cep,this.endereco,this.numero,this.complemento,this.estado,this.cidade,this.telefone,this.senha,this.flg_possui_carro,this.marca_carro,this.modelo,this.ano,this.marca_pneu_carro,this.flg_receber_news, 0).value;
			document.getElementById('sucesso').style.display='block';
			document.getElementById('cadastro_form').style.display='none';	
			
			}else{	
				document.getElementById('msgErro').style.display='block';
			}

		
	},
	
	
	validaCpfCadastro : function () {
		retorno = cadastro.verificaCpf(this.cpf)	
	
	},
	
	email_atual : '',
	cpf_atual : '',
	
	LoginCadastro : function () {
		this.validaLogin();
		if(this.flg_validacao=='ok'){
			retorno = cadastro_alteracao.login(this.email, this.senha);
			if (retorno.value == 'erro'){
				document.getElementById('msgErroLogin').innerHTML='E-mail e/ou senha inv&aacute;lidos.';
				document.getElementById('msgErroLogin').style.display='block';
			}else{
				document.getElementById('DivDados').style.display='none';
				if(retorno.error == null){
					var retorno = retorno.value;
					var ds = retorno;
					if(ds!=null && typeof(ds) == "object" && ds.Tables!=null){
						if (ds.Tables[0].Rows.length > 0){
							var row = ds.Tables[0].Rows[0];
							
							document.form1.txtIdCadastro.value = row.id_cadastro;
							document.form1.nome.value = row.nome;
							document.form1.email.value = row.email;
							this.email_atual = row.email;
							if (row.sexo == 'Feminino'){
								document.getElementById('sexo_f').checked = true;
							}else if (row.sexo == 'Masculino'){
								document.getElementById('sexo_m').checked = true;
							}
							if (row.dt_nascimento){
								var data_nascimento = row.dt_nascimento.split('/');
								if (data_nascimento[0]){
									document.form1.data_dia.value = data_nascimento[0];
								}
								if (data_nascimento[1]){
									document.form1.data_mes.value = data_nascimento[1];
								}
								if (data_nascimento[2]){
									document.form1.data_ano.value = data_nascimento[2];
								}
							}
							this.cpf_atual = row.cpf;
							if (row.cpf){
								document.form1.cpf1.value = row.cpf.substring(0,9);
								document.form1.cpf2.value = row.cpf.substring(9,11);
							}
							
							
							if(row.cep==null)
							document.form1.cep.value = '';
							else
							document.form1.cep.value = row.cep;
							
							
							if(row.endereco==null)
							document.form1.endereco.value = ''	
							else
							document.form1.endereco.value = row.endereco;
							
							
							if(row.numero==null)
							document.form1.numero.value = '';
							else
							document.form1.numero.value = row.numero;
							
							
							if(row.complemento==null)
							document.form1.complemento.value = '';
							else
							document.form1.complemento.value = row.complemento;
							
							
							
							document.form1.estados.value = row.estado;
							if (row.estado){
								FuncoesGerais.CarregaCidade(row.estado);
							}
							document.form1.NomeCampoCidade.value = row.cidade;
							if (row.telefone){
								var dados_tel = row.telefone.split('-');
								if (dados_tel[0]){
									document.form1.tel_pre.value = dados_tel[0];
								}
								if (dados_tel[1]){
									document.form1.telefone.value = dados_tel[1];
								}
							}
							if (row.flg_possui_carro == 0){
								document.getElementById('possui_nao').checked = true;
							}else if (row.flg_possui_carro == 1){
								document.getElementById('possui_sim').checked = true;
							}

							document.form1.combo_marca_veiculo.value = row.marca_carro;
							if (row.marca_carro){
								Buscador.CarregaModelosCadastro(row.marca_carro);
							}
							document.form1.combo_modelo_veiculo.value = row.modelo;
							
							if(row.ano==null)
							document.form1.anoCarro.value = '';
							else
							document.form1.anoCarro.value = row.ano;
							
							
							
							
							document.form1.marca_pneu_carro.value = row.marca_pneu_carro;
							if (row.flg_receber_news == 1){
								document.form1.news.checked = true;
							}
							document.form1.txtsenha.value = row.senha;
							document.form1.confirmacaoSenha.value = row.senha;
														
							document.getElementById('cadastro_form').style.display = '';
						}
					}
				}
			}
		}else{
			document.getElementById('msgErroLogin').innerHTML='Preencha corretamente o campo e-mail e/ou senha.';
			document.getElementById('msgErroLogin').style.display='block';
		}
	},
	

	reenviaSenha : function() {
	this.email = document.form1.email.value
	document.getElementById('msgErro').innerHTML="";
	document.getElementById('msgErro').style.display='none';
		
		if(FuncoesGerais.ValidaEmail(this.email)==0){
			document.getElementById('msgErro').innerHTML='Preencha corretamente o campo E-mail.'
			document.getElementById('msgErro').style.display='block';		
		}else{
			if (cadastro_esqueci.verificaEmailExistente(this.email).value=='erro'){
				document.getElementById('msgErro').innerHTML='E-mail n&atilde;o cadastrado.'
				document.getElementById('msgErro').style.display='block';
				return
			}else{
				cadastro_esqueci.reenviaSenha(this.email).value
				document.getElementById('sucesso').style.display='block';
				document.getElementById('form_login').style.display='none';	
			}
		}	
			
	},
	
	
	criaSenha : function(){
	this.email = document.form1.emailgerar.value;
	document.getElementById('msgErroGera').style.display='none';
	
		
		if(FuncoesGerais.ValidaEmail(this.email)==0){
			document.getElementById('msgErroGera').innerHTML='Preencha corretamente o campo E-mail.'
			document.getElementById('msgErroGera').style.display='block';		
		}else{
			if (cadastro_alteracao.verificaSenha(this.email).value=='erro'){
				document.getElementById('msgErroGera').innerHTML='E-mail n&atilde;o cadastrado.'
				document.getElementById('msgErroGera').style.display='block';
				return
			}else{
				cadastro_alteracao.criaNovaSenha(this.email);
				document.getElementById('msgSucessoGera').style.display='block';
				document.form1.emailgerar.value = "Seu e-mail cadastrado no site.";
			}
		}	
		
	},
	
	
	carregaCadastro : function(){
		
	},
	
	//carrega combo de cidades
	CarregaCadastro_CallBack : function(response){
		/*if(response.error == null){ 
			nomecampocidade = document.form1.NomeCampoCidade;
			var retorno = response.value;
			var ds = retorno;
			
			if(ds!=null && typeof(ds) == "object" && ds.Tables!=null){
				//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];
					nomecampocidade.options[i].text= row.CIDADE;
					nomecampocidade.options[i].value= row.CIDADE;
				}
			} 
		} */
	
	},
	
	
	
	
	fecharErro : function() {
		document.getElementById('erro').style.display='none';
		document.getElementById('cadastro_form').style.display='block';			
	},
	
	voltaSucesso : function() {
		window.location = 'cadastro.aspx'	
	},
	
	voltaSucessoAlterar : function() {
		window.location = 'cadastro_alteracao.aspx'	
	},
	
	voltaSucessoEsqueci : function() {
		window.location = 'cadastro_esqueci.aspx'	
	},
	
	mascaraCampo : function(campo, valor){
		if (campo.value == ''){
			campo.value = valor;
		}
	},
	
	limpaCampo : function(campo, valor){
		if (campo.value == valor){
			campo.value = '';
		}
	}

}