﻿var cor; 
var classe;
function checar_caps_lock(ev, aviso) {
    var campo = document.getElementById(aviso);
	var e = ev || window.event;
	codigo_tecla = e.keyCode?e.keyCode:e.which;
	tecla_shift = e.shiftKey?e.shiftKey:((codigo_tecla == 16)?true:false);
	if(((codigo_tecla >= 65 && codigo_tecla <= 90) && !tecla_shift) || ((codigo_tecla >= 97 && codigo_tecla <= 122) && tecla_shift)) {
        campo.innerHTML = 'Atenção!\nA Tecla Caps Lock está ativada.\nIsto pode fazer com que você digite a senha incorreta!';
	} else {
        campo.innerHTML = ''
	}
}
function hideLoading() {
    var divs = document.getElementsByTagName("div")
    var f = divs.length;
    var i = 0;
    var pos = -1;
    while(pos == -1 && i < f ) {
        if (divs[i].id.indexOf('loading') != -1) {
            divs[i].style.visibility = 'hidden';
        }
        i++
    }
}
function hideRow(row,gv)
{
    Row_num = row ;
    rows = document.getElementById(gv).rows;
    var pos = -1;
    var f = rows.length;
    var i = 0;
    var j = 0;
    while(pos == -1 && i < f ) {
        var e = rows[i].getElementsByTagName('input');
        if (row == 'Todos') {
            rows[i].style.display='';
            for(var j = 0; j < e.length; j++){
                e[j].disabled = false;
            }             
        } else {
            if (rows[i].id.indexOf('OA_'+row) != -1 || rows[i].id.indexOf('HeaderFooter') != -1) {
                rows[i].style.display='';
                for(var j = 0; j < e.length; j++){
                    e[j].disabled = false;
                }                
            } else {
                rows[i].style.display='none';
                for(var j = 0; j < e.length; j++){
                    e[j].disabled = true;
                }
            }
        }
        i++
    }
    return false;
}
function hideRowTxb(row, gv) {
    Row_num = row;
    rows = document.getElementById(gv).rows;
    var pos = -1;
    var f = rows.length;
    var i = 0;
    var j = 0;
    while (pos == -1 && i < f) {
        var e = rows[i].getElementsByTagName('input');
        if (row == 'Todos') {
            rows[i].style.display = '';
            for (var j = 0; j < e.length; j++) {
                e[j].disabled = false;
            }
        } else {
            for (var j = 0; j < rows[i].cells.length; j++) {
                var col = rows[i].cells.item(j);
                var inputelements = col.getElementsByTagName('input');
                var checkelements = col.getElementsByTagName('checkbox');
                var maxInput = inputelements.length;
                var maxCheck = checkelements.length;
                if (maxInput == 0 && maxCheck == 0) {
                    if (col.innerHTML.toUpperCase().indexOf(row.toUpperCase()) != -1 || rows[i].id.indexOf('HeaderFooter') != -1) {
                        rows[i].style.display = '';
                        for (var k = 0; k < e.length; k++) {
                            e[k].disabled = false;
                        }
                    } else {
                        rows[i].style.display = 'none';
                        for (var k = 0; k < e.length; k++) {
                            e[k].disabled = true;
                        }
                    }
                }
            }
        }
        i++
    }
    return false;
}
function retornaPosicao(element) 
{ 
    var valueT = 0, valueL = 0, valueH = 0; 
    do 
    { 
        valueT += element.offsetTop  || 0; 
        valueL += element.offsetLeft || 0; 
        valueH = element.offsetHeight || 0;
        element = element.offsetParent; 
    } 
    while (element); 
        return [valueL, valueT, valueH]; 
}
//Exibe contador de carcteres.
function mostraContador() {
    try {
        document.getElementById('divCont').style.visibility = 'visible';
    } catch(e) {
	}
}
//Esconde contador de carcteres
function escondeContador() {
    try {
        document.getElementById('divCont').style.visibility = 'hidden';
    } catch(e) {
	}
}
function contaMarcaLimite(idComponente, qtdeMaxCaracteres) {
    if (qtdeMaxCaracteres == undefined) {
        qtdeMaxCaracteres = 5000;
    }
    try {
        if (parseFloat(qtdeMaxCaracteres) <= 2500 && parseFloat(qtdeMaxCaracteres) > 0) {
            var strDados = new String(idComponente.value);
            if (strDados.length > qtdeMaxCaracteres && qtdeMaxCaracteres > 0) {
                alert('Este campo não pode exceder ' + qtdeMaxCaracteres + ' caracteres');
		        idComponente.value = idComponente.value.substr(0,qtdeMaxCaracteres);
		        return false;            
            } else {
	            document.getElementById('divCont').innerHTML = strDados.length + " caracteres (" + qtdeMaxCaracteres + " máximo)";
            }
	        coordenadas = retornaPosicao(idComponente);
	        //alert(coordenadas);
	        getObject('divCont');
	        if (clientNavigator == "IE"){
	            document.getElementById('divCont').style.top = idComponente.offsetHeight + coordenadas[1];//parseFloat(coordenadas[2].split('px')[0]) + coordenadas[1];
	            document.getElementById('divCont').style.left = coordenadas[0];
	        } else {
                document.getElementById('divCont').style.top = idComponente.offsetHeight + coordenadas[1] + 'px';//parseFloat(coordenadas[2].split('px')[0]) + coordenadas[1];
	            document.getElementById('divCont').style.left = coordenadas[0] + 'px';
	        }
        } else {
            //alert(e.description);
            document.getElementById('divCont').style.visibility = 'hidden';
        }
    } catch(e) {
	//alert(e.description);
	if (document.getElementById('divCont')) {
	document.getElementById('divCont').style.visibility = 'hidden';
	}
	}
}
function addTexto(texto, campo) {
    campo.value = campo.value + texto;
    return false;
}
function selecionaGrid(elemento, corElemento) { 
    cor=elemento.style.backgroundColor; 
    elemento.style.backgroundColor = corElemento; 
} 
function deSelecionaGrid(elemento) { 
    elemento.style.backgroundColor = cor; 
}
function selecionaCell(elemento) { 
    classe=elemento.className; 
    elemento.className = "menu_nsel_over"; 
} 
function deselecionaCell(elemento) { 
    elemento.className = classe; 
}
function popup(url,janela,larg,alt) {
    var screenX = screen.availWidth;   
    var screenY = screen.availHeight;   
    var h = alt;
    var w = larg;
    var win = window.open(url,janela,"height="+alt+",width="+larg+",top="+ (screenY - h) / 2 +",left="+ (screenX - w) / 2+",status=no,toolbar=no,location=no,scrollbars=yes,resizable=yes,fullscreen=no");
	var Left = 0;
	var Top = 0;
	win.focus();
	return false;
}
function goToCurso(ddl) {
    var e = document.getElementsByTagName("div");
    for(var i = 0; i < e.length; i++){
        if (e[i].id.indexOf('pnlCurso') != -1) {
            e[i].className = "pnlCursoNSel";
        }
    }
    window.location='#'+ddl.options[ddl.selectedIndex].text
    var pnl = document.getElementById(ddl.options[ddl.selectedIndex].value);
    pnl.className = "pnlCursoSel";
}
function mudaTexto(item) {
    if (item.innerHTML == 'Favoritos (+)') {
        item.innerHTML = 'Favoritos (-)' 
    } else {
        item.innerHTML = 'Favoritos (+)'
    }
}
function abre_curso(url,janela,larg,alt,full) {
    var screenX = screen.availWidth;   
    var screenY = screen.availHeight - 60;   
    var h = alt;
    var w = larg;
    if (full == 'true') {
        var PE = "left=0,screenX=0,top=0,screenY=0,scrollbars=0,fullscreen=1";
        if (window.screen) {
            var ah = screen.availHeight - 60;
            var aw = screen.availWidth - 10;
            PE += ",height=" + ah;
            PE += ",innerHeight=" + ah;
            PE += ",width=" + aw;
            PE += ",innerWidth=" + aw;
        } else {
            PE += ",resizable"; // so the user can resize the window manually
        }
        window.open(url, janela, PE);
    } else {
        var win = window.open(url, janela, "height=" + alt + ",width=" + larg + ",top=" + (screenY - h) / 2 + ",left=" + (screenX - w) / 2 + ",status=no,toolbar=no,location=no,scrollbars=yes,resizable=no,fullscreen=no");
    }
    var Left = 0;
	var Top = 0;
	win.focus();
	return false;
}
function desativa(botao) {
    botao.disabled = 1;
    return true;
}
function ativa(botao) {
    botao.disabled = 0;
}
function verifica_campo(campo, nome) {
    var msg = "Atenção!";
    if (campo.value == '') {
        msg = msg + "\n" + "Você deve preencher o campo " + nome + ".";
    }
    if (msg != "Atenção!") {
	    alert(msg);
	    return false;
	}
}
function valor_maximo(aula, campo, valor) {
if (valor < campo.value) {
    if (confirm('A aula ' + aula + ' pode ter no máximo '+valor+' questões.\nDeseja que altere o número de questões para ' + valor + '?')) {
        campo.value = valor;
        campo.className = 'textbox';
    } else {
        campo.value = '';
        campo.className = 'textbox';
    }
}
campo.className = 'textbox';
}
function verificaChkSel(chk, td, corChecked, corUnChecked) {
checkbox = document.getElementById(chk)
linha = document.getElementById(td)
//alert(linha);
    if (checkbox.checked == true) {
        linha.style.backgroundColor = corChecked; 
    } else {
        linha.style.backgroundColor = corUnChecked; 
    }
}
function check(text, checkbox) {
    if (text.value != "" && text.value >0) {
        checkbox.checked = true;
    } else {
        if (text.value == 0) {
            text.value = "";
        }
    checkbox.checked = false;
    }
}
function oncheck(text, checkbox) {
    if (checkbox.checked == false) {
        text.value='';
    }
}

