function vai()
{

var tproduto = document.FrontPage_Form1.ITEM_PROD.value
var tcor = document.FrontPage_Form1.ITEM_COR.value
var tdesenho = document.FrontPage_Form1.ITEM_DES.value
var tsituacao = document.FrontPage_Form1.ITEM_SITU.value
var tcategoria = document.FrontPage_Form1.ITEM_CAT.value

document.FrontPage_Form1.LINKE.value=document.FrontPage_Form1.ESTOQUE.value+"&ITEM_PROD="+tproduto 
document.FrontPage_Form1.LINKE.value=document.FrontPage_Form1.LINKE.value+"&ITEM_COR="+tcor
document.FrontPage_Form1.LINKE.value=document.FrontPage_Form1.LINKE.value+"&ITEM_DES="+tdesenho
document.FrontPage_Form1.LINKE.value=document.FrontPage_Form1.LINKE.value+"&ITEM_SITU="+tsituacao
document.FrontPage_Form1.LINKE.value=document.FrontPage_Form1.LINKE.value+"&ITEM_CAT="+tcategoria

var tlink = document.FrontPage_Form1.LINKE.value; 

window.open(tlink,"est","toolbar=no, menubar=no, statusbar=no,width=770,height=250, top=150, left=10, location=no, title=no");
}


// trava o usuario de apertar duas vezes no botão para gravações 
function botao()
{

if (document.FrontPage_Form1.CLICOU.value != 'SIM')
  {
   document.FrontPage_Form1.CLICOU.value='SIM';
   document.FrontPage_Form1.submit();
  }
else
  {
   window.alert('Processando... Aguarde alguns instantes');
  }

}

function wd(janelawd, largura, altura)
{
window.open(janelawd,"wdj","toolbar=no, menubar=no, statusbar=no, width="+largura+", height="+altura+", top=30, left=25, location=no, title=no");
}

function Detail(janelapop)
{
window.open(janelapop,"wpop","toolbar=no, menubar=no, statusbar=no,width=550,height=430, top=30, left=25, location=no, title=no");
}

function DetailPed(janelaped)
{
window.open(janelaped,"wped","toolbar=no, menubar=no, statusbar=no,width=720,height=400, top=70, left=65, location=no, title=no");
}


function Pecas(janelapeca)
{
window.open(janelapeca,"wpeca","toolbar=no, menubar=no, statusbar=no,width=300,height=330, top=140, left=165, location=no, title=no");
}

function NF(janelanf)
{
window.open(janelanf,"wnf","toolbar=no, menubar=no, statusbar=no,width=500,height=10, top=220, left=25, location=no, title=no");
}

function Dup(janeladup)
{
window.open(janeladup,"wdup","toolbar=no, menubar=no, statusbar=no,width=550,height=150, top=350, left=25, location=no, title=no");
}

function Rom(janelarom)
{
window.open(janelarom,"wrom","toolbar=no, menubar=no, statusbar=no,width=460,height=200, top=350, left=50, location=no, title=no");
}

function AtualizaItens(link_itens)
{
window.location(link_itens,"ITENS_GRID","toolbar=no, menubar=no, statusbar=no,width=550,height=400, top=30, left=25, location=no, title=no");
}

function Big(janelabig)
{
window.open(janelabig,"bigprod","toolbar=no, menubar=no, statusbar=no,width=450,height=320, top=30, left=25, location=no, title=no");
}


//SELEÇÃO DE ITENS DO PEDIDO
function selecionap() { 
var tproduto = document.frmChamado.codigo_interno.value;  

if (tproduto != "") {
  document.frmChamado.equipamento.value=tproduto;     

  if (tproduto != document.frmChamado.equipamento.value) {
   document.frmChamado.codigo_interno.value="";
   document.frmChamado.equipamento.value=""; 
   alert("Equipamento não encontrado!");
  } 
}

else {
 document.frmChamado.equipamento.value="";
 alert("Equipamento não encontrado!"); 
}

} 

function selecionapc() { 
var tprodutoc = document.FrontPage_Form1.PROD_LIST.value; 
if (tprodutoc != "0") {
 document.FrontPage_Form1.ITEM_PROD.value=tprodutoc; 
}

if (document.FrontPage_Form1.PROD_LIST.value != document.FrontPage_Form1.ITEM_PROD.value)
{
document.FrontPage_Form1.ITEM_PROD.value="";
document.FrontPage_Form1.PROD_LIST.value="0";
}

} 

function selecionac() { 
var tcor = document.FrontPage_Form1.ITEM_COR.value; 

if (tcor != "") {
document.FrontPage_Form1.COR_LIST.value=tcor; 

if (tcor != document.FrontPage_Form1.COR_LIST.value) {
 document.FrontPage_Form1.COR_LIST.value="0";
 document.FrontPage_Form1.ITEM_COR.value=""; 
} 
}

else {
 document.FrontPage_Form1.COR_LIST.value="0";
 }

} 

