/* http://keith-wood.name/realPerson.html Real Person Form Submission for jQuery v1.1.0. Written by Keith Wood (kwood{at}iinet.com.au) June 2009. Dual licensed under the GPL (http://dev.jquery.com/browser/trunk/jquery/GPL-LICENSE.txt) and MIT (http://dev.jquery.com/browser/trunk/jquery/MIT-LICENSE.txt) licenses. Please attribute the author if you use it. */ (function($){function RealPerson(){this._defaults={length:6,includeNumbers:false,regenerate:'Click to change',hashName:'{n}Hash'}}var f='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';var g=[[' * ',' * * ',' * * ',' * * ',' ***** ','* *','* *'],['****** ','* *','* *','****** ','* *','* *','****** '],[' ***** ','* *','* ','* ','* ','* *',' ***** '],['****** ','* *','* *','* *','* *','* *','****** '],['*******','* ','* ','**** ','* ','* ','*******'],['*******','* ','* ','**** ','* ','* ','* '],[' ***** ','* *','* ','* ','* ***','* *',' ***** '],['* *','* *','* *','*******','* *','* *','* *'],['*******',' * ',' * ',' * ',' * ',' * ','*******'],[' *',' *',' *',' *',' *','* *',' ***** '],['* *','* ** ','* ** ','** ','* ** ','* ** ','* *'],['* ','* ','* ','* ','* ','* ','*******'],['* *','** **','* * * *','* * *','* *','* *','* *'],['* *','** *','* * *','* * *','* * *','* **','* *'],[' ***** ','* *','* *','* *','* *','* *',' ***** '],['****** ','* *','* *','****** ','* ','* ','* '],[' ***** ','* *','* *','* *','* * *','* * ',' **** *'],['****** ','* *','* *','****** ','* * ','* * ','* *'],[' ***** ','* *','* ',' ***** ',' *','* *',' ***** '],['*******',' * ',' * ',' * ',' * ',' * ',' * '],['* *','* *','* *','* *','* *','* *',' ***** '],['* *','* *',' * * ',' * * ',' * * ',' * * ',' * '],['* *','* *','* *','* * *','* * * *','** **','* *'],['* *',' * * ',' * * ',' * ',' * * ',' * * ','* *'],['* *',' * * ',' * * ',' * ',' * ',' * ',' * '],['*******',' * ',' * ',' * ',' * ',' * ','*******'],[' *** ',' * * ','* * *','* * *','* * *',' * * ',' *** '],[' * ',' ** ',' * * ',' * ',' * ',' * ','*******'],[' ***** ','* *',' *',' * ',' ** ',' ** ','*******'],[' ***** ','* *',' *',' ** ',' *','* *',' ***** '],[' * ',' ** ',' * * ',' * * ','*******',' * ',' * '],['*******','* ','****** ',' *',' *','* *',' ***** '],[' **** ',' * ','* ','****** ','* *','* *',' ***** '],['*******',' * ',' * ',' * ',' * ',' * ','* '],[' ***** ','* *','* *',' ***** ','* *','* *',' ***** '],[' ***** ','* *','* *',' ******',' *',' * ',' **** ']];$.extend(RealPerson.prototype,{markerClassName:'hasRealPerson',propertyName:'realperson',setDefaults:function(a){$.extend(this._defaults,a||{});return this},_attachPlugin:function(a,b){a=$(a);if(a.hasClass(this.markerClassName)){return}var c={options:$.extend({},this._defaults)};a.addClass(this.markerClassName).data(this.propertyName,c);this._optionPlugin(a,b)},_optionPlugin:function(a,b,c){a=$(a);var d=a.data(this.propertyName);if(!b||(typeof b=='string'&&c==null)){var e=b;b=(d||{}).options;return(b&&e?b[e]:b)}if(!a.hasClass(this.markerClassName)){return}b=b||{};if(typeof b=='string'){var e=b;b={};b[e]=c}$.extend(d.options,b);a.prevAll('.'+this.propertyName+'-challenge,.'+this.propertyName+'-hash').remove().end().before(this._generateHTML(a,d))},_generateHTML:function(a,b){var c='';for(var i=0;i<b.options.length;i++){c+=f.charAt(Math.floor(Math.random()*(b.options.includeNumbers?36:26)))}var d='<div class="'+this.propertyName+'-challenge">'+'<div class="'+this.propertyName+'-text">';for(var i=0;i<g[0].length;i++){for(var j=0;j<c.length;j++){d+=g[f.indexOf(c.charAt(j))][i].replace(/ /g,' ')+' '}d+='<br>'}d+='</div><div class="'+this.propertyName+'-regen">'+b.options.regenerate+'</div></div><input type="hidden" class="'+this.propertyName+'-hash" name="'+b.options.hashName.replace(/\{n\}/,a.attr('name'))+'" value="'+this._hash(c)+'">';return d},_enablePlugin:function(a){a=$(a);if(!a.hasClass(this.markerClassName)){return}a.removeClass(this.propertyName+'-disabled').prop('disabled',false).prevAll('.'+this.propertyName+'-challenge').removeClass(this.propertyName+'-disabled')},_disablePlugin:function(a){a=$(a);if(!a.hasClass(this.markerClassName)){return}a.addClass(this.propertyName+'-disabled').prop('disabled',true).prevAll('.'+this.propertyName+'-challenge').addClass(this.propertyName+'-disabled')},_destroyPlugin:function(a){a=$(a);if(!a.hasClass(this.markerClassName)){return}a.removeClass(this.markerClassName).removeData(this.propertyName).prevAll('.'+this.propertyName+'-challenge,.'+this.propertyName+'-hash').remove()},_hash:function(a){var b=5381;for(var i=0;i<a.length;i++){b=((b<<5)+b)+a.charCodeAt(i)}return b}});var h=[''];function isNotChained(a,b){if(a=='option'&&(b.length==0||(b.length==1&&typeof b[0]=='string'))){return true}return $.inArray(a,h)>-1}$.fn.realperson=function(a){var b=Array.prototype.slice.call(arguments,1);if(isNotChained(a,b)){return k['_'+a+'Plugin'].apply(k,[this[0]].concat(b))}return this.each(function(){if(typeof a=='string'){if(!k['_'+a+'Plugin']){throw'Unknown command: '+a;}k['_'+a+'Plugin'].apply(k,[this].concat(b))}else{k._attachPlugin(this,a||{})}})};var k=$.realperson=new RealPerson();$('div.'+k.propertyName+'-challenge').live('click',function(){if(!$(this).hasClass(k.propertyName+'-disabled')){$(this).nextAll('.'+k.markerClassName).realperson('option',{})}})})(jQuery);