sLastRecaptcha = "";

function ValidateCaptchaHtmlHideCallback( retval ) {
	if (typeof retval.html != "undefined") {
		$("#"+retval.id+"_error").html("");
		$("#"+retval.id+"_html").html( retval.html );
		return;
	}
	$("#"+retval.id+"_error").html( retval.error );
	Recaptcha.reload();
}

function SwitchToRecaptcha( pubkey , element_id ) {
	if (sLastRecaptcha.length>0) {
		$("#"+sLastRecaptcha+"_show_link").css( "display" , "inline" );
		$("#"+sLastRecaptcha+"_form").css( "display" , "none" );
		Recaptcha.destroy();
	}
	$("#"+element_id+"_show_link").css( "display" , "none" );
	$("#"+element_id+"_form").css( "display" , "block" );
	showRecaptcha( pubkey , element_id + '_cdiv' );
	sLastRecaptcha = element_id;
}

function showRecaptcha( pubkey , element_id ) {
	var opts = RecaptchaOptions;
	opts.callback = Recaptcha.focus_response_field;
	Recaptcha.create( pubkey , element_id , opts );
}

function ValidateCaptchaHtmlHide( id , oF ) {
	$.ajax(
		{
			type: "POST",
			cache: false,
			data: (
				{
					inajax : 1,
					captcha : "captcha",
					ajaxevent : "captcha",
					"captcha_id" : id,
					recaptcha_challenge_field : oF.recaptcha_challenge_field.value,
					recaptcha_response_field  : oF.recaptcha_response_field.value
				}
			),success: function( ret ) {
				ValidateCaptchaHtmlHideCallback( ret );
			}
		}
	);
	return false;
}
