jQuery(document).bind('keydown', 'Alt+1',function (evt){document.location.href='/index.html'; return false; });
jQuery(document).bind('keydown', 'Alt+2',function (evt){document.location.href='/Acessibilidade'; return false; });
jQuery(document).bind('keydown', 'Alt+0',function (evt){document.location.href='/pesquisas.html'; return false; });
jQuery(document).bind('keydown', 'Alt+4',function (evt){document.location.href='/produtos.html'; return false; });
jQuery(document).bind('keydown', 'Alt+9',function (evt){document.location.href='/mapa-do-site.html'; return false; });

$(document).ready(function(){
	$(document)[0].oncontextmenu = function() { alert('FOGATTI - Todos os direitos reservados.'); return false;}
	$(".ajax").fancybox();
	$("#cnpj").mask("99.999.999/9999-99",{placeholder:""});
	$("#cpf").mask("999.999.999-99",{placeholder:""});
	$("#tel").mask("9999-9999",{placeholder:""});
	$("#cep").mask("99999-999",{placeholder:""});
	$("#q").focus();
	
	 $("#up").fontscale("p, .reSize","up",{unit:"px",increment:1});
	 $("#down").fontscale("p, .reSize","down",{unit:"px",increment:1});
	 $("#reset").fontscale("p, .reSize","reset");
	
	$('a.iFrame').each(function(){
		var dWidth		= parseInt($(this).attr('href').match(/width=[0-9]+/i)[0].replace('width=',''));  
		var dHeight		= parseInt($(this).attr('href').match(/height=[0-9]+/i)[0].replace('height=',''));
		if (dWidth<=0){dWidth='90%';}
		if (dHeight<=0){dHeight='90%';}
		$(this).fancybox({
			'padding'		: 5,
			'width'			: dWidth,
			'height'		: dHeight,
			'autoScale'		: false,
			'titleShow'     : false,
			'scrolling'		: 'no',
			'transitionIn'	: 'inside',
			'transitionOut'	: 'outside',
			'type'			: 'iframe'
		});
	});
	
	$("a.youtube").click(function() {
		$.fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none',
				'title'			: this.title,
				'width'			: 640,
				'height'		: 510,
				'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: {
					'wmode'				: 'transparent',
					'allowfullscreen'	: 'true'
				}
			});

		return false;
	});
	
	$('#prodmenus a, #display a').click(function(){  
		if (!$(this).hasClass('selected')) {   
			$('#prodmenus a, #display a').removeClass('selected');  
			$(this).addClass('selected'); 
			
		}
	});
});

function callajax(href,local){
	if(local){}else{var local='response';}
	$('#'+local).html('<span class="ajaxload" style="font-size:0.9em;">Carregando, aguarde...</span>');
	var d = new Date();
	var url = href+"&d="+d.getTime();
	$.get(url,{},function(response){ 
		$('#'+local).html(response);
	});
}

function callImags(href,local){
	$('.load').css('background-image', 'url(images/ajax-loader3.gif)');
	if(local){}else{var local='response';}
	$('#'+local).load(function () {
		$('#'+local).hide();
		$('#'+local).fadeIn();
	}).attr('src', href);	
}

