Chris@76
|
1 // This file contains javascript associated with the captcha visual verification stuffs.
|
Chris@76
|
2
|
Chris@76
|
3 function smfCaptcha(imageURL, uniqueID, useLibrary, letterCount)
|
Chris@76
|
4 {
|
Chris@76
|
5 // By default the letter count is five.
|
Chris@76
|
6 if (!letterCount)
|
Chris@76
|
7 letterCount = 5;
|
Chris@76
|
8
|
Chris@76
|
9 uniqueID = uniqueID ? '_' + uniqueID : '';
|
Chris@76
|
10 autoCreate();
|
Chris@76
|
11
|
Chris@76
|
12 // Automatically get the captcha event handlers in place and the like.
|
Chris@76
|
13 function autoCreate()
|
Chris@76
|
14 {
|
Chris@76
|
15 // Is there anything to cycle images with - if so attach the refresh image function?
|
Chris@76
|
16 var cycleHandle = document.getElementById('visual_verification' + uniqueID + '_refresh');
|
Chris@76
|
17 if (cycleHandle)
|
Chris@76
|
18 {
|
Chris@76
|
19 createEventListener(cycleHandle);
|
Chris@76
|
20 cycleHandle.addEventListener('click', refreshImages, false);
|
Chris@76
|
21 }
|
Chris@76
|
22
|
Chris@76
|
23 // Maybe a voice is here to spread light?
|
Chris@76
|
24 var soundHandle = document.getElementById('visual_verification' + uniqueID + '_sound');
|
Chris@76
|
25 if (soundHandle)
|
Chris@76
|
26 {
|
Chris@76
|
27 createEventListener(soundHandle);
|
Chris@76
|
28 soundHandle.addEventListener('click', playSound, false);
|
Chris@76
|
29 }
|
Chris@76
|
30 }
|
Chris@76
|
31
|
Chris@76
|
32 // Change the images.
|
Chris@76
|
33 function refreshImages()
|
Chris@76
|
34 {
|
Chris@76
|
35 // Make sure we are using a new rand code.
|
Chris@76
|
36 var new_url = new String(imageURL);
|
Chris@76
|
37 new_url = new_url.substr(0, new_url.indexOf("rand=") + 5);
|
Chris@76
|
38
|
Chris@76
|
39 // Quick and dirty way of converting decimal to hex
|
Chris@76
|
40 var hexstr = "0123456789abcdef";
|
Chris@76
|
41 for(var i=0; i < 32; i++)
|
Chris@76
|
42 new_url = new_url + hexstr.substr(Math.floor(Math.random() * 16), 1);
|
Chris@76
|
43
|
Chris@76
|
44 if (useLibrary && document.getElementById("verification_image" + uniqueID))
|
Chris@76
|
45 {
|
Chris@76
|
46 document.getElementById("verification_image" + uniqueID).src = new_url;
|
Chris@76
|
47 }
|
Chris@76
|
48 else if (document.getElementById("verification_image" + uniqueID))
|
Chris@76
|
49 {
|
Chris@76
|
50 for (i = 1; i <= letterCount; i++)
|
Chris@76
|
51 if (document.getElementById("verification_image" + uniqueID + "_" + i))
|
Chris@76
|
52 document.getElementById("verification_image" + uniqueID + "_" + i).src = new_url + ";letter=" + i;
|
Chris@76
|
53 }
|
Chris@76
|
54
|
Chris@76
|
55 return false;
|
Chris@76
|
56 }
|
Chris@76
|
57
|
Chris@76
|
58 // Request a sound... play it Mr Soundman...
|
Chris@76
|
59 function playSound(ev)
|
Chris@76
|
60 {
|
Chris@76
|
61 if (!ev)
|
Chris@76
|
62 ev = window.event;
|
Chris@76
|
63
|
Chris@76
|
64 popupFailed = reqWin(imageURL + ";sound", 400, 120);
|
Chris@76
|
65 // Don't follow the link if the popup worked, which it would have done!
|
Chris@76
|
66 if (!popupFailed)
|
Chris@76
|
67 {
|
Chris@76
|
68 if (is_ie && ev.cancelBubble)
|
Chris@76
|
69 ev.cancelBubble = true;
|
Chris@76
|
70 else if (ev.stopPropagation)
|
Chris@76
|
71 {
|
Chris@76
|
72 ev.stopPropagation();
|
Chris@76
|
73 ev.preventDefault();
|
Chris@76
|
74 }
|
Chris@76
|
75 }
|
Chris@76
|
76
|
Chris@76
|
77 return popupFailed;
|
Chris@76
|
78 }
|
Chris@76
|
79 } |