function login (pre) {
	var usuario = $('#'+pre+'-usuario');
	var contrasinal = $('#'+pre+'-contrasinal');

	if ((usuario.value == '') || (usuario.value == 'usuario')) {
		usuario.value = '';

		usuario.focus();

		return false;
	} else if ((contrasinal.value == '') || (contrasinal.value == '********')) {
		contrasinal.value = '';

		contrasinal.focus();

		return false;
	}

	submitonce();

	return true;
}

function submitonce () {
	var inputs = $('input');

	for (var i = 0; i < inputs.length; i++) {
		if ((inputs[i].type.toLowerCase() == 'submit') || (inputs[i].type.toLowerCase() == 'reset')) {
			inputs[i].disabled = true;
		}
	}

	return true;
}

function favorito (id, taboa) {
	$.ajax({
		url: '/ajax/favorito',
		cache: false,
		type: 'POST',
		data: 'id='+id+'&taboa='+taboa,
		success: function (resp) {
			if ((resp == 'on') || (resp == 'off')) {
				$('#ico-favorito').attr('src', '/imx/favorito-'+resp+'.png');
			} else {
				alert(decodeHTML(resp));
			}
		}
	});

	return false;
}
function vota (voto, taboa, id) {
	$.ajax({
		url: '/ajax/voto',
		cache: false,
		type: 'POST',
		data: 'puntos='+voto+'&id='+id+'&taboa='+taboa,
		success: function (resp) {
			if ((resp.length > 0) && !resp.match(/^[0-9-]+$/)) {
				alert(decodeHTML(resp));
			} else if (resp.length > 0) {
				$('#puntos').html('<strong>'+resp+'</strong>').fadeIn('slow');
			}

			$('#votacion a').attr('onclick', 'return false;');
			$('#votacion a.mola').css('background', 'url(/imx/mola-off.png) no-repeat');
			$('#votacion a.non-mola').css('background', 'url(/imx/non-mola-off.png) no-repeat');
		}
	});

	return false;
}

function inapropiado (msx) {
	if (confirm(decodeHTML(msx))) {
		$.ajax({
			url: '/ajax/inapropiado',
			cache: false,
			type: 'POST',
			success: function (resp) {
				alert(decodeHTML(resp));

				$('#inapropiado a').attr('onclick', 'return false;');
				$('#inapropiado a img').attr('src', '/imx/mal-off.png');
			}
		});
	}

	return false;
}

function ajax_opcion (cal, params) {
	if ($('#capa_'+cal).html() == '') {
		$('#capa_'+cal)
			.html('<div class="center" style="margin: 20px 0;"><img src="/imx/loading.gif" alt="..."></div>')
			.slideDown();

		$.ajax({
			url: '/ajax/'+cal,
			cache: false,
			type: 'POST',
			data: params,
			success: function (resp) {
				$('#capa_'+cal).html(resp);
			}
		});

		return false;
	}

	if ($('#capa_'+cal).is(':visible')) {
		$('#capa_'+cal).slideUp('slow');
	} else {
		$('#capa_'+cal).slideDown('slow');
	}

	return false;
}

function data_hoxe (campo) {
	var time = new Date;

	$('#'+campo+'d').children().each(function () {
		if ($(this).val() == time.getDate()) {
			$(this).attr('selected', 'selected');
			return false;
		}
	});

	$('#'+campo+'m').children().each(function () {
		if ($(this).val() == time.getMonth() + 1) {
			$(this).attr('selected', 'selected');
			return false;
		}
	});

	$('#'+campo+'Y').children().each(function () {
		if ($(this).val() == time.getFullYear()) {
			$(this).attr('selected', 'selected');
			return false;
		}
	});

	return false;
}

function decodeHTML (txt) {
	var ta = document.createElement('textarea');
	ta.innerHTML = txt.replace(/</g, '&lt;').replace(/>/g, '&gt;');
	return ta.value;
}
