// Função para limpar os . e / do campo

function replaceStr(campo,mascara){
        var strChar;
		for ( var intCont = 0 ; intCont <= campo.length ; intCont++ ) {
			if (campo.charAt(intCont) != mascara)
			{
				strChar = strChar + validar.charAt(intCont);
        	}
		}
        	return strChar;
}

//Função para abrir pop-up
function abrir(pagina,largura,altura, noscroll, resize) {
	if(!noscroll){
		scrollbars = 'no';
	} else {
		scrollbars = 'yes';
	}

	if(!resize){
		resizable = 'no';
	} else {
		resizable = 'yes';
	}

	config="toolbar=yes,location=no,width="+largura+",height="+altura+",status=no,menubar=no,scrollbars=" + scrollbars + ",resizable="+ resizable+",top=" + ((screen.height - altura) / 2) + ",left=" + ((screen.width - largura) /2);
	pop=window.open(pagina,"newwindow",config);
}


//Função para que o campo aceite somente números inteiros
function checkIt(evt) {
	evt = (evt) ? evt : window.event
	var charCode = (evt.which) ? evt.which : evt.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57)) {
		status = "Este campo aceita somente número."
		return false
	}
	status = ""
	return true
}


//Função para que o campo aceite somente números inteiros e vírgula
function CheckNum(){

	if ((event.keyCode < 48) || (event.keyCode > 57)) {
		if ((event.keyCode != 44) && (event.keyCode != 45)) {
		return false;
		}
	}
return true;
}

//Função para formatação geral

function criamascara(_RefObjeto, _Modelo, num){

         var valorAtual = _RefObjeto.value;

         //alert(valorAtual);

         var valorNumerico = '';

         var nIndexModelo = 0;

         var nIndexString = 0;

         var valorFinal = '';

         var adicionarValor = true;

         //num é um parâmetro para saber se a máscara é apenas numérica ou não

         if (num!=undefined && num!=0){num=1;}else{num=0;}

         // limpa a string valor atual para verificar

         // se todos os caracteres são números

         for (i=0;i<_Modelo.length;i++){

             if (_Modelo.substr(i,1) != '#'){

                valorAtual = valorAtual.replace(_Modelo.substr(i,1),'');

              }
         }

         // verifica se todos os caracteres são números

         for (i=0;i<valorAtual.length;i++){

             if(num==0){

                        if (!isNaN(parseFloat(valorAtual.substr(i,1)))){

                                 valorNumerico = valorNumerico + valorAtual.substr(i,1);

                         }

             }

             else{

                        valorNumerico = valorNumerico + valorAtual.substr(i,1);

             }

          }

          // aplica a máscara ao campo informado usando

          // o modelo de máscara informado no script

          for (i=0;i<_Modelo.length;i++){


              if (_Modelo.substr(i,1) == '#'){

                 if (valorNumerico.substr(nIndexModelo,1) != ''){

                    valorFinal = valorFinal + valorNumerico.substr(nIndexModelo,1);

                    nIndexModelo++;nIndexString++;

                 } else {

                    adicionarValor = false;

                 }
              } else {

                if (adicionarValor && valorNumerico.substr(nIndexModelo,1) != ''){

                   valorFinal = valorFinal + _Modelo.substr(nIndexString,1)

                              nIndexString++;
                 }
               }

           }

//alert(valorFinal)

_RefObjeto.value = valorFinal

}


//Função para que o campo aceite somente números inteiros e barra /
function CheckNum2(){
	if ((event.keyCode < 48) || (event.keyCode > 57)) {
		if ((event.keyCode != 44) && (event.keyCode != 47)) {
		return false;
		}
	}
return true;
}

//Função para que o campo aceite somente números, letras sem acento e espaço;
function CheckNumChar(){
	if ((event.keyCode < 48) || (event.keyCode > 57)){
		if ((event.keyCode < 97) || (event.keyCode > 122)) {
			if (event.keyCode != 32){
				status = "Este campo aceita somente números e letras minúsculas.";
				return false;
			}
		}
	}
	return true;
}

//Função para que o campo aceite somente números, letras e caracteres de arquivo;
function CheckFilename(){
	if ((event.keyCode < 46) || (event.keyCode > 58)){
		if ((event.keyCode < 97) || (event.keyCode > 122)) {
			if (event.keyCode != 95){
				status = "Este caracter não é válido para nome de arquivos.";
				return false;
			}
		}
	}
	return true;
}


//Função que faz uma máscara para telefone
function formataTel(campo) {
	var valor
	valor = campo.value.replace('(','').replace('-','').replace(')','');
	if(valor.length == 1){
		campo.value = "(" + valor;
	}else if(valor.length > 6){
		campo.value = "(" + valor.substr(0,2) + ")" + valor.substr(2,4) + "-" + valor.substr(6,4) ;
	}else if(valor.length == 6){
		campo.value = "(" + valor.substr(0,2) + ")" + valor.substr(2,4) ;
	}else if(valor.length > 2 ){
		campo.value = "(" + valor.substr(0,2) + ")" + valor.substr(2,valor.length-2);
	}
}

