/* *****************************
 * 
 * Especifico para jornalismo 
 * Para mudar troque a variavel areaSelected pelo que vira no campo de Jornalismo
 * 
 * 
 * *****************************/

var areaSelected = 'Jornalismo';
function openFieldsByArea(area, fieldClass) {
	if (area === areaSelected) {
		$(fieldClass).show();
	} else {
		$(fieldClass).hide();
	}
}

/*******************************************************************************
 * 
 * Fim da funcao
 * 
 ******************************************************************************/

function removeClass(classToRemove, elements) {
	$(elements).each(function() {
		$(this).removeClass(classToRemove);
	});
}

function generateFieldsEscolas(from, to) {
	var generatedFields = $(from).html();
	var numberOfSchool = $('.escolas .escola-secretaria-detail').size() + 1;
	generatedFields = generatedFields.replace(/escola_/g,
			'escola' + numberOfSchool);

	$(to).append(generatedFields);
	$('.totaltrabalho').val(numberOfSchool);

}

function generateFieldsCargo(from, to, numberOfSchool) {
	var generatedFields = $(from).html();
	// var numberOfSchool = $('.escola-secretaria-detail' +
	// numberOfSchool).size() + 1;
	var numberOfItem = $(
			'.cadastro .escolas .escola-secretaria-detailescola'
					+ numberOfSchool + ' .lecionaescola' + numberOfSchool
					+ ' .generated-fields').size() + 1;
	generatedFields = generatedFields.replace(/escola-/g,
			'escola' + numberOfSchool);
	generatedFields = generatedFields.replace(/nivelensino_/g,
			'nivelensino' + numberOfItem);
	generatedFields = generatedFields.replace(/disciplina_/g,
			'disciplina' + numberOfItem);
	generatedFields = generatedFields.replace(/totalescola_/g,
			'totalescola' + numberOfSchool)

	$(to)
			.append(
					'<div class="generated-fields">' + generatedFields + '<\/div>');

	$('.totalescola' + numberOfSchool).val(numberOfItem)

}

