/* ==============================
    administracao WORKFILE
    Arquivo de Rotinas JavaScript
	Criado em Janeiro/2003
	Atualizado em Setembro/2010
   ==============================
*/

/* MENSAGEM STATUS BAR */
var msgStatus = "Marcenaria Artesanal"
window.status = msgStatus;

/* TRACKING GOOGLE ANALYTICS */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-332228-14']);
_gaq.push(['_trackPageview']);

(function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

/* FONTES */
var size = 2;
var sizes = new Array(10,11,12,13,14,15);

function fontDel() {
	size--;
	var e = document.getElementById('principal').getElementsByTagName('*');
	if (size < 0) size = 0;
	for (i=0; i<e.length; i++) {
		e[i].style.fontSize = sizes[size] + 'px';
	}
}
function fontAdd() {
	size++;
	var e = document.getElementById('principal').getElementsByTagName('*');
	if (size > 5) size = 5;
	for (i=0; i<e.length; i++) {
		e[i].style.fontSize = sizes[size] + 'px';
	}
}


/* MENU */
function menuOver(menu){
	menu.className = 'menuOver';
}

function menuOut(menu) {
	menu.className = 'menuOut';
}

/* STATUS BAR */
function SetMsg(msgStr) {
	return (window.status = msgStr);
}

link = document.getElementsByTagName('a')
for (i=0; i<link.length; i++) {
	link[i].onmousemove  = function() { window.status = msgStatus; return true; };
	link[i].onmousedown  = function() { window.status = msgStatus; return true; };
	link[i].onmouseenter = function() { window.status = msgStatus; return true; };
	link[i].onmouseup    = function() { window.status = msgStatus; return true; };
}


/* JANELA HELP */

function Help(id)
{
	window.open('/workfile/administracao/ajuda/ajuda.asp?ID='+id,'help','width=300,height=220,top=30,left=10')
}


/* HELP onFOCUS */

function SetHelp(txt) { 
	help.innerText = txt ; 
}



/* FUNÇÕES ESPECIAIS */

function Len(str) {  
	return String(str).length;  
}


function Right(str, n)
{
	if (n <= 0)     // Invalid bound, return blank string
	   return "";
	else if (n > String(str).length)   // Invalid bound, return
	   return str;                     // entire string
	else { // Valid bound, return appropriate substring
	   var iLen = String(str).length;
	   return String(str).substring(iLen, iLen - n);
	}
}


function Left(str, n)
{
	if (n <= 0)     // Invalid bound, return blank string
			return "";
	else if (n > String(str).length)   // Invalid bound, return
			return str;                // entire string
	else // Valid bound, return appropriate substring
			return String(str).substring(0,n);
}


function PressEnter() {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (keycode == 13) {
		Limpar('form1','DESCRICAO');
		return false
	}
	return true 
}


/* DESABILITA BOTÃO */

function Disabled(frm,fld) {
	document.forms[frm].elements[fld].disabled = true;
}


/* TROCA / DESABILITA BOTÃO IMAGE */

function Swap(img,id) {
	var nImg = Left(img,Len(img)-4)+'_d'+Right(img, 4);
	return id.src = nImg;
	return id.hrf = '#';
}

function SwapImg(img) {
//	var nImg = Left(img,Len(img)-4)+'_d'+Right(img, 4);
	var nImg = String(img).substring(0,String(img).length-4) + '_d' + String(img).substring(String(img).length,String(img).length-4) ;
	return nImg;
}

function SwapRestore(img) {
//	var nImg = Left(img,Len(img)-4)+'_d'+Right(img, 4);
	var nImg = String(img).substring(0,String(img).length-6) + String(img).substring(String(img).length,String(img).length-4) ;
	return nImg;
}

/* VALIDAÇÃO SIMPLES */

function valSimples() { 
  var n=document.forms[0];
  for ( var i=0;i<n.length;i++ ) {
    if (n.elements(i).value == "") {
  	  window.alert("Preencha o campo "+n.elements(i).name);
      n.elements(i).focus();
      return (false)
    }
  }
  Disabled(0,'submit');
  document.body.style.cursor = 'wait';
  return (true)

}

/* validacao de relatorio */
function valRelatorio() {
  var n=document.forms[0];
  if (n.CODREDE.value == "" ) {
     window.alert("Selecione a Rede.");
     n.vREDE.focus();
    return (false)
  }
  if (n.CODBAND.value == "" ) {
     window.alert("Selecione a Bandeira.");
     n.vBand.focus();
    return (false)
  }
   
  return (true)
}

/* VERIFICAÇÃO DE CNPJ */

function modulo(str) {
   	soma=0;
   	ind=2;
   	for(pos=str.length-1;pos>-1;pos=pos-1) {
   		soma = soma + (parseInt(str.charAt(pos)) * ind);
   		ind++;
   		if(str.length>11) {
   			if(ind>9) ind=2;
   		}
	}
   	resto = soma - (Math.floor(soma / 11) * 11);
   	if(resto < 2) {
    	return 0
   	}
   	else {
   		return 11 - resto
   	}
}

function checaCNPJ(valor) {
	primeiro=valor.substr(1,1);
	falso=true;
	size=valor.length;
	if (size!=14){ return false; }
	size--;
	for (i=2; i<size-1; ++i){
		proximo=(valor.substr(i,1));
		if (primeiro!=proximo) { falso=false }
	}
	if (falso){ return; }
   	if(modulo(valor.substring(0,valor.length - 2)) + "" + modulo(valor.substring(0,valor.length - 1)) !=valor.substring(valor.length - 2,valor.length)) {
   		return false;
   	}
   	return true
}


/* VERIFICAÇÃO DE CPF */

function checaCPF (CPF) {
	if (CPF == "11111111111") {
		return true;
	}
	if (CPF.length != 11 || CPF == "00000000000" || 
		CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
		CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
		CPF == "88888888888" || CPF == "99999999999")
		return false;
	soma = 0;
	for (i=0; i < 9; i ++)
		soma += parseInt(CPF.charAt(i)) * (10 - i);
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		resto = 0;
	if (resto != parseInt(CPF.charAt(9)))
		return false;
	soma = 0;
	for (i = 0; i < 10; i ++)
		soma += parseInt(CPF.charAt(i)) * (11 - i);
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		resto = 0;
	if (resto != parseInt(CPF.charAt(10)))
		return false;
	return true;
 }


/* VALIDAÇÃO CADASTRO CLIENTE */

function valCliente() { 
  var n=document.forms[0];
	for ( var i=0;i<n.length;i++) {
      if (n.elements(i).value == "") {
		  if (n.elements(i).name == "EMAIL" || n.elements(i).name == "CONTATO" || n.elements(i).name == "IE" || n.elements(i).name == "IM" || n.elements(i).name == "GRUPO" || n.elements(i).name == "CLIENTEDEP") { }
		  else {
			  window.alert("Preencha o Campo "+n.elements(i).name);
			  n.elements(i).focus();
			  return (false)
		  }
	  }
	  if (n.elements(i).name == "CEP" && n.elements(i).value.length < 8) {
		  window.alert("Preencha corretamente o CEP \n ex.: 18123321");
		  n.elements(i).focus();
		  return (false)
	  }
	  if (n.elements(i).name == "CNPJ") {
		  if (checaCNPJ(n.elements(i).value)) { } 
		  else {
		     window.alert("Preencha corretamente o CNPJ");
		     n.elements(i).focus();
		     return (false)
		  }
	  }
	}
  return (true)
}

/* VALIDAÇÃO CADASTRO FILIAL */

function valFilial() { 
  var n=document.forms[0];
	for ( var i=0;i<n.length;i++) {
      if (n.elements(i).value == "") {
		  if (n.elements(i).name == "EMAIL" || n.elements(i).name == "CONTATO" || n.elements(i).name == "IE" || n.elements(i).name == "IM") { }
		  else {
			  window.alert("Preencha o Campo "+n.elements(i).name);
			  n.elements(i).focus();
			  return (false)
		  }
	  }
	  if (n.elements(i).name == "CEP" && n.elements(i).value.length < 8) {
		  window.alert("Preencha corretamente o CEP \n ex.: 18123321");
		  n.elements(i).focus();
		  return (false)
	  }
	  if (n.elements(i).name == "CNPJ") {
		  if (checaCNPJ(n.elements(i).value)) { } 
		  else {
		     window.alert("Preencha corretamente o CNPJ");
		     n.elements(i).focus();
		     return (false)
		  }
	  }
	}
  return (true)
}

/* VALIDAÇÃO CADASTRO ADMINISTRADOR */

function valAdministrador() { 
  var n=document.forms[0];
	for ( var i=0;i<n.length;i++) {
      if (n.elements(i).value == "") {
		  if (n.elements(i).name == "EMAIL" || n.elements(i).name == "CONTATO") { }
		  else {
			  window.alert("Preencha o Campo "+n.elements(i).name);
			  n.elements(i).focus();
			  return (false)
		  }
	  }
	  if (n.elements(i).name == "CEP" && n.elements(i).value.length < 8) {
		  window.alert("Preencha corretamente o CEP \n ex.: 18123321");
		  n.elements(i).focus();
		  return (false)
	  }
	  if (n.elements(i).name == "CNPJ") {
		  if (checaCNPJ(n.elements(i).value)) { } 
		  else {
		     window.alert("Preencha corretamente o CNPJ");
		     n.elements(i).focus();
		     return (false)
		  }
	  }
	}
  return (true)
}

/* VALIDAÇÃO CADASTRO FUNCIONARIO DO ADMINISTRADOR */

function valFuncionario() { 
  var n=document.forms[0];
	for ( var i=0;i<n.length;i++) {
      if (n.elements(i).value == "") {
		  if (n.elements(i).name == "EMAIL" || n.elements(i).name == "TIMEFUT" || n.elements(i).name == "HOBBY" || n.elements(i).name == "txt_1_08_20_USUARIO" || n.elements(i).name == "txt_1_08_20_SENHA") { }
		  else {
			  window.alert("Preencha o Campo "+n.elements(i).name);
			  n.elements(i).focus();
			  return (false)
		  }
	  }
	  if (n.elements(i).name == "CEP" && n.elements(i).value.length < 8) {
		  window.alert("Preencha corretamente o CEP \n ex.: 18123321");
		  n.elements(i).focus();
		  return (false)
	  }
	  if (n.elements(i).name == "CPF") {
		  if (checaCPF(n.elements(i).value)) { } 
		  else {
		     window.alert("Preencha corretamente o CPF");
		     n.elements(i).focus();
		     return (false)
		  }
	  }
	  if (n.elements(i).name == "txt_1_08_20_USUARIO" && n.elements(i).value.length < 8) {
		  window.alert("O Campo Usuário deve conter no mínimo 08 caracteres.");
		  n.elements(i).focus();
		  return (false)
	  }
	  if (n.elements(i).name == "txt_1_08_20_SENHA") {
		  if (valida_senha(n.elements(i))) { }
		  else {
			  return (false)
		  }
	  }
	}
  return (true)
}

/* VALIDAÇÃO CADASTRO FUNCIONARIO DA FILIAL */

function valUsuarioFilial() { 
  var n=document.form1;
	for ( var i=0;i<n.length;i++) {
      if (n.elements(i).value == "") {
		  if (n.elements(i).name == "EMAIL" || n.elements(i).name == "DTNASC" || n.elements(i).name == "TIMEFUT" || n.elements(i).name == "HOBBY" || n.elements(i).name == "txt_1_08_20_USUARIO" || n.elements(i).name == "txt_1_08_20_SENHA") { }
		  else {
			  window.alert("Preencha o Campo "+n.elements(i).name);
			  n.elements(i).focus();
			  return (false)
		  }
	  }
	  if (n.elements(i).name == "CEP" && n.elements(i).value.length < 8) {
		  window.alert("Preencha corretamente o CEP \n ex.: 18123321");
		  n.elements(i).focus();
		  return (false)
	  }
	  if (n.elements(i).name == "CPF") {
		  if (checaCPF(n.elements(i).value)) { } 
		  else {
		     window.alert("Preencha corretamente o CPF");
		     n.elements(i).focus();
		     return (false)
		  }
	  }
	  if (n.elements(i).name == "txt_1_08_20_USUARIO" && n.elements(i).value.length < 8) {
		  window.alert("O Campo Usuário deve conter no mínimo 08 caracteres.");
		  n.elements(i).focus();
		  return (false)
	  }
  }
  return (true)
}

/* VALIDAÇÃO CADASTRO DE FUNÇÕES DOS FUNCIONÁRIOS */

function valFuncao() { 
  var n=document.forms[0];
	for ( var i=0;i<n.length;i++) {
      if (n.elements(i).value == "") {
		  	  window.alert("Preencha o Campo "+n.elements(i).name);
			  n.elements(i).focus();
			  return (false)
		  }
	  }
	  
  return (true)
}

/* VALIDAÇÃO CADASTRO DE EVENTOS DO CLIENTE */

function valEvento() { 
  var n=document.forms[0];
	for ( var i=0;i<n.length;i++) {
      if (n.elements(i).value == "") {
		  	  window.alert("Preencha o Campo "+n.elements(i).name);
			  n.elements(i).focus();
			  return (false)
		  }
	  }
	  
  return (true)
}

/* VALIDAÇÃO CADASTRO DE DEPTOS DO CLIENTE */

function valDeptoCli() { 
  var n=document.forms[0];
	for ( var i=0;i<n.length;i++) {
       if (n.elements(i).value == "") {
	      if (n.elements(i).name == "CODCLI") { }
		  else {
			  window.alert("Preencha o Campo "+n.elements(i).name);
			  n.elements(i).focus();
			  return (false)
		  }
	   }
	  }
	  
  return (true)
}

/* FORMATAÇÃO DE DATA DE NASCIMENTO */

function FormataData(campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.form1(campo).value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			document.form1(campo).value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			document.form1(campo).value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); 
	}
}

