/* Copyright (C) 2007 reCAPTCHA. Please contact us if you are thinking of modifying & hosting this file. */

var RecaptchaTemplates = {
    VertHtml : '<div id="recaptcha_scripts" style="display:none"></div>\n\n<!-- The password thing is so that IE doesn\'t cache this field\n     when the user presses the back button. What a hack! -->\n<input type="password" autocomplete="off" style="display:none" name="recaptcha_challenge_field" id="recaptcha_challenge_field" />\n\n<table id="recaptcha_table" class="recaptchatable" >\n\t<tr>\n\t  <td colspan="6" class=\'recaptcha_r1_c1\'></td>\n\t</tr>\n\t<tr>\n\t  <td class=\'recaptcha_r2_c1\'></td>\n\t  <td colspan="4" class=\'recaptcha_image_cell\'><center><img id="recaptcha_image" width="300" height="57" alt=""><span id=\'recaptcha_play_audio\'></span></center></td>\n\t  <td class=\'recaptcha_r2_c2\'></td>\n\t</tr>\n\t<tr>\n\t  <td rowspan="6" class=\'recaptcha_r3_c1\'></td>\n\t  <td colspan="4" class=\'recaptcha_r3_c2\'></td>\n\t  <td rowspan="6" class=\'recaptcha_r3_c3\'></td>\n\t</tr>\n\t<tr>\n\t  <td rowspan="3" class=\'recaptcha_r4_c1\' height="49">\n\t    <div class="recaptcha_input_area">\n\t      <label for="recaptcha_response_field" id="recaptcha_instructions" class="recaptcha_input_area_text"></label><br/>\n\t      <input name="recaptcha_response_field" id="recaptcha_response_field" type="text" autocomplete="off"/>\n\t    </div>\n\t  </td>\n\t  \n\t  <td rowspan="4" class=\'recaptcha_r4_c2\'></td>\n\t  \n\t  <td><a id=\'recaptcha_reload_btn\' tabindex=\'-1\'><img id=\'recaptcha_reload\' width="25" height="17" /></a></td>\n\t  \n\t  <td rowspan="4" class=\'recaptcha_r4_c4\'></td>\n\t  \n\t</tr>\n\t<tr>\n\t  <td><a id=\'recaptcha_switch_audio_btn\' tabindex=\'-1\'><img id=\'recaptcha_switch_audio\' width="25" height="16" alt="" /></a><a id=\'recaptcha_switch_img_btn\' tabindex=\'-1\' style="display:none"><img id=\'recaptcha_switch_img\' width="25" height="16" alt=""/></a></td>\n\t</tr>\n\t<tr>\n\t  <td><a id=\'recaptcha_whatsthis_btn\' tabindex=\'-1\'><img id=\'recaptcha_whatsthis\' width="25" height="16" /></a></td>\n\t</tr>\n\t<tr>\n\t  <td class=\'recaptcha_r7_c1\'></td>\n\t  <td class=\'recaptcha_r8_c1\'></td>\n\t</tr>\n</table>\n\n',
    VertCss : '.recaptchatable td img {\n  /* see http://developer.mozilla.org/en/docs/Images%2C_Tables%2C_and_Mysterious_Gaps */\n  display: block;\n}\n.recaptchatable .recaptcha_r1_c1 { background: url(IMGROOT/sprite.png) -0px -63px no-repeat; width: 318px; height: 9px; }\n.recaptchatable .recaptcha_r2_c1 { background: url(IMGROOT/sprite.png) -18px -0px no-repeat; width: 9px; height: 57px; }\n.recaptchatable .recaptcha_r2_c2 { background: url(IMGROOT/sprite.png) -27px -0px no-repeat; width: 9px; height: 57px; }\n.recaptchatable .recaptcha_r3_c1 { background: url(IMGROOT/sprite.png) -0px -0px no-repeat; width: 9px; height: 63px; }\n.recaptchatable .recaptcha_r3_c2 { background: url(IMGROOT/sprite.png) -18px -57px no-repeat; width: 300px; height: 6px; }\n.recaptchatable .recaptcha_r3_c3 { background: url(IMGROOT/sprite.png) -9px -0px no-repeat; width: 9px; height: 63px; }\n.recaptchatable .recaptcha_r4_c1 { background: url(IMGROOT/sprite.png) -43px -0px no-repeat; width: 171px; height: 49px; }\n.recaptchatable .recaptcha_r4_c2 { background: url(IMGROOT/sprite.png) -36px -0px no-repeat; width: 7px; height: 57px; }\n.recaptchatable .recaptcha_r4_c4 { background: url(IMGROOT/sprite.png) -214px -0px no-repeat; width: 97px; height: 57px; }\n.recaptchatable .recaptcha_r7_c1 { background: url(IMGROOT/sprite.png) -43px -49px no-repeat; width: 171px; height: 8px; }\n.recaptchatable .recaptcha_r8_c1 { background: url(IMGROOT/sprite.png) -43px -49px no-repeat; width: 25px; height: 8px; }\n.recaptchatable .recaptcha_image_cell center img { height:57px;}\n.recaptchatable .recaptcha_image_cell center { height:57px;}\n.recaptchatable .recaptcha_image_cell {\n  background-color:white; height:57px;\n}\n\n/* some people break their style sheet, we need to clean up after them */\n#recaptcha_area, #recaptcha_table {\n  width: 318px !important;\n}\n\n.recaptchatable, #recaptcha_area tr, #recaptcha_area td, #recaptcha_area th {\n  margin:0px !important;\n  border:0px !important;\n  padding:0px !important;\n  border-collapse: collapse !important;\n  vertical-align: middle !important;\n}\n\n.recaptchatable * {\n\tmargin:0px;\n\tpadding:0px;\n\tborder:0px;\n\tfont-family:helvetica,sans-serif;\n\tfont-size:8pt;\n\tcolor:black;\n\tposition:static;\n\ttop:auto;\n\tleft:auto;\n\tright:auto;\n\tbottom:auto;\n\ttext-align:left !important;\n}\n\n.recaptchatable #recaptcha_image {\n  margin:auto;\n}\n\n.recaptchatable img {\n  border:0px !important;\n  margin:0px !important;\n  padding:0px !important;\n}\n\n.recaptchatable a, .recaptchatable a:hover {\n  -moz-outline:none;\n  border:0px !important;\n  padding:0px !important;\n  text-decoration:none;\n  color:blue;\n  background:none !important;\n  font-weight: normal;\n}\n\n.recaptcha_input_area {\n  position:relative !important;\n  width:146px !important;\n  height:45px !important;\n  margin-left:20px !important;\n  margin-right:5px !important;\n  margin-top:4px !important;\n  background:none !important;\n}\n\n.recaptchatable label.recaptcha_input_area_text {\n  margin:0px !important;  \n  padding:0px !important;\n  position:static !important;\n  top:auto !important;\n  left:auto !important;\n  right:auto !important;\n  bottom:auto !important;\n  background:none !important;\n  height:auto !important;\n  width:auto !important;\n}\n\n.recaptcha_theme_red label.recaptcha_input_area_text,\n.recaptcha_theme_white label.recaptcha_input_area_text {\n  color:black !important;\n}\n\n.recaptcha_theme_blackglass label.recaptcha_input_area_text {\n  color:white !important;\n}\n\n.recaptchatable #recaptcha_response_field  {\n  width:145px !important;\n  position:absolute !important;\n  bottom:7px !important;\n\n  padding:0px !important;\n  margin:0px !important;\n  font-size:10pt;\n}\n\n.recaptcha_theme_blackglass #recaptcha_response_field,\n.recaptcha_theme_white #recaptcha_response_field {\n  border: 1px solid gray;\n}\n\n.recaptcha_theme_red #recaptcha_response_field {\n  border:1px solid #cca940;\n}\n\n.recaptcha_audio_cant_hear_link {\n  font-size:7pt;\n  color:black;\n}\n\n.recaptchatable {\n  line-height:1em;\n}\n\n.recaptcha_error_text {\n  color:red;\n}\n',
    CleanHtml : '<div id="recaptcha_scripts" style="display:none"></div>\n<input type="password" autocomplete="off" style="display:none" name="recaptcha_challenge_field" id="recaptcha_challenge_field" />\n<table id="recaptcha_table" class="recaptchatable">\n  <tr height="73">\n    <td class=\'recaptcha_image_cell\' width="302"><center><img id="recaptcha_image" width="300" height="57" alt="" /><span id=\'recaptcha_play_audio\' style="display: none;"></span></center></td>\n    <td style="padding: 10px 7px 7px 7px;">\n      <a id=\'recaptcha_reload_btn\' tabindex=\'-1\'><img id=\'recaptcha_reload\' width="25" height="18" alt="" /></a>\n      <a id=\'recaptcha_switch_audio_btn\' tabindex=\'-1\'><img id=\'recaptcha_switch_audio\' width="25" height="15" alt="" /></a><a id=\'recaptcha_switch_img_btn\' tabindex=\'-1\' style="display:none"><img id=\'recaptcha_switch_img\' width="25" height="15" alt=""/></a>\n      <a id=\'recaptcha_whatsthis_btn\' tabindex=\'-1\'><img id=\'recaptcha_whatsthis\' width="25" height="16" /></a>\n    </td>\n    <td style="padding: 18px 7px 18px 7px;">\n      <img id=\'recaptcha_logo\' alt="" width="71" height="36" />\n    </td>\n  </tr>\n  <tr>\n    <td style="padding-left: 7px;">\n\t    <div class="recaptcha_input_area" style="padding-top: 2px; padding-bottom: 7px;">\n\t      <input style="border: 1px solid #3c3c3c; width: 302px;" name="recaptcha_response_field" id="recaptcha_response_field" type="text" autocomplete="off"/>\n\t    </div>\n    </td>\n    <td></td>\n    <td style="padding: 4px 7px 12px 7px;">\n      <img id="recaptcha_tagline" width="71" height="17" />\n    </td>\n  </tr>\n</table>\n\n\n',
    CleanCss : '.recaptchatable td img {\n  display: block;\n}\n\n.recaptchatable .recaptcha_image_cell center img { height:57px;}\n.recaptchatable .recaptcha_image_cell center { height:57px;}\n.recaptchatable .recaptcha_image_cell {\n  background-color:white; height:57px; \n  padding: 7px !important;\n}\n\n.recaptchatable, #recaptcha_area tr, #recaptcha_area td, #recaptcha_area th {\n  margin:0px !important;\n  border:0px !important;\n  border-collapse: collapse !important;\n  vertical-align: middle !important;\n}\n\n.recaptchatable * {\n\tmargin:0px;\n\tpadding:0px;\n\tborder:0px;\n\tcolor:black;\n\tposition:static;\n\ttop:auto;\n\tleft:auto;\n\tright:auto;\n\tbottom:auto;\n\ttext-align:left !important;\n}\n\n.recaptchatable #recaptcha_image {\n  margin:auto;\n  border: 1px solid #dfdfdf !important;\n}\n\n.recaptchatable a img {\n  border:0px;\n}\n\n.recaptchatable a, .recaptchatable a:hover {\n  -moz-outline:none;\n  border:0px !important;\n  padding:0px !important;\n  text-decoration:none;\n  color:blue;\n  background:none !important;\n  font-weight: normal;\n}\n\n.recaptcha_input_area {\n  position:relative !important;\n  background:none !important;\n}\n\n.recaptchatable label.recaptcha_input_area_text {\n  border:1px solid #dfdfdf !important;\n  margin:0px !important;  \n  padding:0px !important;\n  position:static !important;\n  top:auto !important;\n  left:auto !important;\n  right:auto !important;\n  bottom:auto !important;\n}\n\n.recaptcha_theme_red label.recaptcha_input_area_text,\n.recaptcha_theme_white label.recaptcha_input_area_text {\n  color:black !important;\n}\n\n.recaptcha_theme_blackglass label.recaptcha_input_area_text {\n  color:white !important;\n}\n\n.recaptchatable #recaptcha_response_field  {\n  font-size:11pt;\n}\n\n.recaptcha_theme_blackglass #recaptcha_response_field,\n.recaptcha_theme_white #recaptcha_response_field {\n  border: 1px solid gray;\n}\n\n.recaptcha_theme_red #recaptcha_response_field {\n  border:1px solid #cca940;\n}\n\n.recaptcha_audio_cant_hear_link {\n  font-size:7pt;\n  color:black;\n}\n\n.recaptchatable {\n  line-height:1em;\n  border: 1px solid #dfdfdf !important;\n}\n\n.recaptcha_error_text {\n  color:red;\n}\n'
};
var RecaptchaStr_en = {
    visual_challenge : "Get a visual challenge",
    audio_challenge : "Get an audio challenge",
    refresh_btn : "Get a new challenge",
    
    instructions_visual : "Type the two words:",
    instructions_audio : "Type the eight numbers:",

    help_btn : "Help",
    cant_hear_this : "Can't hear the sound?"
};

