var cotCidSel = 0;

function ajaxLoadQuotesHomePage() {
	var data = new Date();
	var ajax = AjaxStart();
	if(!ajax) { showMessage('error','Não foi possível atualizar as cotações!'); return false; }
	var objLoading = MM_findObj('ajaxQuotesLoading');
	var objQuotes = MM_findObj('ajaxQuotesBox');
	
	ajax.open("GET", "modules/ajax/cotacoes.home.html.php?area="+id_area+"&time="+data.getTime()+"&ajax", true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	ajax.onreadystatechange = function() {
		try {
			//CARREGANDO CONTEÚDO DO ARQUIVO
			if(ajax.readyState == 1) {
				if(objLoading) objLoading.style.display = '';
				objQuotes.innerHTML = '';
				objQuotes.style.display = 'none';
			}
		
			if(ajax.readyState == 4 ) {
				setTimeout("ajaxLoadQuotesHomePage()",5*60000);
				if(objLoading) objLoading.style.display = 'none';
				
				if (ajax.status == 200) {
					objQuotes.innerHTML = ajax.responseText;
					objQuotes.style.display = '';
					//alteraCotCidade();
				} else {
					showMessage('error','Não foi possível atualizar as cotações! Verifique sua conexão e clique em atualizar.');
				}
			}
		} catch(err) { 
			showMessage('error','Ocorreu um erro ao atualizar as cotações!');
		}
	}
	ajax.send("");
	return true;	
}

function alteraCotCidade() {
	var totalCidades = $('.listaCidadesCotacao .cidadeCotacao').length;
	if(totalCidades) {
		$('#cotacaoCidade_' + cotCidSel).hide();
		cotCidSel++;
		if(cotCidSel >= totalCidades) { cotCidSel = 0; }
		$('#cotacaoCidade_' + cotCidSel).show();
	}
}

function enviaContribuicao (){
	var data = new Date();
	var Contribuir = $('#contribuir').val();
	if(!Contribuir){
		alert('Por favor, preencha o campo.');
	}else{
		$.post('modules/ajax/contribuir.php?contribuicao='+Contribuir+'&time='+data.getTime(), function (dados){
			alert(dados);
		});
	}
}

function AjustaTamanhoJornal () {
	var TamanhoNoticias;
	var ajaxQuotesBox = $('#ajaxQuotesBox').height();
	var menu = $('#menu').height();
	TamanhoNoticias = ajaxQuotesBox;
	if(menu >= ajaxQuotesBox){
		TamanhoNoticias = menu;
	}
	$('#boxNoticiasDestaque').css('height', TamanhoNoticias + 'px');
}