/* VALIDAÇÃO CADASTRO USUARIO */

function valUsuario() { 
var n=document.forms[0];
	for ( var i=0;i<n.length;i++) {
      if (n.elements(i).value == "") {
		  	  window.alert("Preencha o Campo "+n.elements(i).name);
			  n.elements(i).focus();
			  return (false)
	              }
	
	}
  return (true)
}
  
/* VALIDAÇÃO CADASTRO DE TIPOS DE DOCUMENTOS */

function valTipoDoc() { 
  var n=document.forms[0];
	for ( var i=0;i<n.length;i++) {
       if (n.elements(i).value == "") {
	      if (n.elements(i).name == "CODCLI") { }
		  else {
			  window.alert("Preencha o Campo "+n.elements(i).name);
			  n.elements(i).focus();
			  return (false)
		  }
	   }
	  }
	  
  return (true)
}

/* VALIDAÇÃO CADASTRO DE CAIXAS */

function valCaixa() { 
  var n=document.form_caixa; custcli=false;
	for ( var i=0;i<n.length;i++) {
      if (n.elements(i).name == "LOCALCUST"){
		  custcli = n.elements(i).checked; // se custcli = false custodia local, senão custodia cliente
      }
	  //se custodia local não permite inclusão sem endereço
	  if (custcli == false){
        if (n.elements(i).value == "") {
		  if (n.elements(i).name == "DTCUST" || n.elements(i).name == "BUSCA" || n.elements(i).name == "CODENDOLD" || n.elements(i).name == "DESCCAIXA" || n.elements(i).name == "DESCMENOR"  || n.elements(i).name == "DESCLONG" || n.elements(i).name == "LACRE1" || n.elements(i).name == "LACRE2" || n.elements(i).name == "DTINICIAL" || n.elements(i).name == "DTFINAL" || n.elements(i).name == "DTDESTR" || n.elements(i).name == "NUMCAIXAANT" || n.elements(i).name == "DTRECEP" || n.elements(i).name == "LOCALCUST" || n.elements(i).name == "SEQINICIAL" || n.elements(i).name == "SEQFINAL" || n.elements(i).name == "GALPAO" || n.elements(i).name == "AVENIDA" || n.elements(i).name == "PREDIO" || n.elements(i).name == "ANDAR" || n.elements(i).name == "APTO" || n.elements(i).name == "CODEND") { }
		  else {
			  window.alert("Preencha o Campo "+n.elements(i).name);
			  n.elements(i).focus();
			  return (false)
		  }
	    }
	  }
	  //se custodia cliente permite a inclusão sem endereco
	  else {
		if (n.elements(i).value == "") {
		  if (n.elements(i).name == "DTCUST" || n.elements(i).name == "BUSCA" || n.elements(i).name == "CODENDOLD" || n.elements(i).name == "DESCCAIXA" || n.elements(i).name == "DESCMENOR"  || n.elements(i).name == "DESCLONG" || n.elements(i).name == "LACRE1" || n.elements(i).name == "LACRE2" || n.elements(i).name == "DTINICIAL" || n.elements(i).name == "DTFINAL" || n.elements(i).name == "DTDESTR" || n.elements(i).name == "NUMCAIXAANT" || n.elements(i).name == "DTRECEP" || n.elements(i).name == "LOCALCUST" || n.elements(i).name == "SEQINICIAL" || n.elements(i).name == "SEQFINAL" || n.elements(i).name == "GALPAO" || n.elements(i).name == "AVENIDA" || n.elements(i).name == "PREDIO" || n.elements(i).name == "ANDAR" || n.elements(i).name == "APTO" || n.elements(i).name == "CODEND") { }
		  else {
			  window.alert("Preencha o Campo "+n.elements(i).name);
			  n.elements(i).focus();
			  return (false)
		  }
		}
	  }	
	}

	if (n.LACRES.value == "S") {
		if (n.LACRE1.value == "" || n.LACRE2.value == "") {
			window.alert("Este departamento exige que as caixas inclusas possuam lacre.\nFavor informar os mesmos.");
			n.LACRE1.focus();
			return (false)
		}
	}
  return (true)
}