function addSchools() {
	generateFieldsEscolas('.template-fields-escola', '.escolas');

	$('.escolas, .add-buttons-trabalho').show();

	var numberOfSchool = $('.escolas div.escola-secretaria-detail').size();
	$('.redeensino').change(
			function() {
				var classSelected = $(this).find('option:selected').attr(
						'class');
				$(this).parent('p').next('fieldset').find('p').hide();
				$(this).parent('p').next('fieldset').find('p.' + classSelected)
						.show();
				$(this).parent('p').next('fieldset').find('input').rules(
						'remove');
				$(this).parent('p').next('fieldset').find('input').removeClass(
						'required');

				/*
				 * switch (classSelected) { case 'cnpj-field':
				 * $(this).parent('p').next('fieldset').find('p.' +
				 * classSelected + ' input.cnpj').rules('add', { required: true,
				 * cnpj: true }); break; case 'mec-field':
				 * $(this).parent('p').next('fieldset').find('p.' +
				 * classSelected + ' input').rules('add', { required: true });
				 * 
				 * break; default:
				 * $(this).parent('p').next('fieldset').find('input').rules('remove');
				 * $(this).parent('p').next('fieldset').find('input').removeClass('required'); }
				 */
			})

	/* Alimentando campo de cidades */
	loadStateCity('#estadoescola' + numberOfSchool,
			'#cidadeescola' + numberOfSchool);

	/* Mascara campos */
	maskFields();

	/* Gera itens depois que troca o cargo para professor */
	$('.cargoescola' + numberOfSchool)
			.change(
					function() {
						if ($(this).val() === 'Professor') {
							var currentSchool = $(this).attr('name').replace(
									'cargoescola', '');
							if ($(
									'.cadastro .escolas .escola-secretaria-detailescola'
											+ currentSchool + ' .lecionaescola'
											+ currentSchool
											+ ' .generated-fields').size() < 1) {
								$(
										'.cadastro .escolas .escola-secretaria-detailescola'
												+ currentSchool
												+ ' .add-buttonsescola'
												+ currentSchool
												+ ' a.remove-button').hide();
							}

							generateFieldsCargo('.template-fields-cargo',
									'.content form.cadastro .escola-secretaria-detailescola'
											+ numberOfSchool
											+ ' fieldset.lecionaescola'
											+ numberOfSchool, numberOfSchool);
							$(
									'.content form.cadastro .escola-secretaria-detailescola'
											+ numberOfSchool
											+ ' fieldset.lecionaescola'
											+ numberOfSchool).show();
							$(
									'.content form.cadastro .add-buttonsescola' + numberOfSchool)
									.show();

						} else {
							var currentSchool = $(this).attr('name').replace(
									'cargoescola', '');

							$(
									'.escolas .escola-secretaria-detailescola'
											+ currentSchool + ' .lecionaescola'
											+ currentSchool).empty();
							$(
									'.escolas .escola-secretaria-detailescola'
											+ currentSchool
											+ ' .add-buttonsescola'
											+ currentSchool).hide();
							// alert('.cadastro .escolas
							// .escola-secretaria-detailescola'+numberOfSchool+'
							// .lecionaescola'+ numberOfSchool+ '
							// .generated-fields')
							// alert($('.cadastro .escolas
							// .escola-secretaria-detailescola'+numberOfSchool+'
							// .lecionaescola'+ numberOfSchool+ '
							// .generated-fields').size())
							if ($(
									'.cadastro .escolas .escola-secretaria-detailescola'
											+ numberOfSchool
											+ ' .lecionaescola'
											+ numberOfSchool
											+ ' .generated-fields').size() == 1) {
								$(
										'.cadastro .escolas .escola-secretaria-detailescola'
												+ numberOfSchool
												+ ' .add-buttonsescola'
												+ numberOfSchool
												+ ' a.remove-button').hide();
							}
						}

					});

	/*
	 * Adicionar um item de nivel de ensino e disciplina ao clicar no botao
	 * adicionar Mostra o botao de excluir se o total de itens gerados for maior
	 * que 1
	 * 
	 */
	$(
			'.cadastro .escolas .escola-secretaria-detailescola'
					+ numberOfSchool + ' .add-buttonsescola' + numberOfSchool
					+ ' a.add-button')
			.click(
					function() {
						if ($(
								'.cadastro .escolas .escola-secretaria-detailescola'
										+ numberOfSchool + ' .lecionaescola'
										+ numberOfSchool + ' .generated-fields')
								.size() > 0) {
							$(
									'.content form.cadastro .add-buttonsescola' + numberOfSchool + ' a.remove-button')
									.show();
						}
						;
						generateFieldsCargo('.template-fields-cargo',
								'.lecionaescola' + numberOfSchool,
								numberOfSchool);
						return false;
					});

	/*
	 * 
	 * Remove o ultimo item de nivel de ensino e disciplina ao clicar no botao
	 * remover Exclui o botao remover se o total de itens gerados for igual a 1
	 * 
	 */
	$(
			'.cadastro .escolas .escola-secretaria-detailescola'
					+ numberOfSchool + ' .add-buttonsescola' + numberOfSchool
					+ ' a.remove-button')
			.click(
					function() {
						$(
								'.cadastro .escolas .escola-secretaria-detailescola'
										+ numberOfSchool + ' .lecionaescola'
										+ numberOfSchool
										+ ' .generated-fields:last').remove();
						$('.totalescola' + numberOfSchool).val(
								$(
										'.cadastro .escolas .escola-secretaria-detailescola'
												+ numberOfSchool
												+ ' .lecionaescola'
												+ numberOfSchool
												+ ' .generated-fields').size())
						if ($(
								'.cadastro .escolas .escola-secretaria-detailescola'
										+ numberOfSchool + ' .lecionaescola'
										+ numberOfSchool + ' .generated-fields')
								.size() == 1) {
							$(
									'.cadastro .escolas .escola-secretaria-detailescola'
											+ numberOfSchool
											+ ' .add-buttonsescola'
											+ numberOfSchool
											+ ' a.remove-button').hide();
						}
						return false;

					});

	if ($('.cadastro .escolas .escola-secretaria-detail').size() > 1) {
		$('.add-buttons-trabalho .remove-buttontrabalho').show();
	}

}