var RecaptchaStr_de = {
    visual_challenge : "Visuelle Aufgabe generieren",
    audio_challenge : "Audio-Aufgabe generieren",
    refresh_btn : "Neue Aufgabe generieren",
   
    instructions_visual : "Gib die 2 Wörter ein:",
    instructions_audio : "Gib die 8 Ziffern ein:",

    help_btn : "Hilfe",
    cant_hear_this : "Kannst du nichts hören?"
};

var RecaptchaStr_es = {
    visual_challenge : "Obtén un reto visual",
    audio_challenge : "Obtén un reto audible",
    refresh_btn : "Obtén un nuevo reto",
    
    instructions_visual : "Escribe las 2 palabras:",
    instructions_audio : "Escribe los 8 números:",

    help_btn : "Ayuda",
    cant_hear_this : "¿No puedes oírel audio?"
};

var RecaptchaStr_fr = {
    visual_challenge : "Défi visuel",
    audio_challenge : "Défi audio",
    refresh_btn : "Nouveau défi",
    
    instructions_visual : "Entrez les deux mots:",
    instructions_audio : "Entrez les huit chiffres:",

    help_btn : "Aide",
    cant_hear_this : "Vous n'entendez pas de son?"
};

var RecaptchaStr_nl = {
    visual_challenge : "Test me via een afbeelding",
    audio_challenge : "Test me via een geluidsfragment",
    refresh_btn : "Nieuwe uitdaging",
    
    instructions_visual : "Type de twee woorden:",
    instructions_audio : "Type de acht cijfers:",

    help_btn : "Help",
    cant_hear_this : "Kun je het geluid niet horen?"
};