/* VALIDAÇÃO CADASTRO DE DOCUMENTOS */

function valDoc() { 
  var n=document.forms[0];
	for ( var i=0;i<n.length;i++) {
       if (n.elements(i).value == "") {
	      if (n.elements(i).name == "BUSCA" || n.elements(i).name == "SEQINICIAL" || n.elements(i).name == "SEQFINAL" || n.elements(i).name == "DATINICIAL" || n.elements(i).name == "DATFINAL" || n.elements(i).name == "DESCDOC2" || n.elements(i).name == "IMAGEM" || n.elements(i).name == "DATINSCAIXA") { }
		  else {
			  window.alert("Preencha o Campo "+n.elements(i).name);
			  n.elements(i).focus();
			  return (false)
		  }
	   }
	  }
	  
  return (true)
}

/* VALIDAÇÃO CADASTRO DE ENDERECO */

function valEnd() { 
	  var n=document.forms[0];
  	  	
		  if (isNaN(n.AVENIDA.value) != true || n.AVENIDA.value == "") {
		  window.alert("Preencha o campo Avenida corretamente \nEx.: A");
		  n.AVENIDA.focus();
     	  return (false)
          }
		  if (isNaN(n.PREDIO_INI.value) != false || n.PREDIO_INI.value == "") {
		  window.alert("Preencha o campo PREDIO inicial corretamente \nEx.: 6");
		  n.PREDIO_INI.focus();
     	  return (false)
          }
          if (isNaN(n.PREDIO_FIM.value) != false || n.PREDIO_FIM.value == "") {
		  window.alert("Preencha o campo PREDIO final corretamente \nEx.: 26");
		  n.PREDIO_FIM.focus();
     	  return (false)
          }
		  if (confirm("Tem certeza que deseja incluir?")) {
			  n.submit.disabled = true;
			  n.Button.disabled = true;
			  Mensagem();
			  return (true)
		  } else {
		    return (false)
		  }
          
	  
  return (true)
}