function removeSchools() {
	$('.cadastro .escolas .escola-secretaria-detail:last').remove();
	$('.totaltrabalho').val($('.totaltrabalho').val() - 1);
	if ($('.cadastro .escolas .escola-secretaria-detail').size() == 1) {
		$('.add-buttons-trabalho .remove-buttontrabalho').hide();
	}
}

function maskFields() {
	try {
		$(".cep").mask("99999-999");
		$(".telefone").mask("(99) 9999-9999");
		$(".cnpj").mask("99.999.999/9999-99");
		$(".cpf").mask("999.999.999-99");

	} catch (err) {
	}
	;
}

function loadStateCity(state, city) {
	try {
		new dgCidadesEstados( {
			estado : $(state).get(0),
			cidade : $(city).get(0)
		});
	} catch (error) {
	}

}
function geraFiltro(campo) {

	pathArray = window.location.pathname.split('/');

	url = URL_VIRTUAL + 'acoes/geraFiltro';

	tipo = $("#categoria").selectedValues();

	$.post(url, {

		tipo : tipo

	}, function(data) {

		$("." + campo).empty();
		$("." + campo).html(data);

	});

}

function geraSelectProjeto(campo) {

	pathArray = window.location.pathname.split('/');

	url = URL_VIRTUAL + 'acoes/geraSelectProjeto';

	catId = $("#categoria").selectedValues();
	ensId = $("#ensino").selectedValues();

	$.post(url, {

		catId : catId,
		ensId : ensId

	}, function(data) {

		$("#" + campo).removeOption(/./);
		$("#" + campo).html(data);

	});

}

function geraSelectColecoes(campo) {

	pathArray = window.location.pathname.split('/');

	url = URL_VIRTUAL + 'acoes/geraFiltroColecoes';

	catId = $("#categoria").selectedValues();
	ensId = $("#ensino").selectedValues();

	$.post(url, {

		catId : catId,
		ensId : ensId

	}, function(data) {

		$("#" + campo).removeOption(/./);
		$("#" + campo).html(data);

	});

}
function stripVowelAccent(str) {
	var rExps = [ {
		re : /[\xC0-\xC6]/g,
		ch : 'A'
	}, {
		re : /[\xE0-\xE6]/g,
		ch : 'a'
	}, {
		re : /[\xC8-\xCB]/g,
		ch : 'E'
	}, {
		re : /[\xE8-\xEB]/g,
		ch : 'e'
	}, {
		re : /[\xCC-\xCF]/g,
		ch : 'I'
	}, {
		re : /[\xEC-\xEF]/g,
		ch : 'i'
	}, {
		re : /[\xD2-\xD6]/g,
		ch : 'O'
	}, {
		re : /[\xF2-\xF6]/g,
		ch : 'o'
	}, {
		re : /[\xD9-\xDC]/g,
		ch : 'U'
	}, {
		re : /[\xF9-\xFC]/g,
		ch : 'u'
	}, {
		re : /[\xD1]/g,
		ch : 'N'
	}, {
		re : /[\xF1]/g,
		ch : 'n'
	} ];

	for ( var i = 0, len = rExps.length; i < len; i++)
		str = str.replace(rExps[i].re, rExps[i].ch);

	return str;
}

