$().ready( function() {
	confirmacao();
	zebra();
	printing();
	target();
	ieFlickerFix();
	masks();
});


function confirmacao() {
	$('a.confirmacao').bind('click', function() {
		var title = $(this).attr('title');
		if (!confirm(title)) {
			return false;
		}
	});
}


function printing() {
	$('.print').click( function() {
		window.print();
	});
}


function target() {
	$("a[@rel$='external']").each( function(){
		$(this).attr('target','_blank');
		$(this).attr('title', $(this).attr('title')+' (este link abre em nova janela)');
	});
}


function zebra() {
	$('table:not(.nozebra) tr:nth-child(odd)').addClass('par');
}


function ieFlickerFix() {
	try {
	  document.execCommand("BackgroundImageCache", false, true);
	} catch(err) {}
}

function masks() {
	$('.maskdate').mask('99/99/9999');
	$('.maskphone').mask('(99) 9999-9999');
	$('.maskcep').mask('99999-999');	
}

function affectedFields(form,el) {
	var classe = 'affected';
	$(form+' *').each( function() {
		if (el!='') {
			if ($(this).attr('id')==el) {
				$(this).focus().addClass(classe);
			} else {
				$(this).removeClass(classe);
			}
		} else {
			$(this).removeClass(classe);
			$(form).resetForm();
		}
	});
	return false;
}