//MÁSCARA DE VALORES

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;
    }
  }
// Data:<input type="text" size="20" onkeypress="return txtBoxFormat(this, '99/99/9999', event);">
// RG:<input type="text" size="20" onkeypress="return txtBoxFormat(this, '99.999.999-9', event);">
// Telefone:<input type="text" size="20" onkeypress="return txtBoxFormat(this, '(99)9999-9999', event);">
// Código:<input type="text" size="20" onkeypress="return txtBoxFormat(this, '99-999', event);">

function confirmarDeletar(page,id)
	{
		if(	confirm('Deseja realmente excluir esse registro?') 	)
		{
			window.location = page+'&id='+id+'&acao=d'
		}
	}
	
function confirmaEnviar(id){
	entrada = prompt("Informe para qual conjunto de e-mails deseja enviar", "1");
	//alert('http://www.nutriciusvitae.com.br/adm/newsletter_visualizar.php?id='+id+'&qtd='+entrada+'&acao=e');
	window.location = 'http://www.grannutrille.com.br/adm/newsletter_visualizar.php?id='+id+'&qtd='+entrada+'&acao=e'
}
function confirmarPublicar(page,id,acao)
	{
		msg = 'Deseja realmente alterar o status deste registro para ';
		if (acao == 'p'){
			msg += 'PUBLICADO ?';
		}else{
			if (acao == 'pi'){
				msg += 'PUBLICADO NA HOME ?';
			}else{
				msg += 'NÃO PUBLICADO ?';
			}
		}
		if(	confirm(msg))
		{
			window.location = page+'&id='+id+'&acao='+acao
		}
	}
function confirmarPagamento(page,id,id_compra,acao)
	{
		msg = 'Deseja realmente alterar o status do pagamento deste aluno para ';
		if (acao == 'p'){
			msg += 'PAGO ?';
		}else{
			if (acao == 'pp'){
				msg += 'PAGO PARCELADO ?';
			}
			else{
				if (acao == 'c'){
					msg += 'CORTESIA ?';
				}
				else{
					msg += 'NÃO PAGO ?';
				}
			}
		}
		if(	confirm(msg))
		{
			window.location = page+'&idcom='+id_compra+'&id='+id+'&acao='+acao
		}
	}
function exibirLog(usuario,data)
	{
		hora = data.substring(10);
		dia = data.substring(8,10);
		mes = data.substring(5,7);
		ano = data.substring(0,4);
		 
		msg = "";
		msg += "Log de alterações \n";
		msg += "Data última alteração: " +dia+ "/" +mes+ "/" +ano+ " "+hora;
		msg += "\nUsuário responsável: " +usuario;
		alert(msg);
	}
