function confirmarExclusao( url, mensagem ){
    
    if ( confirm("Tem Certeza que você quer excluir "+mensagem+" ?") ) {
        
        location.href=url;
        
    } 
    
}


function criarAjax(){
    
    var xmlHttp;
    
    try{
        
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
        
    } catch (e){
        
        // Internet Explorer
        try{
            
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            
        } catch (e){
            
            try{
                
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                
            } catch (e){
                
                alert("Your browser does not support AJAX!");
                return false;
                
            }
            
        }
    }
    
    return xmlHttp;
}            


function abrirJanelaPrincipal(url) {
    window.open(url, 'principalSGUProfessor', 'toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width='+(screen.width - 5)+', height='+(screen.height - 70)+', left='+0+', top='+0+', screenX='+0+', screenY='+0+'');
}

function abrirJanelaPopUp(urlp) {
    window.open(urlp, 'popupSGUProfessor', 'toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width='+500+', height='+400+', left='+35+', top='+35+', screenX='+35+', screenY='+35+'');
}

function carregarElementosAjax( OgigemDoIdString, comboDestinoDosDadosString, nomeDoNodoXML, urlDeCargaDoAjax ){
    
    var elemento = document.createElement("option");
    
    var OgigemDoId = document.getElementById(OgigemDoIdString);
    
    var comboDestinoDosDados = document.getElementById(comboDestinoDosDadosString);
    
    
    var idDeOrigem = null;
    
    if( OgigemDoId.type == 'select-one' ){
        
        idDeOrigem = OgigemDoId.options[OgigemDoId.selectedIndex].value;
        
    } 
    
    if( OgigemDoId.type == 'text' ){
        
        idDeOrigem = OgigemDoId.value;
        
    }
    
    
    while (comboDestinoDosDados.length > 0) {
        
        comboDestinoDosDados.remove(0);
        
    } 
    
    
    elemento.text = "-SELECIONE-";
    elemento.value = "-SELECIONE-";
    
    comboDestinoDosDados.options.add( elemento );
    
    
    var ajax = criarAjax();
    
    ajax.onreadystatechange=function() {
        
        if( ajax.readyState == 4 ) {
            
            var xmla = ajax.responseXML;
            
            var elementos = xmla.getElementsByTagName( nomeDoNodoXML );
            
            for (i=0; i<elementos.length; i++){
                
                var elementoDoXML = document.createElement("option");
                
                elementoDoXML.text = elementos[i].childNodes[0].nodeValue;
                elementoDoXML.value = elementos[i].attributes[0].value;
                
                comboDestinoDosDados.options.add( elementoDoXML );
                
            }
            
        }
        
    }
    
    ajax.open("GET",urlDeCargaDoAjax+"?id="+idDeOrigem,true);
    ajax.send(null);
}

function carregarElementosDuploAjax( OrigemAno, OrigemPeriodo, comboDestinoDosDadosString, nomeDoNodoXML, urlDeCargaDoAjax ){
    
    var elemento = document.createElement("option");

    var OrigemDoAno = document.getElementById(OrigemAno);

    var OrigemDoPeriodo = document.getElementById(OrigemPeriodo);    
    
    var comboDestinoDosDados = document.getElementById(comboDestinoDosDadosString);

    var idDeOrigemA = null;

    if( OrigemDoAno.type == 'select-one' ){
        
        idDeOrigemA = OrigemDoAno.options[OrigemDoAno.selectedIndex].value;
        
    } 
    
    if( OrigemDoAno.type == 'text' ){
        
        idDeOrigemA = OrigemDoAno.value;
        
    }    
    
    var idDeOrigemB = null;

    if( OrigemDoPeriodo.type == 'select-one' ){
        
        idDeOrigemB = OrigemDoPeriodo.options[OrigemDoPeriodo.selectedIndex].value;
        
    } 
    
    if( OrigemDoPeriodo.type == 'text' ){
        
        idDeOrigemB = OrigemDoPeriodo.value;
        
    }  
 
    while (comboDestinoDosDados.length > 0) {
        
        comboDestinoDosDados.remove(0);
        
    } 
    
    
    elemento.text = "-SELECIONE-";
    elemento.value = "-SELECIONE-";
    
    comboDestinoDosDados.options.add( elemento );
    
    
    var ajax = criarAjax();
    
    ajax.onreadystatechange=function() {
        
        if( ajax.readyState == 4 ) {
            
            var xmla = ajax.responseXML;
            
            var elementos = xmla.getElementsByTagName( nomeDoNodoXML );
            
            for (i=0; i<elementos.length; i++){
                
                var elementoDoXML = document.createElement("option");
                
                elementoDoXML.text = elementos[i].childNodes[0].nodeValue;
                elementoDoXML.value = elementos[i].attributes[0].value;
              
                comboDestinoDosDados.options.add( elementoDoXML );

                
            }
            
        }
        
    }
    
    ajax.open("GET",urlDeCargaDoAjax+"?ida="+idDeOrigemA+"&idb="+idDeOrigemB,true);
    ajax.send(null);
}

/*
 * Obtém a string de um campo do formulário e formata a mesma.
 */
function formataDataComponente( nomeDoCampo ) {
    
    // obtém o primeiro elemento do array de componentes obtidos
    componente = document.getElementsByName( nomeDoCampo )[ 0 ];
    
    valor = componente.value;
    
    componente.value = valor.substring( 8, 10 ) + "/" +
    valor.substring( 5, 7 ) + "/" +
    valor.substring( 0, 4 );
    
}

/*
 * Remove todos os espaços do conteúdo de um componente.
 */
function retiraEspacos( nomeDoCampo, valor ) {
    
    // obtém o primeiro elemento do array de componentes obtidos
    componente = document.getElementsByName( nomeDoCampo )[ 0 ];
    
    componente.value = valor.replace( " ", "" );
    
}

/*
 * Evita timeout da sessão, enviando uma requisição vazia ao servidor, via Ajax, de 10 em 10 minutos
 */
function fazerContatoComServidor( url ){
    
    var ajax = criarAjax();

    ajax.open("GET",url,true);
    ajax.send(null);
    
}


// Navegação entre Abas
function navegarTelas( tela, maximo, grupo ){
    
    for (var m=1;m<(maximo+1);m++){
        //Telas para a consulta
        telaExibir 	= grupo+(tela);
        telaAtual	= grupo+(m);
        
        //Consulta
        if (telaExibir == telaAtual){
            
            document.getElementById(telaAtual).style.visibility="visible";
            document.getElementById('a'+m).style.background="#D5D5D5";
            
        } else {
            
            document.getElementById(telaAtual).style.visibility="hidden";
            document.getElementById('a'+m).style.background="#F5F5F5";
            
        }
    }
    
}


//Chama flash no site (correção do IE)
function exibeFash(swf, width, height, wmode, cache)
{
noCache = cache || cache == undefined ? "" : "?" + new Date();
wmode = wmode || wmode == undefined ? "transparent" : "transparent";

monta_swf = "";
monta_swf += "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\""+ width +"\" height=\""+ height +"\" title=\"\">";
monta_swf += "<param name=\"movie\" value=\""+ swf + noCache +"\" />";
monta_swf += "<param name=\"quality\" value=\"high\" />";
monta_swf += "<param name=\"menu\" value=\"0\" />";
monta_swf += "<param name=\"wmode\" value=\""+ wmode +"\" />";
monta_swf += "<embed src=\""+ swf + noCache +"\" quality=\"high\" wmode=\""+ wmode +"\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+ width +"\" height=\""+ height +"\"></embed>";
monta_swf += "</object>";

document.write(monta_swf);
}


