function valida(){

	mostraCarregando();
	nome     	  =  document.getElementById("nome").value;
	usuario  	  =  document.getElementById("usuario").value;
	senha    	  =  document.getElementById("senha").value;
	email    	  =  document.getElementById("email").value;
	email2        =  document.getElementById("email2").value;
	resposta =  validaForm();
	botao    =  document.getElementById("cadastrar").value;
	var mess = '';




	if(botao == "CADASTRAR"){
		private_key   =  document.getElementById("private_key").value;
		if(private_key  == '') mess += "Preencha o campo validação.\n";
		if(validaResposta()==false){
			escondeCarregando
			return;
		}
	}
	else
	{
		if(validaRespostaStatus())
		{
			escondeCarregando();
			return;
		}
	}

	if(nome     == '') mess = "Preencha o campo nome.\n";
	if(usuario  == '') mess += "Preencha o campo usuário.\n";
	if(senha    == '') mess += "Preencha o campo senha.\n";
	if(resposta != '') mess += resposta;

	if(checkMail(email)){
		if(email != email2){
			mess +="Verifique o email de confirmação.\n";
		}
	}
	else
	{
		mess +="Problemas no campo e-mail.\n";
	}

	if(mess!=''){

		alert(mess);
		escondeCarregando();

	}
	else
	{

		incluiAltera();
	}

}
function validaResposta(){
	if(document.getElementById("nao").checked)
	{
		alert("Para o sistema funcionar todos seus scraps deveram ser \n apagados.")
		return false;
	}

}

function validaRespostaStatus(){
	if(document.getElementById("nao").checked)
	{
		if(confirm("Deseja realmente desativar a conta do ScrapMail?")){
			return false;
		}
		else
		{
			return true;
		}

	}

}

function validaForm(){
	var controle = 0;
	var mess = '';
	for (i=0;i<document.cadastro.elements.length;i++){
		if (document.cadastro.elements[i].type == "radio"){
			if (document.cadastro.elements[i].checked == true){
				controle++;
			}
		}
	}
	if (controle <= 0){
		mess = "Selecione uma das opções.\n";
		return mess;
	}
	return mess;
}

function checkMail(mail){
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	if(typeof(mail) == "string"){
		if(er.test(mail)){ return true; }
	}else if(typeof(mail) == "object"){
		if(er.test(mail.value)){
			return true;
		}
	}else{
		return false;
	}
}
function mostraCarregando()
{
	document.getElementById("carregando").style.display = "";
}
function escondeCarregando()
{
	document.getElementById("carregando").style.display = "none";
}

function mostraHistorico(){
	document.getElementById("historico").style.display = "block";
	document.getElementById("cadastroL").style.display = "none";
    
    carregaHistorico();	

}

function voltar(){
	document.getElementById("cadastroL").style.display = "";
    document.getElementById("historico").style.display = "none";	
}