function filtrarLivros(pagina) {

	pathArray = window.location.pathname.split('/');
	var categoria = $("#categoria").selectedValues();
	var categoriaAlias = $("#categoria option:selected").attr('id');
	var palavras = $('#palavras').val();
	var previousUrl = $('#previousUrl').val();

	if (categoria == 0) {
		if (palavras == '') {
			var url = URL_ABSOLUTA + 'buscarLivro/todos/todos/todos/todos/'
					+ pagina;
		} else {
			var url = URL_ABSOLUTA + 'buscarLivro/todos/todos/todos/todos/'
					+ palavras + '/' + pagina;
		}
	}
	if (categoria == 1) {

		ensinoAlias = $("#ensino option:selected").attr('id');
		projetoAlias = $("#projeto option:selected").attr('id');
		colecaoAlias = 'todos';
		var arrayCampos = new Object();
		$(".campos").each(function(i, selected) {

			arrayCampos[i] = $(selected).val();

		});

		var url = URL_ABSOLUTA + 'buscarLivro/' + categoriaAlias + '/'
				+ ensinoAlias + '/' + projetoAlias + '/' + colecaoAlias;

		for ( var n in arrayCampos) {
			if (arrayCampos[n] != 'todos') {
				url += '/' + arrayCampos[n];
			}
		}

		if (palavras != '') {

			palavras = palavras.toLowerCase();
			palavras = stripVowelAccent(palavras);
			palavras = palavras.replace(' ', '-');
			url += '/' + palavras;

		}

		url += '/' + pagina;

	}
	if (categoria == 2) {

		ensinoAlias = $("#ensino option:selected").attr('id');
		projetoAlias = 'todos';
		colecaoAlias = $("#colecao option:selected").attr('id');
		var arrayCampos = new Object();
		$(".campos").each(function(i, selected) {
			if (arrayCampos[n] != 'todos') {
				arrayCampos[i] = $(selected).val();
			}
		});

		var url = URL_ABSOLUTA + 'buscarLivro/' + categoriaAlias + '/'
				+ ensinoAlias + '/' + projetoAlias + '/' + colecaoAlias;

		for ( var n in arrayCampos) {
			if (arrayCampos[n] != 'todos') {
				url += '/' + arrayCampos[n];
			}
		}

		if (palavras != '') {

			palavras = palavras.toLowerCase();
			palavras = stripVowelAccent(palavras);
			palavras = palavras.replace(' ', '-');
			url += '/' + palavras;

		}

		url += '/' + pagina;

	}
	if (categoria == 3) {

		ensinoAlias = $("#ensino option:selected").attr('id');
		projetoAlias = $("#projeto option:selected").attr('id');
		colecaoAlias = 'todos';
		var arrayCampos = new Object();
		$(".campos").each(function(i, selected) {

			arrayCampos[i] = $(selected).val();

		});

		var url = URL_ABSOLUTA + 'buscarLivro/' + categoriaAlias + '/'
				+ ensinoAlias + '/' + projetoAlias + '/' + colecaoAlias;

		for ( var n in arrayCampos) {
			if (arrayCampos[n] != 'todos') {
				url += '/' + arrayCampos[n];
			}
		}

		if (palavras != '') {

			palavras = palavras.toLowerCase();
			palavras = stripVowelAccent(palavras);
			palavras = palavras.replace(' ', '-');
			url += '/' + palavras;

		}

		url += '/' + pagina;

	}
	if (categoria == 4) {

		ensinoAlias = $("#ensino option:selected").attr('id');
		projetoAlias = 'todos';
		colecaoAlias = 'todos';
		var arrayCampos = new Object();
		$(".campos").each(function(i, selected) {

			arrayCampos[i] = $(selected).val();

		});

		var url = URL_ABSOLUTA + 'buscarLivro/' + categoriaAlias + '/'
				+ ensinoAlias + '/' + projetoAlias + '/' + colecaoAlias;

		for ( var n in arrayCampos) {
			if (arrayCampos[n] != 'todos') {
				url += '/' + arrayCampos[n];
			}
		}

		if (palavras != '') {

			palavras = palavras.toLowerCase();
			palavras = stripVowelAccent(palavras);
			palavras = palavras.replace(' ', '-');
			url += '/' + palavras;

		}

		url += '/' + pagina;

	}
	if (categoria == 5) {

		ensinoAlias = $("#ensino option:selected").attr('id');
		projetoAlias = 'todos';
		colecaoAlias = 'todos';
		var arrayCampos = new Object();
		$(".campos").each(function(i, selected) {

			arrayCampos[i] = $(selected).val();

		});

		var url = URL_ABSOLUTA + 'buscarLivro/' + categoriaAlias + '/'
				+ ensinoAlias + '/' + projetoAlias + '/' + colecaoAlias;

		for ( var n in arrayCampos) {
			if (arrayCampos[n] != 'todos') {
				url += '/' + arrayCampos[n];
			}
		}

		if (palavras != '') {

			palavras = palavras.toLowerCase();
			palavras = stripVowelAccent(palavras);
			palavras = palavras.replace(' ', '-');
			url += '/' + palavras;

		}

		url += '/' + pagina;

	}
	if (categoria == 7) {

		ensinoAlias = $("#ensino option:selected").attr('id');
		projetoAlias = 'todos';
		colecaoAlias = 'todos';
		var arrayCampos = new Object();
		$(".campos").each(function(i, selected) {

			arrayCampos[i] = $(selected).val();

		});

		var url = URL_ABSOLUTA + 'buscarLivro/' + categoriaAlias + '/'
				+ ensinoAlias + '/' + projetoAlias + '/' + colecaoAlias;

		for ( var n in arrayCampos) {
			if (arrayCampos[n] != 'todos') {
				url += '/' + arrayCampos[n];
			}
		}

		if (palavras != '') {

			palavras = palavras.toLowerCase();
			palavras = stripVowelAccent(palavras);
			palavras = palavras.replace(' ', '-');
			url += '/' + palavras;

		}

		url += '/' + pagina;

	}
	if (previousUrl != '') {

		url = previousUrl;
		$('#previousUrl').val('');

	}

	order = $('#form-order').selectedValues();

	$.post(url, {

		order : order

	}, function(data) {

		$(".resultados-catalogo").empty();
		$(".resultados-catalogo").html(data);

	});

}