var RecaptchaStr_pt = {
    visual_challenge : "Obter um desafio visual",
    audio_challenge : "Obter um desafio sonoro",
    refresh_btn : "Obter um novo desafio",
    
    instructions_visual : "Escreva as 2 palavras:",
    instructions_audio : "Escreva os 8 numeros:",

    help_btn : "Ajuda",
    cant_hear_this : "Não consegue ouvir o som?"
};

var RecaptchaStr_ru = {
    visual_challenge : "\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443",
    audio_challenge : "\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0437\u0432\u0443\u043a\u043e\u0432\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443",
    refresh_btn : "\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043d\u043e\u0432\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443",
    
    instructions_visual : "\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0434\u0432\u0430 \u0441\u043b\u043e\u0432\u0430:",
    instructions_audio : "\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0432\u043e\u0441\u0435\u043c\u044c \u0447\u0438\u0441\u0435\u043b:",

    help_btn : "\u041f\u043e\u043c\u043e\u0449\u044c",
    cant_hear_this : "\u041d\u0435 \u0441\u043b\u044b\u0448\u0438\u0442\u0435 \u0437\u0432\u0443\u043a\u0430?"
};

var RecaptchaStr_tr = {
    visual_challenge : "G\u00f6rsel deneme",
    audio_challenge : "\u0130\u015Fitsel deneme",
    refresh_btn : "Yeni deneme",
    
    instructions_visual : "\u0130ki kelimeyi yaz\u0131n:",
    instructions_audio : "Sekiz numaray\u0131 yaz\u0131n:",

    help_btn : "Yard\u0131m (\u0130ngilizce)",
    cant_hear_this : "Duyamad\u0131n\u0131z m\u0131?"
};

