
function barra(objeto){
    if (objeto.value.length == 2 || objeto.value.length == 5 ){
        objeto.value = objeto.value+"/";
    }
}

// Função para formatar a Hora com :
function Formata_Hora(fieldName,keyPressed)
{
    var KeyPress = keyPressed.keyCode;
    vr = document.form[fieldName].value;

    size = vr.length + 1;

    if ( KeyPress != 8 && KeyPress != 9)
    {
        if ( size > 2  &&  size <= 3)
            document.form[fieldName].value = vr.substr( 0, size - 1  ) + ":" + vr.substr( size - 1, size );
    }
}
// Funcao para retirar caracteres especiais em campos de busca
// formName = nome do formulario
// fieldName = nome docampo
function checkQuantidade(formName, fieldName)
{
    // Para aumentar a seguranca, fazer verirficacao tbm no lado servidor
    
    // subistitui diretamente no campo os caracteres especiais por vazio
    // aspas devem ser escapadas sempre
    eval("document."+formName+"."+fieldName+".value = document."+formName+"."+fieldName+".value.replace(/[%$\"\'*#]/g,'')");
    eval("document."+formName+"."+fieldName+".value = document."+formName+"."+fieldName+".value.replace(/\s{2,}/g,' ')");
        
    //testa se o campo foi preenchido com mais de 5 caracteres
    //como substituiu os caracteres especiais por vazio acima, aqui o teste eh feito somente no
    //que sobrou ex. usuario digitou ab%, o teste eh feito em ab.
    if(eval("document."+formName+"."+fieldName+".value.length") < 5)
    {
        alert('Você deve digitar ao menos 5 letras na palavra-chave');
        return false;
    }

    return true;
}

/*
Esconde ou mostra um Div ou outra TAG que tenha ID=****_div
divIDName = Lista de nome dos ID, nao pode ter espacos e separado por virgula
hide = true-esconde false=mostra
*/
function hideDiv(divIDName, hide)
{
    _divID = divIDName.split(",");
    for(i=0 ; i < _divID.length; i++)
    {
        var div = document.getElementById(_divID[i] + "_div");     // W3C DOM level 2
        if (hide == true)
        {
            div.style.display = "none";
            continue;
        }
        else
        {
            div.style.display = "";
        }
    //window.location.hash = _divID[i];
    }
}
/*
	Limita o numero máximo de caracteres a ser digitado em um Campo TEXTAREA
	show_text_len = eh para mostrar o valor num campo text
	Para Usar: onKeyUp="textAreaLimit('form1','mensagem','125')"
*/
function textAreaLimit(form_name,campo,maxlimit,show_text_len) { // v0.1
    if (eval("document." +form_name+ "." +campo+ ".value.length") >= maxlimit) {
        alert ("O Limite de Caracteres Foi Excedido: Permitido=" + maxlimit);
    }
    if (eval("document." +form_name+ "." +campo+ ".value.length") > maxlimit)
        eval("document." +form_name+ "." +campo+ ".value = document." +form_name+"." +campo+ ".value.substring(0, " +maxlimit+ ");");
    else
        status = eval("document." +form_name+ "." +campo+ ".value.length;") + " de " + maxlimit;

    // Insira um campo chamado <input type="text" name="len">
    if (show_text_len) {
        eval("document."+ form_name + ".len.value = document." + form_name + "." +campo+ ".value.length;");
    }
}


/*
Check all checkbox
	formName	= Form Name
	boxName		= Name of input type=checkbox
Usage:
	Put :
	<input type="checkbox" name="sellall" onClick="CheckAll('formName','boxName')">
*/

function CheckAll(formName,boxName) { //v0.2
    
    if (!boxName) boxName = "selall";
    if (!formName) formName = "form";

    for (var i=0 ; i < eval("document." + formName + ".elements.length") ; i++)
    {
        var x = eval("document." + formName + ".elements["+ i + "]");
        status=x.name;
        if (x.name != boxName)
            x.checked = eval("document."+ formName + "." + boxName + ".checked");
    }
}

