function initCaptcha(name)
{
    var captcha = $('input[name=' + bgCaptchaEscape(name) + ']');
    if ($(captcha).size()) {
        $(captcha).attr('emptybg', 'img/bg_captcha.jpg');
        $(captcha).focus(function() { bgCaptchaUpdate.call(this, 'focus'); });
        $(captcha).blur(function() { bgCaptchaUpdate.call(this, 'blur'); });
        $(captcha).each(function(){
                bgCaptchaUpdate.call(this, 'blur');
                this.style.backgroundRepeat = 'no-repeat';
            });
    }

    var captchaWhat = $('img.captcha_what');
    if ($(captchaWhat).size()) {
        $(captchaWhat).qtip({
            content: 'The humanizer image helps us to prevent spam form submissions. '
                   + 'Please enter the text that you see in the image to the left in the text box below. '
                   + 'If you are having difficulty reading the text, you may click the image to get a new '
                   + 'image with different text and you are always welcome to call our offices as well.',
            show: 'mouseover',
            hide: 'mouseout',
			position: {
			  corner: {
				 target: 'bottomLeft',
				 tooltip: 'topRight'
			  }
			}
        });
    }
}

function bgCaptchaEscape(name)
{
    //name = name.replace('[', '\\[');
    //name = name.replace(']', '\\]');
    name = name.replace(':', '\\:');
    name = name.replace("'", "\\'");
    name = name.replace('"', '\\"');
    return name;
}

function bgCaptchaUpdate(func)
{
    if (func == 'focus') {
        this.style.backgroundImage = '';
    } else if (func == 'blur'){
        if (this.value == '') {
            this.style.backgroundImage = "url('" + $(this).attr('emptybg') + "')";
        } else {
            this.style.backgroundImage = '';
        }
    }
}