function verifica_campos(tipo, campo, nome) {
    array_tipo = tipo.split(",");
    array_campo = campo.split(",");
    array_nome = nome.split(",");
    var msg = "Atenção!";
    for (i=0; i < array_tipo.length; i++) {
		if (array_tipo[i] == 1) {
		   campo = document.getElementById(array_campo[i]);
		   if (campo.value == '') {
               msg = msg + "\n" + "Você deve preencher o campo " + array_nome[i] + ".";
            }
        }
        if (array_tipo[i] == 2) {
            campo = array_campo[i];
            alert(campo.innerHtml);
	        if (campo.innerHtml == '') {
		        msg = msg + "\n" + "Preencha o campo " + array_nome[i] + ".";
            }    
	    }
	    if (array_tipo[i] == 3) {
            campo = array_campo[i];
            marcado = -1;
	        for (j=0; j < array_campo[i].length; j++) {
		        if (campo[j].checked) {
			        marcado = i;
		        }
	        }
	        if (marcado == -1) {
		        msg = msg + "\n" + "Selecione uma opção para o item" + array_nome[i] + ".";
            }    
	    }
	}
	if (msg != "Atenção!") {
	    alert(msg);
	    return false;
	}
}
function confirma(msg) {
    if (confirm(msg)) {
        return true;
    } else {
        return false;
    }
}
function getObject(objeto) {
    if (window.document[objeto]) {
        return window.document[objeto];
    }
    if (navigator.appName.indexOf("Microsoft Internet")==-1) {
        if (document.embeds && document.embeds[objeto])
            return document.embeds[objeto]; 
        } else {
            return document.getElementById(objeto);
        }
    }
    if (navigator.appName.indexOf('Microsoft') != -1){
        clientNavigator = "IE";
    } else {
        clientNavigator = "Other";
}
function Remove_Caracteres(campo) {
    novo_texto = "";
    for (i=0; i < campo.value.length; i++) {
        if (campo.value.charCodeAt(i) < 48 || campo.value.charCodeAt(i) > 57){
		    novo_texto = novo_texto;
        } else {
	        novo_texto = novo_texto + campo.value.charAt(i);
	    }
    }
    campo.value = novo_texto;
    campo.className = 'textbox';
}
function Bloqueia_Caracteres(evt){
    var key_code = evt.keyCode  ? evt.keyCode  :
    evt.charCode ? evt.charCode :
    evt.which    ? evt.which    : void 0;
    // Habilita teclas <DEL>, <TAB>, ----<ENTER>---retirado--, <ESC> e <BACKSPACE>
    if (key_code == 8  ||  key_code == 9  ||    key_code == 27  ||  key_code == 46) {//key_code == 13  ||
        return true;
    }
    // Habilita teclas <HOME>, <END>, mais as quatros setas de navegação (cima, baixo, direta, esquerda)
    else if ((key_code >= 35)  &&  (key_code <= 40))
    {
    return true
    }
    // Habilita números de 0 a 9
    else if ((key_code >= 48)  &&  (key_code <= 57))
    {
    return true
    }
    return false;
}
function Bloqueia_Enter(evnt){
	if (clientNavigator == "IE"){
		if (evnt.keyCode == 13){
			return false;
		}
	}else{
		if (evnt.charCode == 13){
			return false;
		}
	}
}
function VerificaCPF(campo){ 
    var i; 
    s = campo.value; 
    if (campo.value != '') {
        if (campo.value == '00000000000'  || campo.value == '22222222222' || campo.value == '33333333333'  || campo.value == '44444444444' || campo.value == '55555555555' || campo.value == '66666666666'  || campo.value == '77777777777' || campo.value == '88888888888'  || campo.value == '99999999999') {
            alert("CPF Invalido") 
            campo.value = "";
            campo.className = 'textbox';
            campo.focus;
            return false; 
        }
        s = s.replace('.',"");
        s = s.replace('.',"");
        s = s.replace('-',"");
        var c = s.substr(0,9); 
        var dv = s.substr(9,2); 
        var d1 = 0; 
        for (i = 0; i < 9; i++) 
        { 
            d1 += c.charAt(i)*(10-i); 
        } 
        if (d1 == 0){ 
            alert("CPF Invalido") 
            campo.value = "";
            campo.className = 'textbox';
            campo.focus;
            return false; 
        } 
        d1 = 11 - (d1 % 11); 
        if (d1 > 9) d1 = 0; 
            if (dv.charAt(0) != d1) 
                { 
                alert("CPF Invalido") 
                campo.focus;
                campo.value = "";
                campo.className = 'textbox';
                return false; 
            } 
            d1 *= 2; 
        for (i = 0; i < 9; i++) { 
            d1 += c.charAt(i)*(11-i); 
        } 
        d1 = 11 - (d1 % 11); 
        if (d1 > 9) d1 = 0; 
        if (dv.charAt(1) != d1) 
        { 
        alert("CPF Invalido") 
        campo.focus;
        campo.value = "";
        campo.className = 'textbox';
        return false; 
        } 
        campo.className = 'textbox';
        return true; 
    } else {
        campo.className = 'textbox';
        return false
    }
} 

