var tipo = 0;

function FaleConosco() {
	tipo = 1;
	document.form1.action = "mail.asp";
	document.form1.method = "post";
}

function Newsletter() {
	tipo = 2;
	document.form1.action = "newsletter-action.asp";
	document.form1.method = "post";
}

function Busca() {
	tipo = 3;
	document.form1.action = "";
	document.form1.method = "get";
}

function Duvida() {
	tipo = 4;
	document.form1.action = "duvidas-mail.asp";
	document.form1.method = "post";
}

function Carrinho() {
	tipo = 5;
	document.form1.action = "../orcamento/orc-upd.asp";
	document.form1.method = "post";
}

function BuscaProd() {
	tipo = 6;
	document.form1.action = "";
	document.form1.method = "get";
}

function BuscaProdPP() {
	tipo = 7;
	document.form1.action = "";
	document.form1.method = "get";
}

function EnviarOrcamento() {
	tipo = 8;
	document.form1.action = "orc-mail.asp";
	document.form1.method = "post";
}

function FaqBusca() {
	tipo = 9;
	document.form1.action = "faq-busca.asp";
	document.form1.method = "get";
}

function Revendedores() {
	tipo = 10;
	document.form1.action = "mail.asp";
	document.form1.method = "post";
}

function TrabalheConosco() {
	tipo = 11;
	document.form1.action = "mail.asp";
	document.form1.method = "post";
}

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------

function EnviaFormulario() {
	switch(tipo) {
		case 1: return VFaleConosco(); break;
		case 2: return VNewsletter(); break;
		case 3:	if (VBusca()) { document.location.href="busca.asp?busca=" + document.form1.busca.value; } break;
		case 4: return VDuvida();
		case 5: return true; break;
		case 6:	if (VBusca()) { document.location.href="../produtos/busca.asp?busca=" + document.form1.busca.value; } break;
		case 7:	if (VBusca()) { document.location.href="produtos/busca.asp?busca=" + document.form1.busca.value; } break;
		case 8: return VEnviarOrcamento(); break;
		case 9:	if (VBuscaFaq()) { document.location.href="faq-busca.asp?busca=" + document.form1.buscafaq.value; } break;
		case 10: return VRevendedores(); break;
		case 11: return VTrabalheConosco(); break;
	}
	return false;
}

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------

function VFaleConosco() {
	if (!document.form1.nome.value) { alert("Por favor, informe seu nome."); document.form1.nome.focus(); return false; };
  if (!VEmail( document.form1.email.value)) { alert("O seu e-mail não é válido!\nVerifique-o novamente."); document.form1.email.focus(); return false; };
  if (!document.form1.cidade.value) { alert("Por favor, informe a cidade."); document.form1.cidade.focus(); return false; };
  if (!document.form1.mensagem.value) { alert("Você deve escrever a mensagem."); document.form1.mensagem.focus(); return false; };
  return true;
}

function VDuvida() {
	if (!document.form1.nome.value) { alert("Por favor, informe seu nome."); document.form1.nome.focus(); return false; };
  if (!VEmail( document.form1.email.value)) { alert("O seu e-mail não é válido!\nVerifique-o novamente."); document.form1.email.focus(); return false; };
  if (!document.form1.cidade.value) { alert("Por favor, informe a cidade."); document.form1.cidade.focus(); return false; };
  if (!document.form1.mensagem.value) { alert("Você deve escrever a mensagem."); document.form1.mensagem.focus(); return false; };
  return true;
}


function VNewsletter() {
	if (!document.form1.newsnome.value) { alert("Por favor, informe seu nome."); document.form1.newsnome.focus(); return false; };
  if (!VEmail(document.form1.newsemail.value)) { alert("O seu e-mail não é válido!\nVerifique-o novamente."); document.form1.newsemail.focus(); return false; };
  return true;
}

function VBusca() {
	if (!(document.form1.busca.value.length > 1)) { alert("Informe um número maior de caracteres para busca."); document.form1.busca.focus(); return false; };
	return true;
}

