msel = '';
function acaoClick(idlayer,e,c,id) {
 voltaSelect();
 pr = '';
 if (e != '') {
  if (e.keyCode == 13) { pr = '1'; }
 } else if (c != '') { pr = '1'; }
 if (pr != '') {
  if (document.getElementById('id01').checked == true) {
   carregandoic('idForm1','');
   acao(idlayer,'idForm1','oper=acao&op=busca',id,'busca','buscaid','');
  } else {
   acao(idlayer,'','oper=acao&op=listform',id,'busca','buscaid','');
  }
 }
}
function verificafoto(op,ids,idg){
 idgpas = '';
 if (idg != '') {
  if (document.getElementById(idg)) {
   if (document.getElementById(idg).value == '') {
    idgpas = '1';
   }
  }
 }
 if (op == 'Adicionar') {
  if (idgpas != '') {
  } else if (document.getElementById(ids).value == '') {
   alert('Você tem que selecionar uma imagem');
   document.getElementById(ids).focus();
   return false;
  } else {
   return true;
  }
 } else {
  
  if (document.getElementById(ids).value != '') {
   return true;
  } else if (idgpas == '') {
   return true;
  } else {
   alert('Você tem que selecionar a imagem, para atualizar tamanho/credito/legenda utilize o icone verde acima')
   return false;
  }
 }
}

function mudaSelect(idlayer,idlayeret,tipoid,id,nome) {
 document.getElementById(idlayer).innerHTML = nome+"<input type='hidden' id='"+tipoid+"' value='"+id+"'>";
 document.getElementById(idlayeret).innerHTML = "<img src='/t.gif' width='1' height='1'>";
 msel = '';
}
function montaSelect(idlayer,idlayeret,tipoid,id,tipo,cod) {
 if (msel == '') {
  if (tipo == '') {
   H = "<div id='"+idlayer+"psel' style='position:absolute;width:120px;background:#FFFFFF;border:1px solid #CACACA'>";
   H = H + "<div onmouseover='this.style.background=&#39;#EAEAEA&#39;' onmouseout='this.style.background=&#39;#FFFFFF&#39;' style='cursor:pointer;padding:2px;' onclick='mudaSelect(&#39;"+idlayer+"&#39;,&#39;"+idlayeret+"&#39;,&#39;"+tipoid+"&#39;,&#39;id&#39;,&#39;Código&#39;)'><a style='display:block;'>Código</a></div>";
   H = H + "<div onmouseover='this.style.background=&#39;#EAEAEA&#39;' onmouseout='this.style.background=&#39;#FFFFFF&#39;' style='cursor:pointer;padding:2px;display:block;' onclick='mudaSelect(&#39;"+idlayer+"&#39;,&#39;"+idlayeret+"&#39;,&#39;"+tipoid+"&#39;,&#39;vnomefantasia&#39;,&#39;Nome&#39;)'>Nome</div>";
   if ((id >= 34)  && (id <= 37)) {
    H = H + "<div onmouseover='this.style.background=&#39;#EAEAEA&#39;' onmouseout='this.style.background=&#39;#FFFFFF&#39;' style='cursor:pointer;padding:2px;display:block;' onclick='mudaSelect(&#39;"+idlayer+"&#39;,&#39;"+idlayeret+"&#39;,&#39;"+tipoid+"&#39;,&#39;vfone&#39;,&#39;Telefone&#39;)'>Telefone</div>";
    H = H + "<div onmouseover='this.style.background=&#39;#EAEAEA&#39;' onmouseout='this.style.background=&#39;#FFFFFF&#39;' style='cursor:pointer;padding:2px;display:block;' onclick='mudaSelect(&#39;"+idlayer+"&#39;,&#39;"+idlayeret+"&#39;,&#39;"+tipoid+"&#39;,&#39;vcpfcnpj&#39;,&#39;CPF/CNPJ&#39;)'>CPF/CNPJ</div>";
    H = H + "<div onmouseover='this.style.background=&#39;#EAEAEA&#39;' onmouseout='this.style.background=&#39;#FFFFFF&#39;' style='cursor:pointer;padding:2px;display:block;' onclick='mudaSelect(&#39;"+idlayer+"&#39;,&#39;"+idlayeret+"&#39;,&#39;"+tipoid+"&#39;,&#39;vendereco&#39;,&#39;Endereço&#39;)'>Endereço</div>";
	if (cod == '2') {
     H = H + "<div onmouseover='this.style.background=&#39;#EAEAEA&#39;' onmouseout='this.style.background=&#39;#FFFFFF&#39;' style='cursor:pointer;padding:2px;display:block;' onclick='mudaSelect(&#39;"+idlayer+"&#39;,&#39;"+idlayeret+"&#39;,&#39;"+tipoid+"&#39;,&#39;vcodbarra&#39;,&#39;Código Produto&#39;)'>Código Produto</div>";
	}
   } else {
    H = H + "<div onmouseover='this.style.background=&#39;#EAEAEA&#39;' onmouseout='this.style.background=&#39;#FFFFFF&#39;' style='cursor:pointer;padding:2px;display:block;' onclick='mudaSelect(&#39;"+idlayer+"&#39;,&#39;"+idlayeret+"&#39;,&#39;"+tipoid+"&#39;,&#39;vdescricao&#39;,&#39;Descrição&#39;)'>Descrição</div>";
   }
   H = H + "</div>";
   msel = document.getElementById('buscaselid').innerHTML;
   document.getElementById('buscaselid').innerHTML = H;
  } else {
   acao(idlayer,idlayeret,'oper=acao&op=montaselect&tipo='+tipo,id,'','','');  
  }
 } else {
  H = msel;
  msel = '';
  document.getElementById('buscaselid').innerHTML = H;
 }
}
function voltaSelect(){
 if (msel != '') {
  document.getElementById('buscaselid').innerHTML = msel;
  msel = '';
 }
}