function formataGrps(campo) {
	var valor
	valor = campo.value.replace('(','').replace('-','').replace(')','');
	if(valor.length == 1){
		campo.value = valor + "/" ;
	}
}

function formataTel7(campo) {
	var valor

	valor = campo.value.replace('(','').replace('-','').replace(')','');
	if(valor.length == 9){
		campo.value = "(" + valor.substr(0,2) + ")" + valor.substr(2,3) + "-" + valor.substr(5,valor.length-5) ;
	}
}


//Função que faz uma máscara para data
function formataData(campo) {
	var valor
	valor = campo.value.replace('/','').replace('/','');
	if(valor.length > 4){
		campo.value = valor.substr(0,2) + "/" + valor.substr(2,2) + "/" + valor.substr(4,4) ;
	}else if(valor.length > 2 ){
		campo.value = valor.substr(0,2) + "/" + valor.substr(2,2);
	}
}

//Função que faz uma máscara para identificação
function formataIdent(campo) {
	var valor
	valor = campo.value.replace('/','');
	valor = campo.value.replace('.','').replace('.','').replace('.','');
	if(valor.length > 9){
		campo.value = valor.substr(0,2) + "." + valor.substr(2,3) + "." + valor.substr(3,5) + "/" + valor.substr(7,2);
 	}else if(valor.length > 4){
		campo.value = valor.substr(0,2) + "." + valor.substr(2,3) + "." + valor.substr(3,5) ;
	}else if(valor.length > 2 ){
		campo.value = valor.substr(0,2) + "." + valor.substr(2,2);
	}
}


//Função que faz uma máscara para cep
function formataCEP(campo) {
	var valor
	valor = campo.value.replace('-','');
	 if(valor.length >= 5){
		campo.value = valor.substr(0,5) + "-" + valor.substr(5,3) ;

	}else{
		campo.value = valor;
	}
}


//Validação de data
function validDate(d) {
	var reData = /(\d{2})\/(\d{2})\/(\d{4})/;
	var datePart = d.match(reData); // datePartconterá [0]=dia, [1]=mes e [2]=ano

	if(datePart == null){
	//alert("Data Invalida");
	return false;
	}

	// passando as partes da data para variáveis mais "amigáveis":
	var dd = datePart[1], mm = datePart[2], yy = datePart[3];
	//alert(dd); // 1o. grupo //alert(mm); // 2o. grupo //alert(yy); // 3o. grupo

	//condições de datas inválidas:
	// dia menor que 1 ou maior que 31
	if (dd<1) { return false;}

	// mes fora dos limites
	if (mm<1 || mm>12) { return false;}

	// meses 4,6,9,11 nao possuem mais de 30 dias
	if ((dd > 30) && (mm == 4)) {return false;}
	if ((dd > 30) && (mm == 6)) {return false;}
	if ((dd > 30) && (mm == 9)) {return false;}
	if ((dd > 30) && (mm == 11)) {return false;}

	if ((dd > 31) && (mm == 1)) {return false;}
	if ((dd > 31) && (mm == 3)) {return false;}
	if ((dd > 31) && (mm == 5)) {return false;}
	if ((dd > 31) && (mm == 7)) {return false;}
	if ((dd > 31) && (mm == 8)) {return false;}
	if ((dd > 31) && (mm == 10)) {return false;}
	if ((dd > 31) && (mm == 12)) {return false;}

	// fevereiro não tem mais de 28 dias, exceto em ano bissexto
	if ((dd > 29) && (mm == 2) && (anobissexto(yy) )) {return false;}
	if ((dd > 28) && (mm == 2) && (!anobissexto(yy) )) {return false;}

// se passou pelos testes acima, então a data é considerada válida.
return true;
}


// retorna verdadeiro se for ano bissexto ou falso se não for bissexto
function anobissexto(yy){
	return (yy % 4 == 0 &&(yy % 100 != 0 || yy % 400 == 0));
}

//VERIFICA O CPF, INCLUSIVE NUMEROS IGUAIS
/*function chCPF(whatForm, whatInput, errorMessage){
  var tmpCPF = whatForm.elements[whatInput];
  var numcpf = tmpCPF.value;*/
function chCPF(whatInput,errorMessage){
  var tmpCPF = whatInput;
  var numcpf = tmpCPF.value;

  x = 0;
  soma = 0;
  dig1 = 0;
  dig2 = 0;
  texto = "";
  numcpf1 = "";
  len = numcpf.length;
  x = len -1;
  for (var i=0; i <= len - 3; i++) {
    y = numcpf.substring(i,i+1);
    soma = soma + ( y * x);
    x = x - 1;
    texto = texto + y;
  }
  dig1 = 11 - (soma % 11);
  if (dig1 == 10) dig1=0 ;
  if (dig1 == 11) dig1=0 ;
    numcpf1 = numcpf.substring(0,len - 2) + dig1 ;
    x = 11; soma=0;
  for (var i=0; i <= len - 2; i++) {
    soma = soma + (numcpf1.substring(i,i+1) * x);
    x = x - 1;
  }
  dig2= 11 - (soma % 11);
  if (dig2 == 10) dig2=0;
  if (dig2 == 11) dig2=0;
  if ((dig1 + "" + dig2) == numcpf.substring(len,len-2)) {
    if(numcpf % 11111111111 == 0){
      //showWarning(errorMessage, tmpCPF);
      tmpCPF.focus();
      return false;
    }
    return true;
  }
  //showWarning(errorMessage, tmpCPF);
  tmpCPF.focus();
  return false;
}

