    // Não permite inputs com letras
    function formatInput(evt)
    {
        evt = (evt) ? evt : window.event
        var charCode = (evt.which) ? evt.which : evt.keyCode
        if (charCode>31 && (charCode<48 || charCode>57))
        {
            status = "Este campo aceita apenas números."; 
            return false;
        }
        status = "";
    }

    // Desmarca a quantidade escolhida de uma variação, se o checkbox relacionado for desmarcado
    /*
     *  Define o valor do combobox de quantidade para '0', ao se desmarcar o checkbox de
     *  quantidade dos itens (variação, produtos, etc.);
     */
    function limpaSelectOption(campoCheck, campoCombo)
    {
        if (!document.getElementById(campoCheck).checked) {
            obj = document.getElementById(campoCombo);
            obj.selectedIndex = 0;
        }
    }
    
    
    // Marca o checkbox ao se selecionar uma quantidade de variação maior que zero
    function marcaProd(campoCheck, campoCombo)
    {
        obj = document.getElementById(campoCombo);
        
        if ( obj.options[obj.selectedIndex].value == '0' ){
            document.getElementById(campoCheck).checked = false;
        } else        
            document.getElementById(campoCheck).checked = true;
    }
    
    //Desabilita um campo via JavaScript
    function disableField(campo)
    {
        document.getElementById(campo).disabled = 'disabled';
    }
    
    
    function validaData (strData)
    {
        //testa valor da data digitada dd/mm/aaaa
        
        if (strData == '') {
            return false;
        }
        
        strValue = strData;
        
        //retirado de http://www.rgagnon.com/jsdetails/js-0063.html
        var strSeparator = strValue.substring(2,3) 
        var arrayDate = strValue.split(strSeparator); 
        //create a lookup for months not equal to Feb.
        var arrayLookup = { '01' : 31,'03' : 31, 
                           '04' : 30,'05' : 31,
                           '06' : 30,'07' : 31,
                           '08' : 31,'09' : 30,
                           '10' : 31,'11' : 30,'12' : 31}
        var intDay = parseInt(arrayDate[0],10); 

        //check if month value and day value agree
        if(arrayLookup[arrayDate[1]] != null) {
          if(intDay <= arrayLookup[arrayDate[1]] && intDay != 0)
            return true; //found in lookup table, good date
        }

        //check for February (bugfix 20050322)
        //bugfix  for parseInt kevin
        //bugfix  biss year  O.Jp Voutat
        var intMonth = parseInt(arrayDate[1],10);
        if (intMonth == 2) { 
           var intYear = parseInt(arrayDate[2]);
           if (intDay > 0 && intDay < 29) {
               return true;
           }
           else if (intDay == 29) {
             if ((intYear % 4 == 0) && (intYear % 100 != 0) || 
                 (intYear % 400 == 0)) {
                  // year div by 4 and ((not div by 100) or div by 400) ->ok
                 return true;
             }   
           }
        }
    }
    
    
    //Calendário
    var oldLink = null;
    // code to change the active stylesheet
    function setActiveStyleSheet(link, title) {
        var i, a, main;
        
        for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
            if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
                a.disabled = true;
                if(a.getAttribute("title") == title) a.disabled = false;
            }
        }
        
        if (oldLink) oldLink.style.fontWeight = 'normal';
        
        oldLink = link;
        link.style.fontWeight = 'bold';
        
        return false;
    }

    function selected(cal, date) {
        cal.sel.value = date; // just update the date in the input field.
        
        if (cal.sel.id == "sel1" || cal.sel.id == "sel3")
            cal.callCloseHandler();
    }

    function closeHandler(cal) {
        cal.hide();                        // hide the calendar
    }

    function showCalendar(id, format) {
        var el = document.getElementById(id);
        
        if (calendar != null) {
            calendar.hide();                 // so we hide it first.
        } else {
            var cal = new Calendar(false, null, selected, closeHandler);
            cal.weekNumbers = false;
            calendar = cal;                  // remember it in the global var
            cal.setRange(1900, 2070);        // min/max year allowed.
            cal.create();
        }
        
        calendar.setDateFormat(format);    // set the specified date format
        calendar.parseDate(el.value);      // try to parse the text in field
        calendar.sel = el;                 // inform it what input field we use
        calendar.showAtElement(el);        // show the calendar below it
        
        return false;
    }

    var MINUTE = 60 * 1000;
    var HOUR = 60 * MINUTE;
    var DAY = 24 * HOUR;
    var WEEK = 7 * DAY;

    function isDisabled(date) {
        var today = new Date();
        
        return (Math.abs(date.getTime() - today.getTime()) / DAY) > 10;
    }

    function flatSelected(cal, date) {
        var el = document.getElementById("preview");
        
        el.innerHTML = date;
    }

    function showFlatCalendar() {
    
        var parent = document.getElementById("display");
        var cal = new Calendar(false, null, flatSelected);
        
        cal.weekNumbers = false;
        cal.setDisabledHandler(isDisabled);
        cal.setDateFormat("DD, M d");
        cal.create(parent);
        cal.show();
    }

    // Fim de Calendário