/*
Check all especific checkbox
	formName	= Form Name
	inputName	= Checkbox will be checked
	boxName		= Name of input type=checkbox
Usage:
	Put :
	<input type="checkbox" name="sellall" onClick="CheckAll('formName')">

formName = name of form

*/
function checkBoxEsp(formName,inputName, boxName) { //v0.2
    //dumpObj(obj,inputName);
    //boxName = formName.name;

    for (var i=0 ; i < eval("document." + formName + ".elements.length") ; i++)
    {
        var x = eval("document." + formName + ".elements["+ i + "]");
        status=x.name;

        if (x.name != boxName && x.name == inputName)
            x.checked = eval("document."+ formName + "." + boxName + ".checked");
    }
}

/*
	Setar Valor em um FORM>SELECT
	Modo de usar:
	setSelectValue(formName, formField, value2sel)
		formName = Nome do Formulario
		formField = Nome do Campo
		value2sel = Valor selecionado, pode ser multiplos quando form for multiple
			'PR|SC|SP'
		targ = Alvo (parent ...)
	ex.: setSelectValue('formulario','uf','PR|SC')

	obs.: Se o "<select" nao tiver multiple, e quando o valor
	value2sel = "A|B|C" ou multiplos, será marcado apenas o ultimo valor
*/
function setSelectValue(formName, formField, value2sel, targ) // 17.07.2003
{
    if(targ) targ = targ + "."
    if('' == value2sel) return;

    objSelect = eval(targ + "document." + formName + "." + formField);
    if(!value2sel) return;
    _values = value2sel.split("|");

    for (var i=0; i < objSelect.options.length; i++)
    {
        objSelect.options[i].selected = false; // Limpa campos
        // Setar os valores
        for(j=0; j < _values.length; j++)
        {
            if (objSelect[i].value == _values[j]) objSelect.options[i].selected = true;
        }
    }
}

/*
	Pega o(s) valores de um FORM > SELECT
*/
function getSelectValue(formName,formField) // 17.07.2003
{
    obj = eval("document." + formName + "." + formField);
    if(obj.selectedIndex == -1) {
        return false
    };
    return obj.options[obj.selectedIndex].value;
}
/*
	Retorna o texto Selecionado ou o TEXTO textSel de um FORM > SELECT 
*/
function getSelectText(formName,formField,textSel) // 17.07.2003
{
    obj = eval("document." + formName + "." + formField);
    if(textSel)
    {
        for(i=0; i < obj.length; i++){
            return obj[i].text;
        }
    }
    if(obj.selectedIndex == -1) {
        return false
    };
    return obj.options[obj.selectedIndex].text;
}

/*
	Pega TODOS os valores Selecionado ou NAO selecionados(all_v=(text|value))
	de um select e retorna uma lista
*/
function getSelectArray(formName, fieldName, sep, all_v)
{
    if(!sep) sep="|"
    objSel = eval("document." + formName + "." + fieldName);
    s="";
    for(i=0 ; i < objSel.length; i++)
    {
        if (all_v)
        {
            if(i > 0) s += sep;
            if(all_v == "text") s += objSel[i].text;
            else s += objSel[i].value;
        }
        else
        {
            if(objSel[i].selected == true)
            {
                if(i > 0) if(s) s += sep;
                s += objSel[i].value;
            }
        }
    }
    return s;
}

/*
	Verifica se existe algum valor no select
	retorna true se encontrar
*/
function HaveInFormSelect(formName,formField,v) // 17.07.2003
{
    obj = eval("document." + formName + "." + formField);
    for(i=0; i < obj.length; i++)
    {
        if(obj[i].value == v) return true;
    }
    return false;
}

/*
	Setar valor em um FORM > INPUT RADIO
	setRadioValue(formName, formField, value2sel)
		formName = Nome do formulario
		formField = Nome do campo
		value2sel = valor para selecionar
*/

function setRadioValue(formName, formField, value2sel) // 01.07.2003
{
    if('' == value2sel) return;
    objRadio = eval("document." + formName + "." + formField);
    for(i=0; i < objRadio.length; i++)
    {
        if(objRadio[i].value == value2sel)
        {
            objRadio[i].checked = true;
        }
    }
}