function VerificaData(campo) {
    vr = campo.value;
    dia = vr.substr(0,2);
    mes = vr.substr(3,2);
    ano = vr.substr(6,4);
    if (mes > 12) {
        alert('Data inválida');
        campo.value = "";
        campo.focus();
        return false
    }
    if (mes <= 12) {
        if (mes == 1) {
            if (dia > 31) {
            alert("Data inválida");
            campo.value = "";
            campo.focus();
            return false
            }
        }
        if (mes == 2) {
            if (dia > 29) {
            alert("Data inválida");
            campo.value = "";
            campo.focus();
            return false
            }
        }    
        if (mes == 3) {
            if (dia > 31) {
            alert("Data inválida");
            campo.value = "";
            campo.focus();
            return false
            }
        }    
        if (mes == 4) {
            if (dia > 30) {
            alert("Data inválida");
            campo.value = "";
            return false
            }
        }    
        if (mes == 5) {
            if (dia > 31) {
            alert("Data inválida");
            campo.value = "";
            campo.focus();
            return false
            }
        }    
        if (mes == 6) {
            if (dia > 30) {
            alert("Data inválida");
            campo.value = "";
            campo.focus();
            return false
            }
        }    
        if (mes == 7) {
            if (dia > 31) {
            alert("Data inválida");
            campo.value = "";
            campo.focus();
            return false
            }
        }    
        if (mes == 8) {
            if (dia > 31) {
            alert("Data inválida");
            campo.value = "";
            campo.focus();
            return false
            }
        }    
        if (mes == 9) {
            if (dia > 30) {
            alert("Data inválida");
            campo.value = "";
            campo.focus();
            return false
            }
        }    
        if (mes == 10) {
            if (dia > 31) {
            alert("Data inválida");
            campo.value = "";
            campo.focus();
            return false
            }
        }    
        if (mes == 11) {
            if (dia > 30) {
            alert("Data inválida");
            campo.value = "";
            campo.focus();
            return false
            }
        }    
        if (mes == 12) {
            if (dia > 31) {
            alert("Data inválida");
            campo.value = "";
            campo.focus();
            return false
            }
        }        
    }
}
//function FormataValor(campo,tammax,teclapres) {
//var tecla = teclapres.keyCode;
//if (!(tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105)) {
//  return false
//  } else {
//	vr = campo.value;
//	vr = vr.replace( "/", "" );
//	vr = vr.replace( "/", "" );
//	vr = vr.replace( ",", "" );
//	vr = vr.replace( ".", "" );
//	vr = vr.replace( ".", "" );
//	vr = vr.replace( ".", "" );
//	vr = vr.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 ){ 
//	 		campo.value = vr ; }
//	 	if ( (tam > 2) && (tam <= 5) ){
//	 		campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
//	 	if ( (tam >= 6) && (tam <= 8) ){
//	 		campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
//	 	if ( (tam >= 9) && (tam <= 11) ){
//	 		campo.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) ){
//	 		campo.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) ){
//	 		campo.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 ) ;}
//	}
//}
//return true
//}
function FormataValor(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;   
    var whichCode = (window.addEventListener) ? 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 mascaraTelefone(objeto,teclapres) {
    a = Bloqueia_Caracteres(teclapres);
    if (a == false) {
        return false
    } else {
    if (objeto.value.length == 0){
	    objeto.value +="(";
	}
    if (objeto.value.length == 3){
        objeto.value +=")";
	}
    if (objeto.value.length == 8){
        objeto.value +="-";
    }
    if (objeto.value.length == 13){
       return false
    }
  }
return true
}
function mascaraCep(objeto,teclapres){
    a = Bloqueia_Caracteres(teclapres);
    if (a == false) {
        return false
    } else {
        if (objeto.value.length == 5 ){
		    objeto.value +="-";
	    }
    }
return true
}
function mascaraCPF(objeto,teclapres) {
a = Bloqueia_Caracteres(teclapres);
    if (a == false) {
        return false
    } else {
        if (objeto.value.length == 3 || objeto.value.length == 7){
		    objeto.value +=".";
	    }
	    if (objeto.value.length == 11){
		    objeto.value +="-";
    	}
	}
return true
}
function mascaraCNPJ(objeto,teclapres) {
a = Bloqueia_Caracteres(teclapres);
    if (a == false) {
        return false
    } else {
        if (objeto.value.length == 2 || objeto.value.length == 6){
		    objeto.value +=".";
	    }
	    if (objeto.value.length == 10){
		    objeto.value +="/";
    	}
    	if (objeto.value.length == 15){
		    objeto.value +="-";
    	}
    	if (objeto.value.length == 18){
		    return false
    	}
	}
return true
}

function mascaraData(objeto,teclapres){
    a = Bloqueia_Caracteres(teclapres);
    if (a == false) {
        return false
    }
    if (objeto.value.length == 2 || objeto.value.length == 5){
        objeto.value +="/";
    }
return true
}


function mascaraHora(objeto,teclapres){
    a = Bloqueia_Caracteres(teclapres);
    if (a == false) {
        return false
    }
    if (objeto.value.length == 2 || objeto.value.length == 5){
        objeto.value +=":";
    }
return true
}

function verifica_ordem(textbox, id) {
   var qtdItens = document.forms.length;
   var campo = textbox;
   var valor = campo.value;
   var i = 0;
   var pos = -1;
   while( pos == -1 && i < qtdItens ) {
       var e = document.forms[i].elements.length;
       var j = 0;
       var qtdText = 0;
       while( pos == -1 && j < e ) {
           if ( document.forms[i].elements[j].type == 'text' && document.forms[i].elements[j].id.indexOf(id) != -1) {
               qtdText++;
           }
           j++;
       }
       j = 0;
       if (valor <= qtdText && valor != 0) {
           while( pos == -1 && j < e ) {
               if ( document.forms[i].elements[j] != campo && document.forms[i].elements[j].type == 'text' && document.forms[i].elements[j].id.indexOf(id) != -1) {
                   if (document.forms[i].elements[j].value == valor) {
                        if (confirm('Não é permitido repetir uma ordem.\nDeseja manter este valor e alterar o valor repetido para vazio?')) {
                            document.forms[i].elements[j].value = '';
                            document.forms[i].elements[j].focus;
                            return false;
                        } else {
                            campo.value = ''
                            campo.focus;
                            return false;
                        }
                   }
               }
               j++;
           } 
       } else {
            if (valor == 0 ) {
                alert('Não é possível utilizar ordem 0.');
            } else {
                alert('Não é possível utilizar ordem acima de ' + qtdText + '.');
            } 
            campo.value = '';
            campo.focus;
            return false;
       }
   i++;
   }
}

function inverter_selecao(id) {
   var f = document.forms.length;
   var i = 0;
   var pos = -1;
   while( pos == -1 && i < f ) {
       var e = document.forms[i].elements.length;
       var j = 0;
       while( pos == -1 && j < e ) {
           if ( document.forms[i].elements[j].type == 'checkbox' && document.forms[i].elements[j].id.indexOf(id) != -1) {
               document.forms[i].elements[j].click();
               //document.forms[i].elements[j].checked =!(document.forms[i].elements[j].checked)
               //document.forms[i].elements[j].blur();
           }
           j++;
       }
   i++;
   }
   if( pos >= 0 ) {
       document.forms[i-1].elements[pos].focus();
   }
}
function selecionar_checkbox(id) {
var f = document.forms.length;
   var i = 0;
   var pos = -1;
   while( pos == -1 && i < f ) {
       var e = document.forms[i].elements.length;
       var j = 0;
       while( pos == -1 && j < e ) {
           if ( document.forms[i].elements[j].type == 'checkbox' && document.forms[i].elements[j].id.indexOf(id) != -1) {
               if (document.forms[i].elements[j].checked == false) {
                    document.forms[i].elements[j].click();
               }
               //document.forms[i].elements[j].checked = true
           }
           j++;
       }
   i++;
   }
   if( pos >= 0 ) {
       document.forms[i-1].elements[pos].focus();
   }
}
function selecionarDDL(ddl, txt, btn) {
    var botao = document.getElementById(btn);
    var dropDown = document.getElementById(ddl);
    var textbox = document.getElementById(txt);
    var qtdItens = dropDown.options.length;
    var atual = dropDown.selectedIndex;
    var volta = 0;
    var proximo;
    if (atual >= qtdItens-1) {
        atual = -1;
    }
    var selecionadoDDL = -1;
    if (textbox.value != '') {
        while(atual < qtdItens -1 && selecionadoDDL == -1 && volta < 2) {
            proximo = atual + 1;
            if (dropDown.options[proximo].text.toUpperCase().indexOf(textbox.value.toUpperCase()) != -1) {
                dropDown.selectedIndex = proximo;
                selecionadoDDL = proximo;
                botao.value = "Localizar Próximo";
            }
            atual++;
            if (atual >= qtdItens -1 && volta < 2) {
                atual = -1;
                volta++;
            }
        }
    }
    if (selecionadoDDL == -1) {
        botao.value = "Localizar Registro";
        alert('Nenhum item encontrado.');
    }
    return false;
}
function Bloquear_enter(evnt){
	if (clientNavigator == "IE"){
		if (evnt.keyCode == 13){
			return false;
		}
	} else {
		if (evnt.charCode == 13){
			return false;
		}
	}
}
function aba(item_mod, img_name, path) {
	div = document.getElementById(item_mod);
	img = document.getElementById(img_name);
	var status = div.style.display;
	if (status == 'none') {
		div.style.display = 'block';
		MM_swapImage(img_name,'',path + '/imagens/sala/bg_seta_cat.gif',0)
	} 
	if (status == 'block' || status == '') {
		div.style.display = 'none';
		MM_swapImage(img_name,'',path + '/imagens/sala/bg_seta_cat_2.gif',0)
	}
	return false;
}
var menuOver;
//tipo = 1 --> Categoria (pode esconder)
//tipo = 2 --> Items (não pode esconder)
function showMenu(item, tipo) {
    menuOver = tipo;
    div = document.getElementById(item);
	div.style.display = 'block';
	div.style.position = 'absolute';
	div.style.position.zIndex = 4;
	return false;
}
function showMenuDireita(item, tipo) {
    menuOver = tipo;
    div = document.getElementById(item);
	div.style.display = 'block';
	div.style.position = 'absolute';
	div.style.position.zIndex = 5;
	return false;
}

function hideMenu(item, tipo) {
    if (menuOver != 2 || tipo == 2) {
        div = document.getElementById(item);
	    div.style.display = 'none';
	    menuOver = 2;
	    return false;
    }
}
function hideMenuTimer(item) {
    var t=setTimeout("hideMenu('" + item + "','1')",500);
}
function abaPesquisa(chk, item_mod) {
	panel = document.getElementById(item_mod);
	checkbox = document.getElementById(chk);
	var statusChk = checkbox.checked;
	if (statusChk == true) {
		panel.style.display = 'block';
	} 
	if (statusChk == false) {
		panel.style.display = 'none';
	}
}
function abaInthegra(chk, item_mod, i) {
    var tableBody = document.getElementById(chk);
    var panel = document.getElementById(item_mod);
    var statusChk = tableBody.rows[i].cells[0].childNodes[0].checked;
	if (statusChk == true) {
		panel.style.display = 'block';
	} 
	if (statusChk == false) {
		panel.style.display = 'none';
	}
}
function fecharAbaInthegra(chk, item_mod, i) {
    var panel = document.getElementById(item_mod);
    panel.style.display = 'none';
}
function fecharAbaDesempenho(chk, item_mod, i, txb) {
    var panel = document.getElementById(item_mod);
    panel.style.display = 'none';
    var textbox = document.getElementById(txb);
    textbox.value = '';
}
//function abaPesquisaRelatorio(item_mod, img_name) {
//	div = document.getElementById(item_mod);
//	img = document.getElementById(img_name);
//	var status = div.style.display;
//	if (status == 'none') {
//		div.style.display = 'block';
//		MM_swapImage(img_name,'','../../imagens/sala/bg_seta_cat.gif',0)
//	} 
//	if (status == 'block' || status == '') {
//		div.style.display = 'none';
//		MM_swapImage(img_name,'','../../imagens/sala/bg_seta_cat_2.gif',0)
//	}
//	return false;
//}
//function aba(item_mod, img_name) {
//	div = document.getElementById(item_mod);
//	img = document.getElementById(img_name);
//	var status = div.style.display;
//	if (status == 'none') {
//		div.style.display = 'block';
//		MM_swapImage(img_name,'','../../../../imagens/sala/bg_seta_cat.gif',0)
//	} 
//	if (status == 'block' || status == '') {
//		div.style.display = 'none';
//		MM_swapImage(img_name,'','../../../../imagens/sala/bg_seta_cat_2.gif',0)
//	}
//	return false;
//}
//function abaSugestao(item_mod, img_name) {
//	div = document.getElementById(item_mod);
//	img = document.getElementById(img_name);
//	var status = div.style.display;
//	if (status == 'none') {
//		div.style.display = 'block';
//		MM_swapImage(img_name,'','../../imagens/sala/bg_seta_cat.gif',0)
//	} 
//	if (status == 'block' || status == '') {
//		div.style.display = 'none';
//		MM_swapImage(img_name,'','../../imagens/sala/bg_seta_cat_2.gif',0)
//	}
//	return false;
//}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
//------------------------------------------------------------------------------------------------------
//Funções para criação dos botões
//------------------------------------------------------------------------------------------------------
//var btn = {
//    init : function() {
//        if (!document.getElementById || !document.createElement || !document.appendChild) return false;
//        as = btn.getElementsByClassName('btn(.*)');
//        for (i=0; i<as.length; i++) {
//            if ( as[i].tagName == "INPUT" && ( as[i].type.toLowerCase() == "submit" || as[i].type.toLowerCase() == "button" ) ) {
//                var a1 = document.createElement("a");
//                a1.appendChild(document.createTextNode(as[i].value));
//                a1.className = as[i].className;
//                a1.id = as[i].id;
//                as[i] = as[i].parentNode.replaceChild(a1, as[i]);
//                as[i] = a1;
//                as[i].style.cursor = "pointer";
//            }
//            else if (as[i].tagName == "A") {
//                var tt = as[i].childNodes;
//            }
//            else { return false };
//            var i1 = document.createElement('i');
//            var i2 = document.createElement('i');
//            var s1 = document.createElement('span');
//            var s2 = document.createElement('span');
//            s1.appendChild(i1);
//            s1.appendChild(s2);
//            while (as[i].firstChild) {
//              s1.appendChild(as[i].firstChild);
//            }
//            as[i].appendChild(s1);
//            as[i] = as[i].insertBefore(i2, s1);
//        }
//    },
//    addEvent : function(obj, type, fn) {
//        if (obj.addEventListener) {
//            obj.addEventListener(type, fn, false);
//        }
//        else if (obj.attachEvent) {
//            obj["e"+type+fn] = fn;
//            obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
//            obj.attachEvent("on"+type, obj[type+fn]);
//        }
//    },
//    getElementsByClassName : function(className, tag, elm) {
//        var testClass = new RegExp("(^|\s)" + className + "(\s|$)");
//        var tag = tag || "*";
//        var elm = elm || document;
//        var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
//        var returnElements = [];
//        var current;
//        var length = elements.length;
//        for(var i=0; i<length; i++){
//            current = elements[i];
//            if(testClass.test(current.className)){
//                returnElements.push(current);
//            }
//        }
//        return returnElements;
//    }
//    
//}
//btn.addEvent(window,'load', function() { btn.init();} );
var btn = {
    init : function() {
        if (!document.getElementById || !document.createElement || !document.appendChild) return false;
        as = btn.getElementsByClassName('btn(.*)');
        for (i=0; i<as.length; i++) {
            if ( as[i].tagName == "INPUT" && ( as[i].type.toLowerCase() == "submit" || as[i].type.toLowerCase() == "button" ) ) {
                var a1 = document.createElement("a");
                a1.appendChild(document.createTextNode(as[i].value));
                a1.className = as[i].className;
                a1.id = as[i].id;
                as[i] = as[i].parentNode.replaceChild(a1, as[i]);
                as[i] = a1;
                as[i].style.cursor = "pointer";
            }
            else if (as[i].tagName == "A") {
                var tt = as[i].childNodes;
            }
            else { return false };
            var i1 = document.createElement('i');
            var i2 = document.createElement('i');
            var s1 = document.createElement('span');
            var s2 = document.createElement('span');
            s1.appendChild(i1);
            s1.appendChild(s2);
            while (as[i].firstChild) {
              s1.appendChild(as[i].firstChild);
            }
            as[i].appendChild(s1);
            as[i] = as[i].insertBefore(i2, s1);
        }
        // The following lines submits the form if the button id is "submit_btn"
        if (document.getElementById('submit_btn')) {
            btn.addEvent(document.getElementById('submit_btn'),'click',function() {
            var form = btn.findForm(this);
            form.submit();
            });
        }
        // The following lines resets the form if the button id is "reset_btn"
        if (document.getElementById('reset_btn')) {
            btn.addEvent(document.getElementById('reset_btn'),'click',function() {
            var form = btn.findForm(this);
            form.reset();
            });
        }
    },
    findForm : function(f) {
        while(f.tagName != "FORM") {
            f = f.parentNode;
        }
        return f;
    },
    addEvent : function(obj, type, fn) {
        if (obj.addEventListener) {
            obj.addEventListener(type, fn, false);
        }
        else if (obj.attachEvent) {
            obj["e"+type+fn] = fn;
            obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
            obj.attachEvent("on"+type, obj[type+fn]);
        }
    },
    getElementsByClassName : function(className, tag, elm) {
        var testClass = new RegExp("(^|\s)" + className + "(\s|$)");
        var tag = tag || "*";
        var elm = elm || document;
        var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
        var returnElements = [];
        var current;
        var length = elements.length;
        for(var i=0; i<length; i++){
            current = elements[i];
            if(testClass.test(current.className)){
                returnElements.push(current);
            }
        }
        return returnElements;
    }
}

btn.addEvent(window,'load', function() { btn.init();} );
function criarBalao(id, pagina, evento, icone) {
    var id = new HelpBalloon({dataURL: pagina, useEvent: [evento], icon: $(icone),cacheRemoteContent: false});
    fecharBalao(id, icone)
}
function fecharBalao(id, icone) {
    Event.observe(icone, 'mouseout', id.hide.bind(id))
}
function OnTreeNodeChecked()
{
var obj = window.event.srcElement;
var treeNodeFound = false;
var checkedState;
if (obj.tagName == "INPUT" && obj.type == "checkbox") {
var treeNode = obj;
checkedState = treeNode.checked;
do
{
obj = obj.parentElement;
} while (obj.tagName != "TABLE")
var parentTreeLevel = obj.rows[0].cells.length;
var parentTreeNode = obj.rows[0].cells[0];
var tables = obj.parentElement.getElementsByTagName("TABLE");
var numTables = tables.length
if (numTables >= 1)
{
for (i=0; i < numTables; i++)
{
if (tables[i] == obj)
{
treeNodeFound = true;
i++;
if (i == numTables)
{
return;
}
}
if (treeNodeFound == true)
{
var childTreeLevel = tables[i].rows[0].cells.length;
if (childTreeLevel > parentTreeLevel)
{
var cell = tables[i].rows[0].cells[childTreeLevel - 1];
var inputs = cell.getElementsByTagName("INPUT");
inputs[0].checked = checkedState;
}
else
{
return;
}
}
}
}
}
}
function noPaste(HtmlEditor) {
    var editor = $find('ctl00_ContentPlaceHolder1_txbResposta');// document.getElementById(HtmlEditor);
    var editPanel = editor.get_editPanel();
    editPanel.set_noPaste(true);
}


