// JavaScript Document

//mascara do CPF e CNPj do cadastro de clientes
function cpfcadastro(){

if (document.cadastro.tipopessoa.value=="f"){
   
   if ( document.cadastro.CPFCliente.value.length == 3){
   document.cadastro.CPFCliente.value = document.cadastro.CPFCliente.value+".";
   }
   if ( document.cadastro.CPFCliente.value.length == 7){
   document.cadastro.CPFCliente.value = document.cadastro.CPFCliente.value+".";
   }
   if ( document.cadastro.CPFCliente.value.length == 11){
   document.cadastro.CPFCliente.value = document.cadastro.CPFCliente.value+"-";
   }
   if ( document.cadastro.CPFCliente.value.length == 14){
   document.cadastro.RgCliente.focus();
   }
   
  }
  else{
  
   if ( document.cadastro.CPFCliente.value.length == 2){
   document.cadastro.CPFCliente.value = document.cadastro.CPFCliente.value+".";
   }
   if ( document.cadastro.CPFCliente.value.length == 6){
   document.cadastro.CPFCliente.value = document.cadastro.CPFCliente.value+".";
   }
   if ( document.cadastro.CPFCliente.value.length == 10){
   document.cadastro.CPFCliente.value = document.cadastro.CPFCliente.value+"/";
   }
   if ( document.cadastro.CPFCliente.value.length == 15){
   document.cadastro.CPFCliente.value = document.cadastro.CPFCliente.value+"-";
   }
   if ( document.cadastro.CPFCliente.value.length == 18){
   document.cadastro.RgCliente.focus();
   }
  
  }

}




//mascara de CEP do cadastro
function cepcadastro(){

 if (document.cadastro.CepCliente.value.length == 5){
 document.cadastro.CepCliente.value = document.cadastro.CepCliente.value+"-";
 }
 
 if (document.cadastro.CepCliente.value.length == 9){
 document.cadastro.NumeroEndCliente.focus();
 VerCEP(document.cadastro.CepCliente.value);
 }
 

}


//mascara de TELEFONE RESIDENCIAL do cadastro
function telrescadastro(){
 if (document.cadastro.NumFoneCliente.value.length == 1){
 document.cadastro.NumFoneCliente.value = "("+document.cadastro.NumFoneCliente.value;
 }
 if (document.cadastro.NumFoneCliente.value.length == 3){
 document.cadastro.NumFoneCliente.value = document.cadastro.NumFoneCliente.value+")";
 }
 if (document.cadastro.NumFoneCliente.value.length == 8){
 document.cadastro.NumFoneCliente.value = document.cadastro.NumFoneCliente.value+"-";
 }
 if (document.cadastro.NumFoneCliente.value.length == 13){
 document.cadastro.NumFoneFaxCliente.focus();
 }
}


//mascara de TELEFONE COMERCIAL do cadastro
function telfaxcadastro(){
 if (document.cadastro.NumFoneFaxCliente.value.length == 1){
 document.cadastro.NumFoneFaxCliente.value = "("+document.cadastro.NumFoneFaxCliente.value;
 }
 if (document.cadastro.NumFoneFaxCliente.value.length == 3){
 document.cadastro.NumFoneFaxCliente.value = document.cadastro.NumFoneFaxCliente.value+")";
 }
 if (document.cadastro.NumFoneFaxCliente.value.length == 8){
 document.cadastro.NumFoneFaxCliente.value = document.cadastro.NumFoneFaxCliente.value+"-";
 }
 if (document.cadastro.NumFoneFaxCliente.value.length == 13){
 document.cadastro.NumFoneCelCliente.focus();
 }
}



//mascara de TELEFONE CELULAR do cadastro
function telcelcadastro(){
 if (document.cadastro.NumFoneCelCliente.value.length == 1){
 document.cadastro.NumFoneCelCliente.value = "("+document.cadastro.NumFoneCelCliente.value;
 }
 if (document.cadastro.NumFoneCelCliente.value.length == 3){
 document.cadastro.NumFoneCelCliente.value = document.cadastro.NumFoneCelCliente.value+")";
 }
 if (document.cadastro.NumFoneCelCliente.value.length == 8){
 document.cadastro.NumFoneCelCliente.value = document.cadastro.NumFoneCelCliente.value+"-";
 }
 if (document.cadastro.NumFoneCelCliente.value.length == 13){
 document.cadastro.EmailCliente.focus();
 }
}