function VEnviarOrcamento() {
	if (!document.form1.nome.value) { alert("Por favor, informe seu nome."); document.form1.nome.focus(); return false; };
	if (!document.form1.empresa.value) { alert("Por favor, informe sua empresa."); document.form1.empresa.focus(); return false; };
  if (!VEmail( document.form1.email.value)) { alert("O seu e-mail não é válido!\nVerifique-o novamente."); document.form1.email.focus(); return false; };
  if (!document.form1.telefone.value) { alert("Por favor, informe seu telefone."); document.form1.telefone.focus(); return false; };
  if (!document.form1.celular.value) { alert("Por favor, informe seu celular."); document.form1.celular.focus(); return false; };
  return true;
}

function VBuscaFaq() {
	if (!(document.form1.buscafaq.value.length > 1)) { alert("Informe um número maior de caracteres para busca."); document.form1.buscafaq.focus(); return false; };
	return true;
}

function VRevendedores() {
	if (!document.form1.nomefantasia.value) { alert("Por favor, informe o nome da empresa."); document.form1.nomefantasia.focus(); return false; };
	if (!document.form1.razaosocial.value) { alert("Por favor, informe a Razão Social."); document.form1.razaosocial.focus(); return false; };
	if (!VCNPJ(document.form1.cnpj.value)) { alert("Por favor, informe o CNPJ corretamente."); document.form1.cnpj.focus(); return false; };
	if (!document.form1.inscestadual.value) { alert("Por favor, informe a I.E. corretamente (numeros ou isenta)."); document.form1.inscestadual.focus(); return false; };
	if (!document.form1.endereco.value) { alert("Por favor, informe o endereco."); document.form1.endereco.focus(); return false; };
	if (!document.form1.cidade.value) { alert("Por favor, informe a cidade."); document.form1.cidade.focus(); return false; };
	if (!document.form1.estado.value) { alert("Por favor, informe o estado."); document.form1.estado.focus(); return false; };
	if (!document.form1.cep.value) { alert("Por favor, informe o CEP."); document.form1.cep.focus(); return false; };
	if (!document.form1.telefone.value) { alert("Por favor, informe o telefone de contato."); document.form1.telefone.focus(); return false; };
	if (!VEmail( document.form1.email.value)) { alert("Por favor, informe um e-mail válido."); document.form1.email.focus(); return false; };
	if (!document.form1.nomecontato.value) { alert("Por favor, informe uma pessoa para contato."); document.form1.nomecontato.focus(); return false; };
	if (!document.form1.segmentoatuacao.value) { alert("Por favor, informe o segmento de atuação."); document.form1.segmentoatuacao.focus(); return false; };
	return true;
}

