	function efetuaBusca(){
		aux = document.getElementById('buscarPor');
		if (aux.value.length < 3){
			alert("Para que seja feita uma busca, é necessário digitar pelo menos 3 caracteres");
			return;
		}
		aux2 = document.getElementById('formBusca');
		aux2.submit();
	}

	function abreSubCate(campo){
		aux = document.getElementById(campo);
		if (aux.className == "visivel"){
			aux.className = "oculto";
		}else{
			aux.className = "visivel";
		}
	}

	function abriPopImg(img,compl,id){
		aux = document.getElementById(id);
		largura = aux.width;
		altura = aux.height;
		w = screen.width;
		h = screen.height;
		meio_w = w/2;
		meio_h = h/2;		
		altura2 = altura/2;
		largura2 = largura/2;
		meio1 = meio_h-altura2;
		meio2 = meio_w-largura2;
		url = "ampliaProduto.asp?img=" + img + compl;
		window.open(url,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,height=' + altura + ', width=' + largura + ', top='+meio1+', left='+meio2+'');
	}
	
	function ObjAjax(){
	  try{return new XMLHttpRequest()}
	  catch(e){try{return new ActiveXObject("Msxml2.XMLHTTP")}
	  catch(e){return new ActiveXObject("Microsoft.XMLHTTP")}}
	  return null;
	}

	function navegar(page, destino){
	  ajax = new ObjAjax();
	  var div = document.getElementById(destino);
	
	  ajax.onreadystatechange = function(){
		if(ajax.readyState == 1){
//			div.className="div_cadastro_formulario_label";
			div.innerHTML="<div style='text-align:center; margin:80px auto; font-family:Verdana, Arial, Helvetica, sans-serif; color:#666666;'><img src='Imagens/preloader.gif' width='37' height='37' alt='Carregando' style='vertical-align:middle;' /><br />Carregando...</div>";
		}
		if(ajax.readyState == 4){div.innerHTML=ajax.responseText;}
	
	  }
	  ajax.open("GET",page,true);
	  ajax.send(null);
	}

	window.onload = function() {
	  var links = document.links;
	  for (var i = 0, s = links.length; i < s; i++) {
		if (links[i].rel == 'external') {
		  links[i].target = '_blank';
		}
	  }
	}
	
	function chkNumero(campo, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	 if (keyCode == '8' || keyCode == '9' || keyCode == '13' || keyCode == '16' || keyCode == '17' || keyCode == '18' || keyCode == '35' || keyCode == '36' || keyCode == '46' || keyCode == '116' || (keyCode > '47' && keyCode < '58') || (keyCode > '95' && keyCode < '106'))
	 {
	 }
	 else{
		if (event.keyCode){
	//		alert("IE");
//			event.keyCode = '127';
		}else{
//			alert("FF");
//			event.returnValue=false; 
		}
		alert('Digite apenas números!');
//		alert(keyCode);
	  }
	}
	
	function verifica_email(campo) {
	var Email = campo.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
	if (campo.value == ''){
	} else{
	if (Email){
	   correto = true;
	   return true;
	} else {
	   alert('Favor entrar com um endereço de e-mail válido!');
	   campo.focus();
	   campo.select();
	   correto = false;
	   return false;
	   }
	}
	}
	
	function proximoVisitados(totalLivros){
		pg = parseInt(document.getElementById("pgLivrosVisitados").innerHTML);
		i = 1;
		while (i<=totalLivros){
			auxId = "Img" + i;
			document.getElementById(auxId).className = "oculto";
			i = i+1;
		}
		i = totalLivros - (pg*3);
		contLivros = 1;
		while (i>=1 && contLivros <=3){
			auxId = "Img" + i;
			document.getElementById(auxId).className = "visivel";
			contLivros = contLivros + 1;
			i = i-1;
		}
		if (i==0){
			document.getElementById("nav_prod_visit_dir").className = "oculto";
		}
		document.getElementById("nav_prod_visit_esq").className = "visivel";
		document.getElementById("pgLivrosVisitados").innerHTML = pg +1;
	}
	
	function anteriorVisitados(totalLivros){
		pg = parseInt(document.getElementById("pgLivrosVisitados").innerHTML);
		i = 1;
		while (i<=totalLivros){
			auxId = "Img" + i;
			document.getElementById(auxId).className = "oculto";
			i = i+1;
		}
		
		i = totalLivros - ((pg-2)*3);
		contLivros = 1;
		while (contLivros <=3){
			auxId = "Img" + i;
			document.getElementById(auxId).className = "visivel";
			contLivros = contLivros + 1;
			i = i-1;
		}
		if (i==totalLivros-3){
			document.getElementById("nav_prod_visit_esq").className = "oculto";
		}
		document.getElementById("nav_prod_visit_dir").className = "visivel";
		document.getElementById("pgLivrosVisitados").innerHTML = pg -1;
	}
	
	function avaliaLivroClique(nota,descricao,flag){
		for(i=1;i<=nota;i++){
			auxId = "Aval" + i;
			document.getElementById(auxId).src = "Imagens/img-avaliacao-1.jpg";
		}
		for(i=nota+1;i<=5;i++){
			auxId = "Aval" + i;
			document.getElementById(auxId).src = "Imagens/img-avaliacao-0.jpg";
		}
		document.getElementById("cliqueFlag").value = flag;
		document.getElementById("opineNota").value = nota;
	}
	
	function avaliaLivroOver(nota,descricao){
		if(document.getElementById("cliqueFlag").value == "false"){
			avaliaLivroClique(nota,descricao,"false");
		}
	}
	
	function chkDados(formulario){
		aux = document.getElementById(formulario);
		i = 1;
		args = aux.getElementsByTagName("input");
		nArgs = chkDados.arguments.length;
		while (i < nArgs){
			campo = chkDados.arguments[i];
			for (j=0; j<args.length; j++){
				arg = args[j];
				nome = arg.getAttribute('name');
				if (campo == nome){
					valor = arg.value;
					if (valor == ""){
						alert("Campo '"+campo+ "' obrigatório!");
						arg.focus();
						return;
					}
					func = arg.getAttribute('onblur');
					if (func == "verifica_email(this);"){
						if (!verifica_email(arg)){
							return;
						}
					}
					if (func == "verifica_data(this);"){
						if(!verifica_data(arg)){
							return;
						}
					}
					if (func == "confirmaSenhas('Senha1', 'Senha2');"){
						if(!confirmaSenhas('Senha1', 'Senha2')){
							alert("Campo 'Senha' e 'Repita a Senha' divergentes!");
							return;
						}
					}
					if (func == "completeCep(this,'false');"){
						if (!completeCep(arg,"false")){
							alert("Digite um CEP válido!");
							return;
						}
					}
//					tipo = arg.getAttribute('type');
					break;
				}
			}
			i++;
		}
		i = 1;
		args = aux.getElementsByTagName("textarea");
		nArgs = chkDados.arguments.length;
		while (i < nArgs){
			campo = chkDados.arguments[i];
			for (j=0; j<args.length; j++){
				arg = args[j];
				nome = arg.getAttribute('name');
				if (campo == nome){
					valor = arg.value;
					if (valor == ""){
						alert("Campo '"+campo+ "' obrigatório!");
						arg.focus();
						return;
					}
					func = arg.getAttribute('onblur');
					if (func == "verifica_email(this);"){
						if (!verifica_email(arg)){
							return;
						}
					}
					if (func == "verifica_data(this);"){
						if(!verifica_data(arg)){
							return;
						}
					}
					if (func == "confirmaSenhas('Senha1', 'Senha2');"){
						if(!confirmaSenhas('Senha1', 'Senha2')){
							alert("Campo 'Senha' e 'Repita a Senha' divergentes!");
							return;
						}
					}
					if (func == "completeCep(this,'false');"){
						if (!completeCep(arg,"false")){
							alert("Digite um CEP válido!");
							return;
						}
					}
//					tipo = arg.getAttribute('type');
					break;
				}
			}
			i++;
		}
		aux.submit();
		aux.reset();
	}
	
	function mascaraCnpj(campo, event){
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode!= 8){
			switch(campo.value.length)
			{
			case 2: campo.value += ".";
				break;
			case 6: campo.value += ".";
				break;
			case 10: campo.value += "/";
				break;
			case 15: campo.value += "-";
				break;
			}
		}
	}
	
	function mascaraData(campo, event){
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode!= 8){
			switch(campo.value.length)
			{
			case 2: campo.value += "/";
				break;
			case 5: campo.value += "/";
				break;
			}
		}
	}
	
	function verifica_data(campo) 
	{
		date = campo.value;
		sMsg = 'Por favor, digite uma data válida';
		
		if	((date.length < 10) && (date != ""))
			{
			window.alert('Por favor, digite uma data válida, formato aceito: dd/mm/aaaa.');
			if	((typeof(campo) == 'object') && (campo.type != 'hidden'))
				{
				campo.focus();
				campo.value="";
				}
			return(false);
			}
	
		if	(date != "") 
			{
			if	(date.indexOf("/")==date.lastIndexOf("/"))
				{
				// se houver menos que duas barras caia fora
				window.alert('Por favor, digite uma data válida, formato aceito: dd/mm/aaaa.');
				if	((typeof(campo) == 'object') && (campo.type != 'hidden'))
					{
					campo.focus();
					campo.value="";
					}
				return(false);
				}
	
			day  =date.substr(0,date.indexOf("/"))
			month=date.substr(date.indexOf("/")+1,date.lastIndexOf("/")-date.indexOf("/")-1)
			year =date.substr(date.lastIndexOf("/")+1,date.length-date.lastIndexOf("/")-1)
	
			if	(isNaN(day) || isNaN(month) || isNaN(year)) 
				{
				window.alert('Por favor, digite uma data válida, formato aceito: dd/mm/aaaa.');
				if	((typeof(campo) == 'object') && (campo.type != 'hidden'))
					{
					campo.focus();
					campo.value="";
					}
				return(false);
				}
				
			if	(day<1 || day>31 || month<1 || month>12 || year<1900 || year>2200) 
				{
				window.alert('Por favor, digite uma data válida, formato aceito: dd/mm/aaaa.');
				if	((typeof(campo) == 'object') && (campo.type != 'hidden'))
					{
					campo.focus();
					campo.value="";
					}
				return(false);
				}
	
			// Janeiro, Março, Maio, Julho, Agosto, Outubro, Dezembro
			if	(((month == "01") ||
				  (month == "03") ||
				  (month == "07") ||
				  (month == "08") ||
				  (month == "10") ||
				  (month == "12")) && 
				 ((day <= "0")	  ||
				  (day > "31")))
				{
				window.alert(sMsg);
				if	((typeof(campo) == 'object')&& (campo.type != 'hidden'))
					{
					campo.focus();
					campo.value="";
					}
				 
				return(false);
				}
				 
			// Fevereiro
			if	(month == "02")
				{
				if	((isBissexto(year)==false) &&
					 (day > 28))
					{
					window.alert(sMsg);
					if	((typeof(campo) == 'object') && (campo.type != 'hidden'))
						{
						campo.focus();
						campo.value="";
						}
					return(false);
					}
				
				if	(day > 29)
					{
					window.alert(sMsg);
					if	((typeof(campo) == 'object')&& (campo.type != 'hidden'))
						{
						campo.focus();
						campo.value="";
						}
					return(false);
					}
				}
	
			// Abril, Junho, Setembro, Novembro
			if	(((month == "04") ||
				  (month == "06") ||
				  (month == "09") ||		
				  (month == "11")) &&
				 ((day <= "0")    ||
				  (day > "30")))
				{
				window.alert(sMsg);
				if	((typeof(campo) == 'object')&& (campo.type != 'hidden'))
					{
					campo.focus();
					campo.value="";
					}
				return(false);
				}
	
			return(true);
			}
	}
	
	function mascaraCpf(campo, event){
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode!= 8){
			switch(campo.value.length)
			{
			case 3: campo.value += ".";
				break;
			case 7: campo.value += ".";
				break;
			case 11: campo.value += "-";
				break;
			}
		}
	}
	
	function mascaraTelefone(campo, event){
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode!= 8){
			switch(campo.value.length)
			{
			case 4: campo.value += "-";
				break;
			}
		}
	}
	
	function completeCep(campo, flag){
		if (campo.value.length == 9){
			if (flag == "true"){
				buscaCep(campo);
			}else{
				if (document.getElementById("retornoErro").innerHTML != ""){
					alert(document.getElementById("retornoErro").innerHTML);
					return false;
				}
			}
			return true;
		}else{
			return false;
		}
	}
	
	function buscaCep(campo){
		valor = campo.value;
		valor = valor.replace("-","");
		if (valor != ""){
			if (valor.length >= 8){
				ende = "localizacep.asp?cep="+ valor;
				navegar(ende, "retornoCep");
			}else{
				alert("Digite um CEP válido!");
				campo.focus();
			}
		}
	}

	function mascaraCep(campo, event){
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode!= 8){
			switch(campo.value.length)
			{
			case 5: campo.value += "-";
				break;
			}
		}
	}


	function validaCPF(campo) {
		cpf = campo.value;
		if (cpf.length == 0){
			return false;
		}
		cpf = cpf.replace(".","");
		cpf = cpf.replace(".","");
		cpf = cpf.replace("-","");
		cpf = cpf.replace("X","0");
		cpf = cpf.replace("X","0");
		cpf = cpf.replace("x","0");
		cpf = cpf.replace("x","0");
		erro = "CPF inválido!"; 
		if (cpf.length < 11){
			if (cpf.length == 10){
				cpf = "0" + cpf;
			}else{
				if (cpf.length == 9){
					cpf = "00" + cpf;
				}else{
					erro = "CPF inválido!"; 
					alert(erro);
					return false;
				}
			}
		}
//		alert("Passou 1");
		var nonNumbers = /\D/;
		if (nonNumbers.test(cpf)){
			erro = "CPF inválido!";
			alert(erro);
			return false;
		}
//		alert("Passou 2");
		if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
			erro = "CPF inválido!"
			alert(erro);
			return false;
		}