/*
	Pega o valor de um FORM >INPUT RADIO
*/
function getRadioValue(formName,formField) // 01.07.2003
{
    objRadio = eval("document." + formName + "." + formField);
    for(i=0; i < objRadio.length; i++)
    {
        if(objRadio[i].checked == true)
        {
            return objRadio[i].value;
        }
    }
    return true;
}

/*
	Setar valor para um FORM > INPUT CHECKBOX
	setCheckboxValue(formName,formField,value2sel)
		formName = Nome do formulario
		formField = Nome do Campo
		value2sel = Valor(es) para ser(em) setados
			ex.: 'mae|pai|avó' ou 'mae'

	Use: setCheckboxValue('formulario','cbox','mae|pai|avó')
*/
function setCheckboxValue(formName,formField,value2sel) // 08.07.03
{
    if('' == value2sel) return;

    objCheckbox = eval("document.all['"+ formField +"']");
    _values = value2sel.split("|");
    // Se houver 1 checkbox
    if(objCheckbox.length == undefined && objCheckbox.value == value2sel)
    {
        objCheckbox.checked = true;
    }

    for(i=0; i < objCheckbox.length ; i++)
    {
        objCheckbox[i].checked = false; // Limpando todos
        for(j=0; j < _values.length; j++)
        {
            if (objCheckbox[i].value == _values[j])
            {
                objCheckbox[i].checked = true;
            }
        }
    }
}



/*
	Construidor de FORM > SELECT a partir de um array do typo
	array (["1","X"],["2","Y"])
	makeSelect(_array,formName, formField)
	parent

	obs.: esta funcao deve ser chamada apos o objeto form, ou seja,
	depois do form>select que esta criando.
*/
function makeSelect(_array, formName, formField, pai) // 02.07.2003
{
    objSel = eval((pai ? pai + "." : "") + "document." + formName + "." + formField);
    objSel.options.length = 0;
    for (k in _array)
    {
        objSel.options[objSel.options.length] = new Option(_array[k],k);
    }
}

/*
	Constroi um array assoc
	lista = "PR|Parana,SC|Santa Catarina" ou "PR|SC|AC.."
	sepOption = Separador de Array/Options ex.: /
	sepValue = Separador de valores ex.: ||
*/
function makeAssocArray(lista,sepOption,sepValue) // 18.07.2003
{
    if(!sepOption) sepOption = ",";
    if(!sepValue) sepValue = "|";
    _a = new Array();
    if(!lista) {
        _a[""]="" ;
        return _a;
    }
    lista = lista.split(sepOption);
    for(k=0; k < lista.length; k++)
    {
        kv = lista[k].split(sepValue);
        if(!kv[1]) _a[kv[0]] = kv[0];
        else _a[kv[0]] = kv[1];
    }
    return _a;
}

/*
	Cria um array associativo de um FORM > SELECT
*/
function makeAssocArraySelect(formName,formField)
{
    _s = new Array();
    obj = eval("document." + formName + "." + formField);
    for(i=0; i < obj.length; i++){
        _s[obj[i].value] = obj[i].text;
    }
    return _s;
}

/*
	habilita e dasabilita campos do formulario.
	formName = Nome do formulario
	fieldName = Nome do campo
	targ = Alvo (parent ...)
	flag = (true|false) habilita,desabilita) padrao=false
*/
function DisEnable(formName,fieldName,flag,targ) // 15.07.2003
{
    flag = flag ? true : false;
    if(targ) targ = targ + ".";
    else targ="";
    obj = eval(targ + "document." + formName + "." + fieldName);
    obj.disabled = flag;
}

/* Carrega link dentro do iframe */
function iframeSrc(iframeName,src) {
    document.getElementById(iframeName).src = src;
}
/* Escreve um iframe sem SRC H=0 W=0 B=0 M=0 FB=0*/
function writeIframe(nome,W,H,FB){
    if(!W) W=0;
    if(!H) L=0;
    if(!FB) FB=0;
    document.write('<iframe id="' +nome+ '" name="'+nome+'" src="" height="'+H+'" width="'+W+'" marginwidth="0" marginheight="0" frameborder="'+FB+'" border="' +FB+ '"> </iframe>');
    return nome;
}