function selecionacc() { 
var tcorc = document.FrontPage_Form1.COR_LIST.value; 

if (tcorc != "0") {
 document.FrontPage_Form1.ITEM_COR.value=tcorc; 
}

if (document.FrontPage_Form1.COR_LIST.value != document.FrontPage_Form1.ITEM_COR.value)
{
document.FrontPage_Form1.ITEM_COR.value="";
document.FrontPage_Form1.COR_LIST.value="0";
}

} 

function selecionad() { 
var tDesenho = document.FrontPage_Form1.ITEM_DES.value; 

if (tDesenho != "") {
 document.FrontPage_Form1.DES_LIST.value=tDesenho; 

if (tDesenho != document.FrontPage_Form1.DES_LIST.value) {
 document.FrontPage_Form1.DES_LIST.value="0";
 document.FrontPage_Form1.ITEM_DES.value=""; 
} 
}

else {
document.FrontPage_Form1.DES_LIST.value="0";
}

} 

function selecionadc() { 
var tdesenhoc = document.FrontPage_Form1.DES_LIST.value; 

if (tdesenhoc != "0") {
  document.FrontPage_Form1.ITEM_DES.value=tdesenhoc; 
 }
if (document.FrontPage_Form1.DES_LIST.value != document.FrontPage_Form1.ITEM_DES.value)
{
document.FrontPage_Form1.ITEM_DES.value="";
document.FrontPage_Form1.DES_LIST.value="0";
}

} 

function selecionas() { 
var tSituacao = document.FrontPage_Form1.ITEM_SITU.value; 

if (tSituacao != "") {
document.FrontPage_Form1.SITU_LIST.value=tSituacao; 
  
   if (tSituacao != document.FrontPage_Form1.SITU_LIST.value) {
      document.FrontPage_Form1.SITU_LIST.value="0";
      document.FrontPage_Form1.ITEM_SITU.value="";
    }
}

else {
 document.FrontPage_Form1.SITU_LIST.value="0";
}

} 

function selecionasc() { 
var tsituacaoc = document.FrontPage_Form1.SITU_LIST.value; 

if (tsituacaoc != "0") {
document.FrontPage_Form1.ITEM_SITU.value=tsituacaoc; 
}

if (document.FrontPage_Form1.SITU_LIST.value != document.FrontPage_Form1.ITEM_SITU.value)
{
document.FrontPage_Form1.ITEM_SITU.value="";
document.FrontPage_Form1.SITU_LIST.value="0";
}

} 

function selecionaca() { 
var tCategoria = document.FrontPage_Form1.ITEM_CAT.value; 

if (tCategoria != "") {
document.FrontPage_Form1.CAT_LIST.value=tCategoria; 

if (tCategoria != document.FrontPage_Form1.CAT_LIST.value) {
  document.FrontPage_Form1.CAT_LIST.value="0";
  document.FrontPage_Form1.ITEM_CAT.value="";  } 
}
else {
 document.FrontPage_Form1.CAT_LIST.value="0";
}

} 

function selecionacac() { 
var tcategoriac = document.FrontPage_Form1.CAT_LIST.value; 
if (tcategoriac != "0") {
  document.FrontPage_Form1.ITEM_CAT.value=tcategoriac; 
 }

if (document.FrontPage_Form1.CAT_LIST.value != document.FrontPage_Form1.ITEM_CAT.value)
{
 document.FrontPage_Form1.ITEM_CAT.value="";
 document.FrontPage_Form1.CAT_LIST.value="0";

}


} 


//COMPLETA COM ZEROS
function zerosp(Texto, Tamanho) { 
if (Texto != "")
{
quant = Texto.length;
totz = Tamanho - quant;
for (x = 0 ; x < totz ; x++) {   Texto = 0 + Texto; }
return Texto
}

else{
return ""}

} 


//***** VALOR TOTAL DO ITEM ******
function total() { 
var vtotal = parseFloat(document.FrontPage_Form1.QTDE_ITEM.value,2,2) * parseFloat(document.FrontPage_Form1.VR_UNITARIO.value,2,2);
if (document.FrontPage_Form1.QTDE_ITEM.value!='')
  { 
   document.FrontPage_Form1.VR_TOTAL.value='R$ '+parseFloat(vtotal,2,2);
   
//   parseFloat(vtotal,2,2);
  }
else {
  document.FrontPage_Form1.VR_TOTAL.value='R$ 0'; 
  } 
} 

