var HOST = '<$MTBlogHost$>';

function OpenComments (c) {
   window.open(c,
               'comments',
               'width=480,height=480,scrollbars=yes,status=yes');
}

function OpenTrackback (c) {
   window.open(c,
               'trackback',
               'width=480,height=480,scrollbars=yes,status=yes');
}


function nextStrip(strip) {

// given a strip, produces an URL pointing to the next in sequence

   var re;
   re = /strips\/strip(\d+).jpg/;
   re.test(strip.src);
   nextStripNum = (parseInt(RegExp.$1) % 265) + 1;
   nextSrc = "http://randomwalks.com/imgs/blog/strips/strip" + nextStripNum + ".jpg";
//   alert(nextSrc);
   return nextSrc;
   }
   
function newStrip() {

// outputs an image which replaces itself with a random strip when clicked

   myStrip = Math.random() * 265;
   myStrip = (Math.round(myStrip)) + 1;
   document.write('<img src="http://randomwalks.com/imgs/blog/strips/strip' + myStrip + '.jpg" width="100%" border="0" name="strip' + myStrip + '" onclick="this.src = nextStrip(this);" />');
}

function srchFor(service, query) {
   switch(service.value) {
      case " rW ":
         window.location = "http://randomwalks.com/" + query.value;
         break;
      case " go ":
         window.location = "http://google.com/search?btnI&q=" + query.value;
         break;
      case " def ":
         window.location = "http://m-w.com/cgi-bin/dictionary?book=Dictionary&va=" + query.value;
         break;
      default:
         alert('no case');
         
   }
}


// Copyright (c) 1996-1997 Athenia Associates.
// http://www.webreference.com/js/
// License is granted if and only if this entire
// copyright notice is included. By Tomer Shiran.

function setCookie (name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
    document.cookie = curCookie;
}

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

function deleteCookie (name, path, domain) {
    if (getCookie(name))
        document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

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

function rememberMe (f) {
    var now = new Date();
    fixDate(now);
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
    setCookie('mtcmtauth', f.author.value, now, '', HOST, '');
    setCookie('mtcmtmail', f.email.value, now, '', HOST, '');
    setCookie('mtcmthome', f.url.value, now, '', HOST, '');
}

function forgetMe (f) {
    deleteCookie('mtcmtmail', '', HOST);
    deleteCookie('mtcmthome', '', HOST);
    deleteCookie('mtcmtauth', '', HOST);
    f.email.value = '';
    f.author.value = '';
    f.url.value = '';
}
