
/*
 *  Modular CAPTCHA class for implementing into any HTML form
 *  Requires jQuery library (http://www.jquery.com)
 *  Taylan Pince (taylan@taylanpince.com) - May 26, 2007
 */

jQuery.noConflict();

modularCAPTCHA = {
	load : function() {
		jQuery.get("/modular-captcha/app/", {'action': 'reload'}, function(form) {
			jQuery("form.captcha").find(".captcha-container").append(form);
		});
	},
	
	process : function(form) {
		var params = {
			'confirmation-code': jQuery('input[@name="confirmation-code"]', form).val(),
			'captcha': jQuery('input[@name="captcha"]', form).val()
		};
		
		jQuery.post("/modular-captcha/app/", params, function(resp) {
			if (jQuery("result", resp).text() == "true") {
				form.submit();
			} else {
				alert("Confirmation code is incorrect. Please make sure you repeat the code exactly.");
			}
		});
	},
	
	init : function() {
		jQuery("form.captcha").submit(function() {
			modularCAPTCHA.process(this);
			return false;
		});
		
		modularCAPTCHA.load();
	}
}

jQuery(function() {
	modularCAPTCHA.init();
});