function mesmo_cobranca() { 
var tcategoriac = 'O MESMO'; 
document.FrontPage_Form1.ENDERECO_COBRANCA.value=tcategoriac; 
tcategoriac = document.FrontPage_Form1.cidade.value; 
document.FrontPage_Form1.cidadec.value=tcategoriac; 
tcategoriac = document.FrontPage_Form1.ESTADO.value; 
document.FrontPage_Form1.ESTADO_COBRANCA.value=tcategoriac; 
document.FrontPage_Form1.BAIRRO_COBRANCA.value=''; 
document.FrontPage_Form1.CEP_COBRANCA.value=''; 
} 

function mesmo_entrega() { 
var tcategoriac = 'O MESMO'; 
document.FrontPage_Form1.ENDERECO_ENTREGA.value=tcategoriac; 
tcategoriac = document.FrontPage_Form1.cidade.value; 
document.FrontPage_Form1.cidadee.value=tcategoriac; 
tcategoriac = document.FrontPage_Form1.ESTADO.value; 
document.FrontPage_Form1.ESTADO_ENTREGA.value=tcategoriac; 
document.FrontPage_Form1.BAIRRO_ENTREGA.value=''; 
document.FrontPage_Form1.CEP_ENTREGA.value=''; 
} 


function f_qtde(numero)
{
if(event.keyCode==44) event.keyCode=46;
}


    //MASCARAS
    function criaMascara(_RefObjeto, _Modelo){
  
    var valorAtual = _RefObjeto.value;        
    var valorNumerico = '';
    var nIndexModelo = 0;
    var nIndexString = 0;
    var valorFinal = '';
    var adicionarValor = true;
    
      // 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 (!isNaN(parseFloat(valorAtual.substr(i,1)))){
          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 
  }              
  
  

function SelObj(formname,selname,textname,str) {
this.formname = formname;
this.selname = selname;
this.textname = textname;
this.select_str = str || '';
this.selectArr = new Array();
//this.initialize = initialize;
//this.bldInitial = bldInitial;
this.bldUpdate = bldUpdate;
}

/*function initialize() {
if (this.select_str =='') {
for(var i=0;i<document.forms[this.formname][this.selname].options.length;i++) {
this.selectArr[i] = document.forms[this.formname][this.selname].options[i];
this.select_str += document.forms[this.formname][this.selname].options[i].value+":"+
document.forms[this.formname][this.selname].options[i].text+",";
   }
}
else {
var tempArr = this.select_str.split(',');
for(var i=0;i<tempArr.length;i++) {
var prop = tempArr[i].split(':');
this.selectArr[i] = new Option(prop[1],prop[0]);
   }
}
return;
}

function bldInitial() {
this.initialize();
for(var i=0;i<this.selectArr.length;i++)
  document.forms[this.formname][this.selname].options[i] = this.selectArr[i];
  document.forms[this.formname][this.selname].options.length = this.selectArr.length;
return;
}*/


function bldUpdate(listagem,digita) {
var i = 0;
i = window.event.keyCode;
var x=0;
var texto =document.FrontPage_Form1[digita].value;
var aux="";

//letras
if ((i>=65) & (i<=90))
 {
  texto = texto + String.fromCharCode(i);
  aux='d';
 }  
 
 //caso a tecla delte seja pressionada
 if (i==46) 
 { 
  texto="";
  document.FrontPage_Form1[listagem].options[0].selected=true;

  }

 //espaço em branco
 if (i==32) 
 { 
  texto = texto + String.fromCharCode(i);
 }  
 
 //numeros
 if ((i>=48) & (i<=57))
  {
     texto = texto + String.fromCharCode(i);
  } 

 //numeros do num lock
 if ((i>=95) & (i<=106))
  {
     i=i-48;
     texto = texto + String.fromCharCode(i);
  } 

 if ((i==193), (i==111))
  {
  texto=texto+'/';
  }
  
 //positivo e negativo (- +)
 if ((i>=106) & (i<=109))
  {
  i=i-64;
  texto = texto + String.fromCharCode(i);
  }  
  
 if ((i>=186) & (i<=189))
  {
  i=i-144;
  texto = texto + String.fromCharCode(i);
  }  
  
  
/* if (aux!='d')
 {
 texto=texto + String.fromCharCode(i);
 }*/
//  i[x-1]='';

document.FrontPage_Form1[digita].value = texto; 


var str = document.FrontPage_Form1[digita].value.replace('^\\s*','');

var a=0;
var j=0;
var j_max=document.FrontPage_Form1[listagem].options.length -1;

if ((texto.length)!=0)
 {
	while (a==0)
	 {
       
		  var lista=document.FrontPage_Form1[listagem].options[j].text;

		  if (texto == lista.substring(0,texto.length))
		   {
		     document.FrontPage_Form1[listagem].options[j].selected=true;
		     a=1;	   
		   }
         
		  else
		   {  
       	    if (j==j_max) 
       	     {
              a=1;       	       
       	     }
     	     
       	    else 
       	     {
       	       j=j+1;
       	     }

		   }

	 }
 }
   
  


}