/* VALIDAÇÃO CADASTRO LOJA */

function valLoja() { 
  var n=document.forms[0];
	for ( var i=0;i<n.length;i++) {
      if (n.elements(i).value == "") {
		  if (n.elements(i).name == "CONTATO" || n.elements(i).name == "EMAIL" || n.elements(i).name == "NUMEROCHECK_OUT") { }
		  else {
			  window.alert("Preencha o Campo "+n.elements(i).name);
			  n.elements(i).focus();
			  return (false)
		  }
	  }
	  if (n.elements(i).name == "CODLOJA" && isNaN(n.elements(i).value)) {
          window.alert("Preencha corretamente o campo CODLOJA \nSomente números.");
          n.elements(i).focus();
          return (false)
      }
	  if (n.elements(i).name == "CEP" && n.elements(i).value.length < 8) {
		  window.alert("Preencha corretamente o CEP \n ex.: 18123321");
		  n.elements(i).focus();
		  return (false)
	  }
	  if (n.elements(i).name == "CNPJ") {
		  if (checaCNPJ(n.elements(i).value)) { } 
		  else {
		     window.alert("Preencha corretamente o CNPJ");
		     n.elements(i).focus();
		     return (false)
		  }
	  }
	}
  return (true)
}


/* VALIDAÇÃO DE CADASTRO PROD. BANDEIRA */