/*

PS: form name should be "form"

Date Format in Brazilian
Usage into tag INPUT TEXT:
onKeyDown=DateFormatBr("fieldName_name",event)
*/
function DateFormatBr(fieldName,keyPressed) { // v0.1
    var KeyPress = keyPressed.keyCode;
    vr = document.form[fieldName].value;
    vr = vr.replace( ".", "" );
    vr = vr.replace( "/", "" );
    vr = vr.replace( "/", "" );
    size = vr.length + 1;

    if ( KeyPress != 9 && KeyPress != 8 ){
        if ( size > 2 && size < 5 )
            document.form[fieldName].value = vr.substr( 0, size - 2  ) + '/' + vr.substr( size - 2, size );
        if ( size >= 5 && size <= 10 )
            document.form[fieldName].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 );
    }
}

/*
Formata data no padrao Brasil (ex.: 30/12/2003)
onKeyDown=DateFormatBr_v2('formulario','fieldName_name',event)
*/
function DateFormatBr_v2(formName, fieldName, keyPressed) { // 08.07.2003
    var KeyPress = keyPressed.keyCode;
    objDate = eval("document." + formName + "." + fieldName);
    vr = objDate.value
    vr = vr.replace( ".", "" );
    vr = vr.replace( "/", "" );
    vr = vr.replace( "/", "" );
    size = vr.length + 1;

    if ( KeyPress != 9 && KeyPress != 8 ){
        if ( size > 2 && size < 5 )
            objDate.value = vr.substr( 0, size - 2  ) + '/' + vr.substr( size - 2, size );
        if ( size >= 5 && size <= 10 )
            objDate.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 );
    }
}




/*
PS: form name should be "form"

Description:	Value Format type Money in Brazilian

Usage on tag INPUT TEXT AND TEXTAREA
onKeyDown=ValueFormatBr("fieldName",<MaxSize>,event)
 - MaxSize can be a value of 0 until 17

*/

function ValueFormatBr(fieldName,maxSize,keyPressed) { //v0.1
    var tecla = keyPressed.keyCode;
    vr = document.form[fieldName].value;
    vr = vr.replace( "/", "" );
    vr = vr.replace( "/", "" );
    vr = vr.replace( ",", "" );
    vr = vr.replace( ".", "" );
    vr = vr.replace( ".", "" );
    vr = vr.replace( ".", "" );
    vr = vr.replace( ".", "" );
    size = vr.length;
    if (size < maxSize && tecla != 8){
        size = vr.length + 1 ;
    }

    if (tecla == 8 ){
        size = size - 1 ;
    }

    if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
        count = 0;
        if ( size <= 2 ){
            count=0;
            document.form[fieldName].value = vr ;
        }
        if ( (size > 2) && (size <= 5) ){
            count=1;
            document.form[fieldName].value = vr.substr( 0, size - 2 ) + ',' + vr.substr( size - 2, size ) ;
        }
        if ( (size >= 6) && (size <= 8) ){
            count=2;
            document.form[fieldName].value = vr.substr( 0, size - 5 ) + '.' + vr.substr( size - 5, 3 ) + ',' + vr.substr( size - 2, size ) ;
        }
        if ( (size >= 9) && (size <= 11) ){
            count=3;
            document.form[fieldName].value = vr.substr( 0, size - 8 ) + '.' + vr.substr( size - 8, 3 ) + '.' + vr.substr( size - 5, 3 ) + ',' + vr.substr( size - 2, size ) ;
        }
        if ( (size >= 12) && (size <= 14) ){
            count=4;
            document.form[fieldName].value = vr.substr( 0, size - 11 ) + '.' + vr.substr( size - 11, 3 ) + '.' + vr.substr( size - 8, 3 ) + '.' + vr.substr( size - 5, 3 ) + ',' + vr.substr( size - 2, size ) ;
        }
        if ( (size >= 15) && (size <= 17) ){
            count=5;
            document.form[fieldName].value = vr.substr( 0, size - 14 ) + '.' + vr.substr( size - 14, 3 ) + '.' + vr.substr( size - 11, 3 ) + '.' + vr.substr( size - 8, 3 ) + '.' + vr.substr( size - 5, 3 ) + ',' + vr.substr( size - 2, size ) ;
        }
    }
    status = size;
    if (size >= maxSize)
    {
        document.form[fieldName].value = document.form[fieldName].value.substring(0, maxSize+count - 1);
    }
}



