/*******************************************************************************
 * This file is part of Educatio.
 *
 *     Educatio is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     Educatio is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with Educatio.  If not, see <http://www.gnu.org/licenses/>.
 *     
 *     Authors:
 *           Filipe Marinho de Brito - filipe.marinho.brito@gmail.com
 *           Rodrigo de Souza Ataides - rodrigoataides@gmail.com
 *******************************************************************************/
$(document).ready(function(){

	//BOTAO ENVIAR
	$("#salvarCalendarioeventoBtn_submitBtn").button().click(function(){ submitCalendarioevento(); });
	$("#downloadArquivoCalendarioEvento").button({icons: {primary: 'ui-icon-arrowthickstop-1-s'}, text: true})

});

//TRATAMENTO DA ACAO NO ONSUBMIT
function submitCalendarioevento(){
	$.ajax({
		"type": "POST",
		"contentType": "application/json; charset=utf-8",
		"dataType": "json",
		"url": "CandidatoEvento/candidatar?evento="+$("#evento").val(),
		"beforeSend": function(xhr,settings){},
		"error":trataErro,
		"complete": function(){},
		"success": function(data){
			messageBoxPopUp("CalendarioEvento_"+$("#id").val()+"_popUp", data.mensagem);
			setTimeout(function() {
				$("#salvarCalendarioeventoBtn_submitBtn").hide("slow");
				var lastModalID = $(".ui-dialog:visible").last().attr('aria-describedby');
				try{$("#"+lastModalID).dialog('close');
				$("#"+lastModalID).dialog('destroy');
				$("#"+lastModalID).remove();} catch(e){}
			},2500);
		}
	});
}



//POPULAR O FORMULARIO PARA VISUALIZACAO OU EDICAO
function preencherFormularioCalendarioevento(data){
	if(typeof(data) !== 'undefined'){
		$("#formCalendarioevento").populate(data,{resetForm:true});
//		var evento = data.evento;
//		var municipio = evento.municipio;
//		var estado = municipio.estado;
//		$("#eventoTematica").attr("value", evento.tematica);
//		$("#local").attr("value", municipio.nome + " - " + estado.uf);
//		$("#dataInicio").attr("value", evento.periodoInicial);
//		$("#dataFim").attr("value", evento.periodoFinal);
//		$("#publicoAlvo").attr("value", data.publicoAlvo);
//		$("#perfilIndicado").attr("value", data.perfilIndicado);
//		$("#descricaoEvento").attr("value", data.descricaoEvento);
		if ($("#arquivoID").val()=="") {
			$("#downloadArquivoCalendarioEvento").hide();
		}
	}
}


function completaHref() {
	if ($("#arquivoID").val()!="") {
		$("#downloadArquivoCalendarioEvento").attr('href', "Arquivo/download/" + $("#arquivoID").val());
	} else {
		return false;
	}
}