function valProdBand() {
  var n=document.forms[0];
  if (n.CODPROD.value == "") {
     window.alert("Selecione o Cliente e informe o Produto");
     n.CODCLI.focus();
    return (false)
  }
  if (n.CODPRODBAND.value == "") {
     window.alert("Informe o Código do Produto na Bandeira");
     n.CODPRODBAND.focus();
    return (false)
  }
  return (true)
}


/* VALIDAÇÃO CADASTRO COORDENADOR */

function valCoordenador() { 
  var n=document.forms[0];
	for ( var i=0;i<n.length;i++) {
      if (n.elements(i).value == "") {
		  if (n.elements(i).name == "EMAIL" || n.elements(i).name == "AREAATUACAO") { }
		  else {
			  window.alert("Preencha o Campo "+n.elements(i).name);
			  n.elements(i).focus();
			  return (false)
		  }
	  }
	  if (n.elements(i).name == "CEP" && n.elements(i).value.length < 8) {
		  window.alert("Preencha corretamente o CEP \n ex.: 18123321");
		  n.elements(i).focus();
		  return (false)
	  }
	  if (n.elements(i).name == "CPF") {
		  if (checaCPF(n.elements(i).value)) { } 
		  else {
		     window.alert("Preencha corretamente o CPF");
		     n.elements(i).focus();
		     return (false)
		  }
	  }
	}
  return (true)
}


/* VALIDAÇÃO CADASTRO PROMOTOR */

function valPromotor() { 
  var n=document.forms[0];
	for ( var i=0;i<n.length;i++) {
      if (n.elements(i).value == "") {
		  if (n.elements(i).name == "EMAIL") { }
		  else {
			  window.alert("Preencha o Campo "+n.elements(i).name);
			  n.elements(i).focus();
			  return (false)
		  }
	  }
	  if (n.elements(i).name == "CEP" && n.elements(i).value.length < 8) {
		  window.alert("Preencha corretamente o CEP \n ex.: 18123321");
		  n.elements(i).focus();
		  return (false)
	  }
	  if (n.elements(i).name == "CPF") {
		  if (checaCPF(n.elements(i).value)) { } 
		  else {
		     window.alert("Preencha corretamente o CPF");
		     n.elements(i).focus();
		     return (false)
		  }
	  }
	}
  return (true)
}


/* VALIDAÇÃO DE CADASTRO COORD./PROMOTOR POR LOJA */

function valCoordPromoLoja() {
  var n=document.forms[0];
  if (n.CODSUPER.value == "") {
     window.alert("Selecione o Coordenador");
     n.Coordenador.focus();
    return (false)
  }
  if (n.CODPROMO.value == "") {
     window.alert("Informe o Promotor");
     n.CODPROMO.focus();
    return (false)
  }
  return (true)
}


/* VALIDAÇÃO DE CADASTRO PRODUTO */

