$jq(document).ready(function(){
    //for scroll in left_side
	$jq('#test').serialScroll({
		items: 'li',
		duration: 500,
		force: false,
		axis: 'y',
		start: 0,
		step: 1,
		lock: false,
		stop: false,
		constant: false,
		prev: 'div#testprev a',
		next: 'div#testnext a',
		cycle: false
	});


    $jq('a#ok_q').click(function(){ //to accept the answer
    	if(!$jq(this).hasClass('no_q')){
	    	t = $jq('#t').val();
	    	q = $jq('#q').val();
	    	u = $jq('#u').val();
	    	a = '';
	    	for(i=1; i<4; i++) a = document.getElementById('r_'+i).checked ? $jq('#r_' + i).val() : a;
	    	if(a){
	    		url_ = 't=' + t + '&q=' + q + '&u=' + u + '&a=' + a;
		    	$jq.post('send_answer.php', url_, function(xml){
		    		if(xml){
		    			if(xml == a){
		    				for(i=1; i<4; i++) $jq('#r_'+ i).parent('li').addClass($jq.trim(xml) == i ? 'correct' : 'incorrect');
		    				xml = '<img src="img/right.jpg" alt="" title="" /> La respuesta es correcta.';
		    			}else{
		    				for(i=1; i<4; i++) $jq('#r_'+ i).parent('li').addClass($jq.trim(xml) == i ? 'correct' : 'incorrect');
		    				xml = '<img src="img/wrong.jpg" alt="" title="" /> La respuesta es incorrecta.<br />La respuesta correcta era: <strong>' + $jq('span.'+xml).html() +  '</strong>';
		    			}
		    			$jq('.answer div').html(xml);

		    			$jq('a#ok_q').addClass('no_q');
		    			for(i=1; i<4; i++) $jq('#r_'+ i).attr('disabled', 'disabled');
		    			url_ = 't=' + t + '&u=' + u;
		    			$jq.post('chk_finish.php', url_, function(xml){//check if the user has finished the test
		    				if(xml == '1'){
		    					//$jq('#sgte_ask').attr('href', '?p=q&t='+t).text('Ver resultado del test');
		    					$jq('#sgte_ask').attr('href', '?p=q&t='+t);
								$jq('#sgte_ask img').attr('src', '/img/ver_btn.jpg');
		    				}
		    			});
		    		}
		    	});//fin del post
	    	}else{
	    		alert('Por favor, seleccione alguna de las respuestas.');
	    	}
    	}
	});

	$jq('.resumen_usr table tbody tr').mouseover(function(){ $jq(this).addClass("over");}).mouseout(function(){ $jq(this).removeClass("over");});
	$jq('.resumen_pm table tbody tr').mouseover(function(){ $jq(this).addClass("over");}).mouseout(function(){ $jq(this).removeClass("over");});

	//ADMIN
	$jq('.home_admin table tbody tr').mouseover(function(){ $jq(this).addClass("over");}).mouseout(function(){ $jq(this).removeClass("over");});
	$jq('a.new_test').click(function(){
		u = $jq('#u').val();
		$jq.post('add_test.php', 'u=' + u, function(xml){
			if(xml){
				window.location.reload();
			}
		});
	});

}); //fin de document.ready

/**
 *
 * @access public
 * @return void
 **/
function uncheckOther(field, value){
    for(i=0; i < field.length; i++){
		if(value == field[i].value){
		}else{
			field[i].checked = false;
		}
	}
}

/**
 *
 * @access public
 * @return void
 **/
function upDown(u, t){
	url_ = 't=' + t + '&u=' + u;
	$jq.post('up_download.php', url_, function(xml){});
}

