// JavaScript Document
	function MostraCalendario(incremento,site) {
		SendAjax('inc/ajax_calendario.php?incremento=' + incremento + '&categoria=' + site, UpdateCalendario);
	}

	function UpdateCalendario(state, results) {
		var PollDiv = document.getElementById('Calendario');
		if(state == 4){
			PollDiv.innerHTML = results;
		}else if(state == 1){
			PollDiv.innerHTML = 'Carregando...<br /><br /><img src="img/layout/loading.gif" border=0 />';
		}

    }

    /*
     * SIMULADO
     */

    function getDificuldades(id,pcount){
		SendAjax('../inc/simulado_online_ajax.php?id=' + id + '&pcount=' +pcount, updateDificuldades);
    }

	function updateDificuldades(state, results) {
		var PollDiv = document.getElementById('dificuldades');
        //alert(results);
		if(state == 4){
			PollDiv.innerHTML = results;
		}else if(state == 1){
			PollDiv.innerHTML = 'Carregando... <img src="img/layout/loading.gif" border=0 />';
		}

    }

    function getCategorias(id,minimoDificuldades){
        //alert('oi');
		SendAjax('../inc/simulado_online_ajax.php?id=' + id + '&modo=categorias&minimoDificuldades='+minimoDificuldades, updateCategorias);
    }

	function updateCategorias(state, results) {
		var PollDiv = document.getElementById('categorias');
        //alert(results);
		if(state == 4){
			PollDiv.innerHTML = results;
		}else if(state == 1){
			PollDiv.innerHTML = 'Carregando... <img src="img/layout/loading.gif" border=0 />';
		}

    }

/* RSS EXTERNOS */
	function getExternalNews(){
	    SendAjax('inc/rss_externals_ajax.php', updateExternalNews);
	}

	var loadingExtNews = true;

	function updateExternalNews(state, results) {
	    var PollDiv = document.getElementById('external_news');
	    //alert(state);
	    if(state == 4){
			//alert("oi");
	        loadingExtNews = false;
	        PollDiv.innerHTML = results;
	    }else if(state == 1){
	        // alert('images/layout/carregando.gif');

	        PollDiv.innerHTML = '<div style="text-align: center; color: #999999">'+
	                            'Carregando...<br>'+
	                            '<img style="margin: 10px;" src="img/carregando.gif" width="30" border=0 /><br />'+
	                            '<span style="font-size: 1em;">'+
	                            'Estamos lendo notícias de sites externos. Por favor, aguarde.'+
	                            '</span>'+
	                            '</div>';
	        setTimeout( function(){
	            if( loadingExtNews ){
	                PollDiv.innerHTML = '<div style="text-align: center; color: #999999">'+
	                                    'Ainda carregando...<br>'+
	                                    '<img style="margin: 10px;" src="img/carregando.gif" width="30" border=0 /><br />'+
	                                    '<span style="font-size: 1em;">'+
	                                    'Os sites externos estão lentos. Por favor, aguarde um pouco mais.'+
	                                    '</span>'+
	                                    '</div>';
	            }
	        }, 5000);
	        setTimeout( function(){
	            if( loadingExtNews ){
	                PollDiv.innerHTML = '<div style="text-align: center; color: #999999">'+
	                                    'Tentando carregar...<br>'+
	                                    '<img style="margin: 10px;" src="img/carregando.gif" width="30" border=0 /><br />'+
	                                    '<span style="font-size: 1em;">'+
	                                    'Os sites externos estão lentos. Por favor, aguarde um pouco mais.'+
	                                    '</span>'+
	                                    '</div>';
	            }
	        }, 10000);
	        //PollDiv.innerHTML = 'Carregando... <img src="img/layout/loading.gif" border=0 />';
	    }

	}
