﻿//===============================================
function xmlhttpPostBot() 
{
	var strURL     = 'pageConsultaRapida.aspx';
	var xmlHttpReq = false;

   // Mozilla/Safari
    if (window.XMLHttpRequest) 
	{
        xmlHttpReq = new XMLHttpRequest();
	 if (xmlHttpReq.overrideMimeType) {
	       xmlHttpReq.overrideMimeType('text/xml');
		}
    }	
   // IE			
    else if (window.ActiveXObject) 

	try {
	    xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e) {
	try {
		 xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {}
	}

    xmlHttpReq.open('POST', strURL, true);
    xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   	xmlHttpReq.onreadystatechange = function() {
    if (xmlHttpReq.readyState == 4) 
	{
        updatepage(xmlHttpReq.responseText);
    }
	}
    xmlHttpReq.send(getquerystring());
}
function xmlhttpPost() 
{    
 	if(event.keyCode==13)
	{  	   
		var strURL     = 'pageConsultaRapida.aspx';
    	var xmlHttpReq = false;

    // Mozilla/Safari
		if (window.XMLHttpRequest) 
		{
	        xmlHttpReq = new XMLHttpRequest();
		 if (xmlHttpReq.overrideMimeType) {
    	       xmlHttpReq.overrideMimeType('text/xml');
			}
	    }
    // IE
	    else if (window.ActiveXObject) 

		try {
		   xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		try {
			xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
		}

	    xmlHttpReq.open('POST', strURL, true);
	    xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	   	xmlHttpReq.onreadystatechange = function() {				
          if(xmlHttpReq.readyState == 4) 
		  {
            updatepage(xmlHttpReq.responseText);              
	      }
    	}
	    xmlHttpReq.send(getquerystring());	
	    return false;	
	}
}

function getquerystring() 
{
    var nomeProduto = document.getElementById("txtBusca").value;
    qstr = 'nomeProduto='+escape(nomeProduto);  // NOTE: no '?' before querystring
    return qstr;
}

function updatepage(str)
{
	if(str.length > 0)
	{
		var strURL     = 'pageConsultaRapida.aspx';
		//var form        = document.forms['form1'];
	    var nomeProduto = document.getElementById('txtBusca').value;
	
		if(nomeProduto.length > 2)
	    {
			document.getElementById("busca").style.display  =  '';
			document.getElementById("busca").style.visibility  = 'visible';					
		    document.getElementById("buscaI").src = strURL + '?nomeProduto='+escape(nomeProduto);   
		}
		else
		{
		    //alert("É necessário no mínimo 3 letras para efetuar a busca!!!");
			document.getElementById("busca").style.display     =  'none';
			document.getElementById("busca").style.visibility  = 'hidden';	
			return false;				
		}
	}			
}
function fecharConsulta(param)
{
  document.getElementById("busca").style.display     =  'none';
  document.getElementById("busca").style.visibility  = 'hidden';	
  viewPage(param);
}
function tituloDefaultIFrame(titulo,obj,oFrame)
{    	
    str = '<table cellpadding="2" cellspacing="0" width="100%" height="5">' + 
	      '<tr><td height="5" class="fn11BrancaBold" background="imagens/fundo_menu_01.jpg">&nbsp;&nbsp;<b>&raquo;</b>&nbsp;'+titulo+'</td>' +
	      '<td height="5" class="fn10" width="12">' +
	      '<a style="cursor:hand;" onclick="document.all.'+oFrame+'.src=\'\'; document.all.'+obj+'.style.display=\'none\'; document.all.'+obj+'.style.visibility=\'hidden\';">' + 
	      '<img src="images/fecahr.jpg" border="0"></a></td></tr></table>';
    document.write(str);
}
function muda()
{		    
	parent.document.getElementById("auto").style.display = parent.document.getElementById("auto").style.display=='none'?'':'none';
	parent.document.getElementById("fixa").style.display = parent.document.getElementById("fixa").style.display=='none'?'':'none';	
}
//===============================================

  function OnEnter(evt)
  {
    var key_code = evt.keyCode  ? evt.keyCode  :
                       evt.charCode ? evt.charCode :
                       evt.which    ? evt.which    : void 0;


    if (key_code == 13)
    {
        return true;
    }
  }  
  function submitBuscatext(e)
  {
    if(OnEnter(e))
    {
        if(document.getElementById('txtBusca') && document.getElementById('_inc_topo_cboBusca'))
        {
            
           var selectBox = document.getElementById('_inc_topo_cboBusca');
           var value = selectBox.options[selectBox.selectedIndex].value;           
           this.location.href = 'Buscar.aspx?busca=' + document.getElementById('txtBusca').value + "&grupo=" + value;
           return true;
        }
    }
  }
  function submitBusca()
  {
        if(document.getElementById('txtBusca') && document.getElementById('_inc_topo_cboBusca'))
        {
            
           var selectBox = document.getElementById('_inc_topo_cboBusca');
           var value = selectBox.options[selectBox.selectedIndex].value
           
            alert("entrou " + document.getElementById('txtBusca').value + "&grupo=" + value );
           this.location.href = 'Buscar.aspx?busca=' + document.getElementById('txtBusca').value + "&grupo=" + value;
        }    
  }
  function objMN(id)
  {
   
   var arg = document.getElementById('hdMenu');
   
   if(arg)
   { 
        var i = 0;
        var result = arg.value.split('|');
        for (i=0; i< result.length;i++) 
        {
          if(document.getElementById("sc_" + result[i]))
            document.getElementById("sc_" + result[i]).style.display = 'none';
        } 

        document.getElementById("sc_" + id).style.display = 'block';
    }
  }  
  function splash(page,nome,largura,altura) {
    settings='width='+largura+',height='+altura+',scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
    janela=window.open(page,nome,settings);
  } 
  function keyNum() {
    if (event.keyCode < 45 || event.keyCode > 57) {
	  event.returnValue = false;
	}
  }
  
  function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
        var sep = 0;
        var key = '';
        var i = j = 0;
        var len = len2 = 0;
        var strCheck = '0123456789';
        var aux = aux2 = '';
        var whichCode = (window.Event) ? e.which : e.keyCode;
        if (whichCode == 13) return true;
        key = String.fromCharCode(whichCode); // Valor para o código da Chave
        if (strCheck.indexOf(key) == -1) return false; // Chave inválida
        len = objTextBox.value.length;
        for(i = 0; i < len; i++)
            if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
        aux = '';
        for(; i < len; i++)
            if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
        aux += key;
        len = aux.length;
        if (len == 0) objTextBox.value = '';
        if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
        if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
        if (len > 2) {
            aux2 = '';
            for (j = 0, i = len - 3; i >= 0; i--) {
                if (j == 3) {
                    aux2 += SeparadorMilesimo;
                    j = 0;
                }
                aux2 += aux.charAt(i);
                j++;
            }
            objTextBox.value = '';
            len2 = aux2.length;
            for (i = len2 - 1; i >= 0; i--)
            objTextBox.value += aux2.charAt(i);
            objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
        }
        return false;
    }

  // verifica CPF
  function checaCPF(CPF) {
    if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" || 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;
  }
   
  
  function formatar(src, mask) 
  {
      var i = src.value.length;
      var saida = mask.substring(0,1);
      var texto = mask.substring(i)
    if (texto.substring(0,1) != saida) 
    {
        src.value += texto.substring(0,1);
    }
  }
  
  //=============== VALIDA 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); 
 } 
} 

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); 
 } 