function valProduto() {
  var n=document.forms[0];
  if (n.CODPRODCLI.value == "" || isNaN(n.CODPRODCLI.value)) {
     window.alert("Informe corretamente o COD FABRICANTE\nEx.: 1255");
     n.CODPRODCLI.focus();
    return (false)
  }
  if (n.NOMEPROD.value == "") {
     window.alert("Informe o PRODUTO");
     n.NOMEPROD.focus();
    return (false)
  }
  if (n.QTDEEMBALAGEM.value == "" || isNaN(n.QTDEEMBALAGEM.value)) {
     window.alert("Informe corretamente a QTDE. EMBALAGEM \nEx.:36");
     n.QTDEEMBALAGEM.focus();
    return (false)
  }
  if (n.EMBFRENTE.value == "") {
     window.alert("Informe a EMBALAGEM DO PRODUTO");
     n.EMBFRENTE.focus();
    return (false)
  }
  if (n.QTDEUNIDADE.value == "" || isNaN(n.QTDEUNIDADE.value)) {
     window.alert("Informe corretamente a UNIDADE DO PRODUTO\nEx.:110");
     n.QTDEUNIDADE.focus();
    return (false)
  }
  if (n.UNIDADE.value == "") {
     window.alert("Informe a UNIDADE DE GRAMAGEM");
     n.UNIDADE.focus();
    return (false)
  }
  if (n.QTDEEMBTRANS.value == "" || isNaN(n.QTDEEMBTRANS.value)) {
     window.alert("Informe corretamente a QTDE. EMBALAGEM DE ESTOQUE\nEx.:24");
     n.QTDEEMBTRANS.focus();
    return (false)
  }
  if (n.EMBALAGEM.value == "") {
     window.alert("Informe a EMBALAGEM DE ESTOQUE");
     n.EMBALAGEM.focus();
    return (false)
  }
  if (n.EMBTRANS.value == "") {
     window.alert("Informe a EMBALAGEM DE TRANSPORTE");
     n.EMBTRANS.focus();
    return (false)
  }
  if (n.TIPOPROD.value == "P" && n.DATFIMPROMO.value == "") {
     window.alert("Informe a data do fim da Promoção\nEx.:1/1/2003");
     n.DATFIMPROMO.focus();
    return (false)
  }

  return (true)
}


/* CHECK ALL */

function SetChecked(form,val) {
  dml=document.forms[form];
  len = dml.elements.length;
  var i=0;
  for(i=0 ; i<len ; i++) { 
     dml.elements[i].checked=val;
  }
}

function SetCheckAll(form) {
  dml=document.forms[form];
  len = dml.elements.length;
  var i=0;
  for(i=0 ; i<len ; i++) { 
     dml.elements[i].checked = (dml.elements[i].checked == 1 ) ? 0 : 1;
  }
}


/* EXPANDIR MENU */

function expandMenu(varclass) {
var myclass=varclass
divColl = document.getElementsByTagName("tr");

	for (i=0; i<divColl.length; i++) {

		if (divColl(i).className == myclass) {
		divColl(i).style.display = (divColl(i).style.display == "none" ) ? "" : "none";
        }
    }
}


/* VERIFICA CHECKED */

function valCheck() {
  len = document.form1.elements.length;
  var i = 0;
  var msgchk = false;
  for (var i=0;i<len;i++){
  		var e = document.form1.elements[i];
		if (e.checked == true) {
			msgchk = true;
		}
  }
  if (msgchk != true) { 
	  alert('Selecione pelo menos uma caixa para excluir');
	  return false;
  }
  return true;
}


/* CONFIRMA SAÍDA */

function confSaida() {
  if (confirm("Você tem certeza que deseja fechar?")) {
	  window.close();
  } else { }
}


/* MASCARA PARA VALORES */

function frmtVR(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.form1(campo).value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	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 <= 2 ){
	 		document.form1(campo).value = vr ; }
	 	if ( (tam > 2) && (tam <= 9) ){
	 		document.form1(campo).value = vr.substr( 0, tam - 2 ) + '.' + vr.substr( tam - 2, tam ) ; }
	}		
}



/* JANELA MODAL */

function Modal(page,tamX,tamY){
   window.showModalDialog(page, "dialog", "dialogWidth:"+tamX+"px; dialogHeight:"+tamY+"px; resizable:no; help:no; status:no; scroll:no; dialogLeft:"+screen.center+"; dialogTop:"+screen.center+"");
}

function ModalCalendario(page){
   window.showModalDialog(page, "dialog", "dialogWidth:440px; dialogHeight:230px; resizable:no; help:no; status:no; scroll:no; dialogLeft:200; dialogTop:200");
}



/* VALIDAÇÃO DE IMPORTAÇÃO */

function vImport(form) {
	if (form.DESCPRINC.value == "") {
		alert("Informe o nr correspondente a \n'Descrição Principal' na lista ao lado");
		form.DESCPRINC.focus();
		return false;
	}
	Disabled(0,'Submit'); 
	Disabled(0,'Submit2');

}


/* VERIFICA ENVIO DE ARQUIVO */

function TestarCampo()
{
	if (document.form1.Arquivo.value == "")
	{
		alert("Nenhum arquivo especificado !");
		document.form1.Arquivo.focus();
		return false;
	}
	else
	{
		var strFile, strExtension, intLenth;
		strExtension = "";
		strFile = document.form1.Arquivo.value;
		intLenth = strFile.length;
		if(intLenth > 7 && strFile.indexOf(".") != -1)
		{
			strExtension = strFile.substring(intLenth-4, intLenth);
			if(strExtension.indexOf(".") != -1)
			strExtension = strExtension.substring(1,4)
		}
		var Extensions = "TXT,CSV,DBF";
		if(Extensions.indexOf(strExtension.toUpperCase()) == -1)
			strExtension = "";
		if(strExtension == "")
		{
			alert("Arquivo deve ser do formato TXT ou CSV");
			document.form1.Arquivo.focus();
			return false;
		}
	}
	Disabled('form1','Submit');
}


/* EXIBIR MENSAGEM PISCANDO */

function initArray() {
	this.length = initArray.arguments.length; 
	for (var i = 0; i < this.length; i++) { 
		this[i] = initArray.arguments[i];
	}
}

