var analytics_code = "UA-574944-22";
var assets_index = 1;
function runpir() {
  $("#header-name-text").pir({size: 36, font: "euphor3d.ttf", color:"white"});
}


var svx_blog_id = 219;
var cgipath = 'http://www.informedretail.com/blog/cgi-bin/movabletype/';
var admincgi = 'http://www.savonix.com/blog/cgi-bin/movabletype/';
var commentscript = 'mt-comments.cgi';
var is_preview;
var armorval = 'c1acc7ae5b5a68b1129edf355e96a938fd469275';
var mtCookieName = "mt_blog_user";
var mtCookieDomain = ".informedretail.com";
var mtCookiePath = "/";
var mtCookieTimeout = 14400;
var svx_cdns = 'http://www-01.evenserver.com/s/';
var hostname = location.hostname.replace(/^www\./i,'');
var svx_pageslot_base = "SVX_"+hostname.replace(/\.(com|org|net|info)$/i,'')+"_";
svx_pageslot_base = svx_pageslot_base.replace(/\./,'-');
if(typeof(webpage_type) !== 'undefined') {
var svx_leaderboard = svx_pageslot_base+"blog_"+webpage_type+"_728x90";
var svx_banner_top = svx_pageslot_base+"blog_"+webpage_type+"_468x60";
var svx_box_right = svx_pageslot_base+"blog_"+webpage_type+"_300x250";
var svx_bbox_right = svx_pageslot_base+"blog_"+webpage_type+"_336x280";
}
var mtFetchedUser = false;
var mtCaptchaVisible = false;
var is_preview;
var user;


function mtHide(id) { $('#'+id).hide; }
function mtShow(id) { $('#'+id).show; }


function mtClearUser() {
    user = null;
    mtDeleteCookie(mtCookieName, mtCookiePath, mtCookieDomain,
        location.protocol == 'https:');
}


function mtSetCookie(name, value, expires, path, domain, secure) {
    if (domain && domain.match(/^\.?localhost$/))
        domain = null;
    var curCookie = name + "=" + escape(value) +
        (expires ? "; expires=" + expires.toGMTString() : "") +
        (path ? "; path=" + path : "") +
        (domain ? "; domain=" + domain : "") +
        (secure ? "; secure" : "");
    document.cookie = curCookie;
}


function mtGetCookie(name) {
    var prefix = name + '=';
    var c = document.cookie;
    var cookieStartIndex = c.indexOf(prefix);
    if (cookieStartIndex == -1)
        return '';
    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
    if (cookieEndIndex == -1)
        cookieEndIndex = c.length;
    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}