function VerifyCNPJ(CNPJ) 
 { 
  CNPJ = LIMP(CNPJ); 
  if(isNUMB(CNPJ) != 1) 
  { 
    return(0); 
  } 
  else 
  { 
  if(CNPJ == 0) 
   { 
   return(0); 
   } 
  else 
   { 
   g=CNPJ.length-2; 
   if(RealTestaCNPJ(CNPJ,g) == 1) 
    { 
    g=CNPJ.length-1; 
    if(RealTestaCNPJ(CNPJ,g) == 1) 
     { 
     return(1); 
     } 
    else 
     { 
     return(0); 
     } 
    } 
   else 
    { 
    return(0); 
    } 
   } 
  } 
 } 
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(0); 
   } 
   else 
   { 
    return(1); 
   } 
 }   
  function FormataCGC(Formulario, Campo, TeclaPres) 
  { 
    var tecla = TeclaPres.keyCode; 
    var strCampo; 
    var vr; 
    var tam; 
    var TamanhoMaximo = 14; 
  
    eval("strCampo = document." + Formulario + "." + Campo); 
  
    vr = strCampo.value; 
    vr = vr.replace("/", ""); 
    vr = vr.replace("/", ""); 
    vr = vr.replace("/", ""); 
    vr = vr.replace(",", ""); 
    vr = vr.replace(".", ""); 
    vr = vr.replace(".", ""); 
    vr = vr.replace(".", ""); 
    vr = vr.replace(".", ""); 
    vr = vr.replace(".", ""); 
    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 < TamanhoMaximo && 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) 
      { 
        strCampo.value = vr; 
      } 
       if ((tam > 2) && (tam <= 6)) 
       { 
         strCampo.value = vr.substr(0, tam - 2) + '-' + vr.substr(tam - 2, tam); 
       } 
       if ((tam >= 7) && (tam <= 9)) 
       { 
         strCampo.value = vr.substr(0, tam - 6) + '/' + vr.substr(tam - 6, 4) + '-' + vr.substr(tam - 2, tam); 
      } 
       if ((tam >= 10) && (tam <= 12)) 
       { 
         strCampo.value = vr.substr(0, tam - 9) + '.' + vr.substr(tam - 9, 3) + '/' + vr.substr(tam - 6, 4) + '-' + vr.substr(tam - 2, tam); 
      } 
       if ((tam >= 13) && (tam <= 14)) 
       { 
         strCampo.value = vr.substr(0, tam - 12) + '.' + vr.substr(tam - 12, 3) + '.' + vr.substr(tam - 9, 3) + '/' + vr.substr(tam - 6, 4) + '-' + vr.substr(tam - 2, tam); 
      } 
       if ((tam >= 15) && (tam <= 17)) 
       { 
         strCampo.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); 
      } 
    } 
  } 
