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 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\(\)\s-]+$/)) {
				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 (url, obx) {
	if (confirm(decodeHTML('Realmente desexa marcar isto como inapropiado?'))) {
		$.ajax({
			url: '/ajax/inapropiado',
			cache: false,
			type: 'POST',
			data: 'url='+url,
			success: function (resp) {
				if (resp.length > 0) {
					alert(decodeHTML(resp));
				} else {
					alert(decodeHTML('A t&uacute;a solicitude ser&aacute; revisada o antes posible'));
				}

				if (obx) {
					$(obx).attr('onclick', 'return false;');
					$(obx).css('background', 'url(/imx/mal-off.png) no-repeat');
				} else {
					$('#inapropiado a').attr('onclick', 'return false;');
					$('#inapropiado a').css('background', 'url(/imx/mal-off.png) no-repeat');
				}
			}
		});
	}

	return false;
}

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