// função antiga
/*function bldUpdate() {
//var i = window.event.keyCode;//document.forms[this.formname][this.selname].;
//document.forms[this.formname].digitado.value= char(39);
var str = document.forms[this.formname][this.textname].value.replace('^\\s*','');
if(str == '') {
 this.bldInitial();
return;
}

this.initialize();
var j = 0;
pattern1 = new RegExp("^"+str,"i");
for(var i=0;i<this.selectArr.length;i++)
 if(pattern1.test(this.selectArr[i].text)) 
  document.forms[this.formname][this.selname].options[j++] = this.selectArr[i];
  document.forms[this.formname][this.selname].options.length = j;

if(j==1){
document.forms[this.formname][this.selname].options[0].selected = true;
document.forms[this.formname][this.textname].value = document.forms[this.formname][this.selname].options[0].text;
   }
   
   
}*/


function setUp(listagem,digita) {
obj1 = new SelObj('FrontPage_Form1',listagem,digita);
// menuform is the name of the form you use
// itemlist is the name of the select pulldown menu you use
// entry is the name of text box you use for typing in
//obj1.bldInitial(); 
}
//  End --> 


function enter()
{
if(event.keyCode==13) event.keyCode=9;
}

function grava()
{
if(event.keyCode==13) {
 validateForm();
}
}

function apaga(digita)
{ 

if(event.keyCode==8) event.keyCode=46;

var i = 0;
i = event.keyCode;
var x=0;
var texto =document.FrontPage_Form1[digita].value;

if (i==46)
{
texto="";
document.FrontPage_Form1[digita].value=texto;
}

}



//METRAGEM DAS PEÇAS
function pecas() { 
if (document.FrontPage_Form1.PECAS.value != "")
{

var vpecas = parseFloat(document.FrontPage_Form1.QTDE_ITEM.value,2,2) / parseFloat(document.FrontPage_Form1.PECAS.value,2,2);
document.FrontPage_Form1.METROS.value = Math.round(parseFloat(vpecas,2,0));
}
else {
 document.FrontPage_Form1.METROS.value = 0;
 }
 
} 


function checknet() {
if (document.FrontPage_Form1.FINALIZADO.checked==true) {
  document.FrontPage_Form1.FINALIZADO.checked=false;
  }

}

function checkfin() {
if (document.FrontPage_Form1.INTERNET.checked==true) {
  document.FrontPage_Form1.INTERNET.checked=false;
  }
}


function DataFrac(CAMPO1, CAMPO2, CAMPO3)
{

var today = new Date();
var Day = today.getDate();
var Mnth = today.getMonth();
var Year = today.getFullYear();
var MnthNam = new Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");

document.FrontPage_Form1[CAMPO1].value= Day;
document.FrontPage_Form1[CAMPO2].value = MnthNam[Mnth];
document.FrontPage_Form1[CAMPO3].value = Year;
}


function setOrdena(num)
{
  document.forms[0].ordena.value = num;
  document.forms[0].submit(); 
}



function proximo_campo(e, campo)
    {
     	  
        for (var i=0;i < document.forms[0].elements.length;i++)
        {
            if (document.forms[0].elements[i].name == campo)
            {
                var proximo_campo=document.forms[0].elements[i+1].name;			
				
				if (document.forms[0].elements[i+1].type=="hidden") {
				   proximo_campo=document.forms[0].elements[i+2].name;
				}
			
                if (proximo_campo.indexOf('[')!=-1)
                {
                    proximo_campo=document.forms[0].elements[i+2].name;
                }
            }
        }

       var ie = (typeof window.ActiveXObject != 'undefined');
       if(ie)
       {
          code = event.keyCode;
       }
       else // Firefox
       {	   
          code = e.which; 		  
       }
	   
       if(code == 13)
       {			
			if (campo == 'false')
            {
                return false;
            }
            campo = document.getElementById(proximo_campo);
 		    campo.focus();
            //eval('document.forms[0].' + proximo_campo + '.focus();');
            return false;	
       } //if code = 13
    }
	
function primeiro()
{
document.forms[0].elements[0].focus();
}	




function openAjax() {

var ajax;

try{
    ajax = new XMLHttpRequest(); // XMLHttpRequest para Firefox, Safari, dentre outros.
}catch(ee){
    try{
        ajax = new ActiveXObject("Msxml2.XMLHTTP"); // Para o Internet Explorer
    }catch(e){
        try{
            ajax = new ActiveXObject("Microsoft.XMLHTTP"); // Para o Internet Explorer
        }catch(E){
            ajax = false;
        }
    }
}
return ajax;
}