var RecaptchaLangMap = { 
  en: RecaptchaStr_en,
  de: RecaptchaStr_de,
  es: RecaptchaStr_es,
  fr: RecaptchaStr_fr,
  nl: RecaptchaStr_nl,
  pt: RecaptchaStr_pt,
  ru: RecaptchaStr_ru,
  tr: RecaptchaStr_tr
};

var RecaptchaStr = RecaptchaStr_en;

var RecaptchaOptions;

var RecaptchaDefaultOptions = {
    tabindex: 0,
    theme: 'red',
    callback: null,
    lang: 'en'
};

var Recaptcha = {

    widget: null,
    
    timer_id: -1,

    style_set: false,

    theme: null,

    callback: null,

    type: 'image',

    helplink: 'http://recaptcha.net/popuphelp/',

    ajax_verify_cb : null,

    $: function(id) { 
      if (typeof(id) == "string") {
        return document.getElementById(id); 
      }
      else {
        return id;
      }
    },
    
    create: function(public_key, element, options) {
	Recaptcha.destroy();
	
	if (element) {
	    Recaptcha.widget = Recaptcha.$(element);
	}

	RecaptchaOptions = options;
	Recaptcha._call_challenge(public_key);
    },

    destroy: function() {
	if (!Recaptcha.widget) {
            return;
	}
	var challengefield = Recaptcha.$('recaptcha_challenge_field');
	if (challengefield) {
	    challengefield.parentNode.removeChild(challengefield);
	}

	if (Recaptcha.timer_id != -1) {
            clearInterval(Recaptcha.timer_id);
	}
	Recaptcha.timer_id = -1;
	
	if (Recaptcha.widget) {
	    Recaptcha.widget.innerHTML = "";
	    Recaptcha.widget = null;
	}
    },

    focus_response_field: function() {
	var $ = Recaptcha.$;
	var field = $('recaptcha_response_field');
        field.focus();
    },

    get_challenge: function() {
      if (typeof(RecaptchaState) == "undefined") {
        return null;
      }
      return RecaptchaState.challenge;
    },

    get_response: function() {
      var $ = Recaptcha.$;
      var field = $('recaptcha_response_field');
      if (!field) {
        return null;
      }
      return field.value;
    },

    ajax_verify: function(callback) {
	Recaptcha.ajax_verify_cb = callback;
	var scriptURL = Recaptcha._get_api_server() + "/ajaxverify" +
	    "?c=" + encodeURIComponent(Recaptcha.get_challenge()) +
	    "&response=" + encodeURIComponent(Recaptcha.get_response());
	Recaptcha._add_script(scriptURL);
    },

    _ajax_verify_callback : function(data) {
	Recaptcha.ajax_verify_cb(data);
    },

    _get_api_server : function() {
	var protocol = window.location.protocol;
	var server;
	if (typeof(_RecaptchaOverrideApiServer) != "undefined") {
	    server = _RecaptchaOverrideApiServer;
	} else if (protocol == 'https:') {
	    server = "api-secure.recaptcha.net";
	} else {
	    server = "api.recaptcha.net";
	}
	
	return protocol + "//" + server;
    },

    _call_challenge: function(public_key) {
		
	var scriptURL = Recaptcha._get_api_server() + "/challenge?k=" + public_key + "&ajax=1";
	if (typeof(RecaptchaOptions.extra_challenge_params) != "undefined") {
            scriptURL += "&" + RecaptchaOptions.extra_challenge_params;
	}
	
	Recaptcha._add_script(scriptURL);
    },

    _add_script: function(scriptURL) {
      var scriptTag = document.createElement("script");
      scriptTag.type = "text/javascript";
      scriptTag.src = scriptURL;
      Recaptcha._get_script_area().appendChild(scriptTag);
    },

    _get_script_area: function() {
      var parentElement = document.getElementsByTagName("head");
      if (!parentElement || parentElement.length < 1) {
        parentElement = document.body;
      }
      else {
        parentElement = parentElement[0];
      }
      return parentElement;
    },

    challenge_callback: function() {
      var element = Recaptcha.widget;
      Recaptcha._reset_timer ();

      var comb_opt = RecaptchaDefaultOptions;
      RecaptchaOptions = RecaptchaOptions || {};

      for (var p in RecaptchaOptions) {
        comb_opt[p] = RecaptchaOptions[p];
      }
      RecaptchaOptions = comb_opt;

      var lang = RecaptchaLangMap[RecaptchaOptions.lang];
      if (typeof(lang) != "undefined") {
        RecaptchaStr = lang;
      }

      /* Try to avoid back/forward cache problems */
      // firefox
      if (window.addEventListener) {
        window.addEventListener('unload', function(e){ Recaptcha.destroy(); }, false );
      }
      // IE
      if (Recaptcha._is_ie() && window.attachEvent) {
        window.attachEvent('onbeforeunload', function () {
          // I think this may be causing some errors -- it seems
          // that sometimes IE isn't submitting the form fully
          // This may be breaking the back button functionality
          // :-(
          //Recaptcha.destroy();
        });
      }
      // safari
      if (navigator.userAgent.indexOf("KHTML") > 0) {
        var iframe = document.createElement('iframe');
        iframe.src = "about:blank";
        iframe.style.height = "0px";
        iframe.style.width = "0px";
        iframe.style.visibility = "hidden";
        iframe.style.border = "none";
        var textNode = document.createTextNode("This frame prevents back/forward cache problems in Safari.");
        iframe.appendChild(textNode);
        document.body.appendChild(iframe);
      }   
      
      Recaptcha.finish_widget();
    },

    set_style: function(css) {
      // We only allow the style to be set once, because IE behaves
      // poorly otherwise.  Same goes for Recaptcha.theme.
      if (Recaptcha.style_set) {
        return;
      }
      Recaptcha.style_set = true;
      var styleTag = document.createElement("style");
      styleTag.type = "text/css";
      if (styleTag.styleSheet) { // IE only
        if (navigator.appVersion.indexOf("MSIE 5") != -1) { // IE 5 crashes if we add a style tag to the DOM
          document.write("<style type='text/css'>" + css + "</style>");
        }
        else {
          styleTag.styleSheet.cssText = css;
        }
      }
      else {
        var textNode = document.createTextNode(css);
        styleTag.appendChild(textNode);
      }
      Recaptcha._get_script_area().appendChild(styleTag);
    },

    finish_widget: function() {
      var $ = Recaptcha.$;
      var $_ = RecaptchaStr;
      var $ST = RecaptchaState;
      var $OPT = RecaptchaOptions;

      var theme = $OPT.theme;
      switch (theme) {
      case 'red': case 'white': case 'blackglass': case 'clean':
        break;
      default:
        theme = 'red';
        break;
      }
      if (!Recaptcha.theme) {
        Recaptcha.theme = theme;
      }
      

      var server_no_slash = $ST.server;
      if (server_no_slash[server_no_slash.length - 1] == "/")
      server_no_slash = server_no_slash.substring (0, server_no_slash.length - 1);
      var IMGROOT = server_no_slash + "/img/" + Recaptcha.theme
      
      var css;
      var html;
      var img_format;
      if (Recaptcha.theme == 'clean') {
        css = RecaptchaTemplates.CleanCss;
        html = RecaptchaTemplates.CleanHtml;
        img_format = "png";
      }
      else {
        css = RecaptchaTemplates.VertCss;
        html = RecaptchaTemplates.VertHtml;
        img_format = "gif";
      }
      css = css.replace (/IMGROOT/g, IMGROOT);
      
      Recaptcha.set_style(css);
      Recaptcha.widget.innerHTML = "<div id='recaptcha_area'>" + html + "</div>";

      $('recaptcha_table').className = "recaptchatable " + "recaptcha_theme_" + Recaptcha.theme
      $('recaptcha_image').src = $ST.server + 'image?c=' + $ST.challenge;
      
      $('recaptcha_challenge_field').value = $ST.challenge;
      $('recaptcha_response_field').tabIndex = $OPT.tabindex;
      
      $('recaptcha_reload_btn').href = "javascript:Recaptcha.reload ('r');";
      $('recaptcha_reload_btn').title = $_.refresh_btn;
      $('recaptcha_reload').alt = $_.refresh_btn;
      
      $('recaptcha_switch_audio_btn').href = "javascript:Recaptcha.switch_type('audio');";
      $('recaptcha_switch_audio').title = $_.audio_challenge;
      $('recaptcha_switch_audio').alt = $_.audio_challenge;
      
      $('recaptcha_switch_img_btn').href = "javascript:Recaptcha.switch_type('image');";
      $('recaptcha_switch_img').title = $_.visual_challenge;
      $('recaptcha_switch_img').alt = $_.visual_challenge;
      
      $('recaptcha_whatsthis_btn').href = Recaptcha.helplink;
      $('recaptcha_whatsthis_btn').target = "_blank";
      $('recaptcha_whatsthis').title = $_.help_btn;
      $('recaptcha_whatsthis').alt = $_.help_btn;
      
      $('recaptcha_whatsthis_btn').onclick = function () {
        Recaptcha.showhelp();
        return false; 
      };
      
      Recaptcha.set_instructions();
      
      if ($ST.error_message) {
        if ($("recaptcha_instructions")) {
          $("recaptcha_instructions").innerHTML = $ST.error_message;
        }
      }
      
      $('recaptcha_reload').src = IMGROOT + "/refresh." + img_format;
      $('recaptcha_switch_audio').src = IMGROOT + "/audio." + img_format;
      $('recaptcha_switch_img').src = IMGROOT + "/text." + img_format;
      $('recaptcha_whatsthis').src = IMGROOT + "/help." + img_format;
      if (Recaptcha.theme == 'clean') {
        $('recaptcha_logo').src = IMGROOT + "/logo." + img_format;
        $('recaptcha_tagline').src = IMGROOT + "/tagline." + img_format;
      }

      Recaptcha.widget.style.display = '';

      if ($OPT.callback) {
        $OPT.callback();
      }
    },

    switch_type : function (new_type) {
	var $C = Recaptcha;
	$C.type = new_type;
	$C.reload ($C.type == 'audio' ? 'a' : 'v');
    },
    
    reload: function (reason) {
	var $C = Recaptcha;
	var $ = $C.$;
	var $ST = RecaptchaState;
	
	$('recaptcha_area').style.cursor = 'progress';
	$('recaptcha_reload_btn').style.cursor = 'progress';
	// disable the button
	$('recaptcha_reload_btn').onclick = function () { return false; };


	var scriptURL = $ST.server + "reload?c=" + $ST.challenge + "&k=" + $ST.site + "&reason=" + reason + "&type=" + $C.type;
	if (typeof(RecaptchaOptions.extra_challenge_params) != "undefined") {
            scriptURL += "&" + RecaptchaOptions.extra_challenge_params;
	}
        $C._add_script(scriptURL);
	$C.doing_timeout = reason == 't';    
    },

    finish_reload: function (new_challenge, type) 
    {
	var $C = Recaptcha;
	var $ST = RecaptchaState;
	var $ = $C.$;
	$ST.challenge = new_challenge;
	
	// this should really be the case already...
	$C.type = type;

	$ ('recaptcha_challenge_field').value = $ST.challenge;

	function unwait () {
	    $('recaptcha_area').style.cursor = '';
	    $('recaptcha_reload_btn').style.cursor = '';
	    $('recaptcha_reload_btn').onclick = null;
	}

	if (type == 'audio') {
	    $('recaptcha_image').style.display = 'none'
	    unwait ();
	    var wavurl = $ST.server + "image?c=" + $ST.challenge;
	    var httpwavurl = wavurl;
	    
	    if (httpwavurl.indexOf("https://") == 0) {
		httpwavurl = "http://" + httpwavurl.substring(8);
	    }
	    
	    var embedCode;
	    if ($C._is_ie()) {
		embedCode = '<object height="40" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" src="' + httpwavurl + '" ><param name="URL" value="' + httpwavurl + '"><param name="autoStart" value="true"><param name="uimode" value="mini"></object>';
	    } else {
		embedCode = '<EMBED SRC="' + wavurl + '" height="40" bgcolor="white" AUTOSTART="true"/>';
	    }

	    var cantHearCode = '<br/><a class="recaptcha_audio_cant_hear_link" target="_blank" href="' + httpwavurl + '">' + RecaptchaStr.cant_hear_this + '</a>';
	    $("recaptcha_play_audio").innerHTML = embedCode + cantHearCode;
	    $("recaptcha_play_audio").style.display = 'block';

	    $("recaptcha_switch_audio_btn").style.display = 'none';
	    $("recaptcha_switch_img_btn").style.display = '';
	    
	} else if (type == 'image') {
	    $('recaptcha_image').onload = function () {
                
		$('recaptcha_image').style.display = ''
                $("recaptcha_play_audio").style.display = 'none';
		unwait ();
	    }
		
	    $("recaptcha_play_audio").innerHTML = "";

	    $('recaptcha_image').src = $ST.server + 'image?c=' + $ST.challenge;
	    
	    $("recaptcha_switch_img_btn").style.display = 'none';
	    $("recaptcha_switch_audio_btn").style.display = '';
	}
	
	$C.set_instructions();

	$C._clear_input ();
	if (!$C.doing_timeout) {
	    $ ('recaptcha_response_field').focus ();
	}

	$C._reset_timer ();
	$C.doing_timeout = false;
    },
    _reset_timer : function () {
        var $ST = RecaptchaState;
	clearInterval(Recaptcha.timer_id);
	Recaptcha.timer_id = setInterval ("Recaptcha.reload('t');", ($ST.timeout - 60*5) * 1000);
    },
    showhelp : function () {
	window.open(Recaptcha.helplink,"recaptcha_popup","width=460,height=570,location=no,menubar=no,status=no,toolbar=no,scrollbars=yes,resizable=yes");
    },
    _clear_input : function () {
	var resp=Recaptcha.$('recaptcha_response_field');
	resp.value = ""

    },
    set_instructions : function () {
        if (!Recaptcha.$("recaptcha_instructions")) {
          return;
        }
	var div = Recaptcha.$("recaptcha_instructions")
	if (Recaptcha.type == "image")
	    div.innerHTML = RecaptchaStr.instructions_visual
	else if (Recaptcha.type == "audio")
	    div.innerHTML = RecaptchaStr.instructions_audio
    },
    reloaderror : function (msg) {
        var $=Recaptcha.$;
	$('recaptcha_area').style.cursor = '';
	$('recaptcha_reload_btn').style.cursor = '';
	$('recaptcha_reload_btn').onclick = null;
	
	$('recaptcha_image').style.display = 'none'
	$("recaptcha_play_audio").innerHTML = msg;
    },
    _is_ie : function () { return (navigator.userAgent.indexOf("MSIE") > 0) && !window.opera; }

};
