//Agrega Captcha
$("div[esCaptcha=si]").each(function(){
    $(this).append('<img id="siimage" style="padding-right: 5px; border: 0" src="'+$(this).attr("ruta")+'genera_captcha.php?sid='+Math.random()+'&alto='+$(this).attr("alto")+'&ancho='+$(this).attr("ancho")+'" /><a tabindex="-1" id="actualizarCaptcha" style="border-style: none" href="#" title="Actualizar imagen"><img src="'+$(this).attr("ruta")+'/images/refresh.gif" alt="Actualizar Imagen" border="0" align="bottom" /></a><br /><input style="width:'+$(this).attr("ancho")+'px;" type="text" class="'+$(this).attr("claseInput")+'" name="captcha" />');
});

//Actualiza la imagen al presionar el boton actualizar
$("#actualizarCaptcha").click(function(){
    $("#siimage").attr("src", $("div[esCaptcha=si]").attr("ruta")+'genera_captcha.php?sid='+Math.random()+'&alto='+$("div[esCaptcha=si]").attr("alto")+'&ancho='+$("div[esCaptcha=si]").attr("ancho"));
    return false;
});

//Agrega regla de validacion
$("div[esCaptcha=si]").closest("form").each(function(){
    $(this).validate({
        debug: false,
		rules: {
			captcha: { remote: $("div[esCaptcha=si]").attr("ruta")+"chequea_captcha.php", required: true }
		},
		messages: {
			captcha:{
				remote:"Codigo de validacion invalido",  
				required: "Complete el codigo de validacion"
            }
		}
	});
});