var skey = ; var cform = null; jQuery(document).ready(function() { //alert('ready'); //alert('sk: ' + skey); var abc = null; var start = Array(); var offsets = Array(); var position = Array(); jQuery('form').each(function() { var action = jQuery.trim(jQuery(this).attr('action')); var form = this; jQuery(form).find('input, textarea, button').bind('focus', function(e) {cform = form;}); jQuery(form).find('img[alt=captcha]').each(function() { //alert('captcha'); var captcha = this; //for (var idx in this) alert(idx + ': ' + this[idx]); var width = this['naturalWidth'] + 'px'; var height = this['naturalHeight'] + 'px'; //alert('w: ' + width + ', h: ' + height); var target = jQuery(form).find('input.captcha'); if (target.length > 0) { var afield = jQuery(form).find('input[name=afield]'); if (afield.length == 0) { // add one if not found? jQuery(form).append(''); afield = jQuery(form).find('input[name=afield]'); } if (afield.length > 0) { // all elements present and accounted for; //alert('w: ' + width + ', h: ' + height); if (! jQuery(target).hasClass('webkit')) { jQuery(target).css('padding', '0'); jQuery(target).css('width', width); jQuery(target).css('line-height', height); jQuery(target).css('height', height); jQuery(target).css('border-color', 'red'); } jQuery(captcha).prop('draggable', false); jQuery(captcha).bind('mousedown', function(e) { //alert('md'); jQuery(afield).attr('value', ''); // div's starting position on page start['left'] = e['target'].offsetLeft; start['top'] = e['target'].offsetTop; //alert(start['left'] + '/' + start['top']); // click location on page position['left'] = e.pageX; position['top'] = e.pageY; // click offset within div offsets['left'] = e.offsetX; offsets['top'] = e.offsetY; //alert('left: ' + offsets['left'] + ', top: ' + offsets['top']); abc = jQuery(e.target); }) jQuery('body').bind('mousemove', function(e) { if (abc) { var moveX = e.pageX - position['left']; var moveY = e.pageY - position['top']; // jQuery.offset() is relative to the document // jQuery.position() is relative to the offset parent // current location var location = jQuery(abc).offset(); jQuery(abc).offset({ top: location.top + moveY, left: location.left + moveX }) // mouse location on page position['left'] = e.pageX; position['top'] = e.pageY; } }) jQuery(captcha).bind('mouseup', function(e) { abc = null; var hit = false; offsets = jQuery(target).offset(); // mouse location on page position['left'] = e.pageX; position['top'] = e.pageY; if (position['left'] >= offsets.left && position['left'] <= (offsets['left'] + jQuery(target).prop('offsetWidth'))) { if (position['top'] >= offsets.top && position['top'] <= (offsets['top'] + jQuery(target).prop('offsetTop'))) { //alert('hit'); hit = true; jQuery(afield).attr('value', skey); if (jQuery(target).hasClass('webkit')) { offsets.top = parseFloat(offsets.top) + 3; offsets.left = parseFloat(offsets.left) + 3; jQuery(target).focus(); } else { jQuery(target).css('border-width', '3px'); offsets.top = parseFloat(offsets.top) + parseFloat(jQuery(target).css('border-top-width')); offsets.left = parseFloat(offsets.left) + parseFloat(jQuery(target).css('border-left-width')); } //offsets.top = parseFloat(offsets.top) + parseFloat(jQuery(target).css('border-top-width')); //offsets.left = parseFloat(offsets.left) + parseFloat(jQuery(target).css('border-left-width')); jQuery(captcha).offset(offsets); //jQuery(target).val(''); //jQuery(captcha).prop('disabled', true); } } if (! hit) { jQuery(target).css('border-width', ''); } }) jQuery(captcha).bind('mouseout', function(e) { abc = null; }) } } }) }) }) function CaptchaCheck3(oStatus) { oStatus.isvalid = false; //oStatus.errmsg = 'hello world'; if (cform != null) { if( jQuery(cform).find('input[name=afield]').val() == skey && jQuery(cform).find('input.captcha').val() == '' ) { oStatus.isvalid = true; } } }