/*
	jumpMenu()

	Usage:<select>
		<option value="URL">Valor
	</select>
*/

function jumpMenu(targ,selObj,restore){ // v0.1
    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
}


/*
	Abre janelas popup.

*/
function openWindow(theURL,winName,features) { //v2.0
    if(!features)
    {
        features="width=350,height=350,status=yes,scrollbars=1";
    }
    window.open(theURL,winName,features);
}


/*
	dumpObj objects and contents
	Use: dumpObj(this,NomeDoCampo)
*/
function dumpObj (obj, str) { // v0.1
    var s = new Array ();
    var i;
    var j = 0;
    for (i in obj) {   // get all objects, and contents
        s[j] = i + ": " + obj[i];
        j = j + 1;
    }
    s.sort ();         // sort them data down
    document.open ("text/html");  // open a new document
    document.write ("<html><head>");  //  with full XHTML style
    document.write ("<title>Dump page</title>");
    document.write ("</head><body>");
    document.write ("<p><b>");  // make it kosher
    document.write (str, " contents.<br />");
    document.write (navigator.appName, "<br />");
    document.write (navigator.userAgent, "</b><br /><br />");
    for (i=0; i<j; i++) {
        document.write (s[i], "<br />");
    }
    document.write ("</p>");
    document.write ("</body></html>");
    document.close ();  // close down output stream
}



/*
Mostra mensagem, quando for escolhido mais de (n QUANTIDADE} na caixa de selecao (multiple)

	Obj 	- Use (this)
	nome	- Nome do Campo
	quantidade - Numero máximo de selecoes pode ter
Use: onBlur="escolha_n(this, NomeDoCampo, 3)"
*/

function escolha_n(Obj, nome, quantidade) { // v0.1

    var i = 0;
    var x;
    total = Obj.length;
    if (!quantidade) quantidade=3;
    count=0;
    for (i=0; i < total ;i++)
    {
        x = Obj[i] //.options[i];
        if (x.type == "select-multiple" && x.name == nome)
        {
            for(j=0; j < x.length; j++)
            {
                if (x[j].selected == true) count = count + 1
            }
        }
    }
    if (count > quantidade)
    {
        alert("Você só pode selecionar no máximo " + quantidade)

        // Dermarcar todos
        for (i=0; i < total ;i++)
        {
            x = Obj[i] //.options[i];
            if (x.type == "select-multiple" && x.name == nome)
            {
                for(j=0; j < x.length; j++)
                {
                    x[j].selected = false;
                }
            }
        }
    }
//Obj.nome.focus();

}
function email(action)
{
    document.boletim.action.value=action;
    document.boletim.submit();
		
}

