$(document).ready(
	function() {

		//------------------
		// INPUT fields default values
		//------------------

		$('INPUT[@onempty]').focus(
			function() {
				var obj = $(this).get(0);
				if(obj.value == $(this).attr('onempty')) { obj.value = ''; }
			}
		)

		$('INPUT[@onempty]').blur(
			function() {
				var obj = $(this).get(0);
				if(obj.value == '') { obj.value = $(this).attr('onempty'); }
			}
		)

	}
)


//------------------------
// Sub-Areas
//------------------------
function switchSubArea(obj) {
	if($(obj).hasClass('ArticleTabTitleSel')) { return(false); }
	$('.ArticleTabContent').hide('fast');
	$('.ArticleTabTitleSel').addClass('ArticleTabTitle');
	$('.ArticleTabTitle').removeClass('ArticleTabTitleSel');
	$(obj).removeClass('ArticleTabTitle');
	$(obj).addClass('ArticleTabTitleSel');
	$(obj).next().show('fast');
}


//------------------------
// Home search form
//------------------------
function onSubmitHomeSearchForm(sDefaultValue, sErrorText) {
	if($('#pesquisa_homepage INPUT[@name=q]').get(0).value == sDefaultValue) {
		alert(sErrorText);
		return(false);
	}
	return(true);
}


//------------------------
// Advogados search form
//------------------------

function onSubmitAdvogadosSearchForm() {
	$.post('ajx.adv_pesquisa.php', $('#pesquisa_advogados').serialize(), function(data) {
		$('.AdvogadosResults').html(data);
		try { window.location = "#anchor_search_results"; } catch(err) {}
	});
	return(false);
}

function onClickAdvogadosLetter(obj, sChar) {
	$('.LetterMenuSearch A').removeClass('Sel');
	
	if($('INPUT[@name=firstchar]').get(0).value==sChar) {
		$('INPUT[@name=firstchar]').get(0).value='';
	}
	else {
		$(obj).addClass('Sel');
		$('INPUT[@name=firstchar]').get(0).value=sChar;
	}

	onSubmitAdvogadosSearchForm();
	return(false);
}

function onChangeAdvogadosCategory(obj) {
	if($(obj).attr('checked')) {
		if($(obj).attr('value') == 'todos') {
			$('#pesquisa_advogados .InputAdvogadosType[@value=socios]').removeAttr('checked');
			$('#pesquisa_advogados .InputAdvogadosType[@value=associados]').removeAttr('checked');
			$('#pesquisa_advogados .InputAdvogadosType[@value=estagiarios]').removeAttr('checked');
		}
		else {
			$('.InputAdvogadosType[@value=todos]').removeAttr('checked');
		}
	
	}
	return(true);
}

function onClickAdvogadosClean() {
	$('.LetterMenuSearch A').removeClass('Sel');
	$('#pesquisa_advogados INPUT[@name=firstchar]').each(function() { this.value = ''; })
	$('#pesquisa_advogados INPUT[@type=text]').each(function() { this.value = ''; })
	$('#pesquisa_advogados SELECT').selectOptions('');
	$('#pesquisa_advogados .InputAdvogadosType[@value=socios]').removeAttr('checked');
	$('#pesquisa_advogados .InputAdvogadosType[@value=associados]').removeAttr('checked');
	$('#pesquisa_advogados .InputAdvogadosType[@value=estagiarios]').removeAttr('checked');
	$('#pesquisa_advogados .InputAdvogadosType[@value=todos]').attr('checked','checked');
	return(false);
}


//------------------
// Notícias
//------------------

function onSubmitFilterNoticias() {
	var filter_year = $('.FilterNoticias SELECT[@name=filter_year] option:selected').attr('value');
	var filter_month = $('.FilterNoticias SELECT[@name=filter_month] option:selected').attr('value');
	if(((filter_year == '') || (filter_year == undefined)) &&
	   ((filter_month != '') && (filter_month != undefined))) {
		alert(MESSAGE_AnoValido);
		return(false);
	}
}

function onChangeFilterNoticiasYear(iCategoryId) {
	var filter_year = $('.FilterNoticias SELECT[@name=filter_year] option:selected').attr('value');
	$('.FilterNoticias SELECT[@name=filter_month]').attr('disabled', 'disabled');

	$.get("ajx.get_months.php", { filter_year:filter_year, iCatId:iCategoryId },
		function(data){
			$('.FilterNoticias SELECT[@name=filter_month]').html(data);
			$('.FilterNoticias SELECT[@name=filter_month]').removeAttr('disabled');
		}
	);
}


//------------------
// Premios
//------------------

function onSubmitFilterPremios() {
	var filter_year = $('.FilterPremios SELECT[@name=filter_year] option:selected').attr('value');
	var filter_month = $('.FilterPremios SELECT[@name=filter_month] option:selected').attr('value');
	if(((filter_year == '') || (filter_year == undefined)) &&
	   ((filter_month != '') && (filter_month != undefined))) {
		alert(MESSAGE_AnoValido);
		return(false);
	}
}


//------------------
// Publicacoes
//------------------

function onSubmitFilterPublicacoes() {
	var filter_year = $('.FilterPublicacoes SELECT[@name=filter_year] option:selected').attr('value');
	var filter_month = $('.FilterPublicacoes SELECT[@name=filter_month] option:selected').attr('value');
	if(((filter_year == '') || (filter_year == undefined)) &&
	   ((filter_month != '') && (filter_month != undefined))) {
		alert(MESSAGE_AnoValido);
		return(false);
	}
}

function onChangeFilterPublicacoesYear(iCategoryId) {
	var filter_year = $('.FilterPublicacoes SELECT[@name=filter_year] option:selected').attr('value');
	$('.FilterPublicacoes SELECT[@name=filter_month]').attr('disabled', 'disabled');

	$.get("ajx.get_months.php", { filter_year:filter_year, iCatId:iCategoryId },
		function(data){
			$('.FilterPublicacoes SELECT[@name=filter_month]').html(data);
			$('.FilterPublicacoes SELECT[@name=filter_month]').removeAttr('disabled');
		}
	);
}


//------------------
// Newsletters
//------------------

function onSubmitFilterNewsletters() {
	var filter_year = $('.FilterNewsletters SELECT[@name=filter_year] option:selected').attr('value');
	var filter_month = $('.FilterNewsletters SELECT[@name=filter_month] option:selected').attr('value');
	if(((filter_year == '') || (filter_year == undefined)) &&
	   ((filter_month != '') && (filter_month != undefined))) {
		alert(MESSAGE_AnoValido);
		return(false);
	}
}

function onChangeFilterNewslettersYear(iCategoryId) {
	var filter_year = $('.FilterNewsletters SELECT[@name=filter_year] option:selected').attr('value');
	$('.FilterNewsletters SELECT[@name=filter_month]').attr('disabled', 'disabled');

	$.get("ajx.get_months.php", { filter_year:filter_year, iCatId:iCategoryId },
		function(data){
			$('.FilterNewsletters SELECT[@name=filter_month]').html(data);
			$('.FilterNewsletters SELECT[@name=filter_month]').removeAttr('disabled');
		}
	);
}






