function escreverDataPorExtenso(){
    var Today = new Date();
    var week, month;
    var y2000 = Today.getFullYear();

    switch (Today.getMonth()) {
    case 0:
    month = "janeiro";
    break;
    case 1:
    month = "fevereiro";
    break;
    case 2:
    month = "março";
    break;
    case 3:
    month = "abril";
    break;
    case 4:
    month = "maio";
    break;
    case 5:
    month = "junho";
    break;
    case 6:
    month = "julho";
    break;
    case 7:
    month = "agosto";
    break;
    case 8:
    month = "setembro";
    break;
    case 9:
    month = "outubro";
    break;
    case 10:
    month = "novembro";
    break;
    case 11:
    month = "dezembro";
    break;
    }
    document.write ("" + Today.getDate() + " de " + month + " de " + Today.getFullYear());
}



//	Funcao Javascript para formatar campo monetario
function formataValor(id,tammax,teclapres) {

    // Internet Explorer
    if(window.event) {
        var tecla = teclapres.keyCode;
    }
    // Nestcape / firefox
    else if(teclapres.which) {
        var tecla = teclapres.which;
    }

    vr = document.getElementById(id).value;
    vr = vr.toString().replace( "/", "" );
    vr = vr.toString().replace( "/", "" );
    vr = vr.toString().replace( ",", "" );
    vr = vr.toString().replace( ".", "" );
    vr = vr.toString().replace( ".", "" );
    vr = vr.toString().replace( ".", "" );
    vr = vr.toString().replace( ".", "" );
    tam = vr.length;
	
    if (tam < tammax && 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 ){
            document.getElementById(id).value = vr;
        }
        if ( (tam > 2) && (tam <= 5) ){
            document.getElementById(id).value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam );
        }
        if ( (tam >= 6) && (tam <= 8) ){
            document.getElementById(id).value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );
        }
        if ( (tam >= 9) && (tam <= 11) ){
            document.getElementById(id).value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );
        }
        if ( (tam >= 12) && (tam <= 14) ){
            document.getElementById(id).value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );
        }
        if ( (tam >= 15) && (tam <= 17) ){
            document.getElementById(id).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 );
        }
    }
}


// Funcao Confirmacao de operacao
function confirmacao(msg) {
    var answer
    if(msg){
        answer = confirm(msg)
    }else{
        answer = confirm("Tem certeza que deseja apagar?")
    }
	
    if (answer){
        return true;
    }
    else{
        return false;
    }
}

// Acha o tamanho da strig e passa para o proximo campo
function proximoCampo(tamanho,id_atual,id_proximo){
    var tam = document.getElementById(id_atual).value.length;
    if (tam == tamanho){
        document.getElementById(id_proximo).focus();
    }
}

function checkbox(id) {

    // Pega todos os campos do formulário
    campos = document.getElementById(id).elements;

    // Verifica se o checkbox "todos" esta checado
    if(document.getElementById(id).todos.checked == true){
        for (x=0; x<campos.length; x++)
            if (campos[x].type == "checkbox") campos[x].checked = true;
    }
    // Se o checkbox "todos" não tiver checado
    else{
        for (x=0; x<campos.length; x++)
            if (campos[x].type == "checkbox") campos[x].checked = false;
    }

}

//////////////////////////////////////////////////
//												//
//			  Desenvolvido por DMTI				//
//												//
//		Função de JUMP MENU com REFRESH na		//
//												//
//				       PAGINA					//
//												//
//////////////////////////////////////////////////

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

//////////////////////////////////////////////////
//												//
//			  Desenvolvido por DMTI				//
//												//
//				Função de POPUP					//
//												//
//////////////////////////////////////////////////

function popup(popup_url,name,Xlargura,Xaltura,Xbarra,bstatus,Xbarramenu,Xdimensao) {
    size = 'status=' + bstatus + ',menubar=' + Xbarramenu + ',resizable=' + Xdimensao + ',width=' + Xlargura + ',height=' + Xaltura + ',scrollbars=' + Xbarra;
    window.open(popup_url,name,'directories=no, location=no, toolbar=no, ' + size);
}

//////////////////////////////////////////////////
//												//
//			  Desenvolvido por DMTI				//
//												//
//				Função de POPUP					//
//												//
//////////////////////////////////////////////////

function fecha(valor){
    this.opener.location="conteudo_editar.php?conteudo="+valor;
    window.setInterval("close();window.opener.focus();",1000);
}

/**
 * Mostra e Esconde
 * 
 * @param id: String contendo a identificação do id das Tags
 * 
 * @version 1.0
 * @author Renato Keiti Sukomine <renato@dmti.com.br>
 * @copyright Copyright (c) 2009 DM Produções Ltda. ME
 */
function trocar(id) {
    var objeto = document.getElementById(id);
    if (objeto.style.display == "block") {
        objeto.style.display = "none";
    } else {
        objeto.style.display = "block";
    }
}

/**
 * Esconde
 *
 * @param id: String contendo a identificação do id das Tags
 *
 * @version 1.0
 * @author Renato Keiti Sukomine <renato@dmti.com.br>
 * @copyright Copyright (c) 2009 DM Produções Ltda. ME
 */
function esconde(id) {
    var objeto = document.getElementById(id);
    if (objeto.style.display == "block") {
        objeto.style.display = "none";
    }
}
