// fichier js captcha

function refreshcaptcha(){
	valid_captcha = false;
	$('#valid_captcha_result').html(' ');
	document.getElementById('captcha').value='';
	document.images['captchaimg'].src='index.php?option=com_tincaptcha&amp;task=captcha_display&amp;t='+(new Date()).getTime();
	return false;
}

// jQuery form validation for captch
$(document).ready(function() {

		var checking_html = 'Vérification...';
		//when filed is changed
		$('#captcha').keyup(function(){
			//run the character number check
			if($('#captcha').val().length < 6){
				//if it's bellow the minimum show characters_error text '
				valid_captcha = false;
				$('#valid_captcha_result').html(' ');
			}else{
				//else show the cheking_text and run the function to check
				$('#valid_captcha_result').html('<img src=\'/captcha/captcha_check.gif\' />');
				compare_captcha();
			}
		});
  });

//function to check username availability
function compare_captcha(){

		//get the username
		var captcha = $('#captcha').val();
		//use ajax to run the check
		$.post("/captcha/check_captcha.php", { c: captcha },
			function(result){
				//captch is ok if the result is 1
				if(result == 1){
					valid_captcha = true;
					$('#valid_captcha_result').html('<img src=\'/captcha/captcha_ok.gif\' />');
				}else{
					valid_captcha = false;
					$('#valid_captcha_result').html('<img src=\'/captcha/captcha_ko.gif\' />');
				}
		});
}