//		alert("Passou 3");
		var a = [];
		var b = new Number;
		var c = 11;
		for (i=0; i<11; i++){
			a[i] = cpf.charAt(i);
			if (i < 9)
				b += (a[i] * --c);
		}
		if ((x = b % 11) < 2) {
			a[9] = 0
		} else {
			a[9] = 11-x
		}
		b = 0;
		c = 11;
		for (y=0; y<10; y++)
			b += (a[y] * c--); 
		if ((x = b % 11) < 2) {
			a[10] = 0;
		} else {
			a[10] = 11-x;
		}
		if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
			erro = "CPF inválido!";
			alert(erro);
			return false;
		}
		return true;
	}


	function validaCNPJ(campo) {
		cnpj = campo.value;
		if (cnpj.length == 0){
			return false;
		}
		cnpj = cnpj.replace(".","");
		cnpj = cnpj.replace(".","");
		cnpj = cnpj.replace("/","");
		cnpj = cnpj.replace("-","");
		cnpj = cnpj.replace("X","0");
		cnpj = cnpj.replace("X","0");
		cnpj = cnpj.replace("x","0");
		cnpj = cnpj.replace("x","0");
		erro = "CNPJ inválido!"; 
		if (cnpj.length < 14){
			if (cnpj.length == 13){
				cnpj = "0" + cnpj;
			}else{
				if (cnpj.length == 12){
					cnpj = "00" + cnpj;
				}else{
					erro = "<11"; 
					alert(erro);
					return false;
				}
			}
		}
//		alert("Passou 1");
		var nonNumbers = /\D/;
		if (nonNumbers.test(cnpj)){
			erro = "CNPJ inválido!";
			alert(erro);
			return false;
		}
//		alert("Passou 2");
		var a = [];
		var b = new Number;
		var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
		for (i=0; i<12; i++){
			a[i] = cnpj.charAt(i);
			b += a[i] * c[i+1];
		}
		if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
		b = 0;
		for (y=0; y<13; y++) {
			b += (a[y] * c[y]); 
		}
		if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
		if ((cnpj.charAt(12) != a[12]) || (cnpj.charAt(13) != a[13])){
			erro ="CNPJ inválido!";
			alert(erro);
			return false;
		}
/*		if (erro.length > 0){
			alert(erro);
			return false;
		}*/
		return true
	}
	
	function confirmaSenhas(idCampo1, idCampo2){
		c1 = document.getElementById(idCampo1);
		c2 = document.getElementById(idCampo2);
		if (c1.value.length < 5){
			alert("Sua senha deve conter pelo menos 5 caracteres");
			return false;
		}
		if (c1.value == c2.value){
			return true;
		}else{
			return false;
		}
	}
	
	function excluirNews(form){
		aux = document.getElementById(form);
        aux.acao.value = "excluir";
        chkDados(form,'E-mail');
	}
	
	function incluirNews(form){
		aux = document.getElementById(form);
        aux.acao.value = "incluir";
        chkDados(form,'Nome','E-mail');
	}
	
	function abreAbas(campo){
		aux = document.getElementById("PromocoesA");
		aux.className = "oculto";
		aux = document.getElementById("LancamentosA");
		aux.className = "oculto";
		aux = document.getElementById("SugestoesA");
		aux.className = "oculto";
		aux = document.getElementById("Pre-VendaA");
		aux.className = "oculto";
		aux = document.getElementById("Mais-VendidosA");
		aux.className = "oculto";
		aux = document.getElementById("Mais-PresenteadosA");
		aux.className = "oculto";
		aux = document.getElementById("Promocoes");
		aux.className = "visivel";
		aux = document.getElementById("Lancamentos");
		aux.className = "visivel";
		aux = document.getElementById("Sugestoes");
		aux.className = "visivel";
		aux = document.getElementById("Pre-Venda");
		aux.className = "visivel";
		aux = document.getElementById("Mais-Vendidos");
		aux.className = "visivel";
		aux = document.getElementById("Mais-Presenteados");
		aux.className = "visivel";
		aux = document.getElementById(campo);
		aux.className = "oculto";
		url = campo + ".asp";
		campo = campo + "A";
		aux = document.getElementById(campo);
		aux.className = "visivel";
		navegar(url, "Home");
	}