function VTrabalheConosco() {
	if (!document.form1.nome.value) { alert("Por favor, informe seu nome."); document.form1.nome.focus(); return false; };
	if (!VEmail( document.form1.email.value)) { alert("Por favor, informe seu e-mail."); document.form1.email.focus(); return false; };
	if (!document.form1.nascimento.value) { alert("Por favor, informe a data de nascimento."); document.form1.nascimento.focus(); return false; };
	if ((!document.form1.sexo[0].checked) && (!document.form1.sexo[1].checked)) { alert("Por favor, selecione o sexo."); document.form1.sexo[0].focus(); return false; };
	if (!document.form1.estadocivil.value) { alert("Por favor, informe seu estado civil."); document.form1.estadocivil.focus(); return false; };
	if (!VCPF(document.form1.cpf.value)) { alert("Por favor, informe seu CPF corretamente."); document.form1.cpf.focus(); return false; };
	if (!document.form1.rg.value) { alert("Por favor, informe seu RG."); document.form1.rg.focus(); return false; };
	if (!document.form1.naturalidade.value) { alert("Por favor, informe sua naturalidade."); document.form1.naturalidade.focus(); return false; };

	if (!document.form1.rua.value) { alert("Por favor, informe o nome da rua  de residência."); document.form1.rua.focus(); return false; };
	if (!document.form1.numero.value) { alert("Por favor, informe o número de residência."); document.form1.numero.focus(); return false; };
	if (!document.form1.bairro.value) { alert("Por favor, informe o bairro de residência."); document.form1.bairro.focus(); return false; };
	if (!document.form1.cidade.value) { alert("Por favor, informe a cidade de residência."); document.form1.cidade.focus(); return false; };
	if (!document.form1.estado.value) { alert("Por favor, informe o estado de residência."); document.form1.estado.focus(); return false; };
	if ((!document.form1.telefone.value) || (!document.form1.celular.value)) { alert("Por favor, informe um telefone de contato."); document.form1.telefone.focus(); return false; };

	if (!document.form1.nivel01.value) { alert("Por favor, selecione o nível de formação."); document.form1.nivel01.focus(); return false; };
	if (!document.form1.curso01.value) { alert("Por favor, informe o curso."); document.form1.curso01.focus(); return false; };
	if (!document.form1.inicio01.value) { alert("Por favor, informe a data de início."); document.form1.inicio01.focus(); return false; };
	if (!document.form1.termino01.value) { alert("Por favor, informe a data de término/conclusão."); document.form1.termino01.focus(); return false; };
	if (!document.form1.situacao01.value) { alert("Por favor, informe a situação do curso."); document.form1.situacao01.focus(); return false; };
 return true;
}

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------

function BuscaFabricantePP(codfab){
	if (isNaN(codfab)) {
		alert("Selecione o Fabricante desejado!");
	} else {
		document.location.href="produtos/buscafab.asp?fab="+ codfab;
	};
}

function BuscaFabricante(codfab){
	if (isNaN(codfab)) {
		alert("Selecione o Fabricante desejado!");
	} else {
		document.location.href="../produtos/buscafab.asp?fab="+ codfab;
	};
}

function Esconde (id) {
	document.getElementById(id).style.display = (document.getElementById(id).style.display == "none") ? "" : "none";
}

