var mtCaptchaVisible = false;
function mtShowCaptcha() {
    var u = mtGetUser();
    if ( u && u.is_authenticated ) return;
    if (mtCaptchaVisible) return;
    var div = document.getElementById('comments-open-captcha');
    if (div) {
        div.innerHTML = '<div class="label"><label for="captcha_code">Captcha:</label></div><div class="field"><input type="hidden" name="token" value="Vft9AsUXellBb5wOE5rKhFDnX6VE6qf3TzfdMwLB" /><img src="http://raspberryfalls.org/cgi-bin/mt435/mt-comments.cgi/captcha/1/Vft9AsUXellBb5wOE5rKhFDnX6VE6qf3TzfdMwLB" width="150" height="35" /><br /><input name="captcha_code" id="captcha_code" value="" autocomplete="off" /><p>Type the characters you see in the picture above.</p></div>';
        mtCaptchaVisible = true;
    }
}

function mtEscapeJS(s) {
    s = s.replace(/'/g, "&apos;");
    return s;
}

function mtUnescapeJS(s) {
    s = s.replace(/&apos;/g, "'");
    return s;
}

function mtRememberMeOnClick(b) {
    if (!b.checked)
        mtClearUser(b.form);
    return true;
}

function mtCommentSessionVerify(app_user) {
    var u = mtGetUser();
    var f = document['comments_form'];
    if ( u && app_user && app_user.sid && ( u.sid == app_user.sid ) ) {
        f.submit();
    } else {
        alert('Your session has expired. Please sign in again to comment.');
        mtClearUser();
        mtFireEvent('usersignin');

    }
}

function mtReplyCommentOnClick(parent_id, author) {
    $('#comment-form-reply').show();

    var checkbox = document.getElementById('comment-reply');
    var label = document.getElementById('comment-reply-label');
    var text = document.getElementById('comment-text');

    // Populate label with new values
    var reply_text = 'Replying to <a href="#comment-'+ parent_id +'" onclick="location.href=this.href; return false">comment from '+ author +'</a>';
    label.innerHTML = reply_text;

    checkbox.value = parent_id; 
    checkbox.checked = true;
    text.focus();

    mtSetCommentParentID();
}

function mtSetCommentParentID() {
    var checkbox = document.getElementById('comment-reply');
    var parent_id_field = document.getElementById('comment-parent-id');
    if (!checkbox || !parent_id_field) return;

    var pid = 0;
    if (checkbox.checked == true)
        pid = checkbox.value;
    parent_id_field.value = pid;
}

function hideElement(id) {
    var el = document.getElementById(id);
    if (el.style.display == 'inline') 
       {
       el.style.display = 'none';
       }
    else 
       {
       el.style.display = 'inline';
       }
}

function showElement(id) {
    var el = document.getElementById(id);
    if (el.style.display == 'none') 
       {
       el.style.display = 'inline';
       }
    else 
       {
       el.style.display = 'none';
       }
}

// ***** Toggle Visibility *****
  function toggle_visibility(id, idimage, add, remove) {
    var e = document.getElementById(id);
    //       var f = document.getElementById(idtext);
    var g = document.getElementById(idimage);
    if(e.style.display == 'inline')
      {
      e.style.display = 'none';
    //          f.innerHTML = 'Show';
      g.src = 'http://www.theconsultingtimes.com/mt-static/mt-icons/'+add;
      }
    else
      {
      e.style.display = 'inline';
    //          f.innerHTML = 'Hide';
      g.src = 'http://www.theconsultingtimes.com/mt-static/mt-icons/'+remove;
      }
  }

