/*función que realiza la comprobación para que no se registren bots: CAPTCHA
 * 
 * Parametros:
 * 				txtUsu: el id del campo con código que mete el usuario y que comprobamos
 * 				imgCaptcha: el identificador de la imagen que muestra el código captcha
*/

var captcha = false;

function validarCaptchaComprar() {
	var texto = $("tmptxt").value;	

	if (texto.length==8) {
		comprobarCaptchaComprar(texto);
	} 
}

function comprobarCaptchaComprar(txtUsu){	
	var url = '/includes/captcha/compruebaCaptcha.php';
	   
    var myAjax = new Ajax.Request(url, {
		method: 'post',
		parameters:{security_code : txtUsu, action: 'checkdata'},
   	    onComplete: function(transport){					
				var resultado=transport.responseText;			
				//acertó captcha
				if(resultado=='true'){					
					$("imagenCargaCaptcha").innerHTML="<img alt=\"Texto correcto\" title=\"Texto correcto\" src=\"/images/paso/ok.gif\"/>";
					$("imagenCargaCaptcha").style.visibility="visible";
					$("btRegistrar").removeAttribute("disabled");
					$("btRegistrar").className = "registrate";
					captcha = true;
					$("tmptxt").disabled = true;
					return true;
				//falló captcha
				} else {				
					$("imagenCargaCaptcha").innerHTML="<img alt=\"Texto incorrecto\" title=\"Texto incorrecto\" src=\"/images/paso/nok.gif\"/>";
					$("imagenCargaCaptcha").style.visibility="visible";
					return false;
				}							
			} 
    });		
}

/*
function comprobarCaptcha(txtUsu,idBoton,imgCaptcha){	
	var url = '/includes/captcha/compruebaCaptcha.php';
	   
    var myAjax = new Ajax.Request(url, {
		method: 'post',
		parameters:{security_code : $F(txtUsu), action: 'checkdata'},
   	    onComplete: function(transport){					
				var resultado=transport.responseText;			
				//acertó captcha
				if(resultado=='true'){
					$('resultadoCapt').innerHTML = resultado;					
					return true;
				//falló captcha
				}else{
					$('resultadoCapt').innerHTML = resultado;
					//recargamos la imagen
					$(imgCaptcha).src='/includes/captcha/captcha.php?'+ Math.random();					
					$(txtUsu).value='';
					return false;
				}
			} 
    });		
}
*/
function refrescar() {
	$('imgCaptcha').src='/includes/captcha/captcha.php?'+ Math.random();					
	$('tmptxt').value='';
	return false;
}

/*función que realiza la comprobación para que no se registren bots: CAPTCHA
 * esta variante incluye un botón que se bloquea y muestra el mensaje
 * cargando mientras se realiza la comprobación
 * 
 * Parametros:
 * 				txtUsu: el id del campo con el código que mete el usuario y que comprobamos
 * 				idBotón: el identificador con el botón que realiza la comprobación
 * 				imgCaptcha: el identificador de la imagen que muestra el código captcha
*/
/*
function comprobarCaptchaConBoton(txtUsu,idBoton,imgCaptcha){	
	var url = '/includes/captcha/compruebaCaptcha.php';
	
	//bloqueamos el botón
	//$("idBoton").disabled=true;
	//var valorAnterior=$('btget').value;
	//$("idBoton").value="comprobando";
     
    var myAjax = new Ajax.Request(url, {
		method: 'post',
		parameters:{security_code : $F(txtUsu), action: 'checkdata'},
   	    onComplete: function(transport){					
				var resultado=transport.responseText;			
				//acertó captcha
				if(resultado=='true'){
					//devolvemos el botón a su estado inicial
					//$("idBoton").value = "correcto";
					//$("txtUsu").disabled = true;
					$("btRegistrar").removeAttribute("disabled");
					$("btRegistrar").className = "registrate";
					$("btget").removeAttribute("disabled");
					$("btget").className = "comprobar_disabled";
					captcha = true;
					return true;
				//falló captcha
				}else{
					//devolvemos el botón a su estado inicial					
					//$(idBoton).disabled = false;
					$("btget").removeAttribute("disabled");
					//$("idBoton").value = valorAnterior;
					$("tmptxt").value='';
					$("imgCaptcha").src='/includes/captcha/captcha.php?'+ Math.random();

					return false;
				}
			} 
    });		
}
*/
