$(document).ready(function() {
	zebraTables();
	clearDefaultFormValues();
	popOutsideLinks();
});

function zebraTables() {
	$('table').filter(':not(table.no-auto-zebra)').filter(':not(table.zebra-body-only)').each(function(i) {
		$(this).find('tr:even').addClass('odd');
	});
	
	// body only
	$('table.zebra-body-only tbody').each(function(i) {
		$(this).find('tr:even').addClass('odd');
	})
}

function clearDefaultFormValues() {
	$('input[type=text]')
		.each(function() {
			$(this)
				.focus(function() {
					if ($(this).val() == $(this).get(0).defaultValue) {
						$(this).val('');
					}
				})
				.blur(function() {
					if ($(this).val() == '') {
						$(this).val($(this).get(0).defaultValue);
					}
				});
		});
}

function popOutsideLinks() {
	$('a')
		.filter(function (index) {
			// apply to all non-local links
			return ($(this).attr('href').search(/http[s]?:\/\//i) > -1 && !$(this).hasClass('no-pop'));
		})
		.click(function(e) {
		e.preventDefault();
		window.open($(this).attr('href'));
		return false;
	});
}