function SubmitForm() {
	document.form1.submit();
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function mudacor(prmThis,prmName)	{
	if ((window.document.all) || (window.document.getElementById))
		prmThis.className = prmName;
	else if (window.document.layers)
		prmThis.className = prmName;
}

//===============================================================================
//= ABRE POP-UP CENTRALIZADO ====================================================
//===============================================================================
var win = null;
function NewWindow(mypage,myname,w,h,scroll){
	LeftPosition = parseInt((screen.width) ? (screen.width-w)/2 : 0);
	TopPosition = parseInt((screen.height) ? (screen.height-h)/2 : 0);
	settings = 'width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',noresizable,status=yes'
	win = window.open(mypage,myname,settings)
}


//===============================================================================
//= REDIMENSIONA POP-UP =========================================================
//===============================================================================
function Redimensiona(w, h) {
	//Corrige o tamanho da janela
	if (navigator.appName == "Microsoft Internet Explorer") {
		w = parseInt(w) + 10;
		h = parseInt(h) + 48;
	} else {
		w = parseInt(w) + 6;
		h = parseInt(h) + 49;
	};
	// IE 7
	var nversao = navigator.userAgent;
	var nresult = nversao.search(/\bMSIE 7.0\b/g);
	if (nresult > 0) {
		h = parseInt(h) + 30;
	};
	//
	// FIREFOX 3
	var nversao = navigator.userAgent;
	var nresult = nversao.search(/\bFirefox\/3.0\b/g);
	if (nresult > 0) {
		h = parseInt(h) + 30;
	};
	//
	window.resizeTo(w, h);
	LeftPosition =  parseInt((screen.width) ? (screen.width-w)/2 : 0);
	TopPosition =  parseInt((screen.height) ? (screen.height-h)/2 : 0);
	window.moveTo(LeftPosition,TopPosition);
	window.focus();
}
// ----------------------------------------------------------------------------

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

// Recupera informações de um cookie
function getCookieVal(inicio) {
	var fim = document.cookie.indexOf(";", inicio);
	if (fim == -1) fim = document.cookie.length;
	return unescape(document.cookie.substring(inicio, fim));
}

function getCookie(label) {
	var arg = label + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i,j) == arg) return getCookieVal(j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function setCookie(label, valor, expires) {
	document.cookie = label + "=" + escape(valor) + 
		((expires) ? "; expires=" + expires.toGMTString() : "");
}

function delCookie(label) {
	if (getCookie(label)) {
		document.cookie = label + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

//===============================================================================
//= MASCARAS ====================================================================
//===============================================================================
/* 
	Mascara para Campos.
	"#" - Numeros
	"A" - Letras UpperCase
	"a" - Letras LowerCase
	"Z" - Letras
	"*" - Qualquer Caracter
	"/", ".", "-", " ", ":" - Caracteres Fixos

	USO:
	somente números
		onKeyPress="if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;"
		
		onKeyUp="mascara_hora(this.value)"
*/

function Mascara(objeto, evt, mask) {
	var LetrasU = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var LetrasL = 'abcdefghijklmnopqrstuvwxyz';
	var Letras 	= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
	var Numeros = '0123456789';
	var Fixos 	= '().-:/ '; 
	var Charset = " !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_/`abcdefghijklmnopqrstuvwxyz{|}~";
	
	evt = (evt) ? evt : (window.event) ? window.event : "";
	var value = objeto.value;
	if (evt) {
		var ntecla = (evt.which) ? evt.which : evt.keyCode;
		tecla = Charset.substr(ntecla - 32, 1);
		if (ntecla < 32) return true;

		var tamanho = value.length;
		if (tamanho >= mask.length) return false;

		var pos = mask.substr(tamanho,1); 
		while (Fixos.indexOf(pos) != -1) {
			value += pos;
			tamanho = value.length;
			if (tamanho >= mask.length) return false;
			pos = mask.substr(tamanho,1);
		}

		switch (pos) {
				case '#' : if (Numeros.indexOf(tecla) == -1) return false; break;
				case 'A' : if (LetrasU.indexOf(tecla) == -1) return false; break;
				case 'a' : if (LetrasL.indexOf(tecla) == -1) return false; break;
				case 'Z' : if (Letras.indexOf(tecla) == -1) return false; break;
				case '*' : objeto.value = value; return true; break;
				default : return false; break;
		}
	}
	objeto.value = value; 
	return true;
}

/// SOMENTE NÚMEROS
// ----------------------------------------------------------------------------
function trimToDigits(string) {
	s = "";
	var Numeros = /\d/;
	for (i = 0; i <= string.length; i++) 
		if (Numeros.test(string.substr(i,1))) s += string.substr(i,1);
	return s;	
}

/// VERIFICA E-MAIL
// ----------------------------------------------------------------------------
function VEmail( strEmail ) {
     var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
     return (filter.test(strEmail));
}

/// VERIFICA ANO
// ----------------------------------------------------------------------------
function VAno(ano) {
	ano = trimToDigits(ano);
	return ((parseInt(ano) < 1900) || (ano.length != 4) || (parseInt(ano) > 2050)) ? false : true; 
}

/// VERIFICA MÊS
// ----------------------------------------------------------------------------
function VMes(mes) {
	mes = trimToDigits(mes);
	return ((mes.length != 2) || (parseInt(mes) < 1) || (parseInt(mes) > 12)) ? false : true; 
}

/// VERIFICA MÊS/ANO
// ----------------------------------------------------------------------------
function VMesAno(data) {
	data = trimToDigits(data);
	if (data.length < 6) return false;
	mes = data.substr(0,2);
	ano = data.substr(2,4);
	return (!VAno(ano) || !VMes(mes)) ? false : true;
}

/// VERIFICA DATA
// ----------------------------------------------------------------------------
function VData(data) {
	data = trimToDigits(data);
	if (data.length < 8) return false;
	dia = data.substr(0,2);
	mes = data.substr(2,2);
	ano = data.substr(4,4);
	
	if(ano >= 0 && ano < 1900) return false; 
	if(ano > 2100 || ano < 0 || mes > 12 || mes < 1) return false; 
	numero = ((parseInt(ano) - 1884) / 4) 
	dias = (numero == Math.floor(numero)) ? "312931303130313130313031" : "312831303130313130313031"; 
	diamax = parseInt(dias.substring((mes - 1) * 2, ((mes - 1) * 2) + 2)); 
	if(dia < 1 || dia > diamax) return false; 	
	
	return true;
}

/// VERIFICA CPF
// ----------------------------------------------------------------------------
function VCPF(cpf) {
	cpf = trimToDigits(cpf);
	if (cpf.length < 11) return false;
	valor = true;
	if (cpf == "00000000000" || cpf == "11111111111" || 
			cpf == "22222222222" || cpf == "33333333333" || 
			cpf == "44444444444" || cpf == "55555555555" || 
			cpf == "66666666666" || cpf == "77777777777" || 
			cpf == "88888888888" || cpf == "99999999999") return false;

	var a = [];
	var b = new Number;
	var c = 11;
	for (i = 0; i < 11; i++) {
		a[i] = cpf.charAt(i);
		b = (i < 9) ? b + (a[i] *  --c) : b;
	}
	
	a[9] = ((x = b % 11) < 2) ? 0 : 11 - x;

	b = 0;
	c = 11;
	for (y = 0; y < 10; y++) b += (a[y] *  c--); 
	a[10] = ((x = b % 11) < 2) ? 0 : 11 - x;

	return (cpf.charAt(9) == a[9]) && (cpf.charAt(10) == a[10]);
}	

/// VERIFICA CNPJ
// ----------------------------------------------------------------------------
function VCNPJ(cnpj) {
	cnpj = trimToDigits(cnpj);
	if (cnpj.length < 14) return false;
	m2 = 2;		
	soma1 = 0;
	soma2 = 0;
	for ( i = 11; i >= 0; i--) {
		val = eval(cnpj.charAt(i));
		m1 = m2;
		if (m2 < 9) { m2++ }
	 	else { m2 = 2 }
		soma1 = soma1 + (val * m1)
		soma2 = soma2 + (val * m2)
  }
	soma1 = soma1 % 11
	if (soma1 < 2) { d1 = 0 }
  else { d1 = 11 - soma1}
	soma2 = (soma2 + (2 * d1)) % 11
	if (soma2 < 2) { d2 = 0 }
  else { d2 = 11 - soma2}
	return (cnpj.charAt(12) == d1) && (cnpj.charAt(13) == d2);
}

function MaskAno(objeto, evt) { 
	return Mascara(objeto, evt, '####');
}

function MaskMesAno(objeto, evt) { 
	return Mascara(objeto, evt, '##/####');
}

function MaskCEP(objeto, evt) { 
	return Mascara(objeto, evt, '##.###-###');
}

function MaskTelefone(objeto, evt) { 
	return Mascara(objeto, evt, '(##) ####-####');
}

function MaskCPF(objeto, evt) { 
	return Mascara(objeto, evt, '###.###.###-##');
}

function MaskCNPJ(objeto, evt) { 
	return Mascara(objeto, evt, '##.###.###/####-##');
}

function MaskData(objeto, evt) { 
	return Mascara(objeto, evt, '##/##/####');
}

function MaskData2(objeto, evt) { 
	return Mascara(objeto, evt, '##/##/##');
}

function MaskHora(objeto, evt) { 
	return Mascara(objeto, evt, '##:##');
}

function MaskHora2(objeto, evt) { 
	return Mascara(objeto, evt, '##:##:##');
}

function ExibeFlash(w,h,wmode,movie) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+w+'" height="'+h+'">');
	document.write('<param name="wmode" value="'+wmode+'"/>');
	document.write('<param name="quality" value="high"/>');
	document.write('<param name="movie" value="'+movie+'"/>');
	document.write('<embed src="'+movie+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="'+wmode+'" width="'+w+'" height="'+h+'"></embed>');
	document.write('</object>');
}