function cpflogin(){

if (document.cadastro.tipopessoa.value=="f"){
   
   if ( document.cadastro.CPFCliente.value.length == 3){
   document.cadastro.CPFCliente.value = document.cadastro.CPFCliente.value+".";
   }
   if ( document.cadastro.CPFCliente.value.length == 7){
   document.cadastro.CPFCliente.value = document.cadastro.CPFCliente.value+".";
   }
   if ( document.cadastro.CPFCliente.value.length == 11){
   document.cadastro.CPFCliente.value = document.cadastro.CPFCliente.value+"-";
   }
   if ( document.cadastro.CPFCliente.value.length == 14){
   document.cadastro.SenhaCliente.focus();
   }
   
  }
  else{
  
   if ( document.cadastro.CPFCliente.value.length == 2){
   document.cadastro.CPFCliente.value = document.cadastro.CPFCliente.value+".";
   }
   if ( document.cadastro.CPFCliente.value.length == 6){
   document.cadastro.CPFCliente.value = document.cadastro.CPFCliente.value+".";
   }
   if ( document.cadastro.CPFCliente.value.length == 10){
   document.cadastro.CPFCliente.value = document.cadastro.CPFCliente.value+"/";
   }
   if ( document.cadastro.CPFCliente.value.length == 15){
   document.cadastro.CPFCliente.value = document.cadastro.CPFCliente.value+"-";
   }
   if ( document.cadastro.CPFCliente.value.length == 18){
   document.cadastro.SenhaCliente.focus();
   }
  
  }

}

function cpfloginorc(){

if (document.cadastro.tipopessoa.value=="f"){
   
   if ( document.cadastro.CPFCliente.value.length == 3){
   document.cadastro.CPFCliente.value = document.cadastro.CPFCliente.value+".";
   }
   if ( document.cadastro.CPFCliente.value.length == 7){
   document.cadastro.CPFCliente.value = document.cadastro.CPFCliente.value+".";
   }
   if ( document.cadastro.CPFCliente.value.length == 11){
   document.cadastro.CPFCliente.value = document.cadastro.CPFCliente.value+"-";
   }
   if ( document.cadastro.CPFCliente.value.length == 14){
   document.cadastro.ok.focus();
   }
   
  }
  else{
  
   if ( document.cadastro.CPFCliente.value.length == 2){
   document.cadastro.CPFCliente.value = document.cadastro.CPFCliente.value+".";
   }
   if ( document.cadastro.CPFCliente.value.length == 6){
   document.cadastro.CPFCliente.value = document.cadastro.CPFCliente.value+".";
   }
   if ( document.cadastro.CPFCliente.value.length == 10){
   document.cadastro.CPFCliente.value = document.cadastro.CPFCliente.value+"/";
   }
   if ( document.cadastro.CPFCliente.value.length == 15){
   document.cadastro.CPFCliente.value = document.cadastro.CPFCliente.value+"-";
   }
   if ( document.cadastro.CPFCliente.value.length == 18){
   document.cadastro.ok.focus();
   }
  
  }

}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function jump(form) 
{
var myindex=form.CodFornecedor.selectedIndex
if (form.CodFornecedor.options[myindex].value != "" && form.CodFornecedor.options[myindex].value != "null") 
	{
	window.open(form.CodFornecedor.options[myindex].value,target="_self");
	}
	
}

function Valida()
{
	if (document.pedido.CodProd.value=="")
 	{
		alert("O código do produto não pode ser vazil.")
		document.pedido.CodProd.focus()
	}
}

function OpenWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
	}