function chCNPJ(whatInput,errorMessage){
  var tmpCNPJ = whatInput;
  CNPJ = tmpCNPJ.value;

  CNPJ = LIMP(CNPJ);
  if(isNUMB(CNPJ) != 1){
   // showWarning(errorMessage, tmpCNPJ);
    tmpCNPJ.focus();
    return false;
  }
  else{
    if(CNPJ == 0){
      //showWarning(errorMessage, tmpCNPJ);
      tmpCNPJ.focus();
      return false;
    }
    else{
      g = CNPJ.length - 2;
      if (RealTestaCNPJ(CNPJ,g) == 1){
        g = CNPJ.length - 1;
        if(RealTestaCNPJ(CNPJ,g) == 1){
          return true;
        }
        else{
          return true;
        }
      }
      else{
		//showWarning(errorMessage, tmpCNPJ);
        tmpCNPJ.focus();
        return false;
      }
    }
  }
}

//DEPENDENCIA PARA O CNPJ
function RealTestaCNPJ(CNPJ,g){
  var VerCNPJ=0;
  var ind=2;
  var tam;
  for(f = g; f > 0; f--){
    VerCNPJ+=parseInt(CNPJ.charAt(f-1))*ind;
    if(ind>8){
      ind=2;
    }
    else{
      ind++;
    }
  }
  VerCNPJ%=11;
  if(VerCNPJ==0 || VerCNPJ==1){
    VerCNPJ=0;
  }
  else{
    VerCNPJ=11-VerCNPJ;
  }
  if(VerCNPJ!=parseInt(CNPJ.charAt(g))){
    return false;
  }
  else{
    return true;
  }
}

//DEPENDENCIA PARA O CNPJ
function LIMP(c){
  while((cx=c.indexOf("-"))!=-1){
    c = c.substring(0,cx)+c.substring(cx+1);
  }
  while((cx=c.indexOf("/"))!=-1){
    c = c.substring(0,cx)+c.substring(cx+1);
  }
  while((cx=c.indexOf(","))!=-1){
    c = c.substring(0,cx)+c.substring(cx+1);
  }
  while((cx=c.indexOf("."))!=-1){
    c = c.substring(0,cx)+c.substring(cx+1);
  }
  while((cx=c.indexOf("("))!=-1){
    c = c.substring(0,cx)+c.substring(cx+1);
  }
  while((cx=c.indexOf(")"))!=-1){
    c = c.substring(0,cx)+c.substring(cx+1);
  }
  while((cx=c.indexOf(" "))!=-1){
    c = c.substring(0,cx)+c.substring(cx+1);
  }
  return(c);
}

//DEPENDENCIA PARA O CNPJ
function isNUMB(c){
  if((cx=c.indexOf(","))!=-1){
    c = c.substring(0,cx)+"."+c.substring(cx+1);
  }
  if((parseFloat(c) / c != 1)){
    if(parseFloat(c) * c == 0){
      return(1);
    }
    else{
      return(0);
    }
  }
  else{
    return(1);
  }
}

