﻿    function ClearTextBox(id, texto)
    {
        var text = document.getElementById(id);
        if(text.value == "")
        {
        text.value = texto;
        }
    }
   
    function ConfirmaExclusao()
    {
        if (confirm("Tem certeza que deseja remover este produto do carrinho?")==true)
            return true;
	    else
		    return false;
	}
	
	function ConfirmaExclusaoEndereco()
    {
        if (confirm("Tem certeza que deseja excluir este endereço?")==true)
            return true;
	    else
		    return false;
	}
	
    function mascaraCep(objeto)
	{
	    if (objeto.value.indexOf("-") == -1 && objeto.value.length > 5)
	    { 
	        objeto.value = ""; 
	    }
	    if (objeto.value.length == 5)
	    {
	        objeto.value += "-";
	    }
	    if (event.keyCode == 8) 
	    {
		    objeto.value = '';
	    }
    }
    
    function SomenteNumeros() 
    {
	    if ( event.keyCode < 48 || event.keyCode > 57 ) //Só aceita caracteres com código ASCII entre 48..57 (números)
	    { 
    		event.returnValue = false;
    	}
    }
    
        function SomenteNumerosSemZero() 
    {
	    if ( event.keyCode < 48 || event.keyCode > 57 ) //Só aceita caracteres com código ASCII entre 48..57 (números)
	    { 
    		event.returnValue = false;
    	}
    }
    
    function input_filterAmt (str, dec, bNeg) 
    { // auto-correct input - force numeric data based on params. 
         var cDec = '.'; // decimal point symbol 
         var bDec = false; var val = ""; 
         var strf = ""; var neg = ""; var i = 0; 

         if (str == "") return; 
         parseFloat ("0").toFixed (dec); 
         if (bNeg && str.charAt (i) == '-') { neg = '-'; i++; } 

         for (i; i < str.length; i++) 
         { 
          val = str.charAt (i); 
          if (val == cDec) 
          { 
           if (!bDec) { strf += val; bDec = true; } 
          } 
          else if (val >= '0' && val <= '9') 
           strf += val; 
         } 
         strf = (strf == "" ? 0 : neg + strf); 
         valor = parseFloat (strf).toFixed (dec); 
         if (valor == "0")
         {
            alert('Quantidade inválida.');
            return 1;
         }
         else
         {
            return valor;
         }
    } 


    
    function mascara_cpf(campo) 
    { 
	    tam_cpf = 0;
	    if (tam_cpf < campo.value.length)
	    {
		    if (campo.value.length == 3) 
		    { 
			    campo.value = campo.value + '.';
		    } 
		    if (campo.value.length == 7) 
		    { 
			    campo.value = campo.value + '.'; 
		    } 
		    if (campo.value.length == 11) 
		    { 
		    campo.value = campo.value + '-'; 
		    } 
	    } 
	    tam_cpf = campo.value.length;
	    if (event.keyCode == 8) 
	    {
	    	campo.value = '';
	    }
    }
    
    function mascaraTel(objeto)
    {
	    if (objeto.value.indexOf("-") == -1 && objeto.value.length > 4){ objeto.value = ""; }
	    if (objeto.value.length == 4){objeto.value += "-";}
	    if (event.keyCode == 8) 
	    {
		    objeto.value = '';
	    }
    }

    function MascaraData(fld)
    {
	    if (fld.value.length == 2){fld.value = fld.value + '/';}
	    if (fld.value.length == 5){fld.value = fld.value + '/';}
	    if (fld.value.length > 10){fld.value = fld.value.substring(0,9);}
	    if (event.keyCode == 8) 
	    {
		    fld.value = '';
	    }
    }

    function FormataCNPJ(Campo, teclapres)
    {
        var tecla = teclapres.keyCode;
        var vr = new String(Campo.value);
        vr = vr.replace(".", "");
        vr = vr.replace(".", "");
        vr = vr.replace("/", "");
        vr = vr.replace("-", "");
        tam = vr.length + 1 ;
        if (tecla != 9 && tecla != 8)
        {
            if (tam > 2 && tam < 6)
                Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
            if (tam >= 6 && tam < 9)
                Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
            if (tam >= 9 && tam < 13)
                Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
            if (tam >= 13 && tam < 15)
                Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
        }
   	    if (event.keyCode == 8) 
	    {
		    Campo.value = '';
	    }
    }
    
    function AbreIndiqueAmigo(IDProduto, Nome)
    {
        window.open("Indique.aspx?ID=" + IDProduto + "&Nome=" + Nome,"dfd","height=280,width=520,status=no,toolbar=no,menubar=no,location=no");
    }

    function AbrePopUp()
    {
        window.open("popup.aspx","dfd","height=280,width=520,status=no,toolbar=no,menubar=no,location=no");
    }
    
    function txtBoxFormat(objeto, sMask, evtKeyPress) 
{
    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
    if(document.all) 
    { // Internet Explorer
        nTecla = evtKeyPress.keyCode;
    } 
    else if(document.layers) 
    { // Nestcape
    nTecla = evtKeyPress.which;
    } 
    else 
    {
        nTecla = evtKeyPress.which;
        if (nTecla == 8) 
        {
        return true;
        }
    }

    sValue = objeto.value;

    // Limpa todos os caracteres de formatação que
    // já estiverem no campo.
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( " ", "" );
    sValue = sValue.toString().replace( " ", "" );
    fldLen = sValue.length;
    mskLen = sMask.length;

    i = 0;
    nCount = 0;
    sCod = "";
    mskLen = fldLen;

    while (i <= mskLen) 
    {
        bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
        bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

        if (bolMask) 
        {
            sCod += sMask.charAt(i);
            mskLen++; 
        }
        else 
        {
            sCod += sValue.charAt(nCount);
            nCount++;
        }
      i++;
    }

    objeto.value = sCod;

    if (nTecla != 8) 
    { // backspace
        if (sMask.charAt(i-1) == "9") 
        { // apenas números...
            return ((nTecla > 47) && (nTecla < 58)); 
        } 
        else 
        { // qualquer caracter...
            return true;
        } 
    }
    else 
    {
      return true;
    }
 }