function chcolor(){
	if (navigator.appName == "Netscape") {
		document.message.document.write('<center><font color="'+color[x]);
		document.message.document.write('">'+ctext+'</font></center>');
		document.message.document.close();
	}
	else if (navigator.appVersion.indexOf("MSIE") != -1) {
		document.forms["form1"].message.style.color = color[x];
	}
	(x < color.length-1) ? x++ : x = 0;
}



/* VALIDAÇÃO DO DESTINO DA IMPORTAÇÃO */

function valDestino() {
	if (document.form1.CODFILIAL.value == "")
	{ 
		alert('Selecione a Filial');
		document.form1.FILIAL.focus();
		return false;
	} 
	if (document.form1.CODDEPTO.value == "")
	{
		alert('Selecione o Departamento');
		document.form1.DEPTO.focus();
		return false;
	} 
	if (document.form1.CODDEPTOFILIAL.value == "")
	{
		alert('Selecione o Departamento da Filial');
		document.form1.CODDEPTOFILIAL.focus();
		return false;
	} 
	if ((document.form1.CODFILIAL.value != "") && (document.form1.CODDEPTO.value != "") && (document.form1.CODDEPTOFILIAL.value != ""))
	{
		document.form1.submit(); 
		document.form1.Submit.disabled=true; 	
		document.form1.Submit2.disabled=true;
		Mensagem();
		return true;
	}
}


/* VALIDAÇÃO DO DESTINO DA IMPORTAÇÃO DOCUMENTOS */

function valDestinoDoc() {
	if (document.form1.CODTIPODOC.value == "") { 
		alert('Selecione o Tipo do Documento');
		document.form1.FILIAL.focus();
		return false;
	} 
	if (document.form1.CODTIPODOC.value != "") {
		document.form1.submit(); 
		document.form1.Submit.disabled=true; 	
		document.form1.Voltar.disabled=true;
		Mensagem();
		return true;
	}
}



/* LIMPANDO CAMPO APÓS CONSULTA */

function Limpar(frm, fld) {
	var d=document.forms[frm]
//	d.target='_blank';
	d.method='get';
	d.action='busca/relat_documentos.asp';
	document.body.style.cursor = 'wait';
	d.elements[fld].style.cursor = 'wait';
	d.submit();
	return d.elements[fld].value = '';
}


/* VALIDAÇÃO DA GERAÇÃO DE ETIQUETAS */

function valGeraEtiqueta() {
	var f = document.forms[0];

	if (f.QTDE.value == "" || isNaN(f.QTDE.value)) {
		alert("Preencha corretamente a quantidade de Etiquetas a serem geradas");
		f.QTDE.focus();
		return false
	}
	if (f.CHECK.value == '1') {
		if (f.GALPAO.value == "" || isNaN(f.GALPAO.value) == true) {
			alert("Informe corretamente o campo Galpão\nEx.: 1 a 9999");
			f.AVENIDA.focus();
			return false;
		}
		if (f.AVENIDA.value == "" || isNaN(f.AVENIDA.value) == false) {
			alert("Informe corretamente o campo Avenida\nEx.: A a Z");
			f.AVENIDA.focus();
			return false;
		}
		if (f.PREDIO.value == "" || isNaN(f.PREDIO.value) == true) 	{
			alert("Informe corretamente o campo PREDIO\nEx.: 1 a 26");
			f.PREDIO.focus();
			return false;
		}
		if (f.ANDAR.value == "" || isNaN(f.ANDAR.value) == false) {
			alert("Informe corretamente o campo Andar.\nEx.: A a F");
			f.ANDAR.focus();
			return false;
		}
		if (f.APTO.value == "" || isNaN(f.APTO.value) == true) {
			alert("Informe corretamente o campo Apto.\nEx.: 1 a 36");
			f.APTO.focus();
			return false;
		}
	}

	if (f.CHECK.value == '2') {
		if (f.CAIXA_INICIAL.value == "" || isNaN(f.CAIXA_INICIAL.value)) {
			alert("Informe corretamente o número Inicial da Caixa");
			f.CAIXA_INICIAL.focus();
			return false;
		}
		if (f.CAIXA_FINAL.value == "" || isNaN(f.CAIXA_FINAL.value)) {
			alert("Informe corretamente o número Final da Caixa");
			f.CAIXA_FINAL.focus();
			return false;
		}
		if (parseInt(f.CAIXA_FINAL.value) < parseInt(f.CAIXA_INICIAL.value)) {
			alert("O número da Caixa Final deve ser maior que o Inicial");
			f.CAIXA_FINAL.focus();
			return false;
		}
	}

	if (f.CHECK.value == '3') { 
		if (f.ITENS.value == "") {
			alert("Informe os números antigos das caixas, separados por virgula");
			f.ITENS.focus();
			return false;
		{
	}

	return true;
	}
  }
}


