/*DESENVOLVIDO POR LIME COMERCIO DE PRODUTOS DE INFORMATICA LTDA*/
/* Funcao para armazenar um cookie*/
function grava_cookie(n,v) {
        document.cookie = n + "=" + v;
}
/* Funcao para ler um cookie*/
function le_cookie(nome) {
	temp = document.cookie;
	nome = nome + "=";
	max = nome.length;
	valor = "";
	tamanho_valor = 0;
	for(i=0; i<=temp.length; i++) {
		if(temp.substring(i,i+max)==nome) {
			for(i2=i+max+1; i2<=temp.length; i2++) {
				if(temp.substring(i2-1,i2)!=";") {
					tamanho_valor++;
				} else {
					break;	
				}
			}
			valor = temp.substring(i+max,i+max+tamanho_valor);
		}
	}
	return valor;
} 
/* Aplica resolucao do cookie*/
function resolucao_cookie(n) {
	if (document.getElementById(n)!=null) {
		largura = le_cookie('resolucao');
		if(largura != "") {
			document.getElementById(n).style.width = largura;
		}
	}
}
/* Ajusta o site para o tamanho da tela do usuario*/
function ajusta(n) {
	largura = document.documentElement.clientWidth;
	largura = largura - 315;
	largura = largura + "px";
	grava_cookie('resolucao', largura);
	document.getElementById(n).style.width = largura;
}
/* Ajusta a foto conforme resolucao do usuario*/
function ajusta_foto(n) {
	largura = document.documentElement.clientWidth;
	largura = largura - 315;
	if (largura<850) {
		document.getElementById(n).width = "300";
		document.getElementById(n).height = "300";
	}	
}
/* Conjunto de funcoes para transacao de DIVs com botoes para exibir fixo*/
var maximo = 5;
var atual = 1;
var proximo = 1;
var contador = 0;
var avanca = true;
/* Funcao principal para animacao das DIVs*/
function inicia() {
	setInterval('animacao()',tempo);
	setInterval('desenha()',20);
}
/* Laco principal chamado pelo itervalo de tempo*/
function animacao() {	
	if(avanca==true) {
		if(contador>=100) {
			contador = 0;
			exibe(proximo);
		}
	}
}
/* Funcao para parar em uma determinada posicao*/
function para(n) {
	avanca = false;
	exibe(n);
}
/* Funcao para continuar a animacao de uma determinada pasicao*/
function continua() {
	avanca = true;
}
/* Desenha a DIV informada atraves de um efeito tipo fade in*/
function desenha(){
	if(avanca==false) {
		document.getElementById("promo"+atual).style.opacity = 1;
		document.getElementById("promo"+atual).style.filter = "alpha(opacity=100)";
	} else {
		if(contador<=100) {
			contador = contador + 5;
			document.getElementById("promo"+atual).style.opacity = contador/100;
			document.getElementById("promo"+atual).style.filter = "alpha(opacity="+contador+")";
		}
	}
}
/* Exibe uma DIV espeficicada no parametro e chama funcao para desenho com efeito*/
function exibe(n) {
	for(i=1; i<=maximo; i++) {
		document.getElementById("promo"+i).style.opacity = "0";
		document.getElementById("promo"+i).style.filter = "alpha(opacity=0)";
		document.getElementById("promo"+i).style.visibility = "hidden";
		document.getElementById("b"+i).style.background = "#FFFFFF";
		document.getElementById("b"+i).style.color = "#000000";
	}
	document.getElementById("promo"+n).style.visibility = "visible";
	document.getElementById("b"+n).style.background = "#346ABD";
	document.getElementById("b"+n).style.color = "#FFFFFF";
	atual = n;
	proximo = n+1;
	if(n==maximo) {
		proximo = 1;
	}
}
/* Retorna true se a tecla for um numero*/
function so_numero(e) {
	var tecla;
	/* Para internet explorer*/
	if(window.event) {
		tecla = e.keyCode
	} else {
		/* Para firefox ou opera */
		if(e.which) {
			tecla = e.which;
		}
	}
	/* Intervalo de numeros*/
	if(tecla>47 && tecla<58) {
		return true;
	} else {
		/* Itervalo de caracteres*/
		if(tecla>31 && tecla<127) {
			return false;			
		} else {  
			return true;
		}
    }
}
/* Validacao do formulario de contato*/
function valida_contato() {
	if (document.contato.nome.value=="") {
		alert('É necessário inserir um nome...');
		document.contato.nome.focus();
		return false;
	}
	if (document.contato.email.value=="") {
		alert('É necessário inserir um e-mail...');
		document.contato.email.focus();
		return false;
	}
	if (document.contato.telefone.value=="") {
		alert('É necessário inserir um telefone...');
		document.contato.telefone.focus();
		return false;
	}
	if (document.contato.mensagem.value=="") {
		alert('É necessário escrever alguma mensagem...');
		document.contato.mensagem.focus();
		return false;
	}
	return true;
}
/* Validacao do formulario de login*/
function valida_login() {
	if (document.login.email.value=="") {
		alert('É necessário inserir um e-mail...');
		document.login.email.focus();
		return false;
	}
	if (document.login.senha.value=="") {
		alert('É necessário inserir uma senha...');
		document.login.senha.focus();
		return false;
	}
	return true;
}
/* Validacao do formulario de cadastro*/
function valida_cadastro(n,s) {
	if (document.getElementById(n).nome_razao.value=="") {
		alert('Atenção! O campo Nome/Razão Social é obrigatório.');
		document.getElementById(n).nome_razao.focus();
		return false;
	}
	if (document.getElementById(n).cpf_cnpj.value=="") {
		alert('Atenção! O campo CPF/CNPJ é obrigatório.');
		document.getElementById(n).cpf_cnpj.focus();
		return false;
	}
	if (document.getElementById(n).endereco.value=="") {
		alert('Atenção! O campo Endereço é obrigatório.');
		document.getElementById(n).endereco.focus();
		return false;
	}
	if (document.getElementById(n).cidade.value=="") {
		alert('Atenção! O campo Cidade é obrigatório.');
		document.getElementById(n).cidade.focus();
		return false;
	}
	if (document.getElementById(n).cep.value=="") {
		alert('Atenção! O campo CEP é obrigatório.');
		document.getElementById(n).cep.focus();
		return false;
	}
	if (document.getElementById(n).telefone.value=="") {
		alert('Atenção! O campo Telefone é obrigatório.');
		document.getElementById(n).telefone.focus();
		return false;
	}
	if (document.getElementById(n).email.value=="") {
		alert('Atenção! O campo E-mail é obrigatório.');
		document.getElementById(n).email.focus();
		return false;
	}
	if (s==true) {
		if (document.getElementById(n).senha.value=="") {
			alert('Atenção! O campo senha é obrigatório.');
			document.getElementById(n).senha.focus();
			return false;
		}
	}
	return true;
}
/* Processa o envio do pedido*/
function envia_pedido() {
	if (document.pedido.pagamento[0].checked==false && document.pedido.pagamento[1].checked==false && document.pedido.pagamento[2].checked==false) {
		alert('Por favor selecione uma forma de pagamento');
	} else {
		if (valida_cadastro("pedido",false)==true) {
			var email = document.pedido.email.value;
			if (document.pedido.pagamento[0].checked==true) {
				var url = "https://lojaslime.websiteseguro.com/";
				window.open(url,'boleto','width=720,height=600,scrollbars=1,top=50,left=150,status=no,location=no');
				document.pedido.submit();
			}
			if (document.pedido.pagamento[1].checked==true) {
				alert('Os dados para depósito em conta serão enviados para o email ' + email);
				document.pedido.submit();
			}
			if (document.pedido.pagamento[2].checked==true) {
				alert('Atenção! Você escolheu o pagamento através do pagseguro.\nVocê será direcionado para o carrinho pagseguro.');
				window.open('#','pagseguro','width=820,height=600,scrollbars=1,top=50,left=150,status=no,location=no');
				document.formpagseguro.submit();
				document.pedido.submit();
			}
		}
	}
}
/* Atualiza quantidades do pedido*/
function atualiza_quant() {
	document.quantidades.submit()
}
/* Conjunto de funcoes para efeito de cores em tabelas*/
var cor1 = '#F0F0F0';
var cor2 = '#F5F5F5';
var cor3 = '#FFE4E1';
var cor4 = '#FFD0D0';
/* Muda o fundo de um objeto table e aplica a cor especificada no parametro*/
function mudafundo(obj,cor) {
	obj.style.backgroundColor=cor;	
}
/* Muda para proximo campo ao atingir o valor maximo de caracteres*/
function mudacampo(obj,proximo) {
	if (obj.value.length==obj.maxLength) {
		document.getElementById(proximo).focus();
	}
}
/* Alertas comuns*/
function alerta_vazio() {
	alert('Atenção! Não é possivel finalizar o pedido pois o mesmo está vazio.');	
}
function alerta_itens() {
	alert('Atenção! Existem itens que estão com quantidades indisponíveis.\nPor favor reduza a quantidade do(s) item(s) em vermelho, em seguida clique em atualizar.');	
}
function alerta_total() {
	alert('Atenção! O pedido está com um valor total nulo.\nPor favor verifique a(s) quantidade do(s) iten(s), em seguida clique em atualizar.');	
}
function alerta_cep() {
	alert('Por favor preencha o campo CEP mesmo que tenha selecionado Retirar pessoalmente.');	
}
/*DEUS SEJA LOUVADO*/