function ValidaText(nomcampo)
{
  if( eval('document.cadastro.'+nomcampo+'.value') == "" )
  {
    alert("Este campo é obrigatório !");
	eval('document.cadastro.'+nomcampo+'').style.background = "#F5F5F5";
	eval('document.cadastro.'+nomcampo+'').focus();
    return false;
  }
  eval('document.cadastro.'+nomcampo+'').disabled = false;
  eval('document.cadastro.'+nomcampo+'').style.background = "#ffffff";
  return true;
}

//BUSCA CEP PARA ENCONTRAR ENDEREÇO
function VerCEP(cep){

//Mensagens('Procurando Endereço...');

//MM_showHideLayers('LayerMenssagem','','show');

//MM_openBrWindow('recebe_cep.asp?cep='+cep,'','width= 10, height=10');

BuscaCEP.location.href='recebe_cep.asp?cep='+cep;

}

//FUNÇÃO QUE MOSTRA LAYERS

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


//Troca campo com enter;
function TrocaCampo(Campo){

if (event.keyCode == 13){
 eval('document.cadastro.'+Campo+'.focus()');
 return false;
}

}

function Mensagens(aviso){
 document.mensagem.texto.value = aviso;
 MM_showHideLayers('LayerMenssagem','','show');
}

function Carregando(){
 Mensagens('Carregando Página...');
 MM_showHideLayers('LayerMenssagem','','show');
}

function FechaAviso(){
MM_showHideLayers('LayerAviso','','hidden');
}
function AbreAviso(){
MM_showHideLayers('LayerAviso','','show');
}
function LayerPos(pos){
 LayerMenssagem.style.top = pos;
}
//Função que ria ARRAY
function CriaArray(n){
this.length = n;
 for (var i=1 ; i<=n ; i++){
 this[i]=""
 }
}

function ImprimirDocumento(){
 if (confirm('Deseja imprimir esse documento?')){
  print();
 }
}

function FecharDocumento(){
 if (confirm('Deseja fechar esse documento?')){
  window.close();
 }
}

<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function Message(Mensagem,Titulo,Botoes,Icone,Retornos,Focus){

var MaxWidth = 550;
var Width = 250;
var Height = 150;
var Linha = Mensagem.split('\n');
var ABotoes = Botoes.split(',');
var NumLinhas = Linha.length;
var NumBotoes = ABotoes.length;
var LinhaMaior = 0;
var BotaoMaior = 0;
var argumentos = Mensagem+'|'+Titulo+'|'+Botoes+'|'+Icone+'|'+Retornos+'|'+Focus;

 if (NumLinhas > 5){
  Height = Height + (NumLinhas*(NumLinhas/2));
 }
 for(var i=0;i<NumLinhas;i++){
  if(Linha[i].length > LinhaMaior){
   var LinhaMaior = Linha[i].length;
  }
 }
LinhaMaior = LinhaMaior*8;
 if (LinhaMaior > Width && LinhaMaior < MaxWidth){
  Width = LinhaMaior + 10;
 }
 for(var i=0;i<NumBotoes;i++){
   var BotaoMaior = BotaoMaior + (ABotoes[i].length+1)*10;
 }
 if (BotaoMaior > Width && BotaoMaior < MaxWidth){
  Width = BotaoMaior + 10;
 }
Janela = window.showModalDialog('dialog.htm',argumentos,'Resizable:no; DialogHeight:'+Height+'px; DialogWidth:'+Width+'px; Edge:raised; Help:no; Scroll:no; Status:no; Center:yes;');
return Janela;
}

function FormatFloat(casas,varValor){
if (varValor != ''){
 if (varValor.indexOf('.') >= 0){
  separador = '.';
 }else{
  separador = ','
 }
 var posicao = varValor.indexOf(separador);
  if (posicao >= 0){
  var primeiro = varValor.substring(0,posicao);
  var segundo = varValor.substring(posicao+1,varValor.length);
  var segundo = segundo.substring(0,casas);
   if (segundo.length <= 1){
    var segundo = segundo + '0';
   }
  var total = primeiro + separador + segundo
  return total;
  }
}
}
//-->

//programação feita por Douglas Wellington