//	document.write('<div ID=Load style="position:absolute; left:'+((screen.width/2)-200)+'; top:'+((screen.height/2)-19)+'px; width:400px; height:19px; z-index:1; font-size: 10pt; background-color: #FFFFCC; layer-background-color: #FFCC66; border: 1px dotted #FF9900; visibility: hidden;">');
//	document.write('<center><p><strong><font size=1 face=Verdana>Carregando... </font></strong></p></center></div>');


/* AGUARDAR */

function Wait(id) {

//	document.all['Load'].style.visibility='visible'
	document.body.style.cursor = 'wait';
	id.style.cursor = 'wait';

}



/* VALIDAÇÃO DO DESTINO DA IMPORTAÇÃO */

function valMovDepto() {
	if (confirm('Confirma a movimentação das caixas \npara o Departamento selecionado?')) {
		document.form1.submit();
		document.form1.Submit.disabled=true;
		document.form1.Button.disabled=true;
		Mensagem();
		return true;
	} else {
		return false;
	}
}


/* VALIDAÇÃO DO DESTINO DA IMPORTAÇÃO */

function valInclusaoLote() { 
  var n=document.forms[0];
  for ( var i=0;i<n.length;i++ ) {
    if (n.elements(i).value == "") {
  	  window.alert("Preencha o campo "+n.elements(i).name);
      n.elements(i).focus();
      return (false)
    }
  }
  Disabled(0,'submit');
  document.body.style.cursor = 'wait';
//  Mensagem();
  return (true)
}



/* MARCA ITEM DA LISTA */

last_id = '';
color_chk = '#FFCC66';
divColl = document.getElementsByTagName('tr');

function Check(id, color) {
	if ((id != last_id) && (last_id != '')) {
		divColl(last_id).style.backgroundColor = last_color;
		divColl(id).style.backgroundColor = color_chk;
		last_id = id;
		last_color = color;
	} else {
		divColl(id).style.backgroundColor = color_chk;
		last_id = id;
		last_color = color;
	}
}


/* VALIDA MOTORISTA */

function valMotorista() { 
  var n=document.form1;
	for ( var i=0;i<n.length;i++) {
      if (n.elements(i).value == "") {
		  if (n.elements(i).name == "EMAIL" || n.elements(i).name == "DTNASC") { }
		  else {
			  window.alert("Preencha o Campo "+n.elements(i).name);
			  n.elements(i).focus();
			  return (false)
		  }
	  }
	  if (n.elements(i).name == "CEP" && n.elements(i).value.length < 8) {
		  window.alert("Preencha corretamente o CEP \n ex.: 18123321");
		  n.elements(i).focus();
		  return (false)
	  }
	  if (n.elements(i).name == "CPF") {
		  if (checaCPF(n.elements(i).value)) { } 
		  else {
		     window.alert("Preencha corretamente o CPF");
		     n.elements(i).focus();
		     return (false)
		  }
	  }
  }
  return (true)
}


/* Adiciona zeros a esquerda*/

function addxZeros(sText, nQtde) {

	var Result;

	if (sText.length > nQtde) {

		Result = sText;

	} else {

		var zeros = "";
		var tam = parseInt(nQtde) - parseInt(sText.length);

		for (i=0; i<tam; i++) {
			zeros += "0";
		}

		Result = zeros + "" + sText;

	}

	return (Result);

}
function SetFocusFirst() 
{
	var inputCollection = document.getElementsByTagName("input");
	for(var i = 0; i < inputCollection.length; i++)
	{
		var controlType = inputCollection[i].getAttribute('type');
		if(controlType.toLowerCase() == 'text') 
		{ 
			inputCollection[i].focus();
			return;
		}
	}
}


function SetFocusField(ParField) 
{
	var inputCollection = document.getElementById(ParField);
	inputCollection.focus();
	return;
}

function OpenWindow(theURL,winName,Width,Height) { //v2.0
  window.open(theURL,winName,'status=yes,scrollbars=yes,width='+ (Width+40) +',height='+ (Height) +',left='+(((window.screen.width)/2)-200)+',top='+((window.screen.height)/2-150));
}



function Endereco() 
{
	var url  = '../../../tools/asp/bib_cep.asp';
	var pars = 'CEP=' + $('CEP').value
	
	$('result').innerHTML   = '<img src="../../../imagens/diversos/item_loading.gif" width="16" border="0" align="absmiddle"> ';
	$('result').innerHTML  += 'Pesquisando endereço...';
	
	var showResult = function (r) {

		var dados = r.responseText

		if ( dados.indexOf('|') >= 0 )	{
			$('result').innerHTML = '&nbsp;';
			$('ENDERECO').value = dados.split('|')[0];
			$('BAIRRO').value = dados.split('|')[1];
			$('CIDADE').value = dados.split('|')[2];
			$('CODUF').value = dados.split('|')[3];
			$('NUMERO').focus();

		} else {
			$('result').innerHTML = dados;
			setTimeout( "$('result').innerHTML='';", 750 );			
		}

	}
		
	var showError = function (r) {

		$('result').innerHTML = r.responseText;

	}	
		
	var myAjax = new Ajax.Request ( 
			url, 
			{ 
				method: 'post', 
				parameters: pars, 
				onFailure: showError,
				onSuccess: showResult
			}
	); 
	
	return false;
}

