function generateCaptcha() {
  var placeholder=$(".captchaPlaceholder");
  $(".captchaPlaceholder").empty();
  var spinner=document.createElement('img');
  spinner.src='/images/spinner.png';
  $(".captchaPlaceholder").append(spinner);
  $.getJSON('/cgi-bin/captcha.cgi', function(data) {
    var captcha_src=data.img;
    var captcha_digest=data.digest;
    $(".captchaPlaceholder").empty();
    var captcha_img=document.createElement('img');
    captcha_img.src=captcha_src;
    var captcha_hidden=document.createElement('input');
    captcha_hidden.setAttribute('type','hidden');
    captcha_hidden.setAttribute('name','captcha_digest');
    captcha_hidden.setAttribute('value',captcha_digest);
    var captcha_return=document.createElement('input');
    captcha_return.setAttribute('type','text');
    captcha_return.setAttribute('name','captcha');
    var captcha_title=document.createElement('p');
    captcha_title.innerText="Please type the text shown in the image below:";
    var required_mark=document.createElement('font');
    required_mark.setAttribute('color','#ff0000');
    required_mark.innerText='*';
    captcha_title.appendChild(required_mark);
    $(".captchaPlaceholder").append(captcha_title);
    $(".captchaPlaceholder").append(captcha_img);
    $(".captchaPlaceholder").append(captcha_hidden);
    $(".captchaPlaceholder").append(document.createElement('br'));
    $(".captchaPlaceholder").append(captcha_return);

  });
}

generateCaptcha();