//Função De Validação Dos Campos De Fale Conosco
function verifica_campos_contato(f) {

	if (document.form.cmb_assunto.value == ""){
		alert("Selecione um assunto.");
		document.form.cmb_assunto.focus();
	return false;
	}

	if (document.form.txt_nome.value == ""){
		alert("Preencha o campo 'Nome'.");
		document.form.txt_nome.focus();
	return false;
	}

	if (document.form.txt_nome.value.length < 3){
		alert("O campo 'Nome' não está preenchido corretamente!");
		document.form.txt_nome.focus();
	return false;
	}

	if (document.form.txt_email.value < 1){
		alert("Preencha o campo 'E-Mail'.");
		document.form.txt_email.focus();
	return false;
	}

	var  exp = /^([0-9,a-z,A-Z]+)([.,_]([0-9,a-z,A-Z]+))*[@]([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[.]([0-9,a-z,A-Z]){2}([0-9,a-z,A-Z])?$/;
	if (!exp.test(document.form.txt_email.value)) {
		alert("O campo 'E-Mail' não está preenchido corretamente!");
		document.form.txt_email.focus();
	return false;
	}

	if (document.form.txt_cidade.value == ""){
		alert("Preencha o campo 'Cidade'.");
		document.form.txt_cidade.focus();
	return false;
	}

	if (document.form.txt_cidade.value.length < 3){
		alert("O campo 'Cidade' não está preenchido corretamente!");
		document.form.txt_cidade.focus();
	return false;
	}

	if (document.form.txt_escola.value == ""){
		alert("Preencha o campo 'Escola'.");
		document.form.txt_escola.focus();
	return false;
	}

	if (document.form.txt_escola.value.length < 3){
		alert("O campo 'Escola' não está preenchido corretamente!");
		document.form.txt_escola.focus();
	return false;
	}

	if (document.form.txt_material.value == ""){
		alert("Preencha o campo 'Material'.");
		document.form.txt_material.focus();
	return false;
	}

	if (document.form.txt_material.value.length < 3){
		alert("O campo 'Material' não está preenchido corretamente!");
		document.form.txt_material.focus();
	return false;
	}

	if (document.form.txt_tema.value == ""){
		alert("Preencha o campo 'Tema'.");
		document.form.txt_tema.focus();
	return false;
	}

	if (document.form.txt_tema.value.length < 3){
		alert("O campo 'Tema' não está preenchido corretamente!");
		document.form.txt_tema.focus();
	return false;
	}

	if (document.form.txt_mensagem.value == ""){
		alert("Preencha o campo 'Mensagem'.");
		document.form.txt_mensagem.focus();
	return false;
	}

	if (document.form.txt_mensagem.value.length < 1){
		alert("O campo 'Mensagem' não está preenchido corretamente!");
		document.form.txt_mensagem.focus();
	return false;
	}

return true
}

//Função De Validação Dos Campos Do Sistema De Escolas
function verifica_campos_escola(f) {

	if (document.form.txt_qtde_aluno.value == ""){
		alert("Preencha o campo 'Qtde. Aluno'.");
		document.form.txt_qtde_aluno.focus();
	return false;
	}

	if (document.form.txt_qtde_aluno.value.length < 2){
		alert("O campo 'Qtde. Aluno' não está preenchido corretamente!");
		document.form.txt_qtde_aluno.focus();
	return false;
	}

	if (document.form.txt_razao_social.value == ""){
		alert("Preencha o campo 'Razão Social'.");
		document.form.txt_razao_social.focus();
	return false;
	}

	if (document.form.txt_razao_social.value.length < 4){
		alert("O 'Razão Social' deve ter pelo menos 4 caracteres!");
		document.form.txt_razao_social.focus();
	return false;
	}

	if (document.form.txt_nome_fantasia.value == ""){
		alert("Preencha o campo 'Nome Fantasia'.");
		document.form.txt_nome_fantasia.focus();
	return false;
	}

	if (document.form.txt_nome_fantasia.value.length < 3){
		alert("O campo 'Nome Fantasia' deve ter pelo menos 3 caracteres!");
		document.form.txt_nome_fantasia.focus();
	return false;
	}

	if (document.form.txt_cnpj.value < 1){
		alert("Preencha o campo 'CNPJ'.");
		document.form.txt_cnpj.focus();
	return false;
	}

	if (!chCNPJ(document.form.txt_cnpj, 'CNPJ inválido.')){
		alert("'CNPJ' inválido.");
		document.form.txt_cnpj.focus();
		return false;
	}

	if (document.form.txt_telefone.value == ""){
		alert("Preencha o campo 'Telefone'.");
		document.form.txt_telefone.focus();
	return false;
	}

	//if (document.form.txt_telefone.value.length < 13){
	//	alert("O campo 'Telefone' não está preenchido corretamente!");
	//	document.form.txt_telefone.focus();
	//return false;
	//}

	if (document.form.txt_endereco.value == ""){
		alert("Preencha o campo 'Endereço'.");
		document.form.txt_endereco.focus();
	return false;
	}

	if (document.form.txt_endereco.value.length < 3){
		alert("O campo 'Endereço' não está preenchido corretamente!");
		document.form.txt_endereco.focus();
	return false;
	}

	if (document.form.txt_cep.value == ""){
		alert("Preencha o campo 'CEP'.");
		document.form.txt_cep.focus();
	return false;
	}

	if (document.form.txt_cep.value.length < 8){
		alert("O campo 'CEP' não está preenchido corretamente!");
		document.form.txt_cep.focus();
	return false;
	}

	if (document.form.txt_cidade.value == ""){
		alert("Preencha o campo 'Cidade'.");
		document.form.txt_cidade.focus();
	return false;
	}

	if (document.form.txt_cidade.value.length < 3){
		alert("O campo 'Cidade' não está preenchido corretamente!");
		document.form.txt_cidade.focus();
	return false;
	}

	if (document.form.cmb_estado.value == ""){
		alert("Preencha o campo 'Estado'.");
		document.form.cmb_estado.focus();
	return false;
	}

return true;
}


//Função De Validação Dos Campos Do Sistema De Professores
function verifica_campos_professor(f) {

	if (document.form.id_tipo.value == ""){
		alert("Selecione um item no campo 'Tipo'.");
		document.form.id_tipo.focus();
	return false;
	}

	if (document.form.txt_nome.value == ""){
		alert("Preencha o campo 'Nome'.");
		document.form.txt_nome.focus();
	return false;
	}

	if (document.form.txt_nome.value.length < 3){
		alert("O campo 'Nome' não está preenchido corretamente!");
		document.form.txt_nome.focus();
	return false;
	}


	/*if (document.form.txt_data_nasc.value.length < 5){
		alert("Preencha o campo Aniversário (dd/mm).");
		document.form.txt_data_nasc.focus();
	return false;
	}*/

	// validação de aniversário
	var data = document.form.txt_data_nasc.value;

	// verifica se existem 10 digitos
	if( data.length < 5){
		alert("Formato inválido de Aniversário (dd/mm)");
		document.form.txt_data_nasc.focus();
	return false;

	} else {

	// separa dia / mes / ano
		var data2= /\//;
		var lista = data.split(data2);

	if(lista.length < 2){
		alert("Formato inválido de data");
		document.form.txt_data_nasc.focus();
	return false;
	}

	var dia = lista[0];
	var mes = lista[1];
	//var ano = lista[2];
	var int_format = /^[ ]*[+-]?\d+[ ]*$/;

	// verifica o dia
	if((dia.length != 2)||(dia > 31)||(dia < 1)||(!int_format.test(dia))){
		alert("Dia inválido");
		document.form.txt_data_nasc.focus();
	return false;
	}

	// verifica o mes
	if((mes.length != 2)||(mes > 12)||(mes < 1)||(!int_format.test(mes))){
		alert("Mês inválido");
		document.form.txt_data_nasc.focus();
	return false;
	}

	// verifica o ano
	//if((ano.length != 4)||(ano <= 1)||(!int_format.test(ano))){
		//alert("Ano inválido");
	//return false;
	//}
	}



	if (document.form.txt_cpf.value == ""){
		alert("Preencha o campo 'CPF'.");
		document.form.txt_cpf.focus();
	return false;
	}

	if (!chCPF(document.form.txt_cpf, 'CPF inválido.')){
		alert("'CPF' inválido.");
		document.form.txt_cpf.focus();
		return false;
	}

	if (document.form.txt_email.value < 1){
		alert("Preencha o campo 'E-Mail'.");
		document.form.txt_email.focus();
	return false;
	}

	var  exp = /^([0-9,a-z,A-Z]+)([.,_]([0-9,a-z,A-Z]+))*[@]([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[.]([0-9,a-z,A-Z]){2}([0-9,a-z,A-Z])?$/;
	if (!exp.test(document.form.txt_email.value)) {
		alert("E-mail inválido!");
		document.form.txt_email.focus();
	return false;
	}

	if (document.form.txt_telefone.value == ""){
		alert("Preencha o campo 'Telefone'.");
		document.form.txt_telefone.focus();
	return false;
	}

	//if (document.form.txt_tel.value.length < 13){
	//	alert("O campo 'Telefone' não está preenchido corretamente!");
	//	document.form.txt_tel.focus();
	//return false;
	//}

	if (document.form.txt_login.value == ""){
		alert("Preencha o campo 'Login'.");
		document.form.txt_login.focus();
	return false;
	}

	if (document.form.txt_login.value < 1){
		alert("Preencha o campo 'Login'.");
		document.form.txt_login.focus();
	return false;
	}

	if (document.form.txt_login.value.length < 3){
		alert("O campo 'Login' não está preenchido corretamente!");
		document.form.txt_login.focus();
	return false;
	}

	if (document.form.txt_senha.value == ""){
		alert("Preencha o campo 'Senha'.");
		document.form.txt_senha.focus();
	return false;
	}

	if (document.form.txt_senha.value < 1){
		alert("Preencha o campo 'Senha'.");
		document.form.txt_senha.focus();
	return false;
	}


	if (document.form.txt_senha.value.length < 3){
		alert("O campo 'Senha' não está preenchido corretamente!");
		document.form.txt_senha.focus();
	return false;
	}

return true;
}

//Função Auxiliar De Validação Dos Campos de escolha dos produtos de pedidos online
function chkRangeQtde(qtde,valor){
	minQ = Math.ceil((qtde * 0.9));	// Valor mínimo: -10%
	maxQ = Math.floor((qtde * 2));		// Valor máximo: +100%
	if((valor >=  minQ)&&(valor <= maxQ)){
		return true;
	}else{
		return false;
	}
}

//Função De Validação Dos Campos de escolha dos produtos de pedidos online
function verifica_campos_pedido_produtos(f) {
	minQ ='';
	maxQ = '';
	chkOk = false;
	if(document.getElementById('hdn_qtd_itens').value > 0){
		itens = document.getElementById('hdn_qtd_itens').value;
		for(i=1;i<=itens;i++){
			if(document.getElementById('chk_solicitar'+i).checked){
				if(!chkRangeQtde(document.getElementById('hdn_qtd_p'+i).value,document.getElementById('txt_qtd'+i).value)){
					minQ = Math.ceil((document.getElementById('hdn_qtd_p'+i).value * 0.9));
					maxQ = Math.floor((document.getElementById('hdn_qtd_p'+i).value * 2));
					prod = document.getElementById('txt_prod'+i).innerHTML;
					document.getElementById('txt_qtd'+i).focus();
					document.getElementById('txt_qtd'+i).select();
					chkOk = false;
					break;
				}else{
					chkOk = true;
				}
			}
		}
		if(chkOk){
			return true;
		}else{
			if(minQ != ""){
				alert('O produto "'+prod+'" está com a quantidade fora dos padrões de contrato.\nPara efetuar pedidos com menos de '+minQ+' ou mais de '+maxQ+' exemplares, entre em contato com nossa equipe através do telefone 0800-551611');
			}else{
				alert('Por favor, você deve checar os produtos desejados.');
			}
			return false;
		}
	}else{
		return false;
	}
}


function verifica_campos_pedido_envia(nform) {
	marcado = 0;
	if(nform.trans.value==-1 && nform.trans.checked){
		if(!verifica_campos_pedido_trans(nform)){
			return false;
		}
	}else{
		for (i=0; i<nform.trans.length; i++) {
			if (nform.trans[i].checked) {
				marcado = 1;
				if(nform.trans[i].value==-1){
					if(!verifica_campos_pedido_trans(nform)){
						return false;
					}
				}
			}
		}
		if(marcado!=1){
		alert('Selecione uma transportadora.');
		return false;
		}
	}



	if(!verifica_campos_escola_pedidos()){
		return false;
	}

	return true;
}


function verifica_campos_pedido_trans(nform) {
	if (nform.txt_razao_social_t.value == ""){
		alert("Preencha o campo 'Razão Social'.");
		nform.txt_razao_social_t.focus();
	return false;
	}

	if (nform.txt_cnpj_t.value == ""){
		alert("Preencha o campo 'CNPJ'.");
		nform.txt_cnpj_t.focus();
	return false;
	}

	if (!chCNPJ(nform.txt_cnpj_t, 'CNPJ inválido.')){
		alert("'CNPJ' inválido.");
		nform.txt_cnpj_t.focus();
		return false;
	}
	/*
	if (!chCNPJ(document.nform.txt_cnpj_t, 'CNPJ inválido.')){
		alert("'CNPJ' inválido.");
		document.nform.txt_cnpj_t.focus();
		return false;
	}*/


	if (nform.txt_insc_estadual_t.value == ""){
		alert("Preencha o campo 'Inscrição Estadual'.");
		nform.txt_insc_estadual_t.focus();
	return false;
	}

	if (nform.txt_cep_t.value == ""){
		alert("Preencha o campo 'CEP'.");
		nform.txt_cep_t.focus();
	return false;
	}

	if (nform.txt_endereco_t.value == ""){
		alert("Preencha o campo 'Endereço'.");
		nform.txt_endereco_t.focus();
	return false;
	}

	if (nform.txt_numero_t.value == ""){
		alert("Preencha o campo 'Numero'.");
		nform.txt_numero_t.focus();
	return false;
	}

	if (nform.txt_bairro_t.value == ""){
		alert("Preencha o campo 'Bairro'.");
		nform.txt_bairro_t.focus();
	return false;
	}

	if (nform.txt_telefone_t.value == ""){
		alert("Preencha o campo 'Telefone'.");
		nform.txt_telefone_t.focus();
	return false;
	}

	if (nform.txt_cidade_t.value == ""){
		alert("Preencha o campo 'Cidade'.");
		nform.txt_cidade_t.focus();
	return false;
	}

	if (nform.cmb_estado_t.value == "" || nform.cmb_estado_t.value == "--"){
		alert("Preencha o campo 'Estado'.");
		nform.cmb_estado_t.focus();
	return false;
	}

	return true;
}



//Função De Validação Dos Campos Do Sistema De Pedidos, escola
function verifica_campos_escola_pedidos(f) {

	if (document.form_dados.txt_razao_social.value == ""){
		alert("Preencha o campo 'Razão Social'.");
		document.form_dados.txt_razao_social.focus();
	return false;
	}

	if (document.form_dados.txt_razao_social.value.length < 4){
		alert("O 'Razão Social' deve ter pelo menos 4 caracteres!");
		document.form_dados.txt_razao_social.focus();
	return false;
	}

	if (document.form_dados.txt_nome_fantasia.value == ""){
		alert("Preencha o campo 'Nome Fantasia'.");
		document.form_dados.txt_nome_fantasia.focus();
	return false;
	}

	if (document.form_dados.txt_nome_fantasia.value.length < 3){
		alert("O campo 'Nome Fantasia' deve ter pelo menos 3 caracteres!");
		document.form_dados.txt_nome_fantasia.focus();
	return false;
	}

	if (document.form_dados.txt_cnpj.value < 1){
		alert("Preencha o campo 'CNPJ'.");
		document.form_dados.txt_cnpj.focus();
	return false;
	}

	if (!chCNPJ(document.form_dados.txt_cnpj, 'CNPJ inválido.')){
		alert("'CNPJ' inválido.");
		document.form_dados.txt_cnpj.focus();
		return false;
	}

	if (document.form_dados.txt_telefone.value == ""){
		alert("Preencha o campo 'Telefone'.");
		document.form_dados.txt_telefone.focus();
	return false;
	}

	//if (document.form_dados.txt_telefone.value.length < 13){
	//	alert("O campo 'Telefone' não está preenchido corretamente!");
	//	document.form_dados.txt_telefone.focus();
	//return false;
	//}

	if (document.form_dados.txt_endereco.value == ""){
		alert("Preencha o campo 'Endereço'.");
		document.form_dados.txt_endereco.focus();
	return false;
	}

	if (document.form_dados.txt_endereco.value.length < 3){
		alert("O campo 'Endereço' não está preenchido corretamente!");
		document.form_dados.txt_endereco.focus();
	return false;
	}

	if (document.form_dados.txt_cep.value == ""){
		alert("Preencha o campo 'CEP'.");
		document.form_dados.txt_cep.focus();
	return false;
	}

	if (document.form_dados.txt_cep.value.length < 8){
		alert("O campo 'CEP' não está preenchido corretamente!");
		document.form_dados.txt_cep.focus();
	return false;
	}

	if (document.form_dados.txt_cidade.value == ""){
		alert("Preencha o campo 'Cidade'.");
		document.form_dados.txt_cidade.focus();
	return false;
	}

	if (document.form_dados.txt_cidade.value.length < 3){
		alert("O campo 'Cidade' não está preenchido corretamente!");
		document.form_dados.txt_cidade.focus();
	return false;
	}

	if (document.form_dados.cmb_estado.value == ""){
		alert("Preencha o campo 'Estado'.");
		document.form_dados.cmb_estado.focus();
	return false;
	}

return true;
}






//Função De Validação Dos Campos De Dúvidas Pedagógicas
function verifica_campos_duvidas(f) {

	if (document.form.txt_nome.value == ""){
		alert("Preencha o campo 'Nome'.");
		document.form.txt_nome.focus();
	return false;
	}

	if (document.form.txt_nome.value.length < 3){
		alert("O campo 'Nome' não está preenchido corretamente!");
		document.form.txt_nome.focus();
	return false;
	}

	if (document.form.txt_email.value < 1){
		alert("Preencha o campo 'E-Mail'.");
		document.form.txt_email.focus();
	return false;
	}

	var  exp = /^([0-9,a-z,A-Z]+)([.,_]([0-9,a-z,A-Z]+))*[@]([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[.]([0-9,a-z,A-Z]){2}([0-9,a-z,A-Z])?$/;
	if (!exp.test(document.form.txt_email.value)) {
		alert("O campo 'E-Mail' não está preenchido corretamente!");
		document.form.txt_email.focus();
	return false;
	}

	if (document.form.txt_cidade.value == ""){
		alert("Preencha o campo 'Cidade'.");
		document.form.txt_cidade.focus();
	return false;
	}

	if (document.form.txt_cidade.value.length < 3){
		alert("O campo 'Cidade' não está preenchido corretamente!");
		document.form.txt_cidade.focus();
	return false;
	}

	if (document.form.txt_escola.value == ""){
		alert("Preencha o campo 'Escola'.");
		document.form.txt_escola.focus();
	return false;
	}

	if (document.form.txt_escola.value.length < 3){
		alert("O campo 'Escola' não está preenchido corretamente!");
		document.form.txt_escola.focus();
	return false;
	}

	if (document.form.txt_disciplina.value == ""){
		alert("Preencha o campo 'Disciplina'.");
		document.form.txt_disciplina.focus();
	return false;
	}

	if (document.form.txt_disciplina.value.length < 3){
		alert("O campo 'Disciplina' não está preenchido corretamente!");
		document.form.txt_disciplina.focus();
	return false;
	}

	if (document.form.cmb_produto.value == ""){
		alert("Selecione um material.");
		document.form.cmb_produto.focus();
	return false;
	}

	if (document.form.txt_tema.value == ""){
		alert("Preencha o campo 'Assunto'.");
		document.form.txt_tema.focus();
	return false;
	}

	if (document.form.txt_tema.value.length < 3){
		alert("O campo 'Assunto' não está preenchido corretamente!");
		document.form.txt_tema.focus();
	return false;
	}

	if (document.form.txt_mensagem.value == ""){
		alert("Preencha o campo 'Mensagem'.");
		document.form.txt_mensagem.focus();
	return false;
	}

	if (document.form.txt_mensagem.value.length < 20){
		alert("O campo 'Mensagem' não está preenchido corretamente!");
		document.form.txt_mensagem.focus();
	return false;
	}

return true
}

//Formatação de Moeda

function Limpar(valor, validos) {
// retira caracteres invalidos da string
var result = "";
var aux;
for (var i=0; i < valor.length; i++) {
aux = validos.indexOf(valor.substring(i, i+1));
if (aux>=0) {
result += aux;
}
}
return result;
}

//Formata número tipo moeda usando o evento onKeyDown

function FormataMoeda(campo,tammax,teclapres,decimal) {
var tecla = teclapres.keyCode;
vr = Limpar(campo.value,"0123456789");
tam = vr.length;
dec=decimal

if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

if (tecla == 8 )
{ tam = tam - 1 ; }

if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
{

if ( tam <= dec )
{ campo.value = vr ; }

if ( (tam > dec) && (tam <= 5) ){
campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 6) && (tam <= 8) ){
campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ;
}
if ( (tam >= 9) && (tam <= 11) ){
campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 12) && (tam <= 14) ){
campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 15) && (tam <= 17) ){
campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;}
}

}

function Limpar(valor, validos) {
// retira caracteres invalidos da string
var result = "";
var aux;
for (var i=0; i < valor.length; i++) {
aux = validos.indexOf(valor.substring(i, i+1));
if (aux>=0) {
result += aux;
}
}
return result;
}

//Formata número tipo moeda usando o evento onKeyDown

function Formata(campo,tammax,teclapres,decimal) {
var tecla = teclapres.keyCode;
vr = Limpar(campo.value,"0123456789");
tam = vr.length;
dec=decimal

if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

if (tecla == 8 )
{ tam = tam - 1 ; }

if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
{

if ( tam <= dec )
{ campo.value = vr ; }

if ( (tam > dec) && (tam <= 5) ){
campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 6) && (tam <= 8) ){
campo.value = vr.substr( 0, tam - 5 ) + "" + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ;
}
if ( (tam >= 9) && (tam <= 11) ){
campo.value = vr.substr( 0, tam - 8 ) + "" + vr.substr( tam - 8, 3 ) + "" + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 12) && (tam <= 14) ){
campo.value = vr.substr( 0, tam - 11 ) + "" + vr.substr( tam - 11, 3 ) + "" + vr.substr( tam - 8, 3 ) + "" + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 15) && (tam <= 17) ){
campo.value = vr.substr( 0, tam - 14 ) + "" + vr.substr( tam - 14, 3 ) + "" + vr.substr( tam - 11, 3 ) + "" + vr.substr( tam - 8, 3 ) + "" + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;}
}

}