function acaoReport(idlayer,id) {
 H = "oper=acao&op=report";
 if (document.getElementById('diaini')) {
  H = H + "&diaini="+document.getElementById('diaini').value + "&mesini="+document.getElementById('mesini').value + "&anoini="+document.getElementById('anoini').value;
  H = H + "&diafim="+document.getElementById('diafim').value + "&mesfim="+document.getElementById('mesfim').value + "&anofim="+document.getElementById('anofim').value;
 }
 if (document.getElementById('iduser')) {
  v = document.getElementById('iduser').value;
  if (v != '') { H = H + '&iduser='+v; }
 }
 if (document.getElementById('busca')) {
  v = document.getElementById('busca').value;
  if (v != '') { H = H + '&busca='+v; }
 }
 if (document.getElementById('buscaid')) {
  v = document.getElementById('buscaid').value;
  if (v != '') { H = H + '&buscaid='+v; }
 }
 for (i=1;i<7;i++) {
  if (document.getElementById('ids'+i)) {
   v = document.getElementById('ids'+i).checked;
   if (v == true) { H = H + '&ids'+i+'=1'; }
  }
 }
 pr = 1;
 for(i = 0; i < document.getElementById('idprod').options.length; i++) { 
  if (document.getElementById('idprod').options[i].selected) { 
   if (document.getElementById('idprod').options[i].value != '') {
    H = H + "&idprod" + pr + "=" + document.getElementById('idprod').options[i].value;
    pr = pr + 1;
   }
  }
 } 
 H = H + "&maxprod=" + document.getElementById('idprod').options.length;
 acao(idlayer,'',H,id,'','','');
}

function carregando(idlayer,swidth,sclass){
 if (swidth != '') { swidth="style='width:"+swidth+"px'"; }
 if (sclass == '') { sclass="frm"; }
 document.getElementById(idlayer).innerHTML = "<select "+swidth+" class='"+sclass+"'><option value=''>Carregando ...</option></select>";
}

var digitos=10; //cantidad de digitos buscados
var puntero=0;
var buffer=new Array(digitos); //declaración del array Buffer
var cadena="";
function buscar_op(obj){
 var letra = String.fromCharCode(event.keyCode)
 if(puntero >= digitos){
  cadena="";
  puntero=0;
 }
 if (event.keyCode == 13){ //si se presiona la tecla ENTER, borro el array de teclas presionadas y salto a otro objeto...
  borrar_buffer();
 } else { //sino busco la cadena tipeada dentro del combo...
  buffer[puntero]=letra;
  //guardo en la posicion puntero la letra tipeada
  cadena=cadena+buffer[puntero]; //armo una cadena con los datos que van ingresando al array
  puntero++;
  //barro todas las opciones que contiene el combo y las comparo la cadena...
  for (var opcombo=0;opcombo < obj.length;opcombo++){
   if(obj[opcombo].text.substr(0,puntero).toLowerCase()==cadena.toLowerCase()){
    obj.selectedIndex = opcombo;
	opcombo = obj.length;
   }
  }
 }
 event.returnValue = false; //invalida la acción de pulsado de tecla para evitar busqueda del primer caracter
}
function borrar_buffer(){
 //inicializa la cadena buscada
 cadena="";
 puntero=0;
}
function menuvertical() { 
   var navItems = document.getElementById("nav").getElementsByTagName("li"); 
   for (var i=0; i< navItems.length; i++) { 
      if(navItems[i].className == "submenu") { 
         navItems[i].onmouseover=function() {this.getElementsByTagName('ul')[0].style.display="block";this.style.backgroundColor = "#f9f9f9";} 
         navItems[i].onmouseout=function() {this.getElementsByTagName('ul')[0].style.display="none";this.style.backgroundColor = "#FFFFFF";} 
      } 
   } 
} 

function menuhorizontal() { 
   var navItems = document.getElementById("barra").getElementsByTagName("li"); 
   for (var i=0; i< navItems.length; i++) { 
      if((navItems[i].className == "menuvertical") || (navItems[i].className == "submenu")) 
      { 
         if(navItems[i].getElementsByTagName('ul')[0] != null) 
         { 
            navItems[i].onmouseover=function() {this.getElementsByTagName('ul')[0].style.display="block";this.style.backgroundColor = "#f9f9f9";} 
            navItems[i].onmouseout=function() {this.getElementsByTagName('ul')[0].style.display="none";this.style.backgroundColor = "#FFFFFF";} 
         } 
      } 
   } 
} 