function blockNumbers(e){
var key;
var keychar;
var reg;
	if(window.event) { 
		// for IE, e.keyCode or window.event.keyCode can be used 
		key = e.keyCode; 
	}else if(e.which) { 
		// netscape 
		key = e.which; 
	}else {
		// no event, so pass through 
		return true;
	}
keychar = String.fromCharCode(key);
reg = /[^\d]/;
return !reg.test(keychar);
}
function chkFormSearch(formname) {
	if (document.forms[formname].q.value == "") {
		alert("Por favor, preencha o campo! ");
		document.forms[formname].q.focus();
		return;
	} else {
		if (document.forms[formname].q.value.length < 3) {
			alert("Por favor, preencha o campo com no mínimo 3 caractéries! ");
			document.forms[formname].q.focus();
			return;
		}
	}
	document.forms[formname].submit();
}
function chkForm(formname) {
	var tipo = document.forms[formname].tipo.value;
	if (tipo==2) {
		if (document.forms[formname].razao.value == "") {
			alert("Preenchimento necessário: Razão social! ");
			document.forms[formname].razao.focus();
			return;
		} else {
			if (document.forms[formname].razao.value.length < 5) {
				alert("Preenchimento necessário: Razão social! ");
				document.forms[formname].razao.focus();
				return;
			}
		}
		if (document.forms[formname].form_cnpj.value == "") {
			alert("Preenchimento necessário: CNPJ! ");
			document.forms[formname].form_cnpj.focus();
			return;
		} else {
		}	
	} else {
	}
	if (document.forms[formname].nome.value == "") {
		alert("Preenchimento necessário: Nome completo! ");
		document.forms[formname].nome.focus();
		return;
	} else {
		if (document.forms[formname].nome.value.length < 5) {
			alert("Preenchimento necessário: Nome completo! ");
			document.forms[formname].nome.focus();
			return;
		}
	}
	if (tipo==1) {
	if (document.forms[formname].NAMEPOST.value == "DOWNLOADS") {
	} else {
		if (document.forms[formname].form_cpf.value == "") {
			alert("Preenchimento necessário: CPF! ");
			document.forms[formname].form_cpf.focus();
			return;
		} else {
		}
	}
		if (document.forms[formname].date.value == "dd") {
			alert("Preenchimento necessário: Dia de Nascimento! ");
			document.forms[formname].date.focus();
			return;
		} else {
		}
		if (document.forms[formname].month.value == "mm") {
			alert("Preenchimento necessário: Mês de Nascimento! ");
			document.forms[formname].month.focus();
			return;
		} else {
		}
		if (document.forms[formname].year.value == "yyyy") {
			alert("Preenchimento necessário: Ano de Nascimento! ");
			document.forms[formname].year.focus();
			return;
		} else {
		}		
	} else {
	}
	if (document.forms[formname].email.value == "") {
		alert("Preenchimento necessário: E-mail! ");
		document.forms[formname].email.focus();
		return;
	} else {
	}
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.forms[formname].email.value)) {
	} else {
		alert("E-mail ("+ document.forms[formname].email.value + ") inválido. Tente novamente. ");
		document.forms[formname].email.value="";
		document.forms[formname].email.focus();
		return;
	}
	if (document.forms[formname].NAMEPOST.value == "DOWNLOADS") {
		var DID = $("#did").val();
	} else {
		if (document.forms[formname].cep.value.length < 9) {
			alert("Preenchimento necessário: CEP! ");
			document.forms[formname].cep.value="";
			document.forms[formname].cep.focus();
			return;
		} else {
		}
		if (document.forms[formname].cidade.value == "") {
			alert("Preenchimento necessário: Cidade! ");
			document.forms[formname].cidade.focus();
			return;
		} else {
		}
		if (document.forms[formname].uf.value == "") {
			alert("Preenchimento necessário: Estado! ");
			document.forms[formname].uf.focus();
			return;
		} else {
		}		
		if (document.forms[formname].end.value.length < 3) {
			alert("Preenchimento necessário: Endereço! ");
			document.forms[formname].end.value="";
			document.forms[formname].end.focus();
			return;
		} else {
		}
		if (document.forms[formname].endnumero.value == "") {
			document.forms[formname].endnumero.value="S/N";
		} else {
		}
		if (document.forms[formname].bairro.value == "") {
			alert("Preenchimento necessário: Bairro! ");
			document.forms[formname].bairro.focus();
			return;
		} else {
		}
		if (document.forms[formname].dddfone.value.length != 2) {
			alert("O DDD do Telefone deve conter 2 dígitos! ");
			document.forms[formname].dddfone.focus();
			return;
		} else {
		}
		if (document.forms[formname].fone.value.length < 8) {
			alert("O Telefone deve conter no mínimo 9 dígitos! ");
			document.forms[formname].fone.focus();
			return;
		} else {
		}
		if (document.forms[formname].NAMEPOST.value == "GARANTIA") {
			if (document.forms[formname].modeloproduto.value == "") {
				alert("Preenchimento necessário: Modelo do produto! ");
				document.forms[formname].modeloproduto.focus();
				return;
			} else {
			}
			if (document.forms[formname].numerodeserie.value == "") {
				alert("Preenchimento necessário: Número de série do produto! ");
				document.forms[formname].numerodeserie.focus();
				return;
			} else {
			}
			if (document.forms[formname].notafiscal.value == "") {
				alert("Preenchimento necessário: Número da nota fiscal! ");
				document.forms[formname].notafiscal.focus();
				return;
			} else {
			}
			if (document.forms[formname].notadate.value == "dd") {
				alert("Preenchimento necessário: Dia da data de saída da nota fiscal! ");
				document.forms[formname].notadate.focus();
				return;
			} else {
				var gdia=document.forms[formname].notadate.value;
			}
			if (document.forms[formname].notamonth.value == "mm") {
				alert("Preenchimento necessário: Mês da data de saída da nota fiscal! ");
				document.forms[formname].notamonth.focus();
				return;
			} else {
				var gmes=document.forms[formname].notamonth.value;
			}
			if (document.forms[formname].notayear.value == "yyyy") {
				alert("Preenchimento necessário: Ano da data de saída da nota fiscal! ");
				document.forms[formname].notayear.focus();
				return;
			} else {
				var gano=document.forms[formname].notayear.value;
			}
			if (document.forms[formname].grazao.value == "") {
				alert("Preenchimento necessário: Nome da Loja! ");
				document.forms[formname].grazao.focus();
				return;
			} else {
			}
			if (document.forms[formname].gcnpj.value == "") {
				alert("Preenchimento necessário: CNPJ da Loja! ");
				document.forms[formname].gcnpj.focus();
				return;
			} else {
			}
			if ((document.forms[formname].q1[0].checked==false) && (document.forms[formname].q1[1].checked==false) && (document.forms[formname].q1[2].checked==false)) {
				alert("Escolha um opção em Produto do Controle de Qualidade! ");
				return;
			} else {
			}	
			if ((document.forms[formname].q2[0].checked==false) && (document.forms[formname].q2[1].checked==false) && (document.forms[formname].q2[2].checked==false)) {
				alert("Escolha um opção em Produto do Controle de Qualidade! ");
				return;
			} else {
			}	
			if ((document.forms[formname].q3[0].checked==false) && (document.forms[formname].q3[1].checked==false) && (document.forms[formname].q3[2].checked==false)) {
				alert("Escolha um opção em Produto do Controle de Qualidade! ");
				return;
			} else {
			}
			if(document.forms[formname].termos.checked!=true) {
				alert("Por favor, aceite os Termos e Condições!");
				document.forms[formname].termos.focus();
				return;
			} else {
			}
			var textok = ('<div style="text-align:center;padding-top:20px;"><strong>Seu cadastro foi realizado com sucesso.</strong><br /><br />Entraremos em contato o mais breve possível,<br />para qualificar sua garantia estendida.</div><div style="text-align:center;padding-top:20px;"><span style="font-weight:bold;color:#c81c23;">Atenção: Guarde a Nota Fiscal de compra do produto.</span><br />A Garantia Estendida Fogatti só será válida mediante apresentação da Nota Fiscal de compra (com a data da compra legível e sem rasuras) na Assistência Técnica Autorizada Fogatti, no momento do reparo/conserto do produto, respeitando o regulamento da Garantia Estendida descrita no site.<br />A comprovação da data de compra do produto é de responsabilidade do cliente.</div>');
		} else {
			if (document.forms[formname].NAMEPOST.value == "VENDADIRETA") {
				if (document.forms[formname].listproduto.value == "") {
					alert("Por favor, selecione um produto! ");
					document.forms[formname].listproduto.focus();
					return;
				} else {
				}
				if (document.forms[formname].voltagem.value == "") {
					alert("Por favor, selecione uma voltagem! ");
					document.forms[formname].voltagem.focus();
					return;
				} else {
				}
				var textok = ('<div style="text-align:center;padding-top:20px;"><strong>Sua mensagem foi enviada para um de nossos atendentes.</strong><br /><br />Entraremos em contato o mais breve possível. Obrigado.</div>');
			} else {
				if (document.forms[formname].assunto.value == "") {
					alert("Por favor, selecione um Assunto! ");
					document.forms[formname].assunto.focus();
					return;
				} else {
				}
				if (document.forms[formname].listproduto.value == "") {
					alert("Por favor, selecione um produto! ");
					document.forms[formname].listproduto.focus();
					return;
				} else {
				}
				if (document.forms[formname].voltagem.value == "") {
					alert("Por favor, selecione uma voltagem! ");
					document.forms[formname].voltagem.focus();
					return;
				} else {
				}
				var forImagem = $('#formImagem').val();
				if (forImagem == "") {
				} else {
					var ext = $('#formImagem').val().split('.').pop().toLowerCase();
					if($.inArray(ext, ['jpg','jpeg']) == -1) {
						alert('Somente extenção .JPG!');
						document.forms[formname].file.focus();
						return;
					}

				}
				if (document.forms[formname].mensagem.value == "") {
					alert("Preenchimento necessário: Mensagem! ");
					document.forms[formname].mensagem.focus();
					return;
				} else {
				}
			var textok = ('<div style="text-align:center;padding-top:20px;"><strong>Sua mensagem foi enviada para um de nossos atendentes</strong><br /><br />Entraremos em contato o mais breve possível. Obrigado.</div>');
			}
			
		}
	}
	var NAMEPOST = $("#NAMEPOST").val();
	var params = $('#'+formname).serialize();
	$('#'+formname).hide();
	$('#error').hide();
	var d = new Date();
	var url = "data/sendmail.php?d="+d.getTime();
	if (NAMEPOST == "SAC") {
		$('#response').hide();
		$('#sendmail').html('<div style="text-align:center;padding-top:20px;"><span class="ajaxload"><strong>Enviando, aguarde...</strong></span></div>');
		document.forms[formname].target="iframePRO";
		document.forms[formname].action=url;
		document.forms[formname].submit();
		$('#sendmail').html(textok);
	} else {
		$('#response').html('<div style="text-align:center;padding-top:20px;"><span class="ajaxload"><strong>Enviando, aguarde...</strong></span></div>');
		$.ajax({
			type: "POST",
			enctype: 'multipart/form-data',
			url: url,
			cache: false,
			data: params,
			success: function(data){
				if (NAMEPOST == "DOWNLOADS") {
					$('#response').html(data+'<div style="text-align:center;padding-top:20px;"><strong>Processo concluído com sucesso.</strong><br /><br /><a class="red" href="central-de-downloads.html" title="Clique aqui..."><strong>Central de Downloads</strong></a></div>');
					window.document.location.href=('download_prosseguir_'+DID+'.html');
				} else if (NAMEPOST == "GARANTIA") {
					var erro1=('Infelizmente seu prazo de 3 meses, a partir da data de compra, para solicitação da garantia estendida já expirou.');
					var erro2=('Produto já cadastrado.');
					if (data=='ERRO1') {
						$('#response').html('<div style="text-align:center;padding-top:20px;font-weight:bold;font-size:1.2em;">'+erro1+'</div>');alert(erro1);
					} else if (data=='ERRO2') {
						$('#response').html('<div style="text-align:center;padding-top:20px;font-weight:bold;font-size:1.2em;">'+erro2+'</div>');alert(erro2);
					} else {
						$('#response').html(textok);
					}
				} else {
					$('#response').html(textok);
				}
			}
		 });
	 }
	return false;
};
function chkAssunto(dados){
	if (dados == 'Venda direta') {
		$('#txtMensagem').hide();
		$('#NAMEPOST').val('VENDADIRETA');
		$("#formImagem").val('');
		$('#mensagem').val('T3LnYW1lbnRv');
	} else {
		$('#NAMEPOST').val('SAC');
		$('#txtMensagem').show();
		$('#mensagem').val('');
	}
}
function proximoCampo(atual,proximo){
	if(atual.value.length >= atual.maxLength){
	document.getElementById(proximo).focus();
	}
}
function verifica_cpf(form){
	value = form.form_cpf.value;
	if (value == "") {
		return;
	}
	value = value.replace('.','');
	value = value.replace('.','');
	cpf = value.replace('-','');
	while(cpf.length < 11) cpf = "0"+ cpf;
	var expReg = /^0+$|^1+$|^2+$|^3+$|^4+$|^5+$|^6+$|^7+$|^8+$|^9+$/;
	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]) || cpf.match(expReg)) {
		form.form_cpf.value = "";
		alert("Informe um CPF válido.");
		form.form_cpf.focus();
		return false;
	}else{
	}
}
function verifica_cnpj(fname){
	var msgerror = "Informe um CNPJ válido.";

	cnpj = fname.value;
	
	// DEIXA APENAS OS NÚMEROS
	cnpj = cnpj.replace('/','');
	cnpj = cnpj.replace('.','');
	cnpj = cnpj.replace('.','');
	cnpj = cnpj.replace('-','');

	var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
	digitos_iguais = 1;
	if (cnpj == "") {
		return;
	}
	if (cnpj.length < 14 && cnpj.length > 15){
		fname.value = "";
		alert(msgerror);
		fname.focus();
		return false;
	}
	for (i = 0; i < cnpj.length - 1; i++){
		if (cnpj.charAt(i) != cnpj.charAt(i + 1)){
			digitos_iguais = 0;
			break;
		}
	}

	if (!digitos_iguais){
		tamanho = cnpj.length - 2
		numeros = cnpj.substring(0,tamanho);
		digitos = cnpj.substring(tamanho);
		soma = 0;
		pos = tamanho - 7;

		for (i = tamanho; i >= 1; i--){
			soma += numeros.charAt(tamanho - i) * pos--;
			if (pos < 2){
				pos = 9;
			}
		}
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if (resultado != digitos.charAt(0)){
			fname.value = "";
			alert(msgerror);
			fname.focus();
			return false;
		}
		tamanho = tamanho + 1;
		numeros = cnpj.substring(0,tamanho);
		soma = 0;
		pos = tamanho - 7;
		for (i = tamanho; i >= 1; i--){
			soma += numeros.charAt(tamanho - i) * pos--;
			if (pos < 2){
				pos = 9;
			}
		}
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if (resultado != digitos.charAt(1)){
			fname.value = "";
			alert(msgerror);
			fname.focus();
			return false;
		}else{

		}
	}else{
		fname.value = "";
		alert(msgerror);
		fname.focus();
		return false;
	}
}
function lical(ulid,i,id) {
	var sum = 0;
	for(var j=1; j<=i; j++) {
		sum = sum + $("ul"+ulid+" li:eq("+(j-1)+")").outerWidth(true);
	}
	$(id).width((sum));
};

function chkVolts(pid){
	var epid = pid.split('|');
	if (pid!=""){
		$("select#voltagem").attr("disabled","disabled").html('<option value="">Carregando...</option>').load("data/voltagem.php?q="+epid[0]).removeAttr("disabled");
	} else {
	}
}