//Função De Validação Dos Campos De Dúvidas Pedagógicas
function verifica_busca(f) {

	if (document.form.txt_busca.value == ""){
		alert("Preencha o campo 'Palavra Chave'.");
		document.form.txt_busca.focus();
	return false;
	}

	if (document.form.txt_busca.value == ""){
		alert("Preencha o campo 'Palavra Chave'.");
		document.form.txt_busca.focus();
	return false;
	}

return true
}

function floatThis(theNumber, Casas){
  inStr = theNumber;
  inAux = "";
  inLen = inStr.length;
  var cont   = 0;
  var milhar = -1; //casas decimais

  if (inStr == "."){
    return ('');
  }
  if (inStr == ","){
    return ('');
  }
  if (inStr == ""){
    return ('');
  }

  for(var i = 0; i < inLen; i++){
      var ch = inStr.substring(i, i+1);
    // verifica a quantidade de casas decimais
    if ( milhar >= 0){
     milhar = milhar + 1;
    }
    if ((ch > "9"))
      if ((ch != ".") && (ch != ",")){
        theNumber.focus();
        return ('');
      }

    if ((ch == ".") || (ch == ",")){
      cont++;
      milhar = 0;
   }

   if (cont >= 2){
      alert("Número inválido.\n\nUtilize apenas um \".\" ou \",\" como separador decimal.\n Não utilize separador de milhar.");
      theNumber.focus();
      return ('');
    }

   if (ch == ",")
      inAux = inAux + "."
    else
      inAux = inAux + ch;
  }
  /*
  if ( milhar == 3)
  {
    theNumber.focus();
    alert("Números no formato \"9,999\" ou \"9.999\" não são aceitos.\n Para
digitar milhares não use separador, o formato é \"9999\".");
    return('');
  }*/

  return (floatFix(inAux, Casas));
}


function floatFix(Val, Decimais)
{
  var Res = "" + Math.round(Val * Math.pow(10, Decimais));
  var Dec = Decimais - Res.length;
  var Zer = Res.length - Decimais;
  var StrZero = "0.";

  Valtmp = Val;

  if (Val < 0) {
   Val = Val.replace("-","");
  }

  if (Decimais != 0)  {
    if (Val < 1)    {
      for (Count=0; Count<=Dec-1; Count+= 1){
        StrZero += "0";
       }
      if (Res < 1 * Math.pow(10, Decimais)){
        OutString = StrZero + Res;
      }else{
        OutString = Res.substring(0, Zer) + "." + Res.substring(Zer, Res.length);
      }
    }else{
      OutString = Res.substring(0, Zer) + "." + Res.substring(Zer, Res.length);
    }
  }else{
      OutString = Res.substring(0, Zer);
  }

  if (Valtmp < 0) {
   Outstring = "-" + OutString;
  }

  return (OutString);
}