function limitinput(evt, strList, bAllow)
/*Limits the input to strList. If bAllow is true, then
only allow what is in strList. If bAllow is false,
then do not allow what is in strList.*/
{
    var charCode = evt.keyCode;
    if (charCode==0)
    {
        charCode = evt.which;
    }
    var strChar = String.fromCharCode(charCode);
    /*controlArray holds the ASCII codes for valid
	control commands (BS, CR, LF, etc)*/
    var controlArray = Array(0, 8, 9, 10, 13, 27);
    var intOut = 0;
    if (bAllow==true)
    {
        if (charCode==8 || charCode==9 || charCode==37 || charCode==39 || charCode==46 || charCode==116 || (strList.indexOf(strChar)!=-1))
        /*Valid*/
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        if (charCode==8 || charCode==9 || charCode==37 || charCode==39 || charCode==46 || charCode==116 || (strList.indexOf(strChar)==-1))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}


//Funcao Data
var days = new Array(7)
days[1] = "Domingo";
days[2] = "Segunda";
days[3] = "Ter&ccedil;a"; 
days[4] = "Quarta";
days[5] = "Quinta";
days[6] = "Sexta";
days[7] = "S&aacute;bado";
var months = new Array(12)
months[1] = "Janeiro";
months[2] = "Fevereiro";
months[3] = "Mar&ccedil;o";
months[4] = "Abril";
months[5] = "Maio";
months[6] = "Junho";
months[7] = "Julho";
months[8] = "Agosto";
months[9] = "Setembro";
months[10] = "Outubro"; 
months[11] = "Novembro";
months[12] = "Dezembro";
var today = new Date();
var day = days[today.getDay() + 1]
var month = months[today.getMonth() + 1]
var date = today.getDate()
var year=today.getYear(); 
var hour = checkTime(today.getHours());
var minute = checkTime(today.getMinutes());
if (year < 2000)
    year = year + 1900;

function checkTime(i)
{
    if (i<10)
        i="0" + i;
    return i;
}

function write_date()
{
    document.write (""+ day + ", " + date + " " + month + " de " + year + "")
}

/* função chamada pelo MaskInput */
addEvent = function(o, e, f, s){
    var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
    r[r.length] = [f, s || o], o[e] = function(e){
        try{
            (e = e || event).preventDefault || (e.preventDefault = function(){
                e.returnValue = false;
            });
            e.stopPropagation || (e.stopPropagation = function(){
                e.cancelBubble = true;
            });
            e.target || (e.target = e.srcElement || null);
            e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
        }catch(f){}
        for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
        return e = null, !!d;
    }
};

/* função chamada pelo MaskInput */
removeEvent = function(o, e, f, s){
    for(var i = (e = o["_on" + e] || []).length; i;)
        if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
            return delete e[i];
    return false;
};
MaskInput = function(f, m){ //v1.0
    function mask(e){
        var patterns = {
            "1": /[A-Z]/i,
            "2": /[0-9]/,
            "4": /[À-ÿ]/i,
            "8": /./
        },
        rules = {
            "a": 3,
            "A": 7,
            "9": 2,
            "C":5,
            "c": 1,
            "*": 8
        };
        function accept(c, rule){
            for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
                if(r & i && patterns[i].test(c))
                    break;
            return i <= r || c == rule;
        }
        var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
        (!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
            r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
            : (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
                r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
    }
    for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {
        keypress: 0,
        keyup: 1
    })
        addEvent(f, i, mask);
};
function setSelectValueId(formName, formField, value2sel, targ) // 17.07.2003
{
    if(targ) targ = targ + "."
    if('' == value2sel) return;

    objSelect = eval(targ + "document.getElementById('" + formField + "')");
    if(!value2sel) return;
    _values = value2sel.split("|");

    for (var i=0; i < objSelect.options.length; i++)
    {
        objSelect.options[i].selected = false; // Limpa campos
        // Setar os valores
        for(j=0; j < _values.length; j++)
        {
            if (objSelect[i].value == _values[j]) objSelect.options[i].selected = true;
        }
    }
}

function BG_over(obj, color)
{
    obj.style.backgroundColor = color;
}
function BG_out(obj, color)
{
    obj.style.backgroundColor = color;
}

//Mascara para moeda
function formataMoeda(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;
    
    // 13=enter, 8=backspace as demais retornam 0(zero)
    // whichCode==0 faz com que seja possivel usar todas as teclas como delete, setas, etc    
    if ((whichCode == 13) || (whichCode == 0) || (whichCode == 8))
        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;
}

function roundNumber (rnum) {

    return Math.round(rnum*Math.pow(10,2))/Math.pow(10,2);

}

function float2moeda(num) {

    x = 0;

    if(num<0) {
        num = Math.abs(num);
        x = 1;
    }
    if(isNaN(num)) num = "0";
    cents = Math.floor((num*100+0.5)%100);

    num = Math.floor((num*100+0.5)/100).toString();

    if(cents < 10) cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
        num = num.substring(0,num.length-(4*i+3))+'.'
        +num.substring(num.length-(4*i+3));
    ret = num + ',' + cents;
    if (x == 1) ret = ' - ' + ret;
    return ret;

}

function moeda2float(moeda){

    moeda = moeda.replace(".","");

    moeda = moeda.replace(",",".");

    return parseFloat(moeda);

}