function loadingRate(element) {
	$(element).hover(function() {
		setRating(this, 'over');
	}, function() {
		removeRating(this, 'over');
	});

	$(element).click(function() {
		avaliar(this);
		setRating(this, 'on');

		$(element).unbind('onmouseout');

	});

	$('.remove-rating').click(function() {
		removerVoto(this);
		removeRating(element, 'on');
		$(element).bind('onmouseout', function() {
			removeRating(this, 'over');
		});
	});

}

function setRating(element, setClass) {
	$(element).addClass(setClass);
	$(element).prevAll().addClass(setClass);
	$(element).nextAll().removeClass(setClass);
}

function avaliar(element) {
	
	 var livroId = $('#livroId').val();
	 var nota = $(element).attr('id');
	
	url = URL_VIRTUAL+'acoes/avaliacoesVotar';

	$.post(url, {

		nota : nota,
		livroId : livroId

	}, function(data) {

		
		
	});

}

function removerVoto(element) {

	var nota = $(element).attr('id');
	var livroId = $('#livroId').val();

	pathArray = window.location.pathname.split('/');

	url = URL_VIRTUAL+'acoes/avaliacoesRemoverVoto';

	$.post(url, {

		nota : nota,
		livroId : livroId

	}, function(data) {

	});

}

function removeRating(element, removeClass) {
	$(element).parent('ul').find('li').removeClass(removeClass);
}

