Chris@76: // This file contains javascript associated with the captcha visual verification stuffs. Chris@76: Chris@76: function smfCaptcha(imageURL, uniqueID, useLibrary, letterCount) Chris@76: { Chris@76: // By default the letter count is five. Chris@76: if (!letterCount) Chris@76: letterCount = 5; Chris@76: Chris@76: uniqueID = uniqueID ? '_' + uniqueID : ''; Chris@76: autoCreate(); Chris@76: Chris@76: // Automatically get the captcha event handlers in place and the like. Chris@76: function autoCreate() Chris@76: { Chris@76: // Is there anything to cycle images with - if so attach the refresh image function? Chris@76: var cycleHandle = document.getElementById('visual_verification' + uniqueID + '_refresh'); Chris@76: if (cycleHandle) Chris@76: { Chris@76: createEventListener(cycleHandle); Chris@76: cycleHandle.addEventListener('click', refreshImages, false); Chris@76: } Chris@76: Chris@76: // Maybe a voice is here to spread light? Chris@76: var soundHandle = document.getElementById('visual_verification' + uniqueID + '_sound'); Chris@76: if (soundHandle) Chris@76: { Chris@76: createEventListener(soundHandle); Chris@76: soundHandle.addEventListener('click', playSound, false); Chris@76: } Chris@76: } Chris@76: Chris@76: // Change the images. Chris@76: function refreshImages() Chris@76: { Chris@76: // Make sure we are using a new rand code. Chris@76: var new_url = new String(imageURL); Chris@76: new_url = new_url.substr(0, new_url.indexOf("rand=") + 5); Chris@76: Chris@76: // Quick and dirty way of converting decimal to hex Chris@76: var hexstr = "0123456789abcdef"; Chris@76: for(var i=0; i < 32; i++) Chris@76: new_url = new_url + hexstr.substr(Math.floor(Math.random() * 16), 1); Chris@76: Chris@76: if (useLibrary && document.getElementById("verification_image" + uniqueID)) Chris@76: { Chris@76: document.getElementById("verification_image" + uniqueID).src = new_url; Chris@76: } Chris@76: else if (document.getElementById("verification_image" + uniqueID)) Chris@76: { Chris@76: for (i = 1; i <= letterCount; i++) Chris@76: if (document.getElementById("verification_image" + uniqueID + "_" + i)) Chris@76: document.getElementById("verification_image" + uniqueID + "_" + i).src = new_url + ";letter=" + i; Chris@76: } Chris@76: Chris@76: return false; Chris@76: } Chris@76: Chris@76: // Request a sound... play it Mr Soundman... Chris@76: function playSound(ev) Chris@76: { Chris@76: if (!ev) Chris@76: ev = window.event; Chris@76: Chris@76: popupFailed = reqWin(imageURL + ";sound", 400, 120); Chris@76: // Don't follow the link if the popup worked, which it would have done! Chris@76: if (!popupFailed) Chris@76: { Chris@76: if (is_ie && ev.cancelBubble) Chris@76: ev.cancelBubble = true; Chris@76: else if (ev.stopPropagation) Chris@76: { Chris@76: ev.stopPropagation(); Chris@76: ev.preventDefault(); Chris@76: } Chris@76: } Chris@76: Chris@76: return popupFailed; Chris@76: } Chris@76: }