$(document).ready(function(){ 
   $("#reasonCategory").change(function() { 
      $(this).parent().parent().submit()
      }); 
   });

$(document).ready(function(){	
	 $('.vote_footer input').hover( 
			 function () { 
				 	$(this).attr("src", appPrefix + "images/vote_footer_a.gif");
				 	
			 },
			 function () { 
				 $(this).attr("src", appPrefix + "images/vote_footer.gif");
			 }				 
	);  
	 
	 
	 $('.vote_footer input').click( 
			 function () { 
				 var ich = this;
				 var uri = $(this).parent().parent().attr('action');
				 
				 $("input[name='jsEnabled']").val("true");
				  
				 if( uri.indexOf( "/lesen" ) == -1 ) {
					 return true;
				 }
				 				
				
				 jQuery.ajax({
					 	type:'POST',
					 	dataType:'html',
					 	data:jQuery(this).parent().parent().serialize() + "&ajaxR=true",
					 	
					 	success:function(data, textStatus) {
					 		if( data == 'ok' ){
					 			$(ich).parent().prev(".vote_body").html( "<img src='" + appPrefix + "/images/ok-Pfeil2.gif'/>" )
					 			$(ich).attr("src", appPrefix + "images/vote_footer.gif");
					 			$(ich).remove();
					 		}
					 		else if( data.indexOf( "RDC" ) == 0 ){
					 			window.location.href=data.substring(3);
					 		}
					 		else if( data == 'refresh' ){
					 			window.location.href=uri
					 		}
					 		else{
					 			$(ich).parent().prev(".vote_body").children(".voteResponeMessage").text("Bitte bewerten Sie beide Kriterien");
					 		}
					 	},
					 	url: uri
				 }); 
				 return false;	 
			 }
			 
	); 	
	
	 
	$('img.btLevel2').hover(
		 function () { 
			 $(this).attr("src", appPrefix + "images/button-grund-auswaehlen_roll.gif");	
		 }	,
		 function () { 
			 $(this).attr("src", appPrefix + "images/button-grund-auswaehlen.gif");
		 }	
	);
	
	$('img.btLevel2').click( 
			function () { 
				 var ich = this;
				 var uri = $(this).parent().parent().attr('action');
				 
				 jQuery.ajax({
					 	type:'POST',
					 	dataType:'json',
					 	data:jQuery(this).parent().parent().serialize() + "&ajaxR=true",
					 	success:function(data, textStatus) {
					 		if( data.gameOver ){
					 			window.location.href = "/argumentationstrainer.xhtml";
					 		}
					 		else {
					 			document.getElementById( "arguTrainerLevel2" ).level2Connector( data.reason, data.these, data.nextThese, data.gameOver, data.theseCount, data.answerCount );
					 		}
					 	},
					 	url: uri
				 }); 
				 
				 return false;	 
			 }
	);
	 
})