function login() {
	var pathArray = window.location.pathname.split('/');
	var booValidation = true;
	var url = URL_VIRTUAL + 'acoes/logarProfessor';

	var email = $(".form-login #email").val();
	var senha = $(".form-login #senha").val();

	$('label,input').not('.bt-buscar input').removeClass('error')
	$('.form-login p.error-container').hide();

	if (jQuery.trim(email) != '') {
		booValidation = validaEmail(email)
	} else {
		booValidation = false
	}

	if (jQuery.trim(senha) == '') {
		booValidation = false;
	}

	if (booValidation) {

		$.post(url, {
			email : email,
			senha : senha

		}, function(data) {

			if (data == 1) {
				tb_remove();
				window.location.reload();
			} else {
				$('.form-login p.sem-acesso').show();
			}

		})
	} else {
		$('label,input').not('.bt-buscar input').addClass('error')
		$('.form-login p.nao-preenchido').show();
	}
	;

	return false;
}

function validaEmail(value) {
	return /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i
			.test(value)
}

function loadProjectButtons(menuElement, contentElement) {
	
	$(menuElement).click(function() {
		var classSelected = $(this).attr('id').replace(/buttons-/g, 'detail-');
		$(this).parent('ul').find('li').removeClass('on');
		$(this).addClass('on');

		$(contentElement).not(contentElement + ' li').hide();
		if (classSelected != '')
			$(contentElement + '.' + classSelected+',' +contentElement + '.' + classSelected + ' li').show();
			//alert(contentElement + '.' + classSelected + ' li')
			
	}).hover(function() {
		$(this).parent('ul li').removeClass('over');
		$(this).addClass('over');
	}, function() {
		$(this).removeClass('over');
	});

	$(menuElement + ':first').addClass('on');
	$(contentElement + ':first').show();

	// $('.recurso

	if ($('.menu-projetos li').size() > 0) {
		var hash = window.location.hash;
		
		var classItem;

		if (hash != '') {
			hash = hash.replace('#', '');

			switch (hash) {
			case 'recursos':
				classItem = 'recurso';
				break;
			default:
				classItem = hash;

			}
			removeClass('on', '.menu-projetos li');
			$('.box-o-projeto li').hide();
			$('.menu-projetos li.buttons-' + classItem).addClass('on');
			
			$('.box-o-projeto li.detail-' + classItem + ', .box-o-projeto li.detail-' + classItem + ' li').show();
			$('.return-resource ul li').show();
			
		}
	}

}

function removeLinkActions(elements) {
	$(elements).click(function(event) {
		event.preventDefault();
	});
}

function loadBookTabs() {
	
	$('.book-content .tabs li').click(function() {
		
		var classItem = this.className.replace(' on', '');
		
		removeClass('on', '.book-content .tabs li');
		$(this).addClass('on');
		
		$('.book-content div').not('.book-content div div').hide();
		$('.book-content div div, .canal-content div div').show();
		$('.book-content div.' + classItem).show();
		
	});

	if ($('.book-content .tabs li, .canal-content .tabs li').size() > 0) {
		var hash = window.location.hash;
		var classItem;

		if (hash != '') {

			hash = hash.replace('#', '');

			switch (hash) {
			case 'recursos':
				classItem = 'recursos-para-professor';
				break;
			default:
				classItem = hash;

			}

			removeClass('on', '.book-content .tabs li, .canal-content .tabs li');
			$('.book-content .tabs li.' + classItem+ ', .canal-content .tabs li.' + classItem).addClass('on');
			$('.book-content div, .canal-content div').not('.book-content div div, .canal-content div div').hide();
			$('.book-content div div, .canal-content div div').show();
			$('.book-content div.' + classItem + ', .canal-content div.'+ classItem).show();
		}
		
	}

}

