function updateVoteDivs(vote, jornada_num, match_id, hvote){
	
	/***
	var div1_html = "<a onclick=\"new Ajax.Updater('response_" + jornada_num + "_1', '/quiniela15_dev.php/quiniela/saveVote', {asynchronous:true, evalScripts:false, onComplete:function(request, json){updateVoteDivs('1', '" + jornada_num + "', '" + match_id + "', 'hvote')}, parameters:'vote=1&match_id=" + match_id + "'});; return false;\" href='#'><img alt='1' src='/images/1.gif' width='13' height='21'/></a>";
	var divX_html = "<a onclick=\"new Ajax.Updater('response_" + jornada_num + "_X', '/quiniela15_dev.php/quiniela/saveVote', {asynchronous:true, evalScripts:false, onComplete:function(request, json){updateVoteDivs('X', '" + jornada_num + "', '" + match_id + "', 'hvote')}, parameters:'vote=X&match_id=" + match_id + "'});; return false;\" href='#'><img alt='X' src='/images/x.gif' width='13' height='21'/></a>";
	var div2_html = "<a onclick=\"new Ajax.Updater('response_" + jornada_num + "_2', '/quiniela15_dev.php/quiniela/saveVote', {asynchronous:true, evalScripts:false, onComplete:function(request, json){updateVoteDivs('2', '" + jornada_num + "', '" + match_id + "', 'hvote')}, parameters:'vote=2&match_id=" + match_id + "'});; return false;\" href='#'><img alt='2' src='/images/2.gif' width='13' height='21'/></a>";
	***/
	
	var div1_html = "<a onclick=\"new Ajax.Updater('response_" + jornada_num + "_1', '/quiniela/saveVote', {asynchronous:true, evalScripts:false, onComplete:function(request, json){updateVoteDivs('1', '" + jornada_num + "', '" + match_id + "', 'hvote')}, parameters:'vote=1&match_id=" + match_id + "'});; return false;\" href='#'><img alt='1' src='/images/1.gif' width='13' height='21'/></a>";
	var divX_html = "<a onclick=\"new Ajax.Updater('response_" + jornada_num + "_X', '/quiniela/saveVote', {asynchronous:true, evalScripts:false, onComplete:function(request, json){updateVoteDivs('X', '" + jornada_num + "', '" + match_id + "', 'hvote')}, parameters:'vote=X&match_id=" + match_id + "'});; return false;\" href='#'><img alt='X' src='/images/x.gif' width='13' height='21'/></a>";
	var div2_html = "<a onclick=\"new Ajax.Updater('response_" + jornada_num + "_2', '/quiniela/saveVote', {asynchronous:true, evalScripts:false, onComplete:function(request, json){updateVoteDivs('2', '" + jornada_num + "', '" + match_id + "', 'hvote')}, parameters:'vote=2&match_id=" + match_id + "'});; return false;\" href='#'><img alt='2' src='/images/2.gif' width='13' height='21'/></a>";
	

	var div1 = 'response_' + jornada_num + '_1';
	var divX = 'response_' + jornada_num + '_X';
	var div2 = 'response_' + jornada_num + '_2';
	
	// set the vote in the hiden field
	$(hvote + '_' + jornada_num).value = vote;
	
	if (vote == '1') {
		$(divX).innerHTML = divX_html;
		$(div2).innerHTML = div2_html;
	}
	else if (vote == '2') {
		$(div1).innerHTML = div1_html;
		$(divX).innerHTML = divX_html;
	}
	else if (vote == 'X') {
		$(div1).innerHTML = div1_html;
		$(div2).innerHTML = div2_html;
	}
}

/**
 *	Chequea que los match_num pronosticos de la jornada se hayan completado
 *
 */
function validateForecast(match_num) {
	var aux_elem = '';
	for (var i = 1; i <= match_num; i++) {
		aux_elem = 'hvote_' + i;
		if ($(aux_elem).value == '') {
			//$('forecast_error_js').show();
			// reset the alert changes to show
			$('mostrar_alerta_quiniela').value = 0;
			alert('pornóstico incompleto, debes completar la quiniela para que pueda ser guardada');
			return false;
		}
	}
	return true;
}

/**
 *	Devuelve el string con el forecast realizado por el usuario
 *
 */
function newUserBets(match_num) {
	var aux_elem = '';
	var new_bets = '';
	for (var i = 1; i <= match_num; i++) {
		aux_elem = 'hvote_' + i;
		new_bets += $(aux_elem).value + ',';
	}
	return new_bets.substr(0, new_bets.length - 1);
}

function submitForm(form) {
	$(form).submit();
}