function mtDeleteCookie(name, path, domain, secure) {
    if (mtGetCookie(name)) {
        if (domain && domain.match(/^\.?localhost$/))
            domain = null;
        document.cookie = name + "=" +
            (path ? "; path=" + path : "") +
            (domain ? "; domain=" + domain : "") +
            (secure ? "; secure" : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function mtFixDate(date) {
    var skew = (new Date(0)).getTime();
    if (skew > 0)
        date.setTime(date.getTime() - skew);
}

function mtAttachEvent(eventName,func) {
    var onEventName = 'on' + eventName;
    var old = window[onEventName];
    if( typeof old != 'function' )
        window[onEventName] = func;
    else {
        window[onEventName] = function( evt ) {
            old( evt );
            return func( evt );
        };
    }
}

function mtFireEvent(eventName,param) {
    var fn = window['on' + eventName];
    if (typeof fn == 'function') return fn(param);
    return;
}

function mtRelativeDate(ts, fds) {
    var now = new Date();
    var ref = ts;
    var delta = Math.floor((now.getTime() - ref.getTime()) / 1000);

    var str;
    if (delta < 60) {
        str = 'moments ago';
    } else if (delta <= 86400) {
        // less than 1 day
        var hours = Math.floor(delta / 3600);
        var min = Math.floor((delta % 3600) / 60);
        if (hours == 1)
            str = '1 hour ago';
        else if (hours > 1)
            str = '2 hours ago'.replace(/2/, hours);
        else if (min == 1)
            str = '1 minute ago';
        else
            str = '2 minutes ago'.replace(/2/, min);
    } else if (delta <= 604800) {
        // less than 1 week
        var days = Math.floor(delta / 86400);
        var hours = Math.floor((delta % 86400) / 3600);
        if (days == 1)
            str = '1 day ago';
        else if (days > 1)
            str = '2 days ago'.replace(/2/, days);
        else if (hours == 1)
            str = '1 hour ago';
        else
            str = '2 hours ago'.replace(/2/, hours);
    }
    return str ? str : fds;
}


function mtCommentFormOnFocus() {
    mtShowCaptcha();
}


function mtSetUser(u) {
    if (u) {
        // persist this
        user = u;
        mtSaveUser();
        // sync up user greeting
        mtFireEvent('usersignin');
    }
}

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

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

function mtBakeUserCookie(u) {
    var str = "";
    if (u.name) str += "name:'" + mtEscapeJS(u.name) + "';";
    if (u.url) str += "url:'" + mtEscapeJS(u.url) + "';";
    if (u.email) str += "email:'" + mtEscapeJS(u.email) + "';";
    if (u.is_authenticated) str += "is_authenticated:'1';";
    if (u.profile) str += "profile:'" + mtEscapeJS(u.profile) + "';";
    if (u.userpic) str += "userpic:'" + mtEscapeJS(u.userpic) + "';";
    if (u.sid) str += "sid:'" + mtEscapeJS(u.sid) + "';";
    str += "is_trusted:'" + (u.is_trusted ? "1" : "0") + "';";
    str += "is_author:'" + (u.is_author ? "1" : "0") + "';";
    str += "is_banned:'" + (u.is_banned ? "1" : "0") + "';";
    str += "can_post:'" + (u.can_post ? "1" : "0") + "';";
    str += "can_comment:'" + (u.can_comment ? "1" : "0") + "';";
    str = str.replace(/;$/, '');
    return str;
}

function mtUnbakeUserCookie(s) {
    if (!s) return;

    var u = {};
    var m;
    while (m = s.match(/^((name|url|email|is_authenticated|profile|userpic|sid|is_trusted|is_author|is_banned|can_post|can_comment):'([^']+?)';?)/)) {
        s = s.substring(m[1].length);
        if (m[2].match(/^(is|can)_/)) // boolean fields
            u[m[2]] = m[3] == '1' ? true : false;
        else
            u[m[2]] = mtUnescapeJS(m[3]);
    }
    if (u.is_authenticated) {
        u.is_anonymous = false;
    } else {
        u.is_anonymous = true;
        u.can_post = false;
        u.is_author = false;
        u.is_banned = false;
        u.is_trusted = false;
    }
    return u;
}

function mtGetUser() {
    if (!user) {
        var cookie = mtGetCookie(mtCookieName);
        if (!cookie) return;
        user = mtUnbakeUserCookie(cookie);
        if (! user) {
            user = {};
            user.is_anonymous = true;
            user.can_post = false;
            user.is_author = false;
            user.is_banned = false;
            user.is_trusted = false;
        }
    }
    return user;
}


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


function mtFetchUser(cb) {
    if (!cb) cb = 'mtSetUser';
    if ( ( cb == 'mtSetUser' ) && mtGetUser() ) {
        var url = document.URL;
        url = url.replace(/#.+$/, '');
        url += '#comments-open';
        location.href = url;
    } else {
        // we aren't using AJAX for this, since we may have to request
        // from a different domain. JSONP to the rescue.
        mtFetchedUser = true;
        var script = document.createElement('script');
        var ts = new Date().getTime();
        script.src = cgipath+commentscript+'?__mode=session_js&blog_id='+svx_blog_id+'&jsonp=' + cb + '&ts=' + ts;
        (document.getElementsByTagName('head'))[0].appendChild(script);
    }
}



var mtRequestSubmitted = false;
function mtCommentOnSubmit(f) {
    if (!mtRequestSubmitted) {
        mtRequestSubmitted = true;

        if (f.armor)
            f.armor.value = armorval;

        if (f.bakecookie && f.bakecookie.checked)
            mtSaveUser(f);

        // disable submit buttons
        if (f.preview_button) f.preview_button.disabled = true;
        if (f.post) f.post.disabled = true;

        var u = mtGetUser();
        if ( !is_preview && ( u && u.is_authenticated ) ) {
            // validate session; then submit
            mtFetchedUser = false;
            mtFetchUser('mtCommentSessionVerify');
            return false;
        }

        return true;
    }
    return false;
}

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 mtEditLink() {
    var u = mtGetUser();
    if (! u) return;
    if (! entry_id) return;
    if (! u.is_author) return;
    var link = ' <span class="separator">|</span> <a href="'+admincgi+'mt.cgi?__mode=view&amp;_type=entry&amp;id=' + entry_id + '&amp;blog_id=' + svx_blog_id + '">Edit</a>';
    $('.asset-meta',$('.asset-header')).append(link);
}
function mtUserOnLoad() {
    var u = mtGetUser();

    // if the user is authenticated, hide the 'anonymous' fields
    // and any captcha input if already shown
    if ($('#comments-form').length > 0) {
        if ( u && u.is_authenticated ) {
            $('#comments-form').show();
            $('#comments-open-data').hide();
            if (mtCaptchaVisible) {
              $('#comments-open-data').hide();
            }
        }

        // if we're previewing a comment, make sure the captcha
        // field is visible
        if (is_preview)
            mtShowCaptcha();
        else
            mtShowGreeting();

        // populate anonymous comment fields if user is cookied as anonymous
        var cf = document['comments_form'];
        if (cf) {
            if (u && u.is_anonymous) {
                if (u.email) cf.email.value = u.email;
                if (u.name) cf.author.value = u.name;
                if (u.url) cf.url.value = u.url;
                if (cf.bakecookie)
                    cf.bakecookie.checked = u.name || u.email;
            } else {
                if (u && u.sid && cf.sid)
                    cf.sid.value = u.sid;
            }
            if (cf.post.disabled)
                cf.post.disabled = false;
            if (cf.preview_button.disabled)
                cf.preview_button.disabled = false;
            mtRequestSubmitted = false;
        }
    }
    if ( u && u.is_authenticated ) {
      mtEditLink();
    }
}
function mtEntryOnLoad() {
  //$('#trackbacks-info').hide();
  //
  mtFireEvent('usersignin');
}

function mtEntryOnUnload() {
  if (mtRequestSubmitted) {
      var cf = document['comments_form'];
      if (cf) {
          if (cf.post && cf.post.disabled)
              cf.post.disabled = false;
          if (cf.preview_button && cf.preview_button.disabled)
              cf.preview_button.disabled = false;
      }
      mtRequestSubmitted = false;
  }
  return true;
}

mtAttachEvent('usersignin', mtUserOnLoad);

function mtSignInOnClick(sign_in_element) {
    var el;
    if (sign_in_element) {
        // display throbber
        el = document.getElementById(sign_in_element);
        if (!el)  // legacy MT 4.x element id
            el = document.getElementById('comment-form-external-auth');
    }
    if (el)
        el.innerHTML = 'Signing in... <span class="status-indicator">&nbsp;</span>';

    mtClearUser(); // clear any 'anonymous' user cookie to allow sign in
    mtFetchUser('mtSetUserOrLogin');
    return false;
}

function mtSetUserOrLogin(u) {
    if (u && u.is_authenticated) {
        mtSetUser(u);
    } else {
        // user really isn't logged in; so let's do this!
        mtSignIn();
    }
}


function mtSignOutOnClick() {
    mtSignOut();
    return false;
}



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 mtSaveUser(f) {
    // We can't reliably store the user cookie during a preview.
    if (is_preview) return;

    var u = mtGetUser();

    if (f && (!u || u.is_anonymous)) {
        if ( !u ) {
            u = {};
            u.is_authenticated = false;
            u.can_comment = true;
            u.is_author = false;
            u.is_banned = false;
            u.is_anonymous = true;
            u.is_trusted = false;
        }
        if (f.author != undefined) u.name = f.author.value;
        if (f.email != undefined) u.email = f.email.value;
        if (f.url != undefined) u.url = f.url.value;
    }

    if (!u) return;

    var cache_period = mtCookieTimeout * 1000;

    // cache anonymous user info for a long period if the
    // user has requested to be remembered
    if (u.is_anonymous && f && f.bakecookie && f.bakecookie.checked)
        cache_period = 365 * 24 * 60 * 60 * 1000;

    var now = new Date();
    mtFixDate(now);
    now.setTime(now.getTime() + cache_period);

    var cmtcookie = mtBakeUserCookie(u);
    mtSetCookie(mtCookieName, cmtcookie, now, mtCookiePath, mtCookieDomain,
        location.protocol == 'https:');
}



function mtInit() {
    if (arguments.callee.done) return;
    arguments.callee.done = true;
    if ( window._timer ) clearInterval(window._timer);
    if ( window.onload && ( window.onload !== window.mtInit ) ) {
        window.onload();
        window.onload = function() {};
    }
}



function svxvp(canurl) {
  $.ajax({
     type: 'POST',
     url: '/dyn/ruby/pagepop.fcgi',
     data: 'url='+canurl,
     success: function(msg){
     }
  });
}
function vote4page(canurl,divselect) {
  $.ajax({
     type: 'POST',
     url: '/dyn/ruby/pagepop.fcgi',
     data: 'url='+canurl,
     success: function(msg){
        $(divselect).text(msg);
     }
  });
}
function pagevotes(canurl,divselect) {
  var cd = new Date();
  var epoch = cd.getUTCMilliseconds();
  $.ajax({
     type: 'GET',
     url: '/dyn/ruby/pagepop.fcgi',
     data: 'ts='+epoch,
     success: function(msg){
        $(divselect).text(msg+" views");
     }
  });
}

function svx_loadjs(jshref, callback) {
    var tmp = document.createElement('script'); tmp.type = 'text/javascript'; tmp.async = true;
    tmp.src = jshref;
    var svxsl = document.getElementsByTagName('script').length - 1;
    var s = document.getElementsByTagName('script')[svxsl]; s.parentNode.insertBefore(tmp, s);
}

function svx_loadcss(csshref) {
  $('<link>', {
    'rel':  'stylesheet',
    'type': 'text/css',
    'href': csshref
  }).appendTo('head');
}

function svx_showsnib(svx_divsel,svn_togico) {
  svx_divsel.slideDown('slow');
  svn_togico.html('&#8855;');
}
function svx_hidesnib(svx_divsel,svn_togico) {
  svx_divsel.slideUp('slow');
  svn_togico.html('&#8853;');
}


$('document').ready(function() {
  mtInit();

  var svx_pg_title = $("#page-title",$('#alpha-inner')).text();

  if(typeof(entry_id) !== 'undefined') {

    if($('a', $('.svx_neighbor_pg')).length > 0) {
      svx_loadcss(svx_cdns+'pkgs/tipsy/src/stylesheets/tipsy.css');
      $.getScript(svx_cdns+'pkgs/tipsy/js/jquery.tipsy.min.js', function() {
        $('a', $('.svx_neighbor_pg')).tipsy({gravity: 'n'});
      });
    }
    if($('#comments-form',$('#alpha-inner')).length==0) {
//      $('#comments-open',$('#alpha-inner')).html('<div class="comments-open" id="comments-open-inner">\n    <h2 class="comments-open-header">Leave a comment</h2>\n    <div class="comments-open-content">\n        <div id="comment-greeting"></div>\n\n        <form method="post" action="/blog/cgi-bin/movabletype/mt-comments.cgi" name="comments_form" id="comments-form" onsubmit="return mtCommentOnSubmit(this)">\n            <input type="hidden" name="static" value="1" />\n            <input type="hidden" name="__lang" value="en" />\n            <input type="hidden" name="armor" value="1" />\n            <input type="hidden" name="preview" value="" />\n            <input type="hidden" name="sid" value="" />\n            <div id="comments-open-data">\n                <div id="comment-form-name">\n                    <label for="comment-author">Name</label>\n                    <input id="comment-author" name="author" size="30" value="" onfocus="mtCommentFormOnFocus()" />\n                </div>\n                <div id="comment-form-email">\n                    <label for="comment-email">Email Address</label>\n                    <input id="comment-email" name="email" size="30" value="" onfocus="mtCommentFormOnFocus()" />\n                </div>\n                <div id="comment-form-url">\n                    <label for="comment-url">URL</label>\n                    <input id="comment-url" name="url" size="30" value="" onfocus="mtCommentFormOnFocus()" />\n                </div>\n                <div id="comment-form-remember-me">\n                    <input type="checkbox" id="comment-bake-cookie" name="bakecookie" onclick="mtRememberMeOnClick(this)" value="1" accesskey="r" />\n                    <label for="comment-bake-cookie">Remember personal info?</label>\n                </div>\n            </div>\n            <div id="comment-form-reply" style="display:none">\n                <input type="checkbox" id="comment-reply" name="comment_reply" value="" onclick="mtSetCommentParentID()" />\n                <label for="comment-reply" id="comment-reply-label"></label>\n            </div>\n            <div id="comment-form-subscribe">\n                <label for="comment-subscribe"><input type="checkbox" id="comment-subscribe" name="subscribe" />\n                Receive email notification of further comments.</label>\n            </div>\n            <div id="comments-open-text">\n                <label for="comment-text">Comments\n                (You may use HTML tags for style)</label>\n                <textarea id="comment-text" name="text" rows="15" cols="50" onfocus="mtCommentFormOnFocus()"></textarea>\n            </div>\n            <div id="comments-open-captcha"></div>\n            <div id="comments-open-footer">\n                <input type="submit" accesskey="v" name="preview_button" id="comment-preview" value="Preview" onclick="this.form.preview.value=\'1\';" />\n                <input type="submit" accesskey="s" name="post" id="comment-submit" value="Submit" />\n            </div>\n        </form>\n    </div>\n</div>');
      $('#comments-open',$('#alpha-inner')).html('<div class="comments-open" id="comments-open-inner"><h2 class="comments-open-header">Leave a comment</h2>\n    <div class="comments-open-content">\n        <div id="comment-greeting"></div>\n\n        <form method="post" action="/blog/cgi-bin/movabletype/mt-comments.cgi" name="comments_form" id="comments-form" onsubmit="return mtCommentOnSubmit(this)">\n            <input type="hidden" name="static" value="1" />\n            <input type="hidden" name="__lang" value="en" />\n            <input type="hidden" name="armor" value="1" />\n            <input type="hidden" name="preview" value="" />\n            <input type="hidden" name="sid" value="" />\n            <div id="comments-open-data">\n                <div id="comment-form-name">\n                    <label for="comment-author">Name</label>\n                    <input id="comment-author" name="author" size="30" value="" onfocus="mtCommentFormOnFocus()" />\n                <div id="comment-form-email">\n                    <label for="comment-email">Email Address</label>\n                    <input id="comment-email" name="email" size="30" value="" onfocus="mtCommentFormOnFocus()" />\n                </div>\n                \n                </div><div id="comments-open-text">\n                <label for="comment-text">Comments\n</label>\n                <textarea id="comment-text" name="text" rows="15" cols="50" onfocus="mtCommentFormOnFocus()"></textarea>\n            </div>\n            <div id="comments-open-captcha"></div>\n            <div id="comments-open-footer">\n                <input type="submit" accesskey="v" name="preview_button" id="comment-preview" value="Preview" onclick="this.form.preview.value=\'1\';" />\n                <input type="submit" accesskey="s" name="post" id="comment-submit" value="Submit" />\n            </div>\n        </form>\n    </div>\n</div>');
      $('<input />', {
        'type': 'hidden',
        'name': 'entry_id',
        'val': entry_id
      }).appendTo('#comments-form');
      mtEntryOnLoad();
      $(window).unload(function() { mtEntryOnUnload(); });
    }
  }

  if($('#svx_catarcct',$('.widget-archive-category')).length > 0) {
    var svx_divsel = $('#svx_catarcct',$('.widget-archive-category'));
    var svn_togico = $('h3 span',$('.widget-archive-category'));
    $('h3',$('.widget-archive-category')).css('cursor','pointer').one('click',function() {
      $.get('http://www.informedretail.com/d/html/category_index.html', function(data) {
        svx_divsel.append(data);
        svx_showsnib(svx_divsel,svn_togico);
      });
    });
    $('h3',$('.widget-archive-category')).toggle(
      function() {
        svx_showsnib(svx_divsel,svn_togico);
      },
      function() {
        svx_hidesnib(svx_divsel,svn_togico);
      }
    );
  }

  if(typeof(assets_index) !== 'undefined') {
    $.get('http://www.informedretail.com/d/html/assets_index.html', function(data) {
      $('#beta-inner').append(data);
    });
  }

  if($('.thickbox').length > 0) {
    $.getScript(svx_cdns+'js/jquery/plugins/thickbox-compressed.js', function() {
      svx_loadcss(svx_cdns+'css/thickbox.min.css');
    });
  }
  if($('.tablesorter').length > 0) {
    $.getScript(svx_cdns+'js/jquery/plugins/tablesorter/jquery.tablesorter.min.js', function() {
      if($().metadata) { } else {
        $.getScript(svx_cdns+'js/jquery/plugins/jquery.metadata-2.1.min.js', function() {
          svx_loadcss(svx_cdns+'js/jquery/plugins/tablesorter/themes/blue/style.css');
          $('#svx_tablesort').tablesorter();
        });
      }
    });
  }

  if($('pre').length > 0) {
    if(typeof(sh_theme) == 'undefined') {
      sh_theme = 'sh_vim.min.css';
    }
    $.getScript(svx_cdns+'pkgs/shjs-0.6/sh_main.min.js', function() {
      $('<link>', {
        'rel':  'stylesheet',
        'type': 'text/css',
        'href': svx_cdns+'pkgs/shjs-0.6/css/'+sh_theme
      }).appendTo('head');
      sh_highlightDocument('/s/pkgs/shjs-0.6/lang/', '.min.js');
    });
  }
  if($('.prettyprint').length > 0) {
    $.getScript(svx_cdns+'pkgs/prettify/prettify.js', function() {
      $('<link>', {
        'rel':  'stylesheet',
        'type': 'text/css',
        'href': svx_cdns+'pkgs/prettify/prettify.css'
      }).appendTo('head');
      prettyPrint();
    });
  }

  if($('.svx-jcorner').length > 0) {
    $.getScript(svx_cdns+'js/jquery/plugins/jquery.corner.min.js', function() {
      $('.svx-jcorner').corner().show();
    });
  }

  if ($('.svx_banner_top').height() == 0) {
    $('.svx_banner_top').append('<a href="http://www.informedbanking.com/">Informed Banking is Awesome!</a>');
    $('.lk134def').append('<a href="http://www.pbooks.org/">PBooks Open Source Bookkeeping Software</a>');
  }

  if($('body.mt-entry-archive').length == 0) { } else {
    var canurl = location.hostname + location.pathname;
    svxvp(canurl);
    if($("#34fh84").length == 1) {
      pagevotes(canurl,"#34fh84");
    }
  }

});


var _gaq = _gaq || [];
_gaq.push(['_setAccount', analytics_code]);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();




function svxRunga() { }

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="zI42ctwsD1QkakmFflgTLOYUmICMwKScRczNmgRG" /><img src="/blog/cgi-bin/movabletype/mt-comments.cgi/captcha/219/zI42ctwsD1QkakmFflgTLOYUmICMwKScRczNmgRG" 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 mtSignIn() {
    var doc_url = document.URL;
    doc_url = doc_url.replace(/#.+/, '');
    var url = 'http://www.informedretail.com/blog/cgi-bin/movabletype/mt-comments.cgi?__mode=login&blog_id=219';
    if (is_preview) {
        if ( document['comments_form'] ) {
            var entry_id = document['comments_form'].entry_id.value;
            url += '&entry_id=' + entry_id;
        } else {
            url += '&return_url=http%3A%2F%2Fwww.informedretail.com%2F';
        }
    } else {
        url += '&return_url=' + encodeURIComponent(doc_url);
    }
    mtClearUser();
    location.href = url;
}

function mtSignOut(entry_id) {
    mtClearUser();
    var doc_url = document.URL;
    doc_url = doc_url.replace(/#.+/, '');
    var url = 'http://www.informedretail.com/blog/cgi-bin/movabletype/mt-comments.cgi?__mode=handle_sign_in&static=0&logout=1';
    if (is_preview) {
        if ( document['comments_form'] ) {
            var entry_id = document['comments_form'].entry_id.value;
            url += '&entry_id=' + entry_id;
        } else {
            url += '&return_url=http%3A%2F%2Fwww.informedretail.com%2F';
        }
    } else {
        url += '&return_url=' + encodeURIComponent(doc_url);
    }
    location.href = url;
}

function mtShowGreeting() {

    var reg_reqd = false;

    var cf = document['comments_form'];
    if (!cf) return;

    var el = document.getElementById('comment-greeting');
    if (!el)  // legacy MT 4.x element id
        el = document.getElementById('comment-form-external-auth');
    if (!el) return;

    var eid = cf.entry_id;
    var entry_id;
    if (eid) entry_id = eid.value;

    var phrase;
    var u = mtGetUser();

    if ( u && u.is_authenticated ) {
        if ( u.is_banned ) {
            phrase = 'You do not have permission to comment on this blog. (\<a href=\"javas\cript:void(0);\" onclick=\"return mtSignOutOnClick();\"\>sign out\<\/a\>)';
        } else {
            var user_link;
            if ( u.is_author ) {
                user_link = '<a href="http://www.informedretail.com/blog/cgi-bin/movabletype/mt-comments.cgi?__mode=edit_profile&return_url=' + encodeURIComponent( location.href );
                user_link += '">' + u.name + '</a>';
            } else {
                // registered user, but not a user with posting rights
                if (u.url)
                    user_link = '<a href="' + u.url + '">' + u.name + '</a>';
                else
                    user_link = u.name;
            }
            // TBD: supplement phrase with userpic if one is available.
            phrase = 'Thanks for signing in, __NAME__. (\<a href=\"javas\cript:void(0)\" onclick=\"return mtSignOutOnClick();\"\>sign out\<\/a\>)';
            phrase = phrase.replace(/__NAME__/, user_link);
        }
    } else {
        if (reg_reqd) {
            phrase = '\<a href=\"javas\cript:void(0)\" onclick=\"return mtSignInOnClick(\'comment-greeting\')\"\>Sign in\<\/a\> to comment.';
        } else {
            phrase = '\<a href=\"javas\cript:void(0)\" onclick=\"return mtSignInOnClick(\'comment-greeting\')\"\>Sign in\<\/a\> to comment, or comment anonymously.';
        }
    }
    el.innerHTML = phrase;

}

function mtReplyCommentOnClick(parent_id, author) {
    mtShow('comment-form-reply');

    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__\" onclick=\"location.href=this.href; return false\"\>comment from __AUTHOR__\<\/a\>';
    reply_text = reply_text.replace(/__PARENT__/, parent_id);
    reply_text = reply_text.replace(/__AUTHOR__/, author);
    label.innerHTML = reply_text;

    checkbox.value = parent_id; 
    checkbox.checked = true;
    try {
        // text field may be hidden
        text.focus();
    } catch(e) {
    }
    mtSetCommentParentID();
}