function mudaColecoes() {

	var colecao = $("#colecao option:selected").val();
	
	if(location.pathname.indexOf('/')!=-1){
		var pathArray = location.pathname.split('/');
	
		if (pathArray[1] == 'sm') {
			var url = URL_ABSOLUTA + '' + pathArray[2] + '/' + pathArray[3] + '/' +pathArray[4] +'/' +colecao;
		}
		else{
			var url = URL_ABSOLUTA + '' + pathArray[1] + '/' + pathArray[2] + '/' + pathArray[3] +'/' + colecao;
		}
		window.location = url;
		
	}
	

}
function vaiCatalogo(element) {

	var colecao = $("#colecao option:selected").val();
	if (location.pathname.indexOf('/') != -1) {
	
		var pathArray = location.pathname.split('/');
		
		if (pathArray[1] == 'sm') {
			var url = URL_ABSOLUTA + 'catalogo/' + pathArray[2] + '/' + pathArray[3] + '/' + pathArray[4] + '/todos/' + colecao + '/0';
		}
		else {
			var url = URL_ABSOLUTA + 'catalogo/' + pathArray[1] + '/' + pathArray[2] + '/' + pathArray[3] + '/' + pathArray[4] + '/todos/' + colecao + '/0';
		}
		
		window.location = url;
	}

}
function filtrarRecursosTema(pagina, externo) {
	
	var temaEnsino = $('#temaEnsino').val();
	if (externo == 1) {
		var temaTema = $('#temaTemaExterno').val();
	} else {
		var temaTema = $('#temaTema').val();
	}
	var temaPalavra = $('#temaPalavra').val();
	if (temaPalavra == '') {

		var temaPalavra = 'todos';

	}

	pathArray = window.location.pathname.split('/');

	url = URL_VIRTUAL + 'acoes/filtrarConteudoPorTema/' + pagina;

	$.post(url, {

		temaEnsino : temaEnsino,
		temaTema : temaTema,
		temaPalavra : temaPalavra

	}, function(data) {
		
		$('.conteudo-propostas').empty();
		$('.conteudo-propostas').html(data);
				
		tb_init('a.thickbox, area.thickbox, input.thickbox');
	});

}

function mudaAbaRecurso(estou, vou) {

	$('.' + estou).removeClass('on');
	$('.' + vou).addClass('on');
	$('.' + estou + 'ResultadosTema').hide();
	$('.' + vou + 'ResultadosTema').show();

}

function filtrarRecursosDisciplina(pagina) {

	disciplinaCategoria = $('#disciplinaCategoria').val();
	disciplinaTipo = $('#disciplinaTipo').val();
	disciplinaAno = $('#disciplinaAno').val();

	disciplinaEnsino = $('#disciplinaEnsino').val();

	disciplinaColecao = $('#disciplinaColecao').val();
	disciplinaProjeto = $('#disciplinaProjeto').val();
	disciplinaPalavra = $('#disciplinaPalavra').val();

	if (disciplinaPalavra == '') {

		disciplinaPalavra = 'todos';

	}

	pathArray = window.location.pathname.split('/');

	url = URL_VIRTUAL + 'acoes/filtrarConteudoPorDisciplina/' + pagina;

	$.post(url, {

		disciplinaCategoria : disciplinaCategoria,
		disciplinaTipo : disciplinaTipo,
		disciplinaAno : disciplinaAno,
		disciplinaEnsino : disciplinaEnsino,
		disciplinaColecao : disciplinaColecao,
		disciplinaProjeto : disciplinaProjeto,
		disciplinaPalavra : disciplinaPalavra

	}, function(data) {

		$('.conteudo-propostas').empty();
		$('.conteudo-propostas').html(data);

	});

}


/*function abaFiltraRecursos(clickableItem){
	$(clickableItem).click(function(){
		$('.content-result').hide();
		filtrarRecursosTema('0',1);
		$('.propostas').click();
		
	});
}*/


function toogleResult(clickableItem, allItens){
	
	$(clickableItem).click(function(event){
		//event.preventDefault();
		$(allItens).hide();
		$(clickableItem).next('.content-result').show();
	});
	$(clickableItem).next('.content-result').show();
}
