  function setCommentProperties(cid){
       document.write('<a href="javascript:showCommentWindow(\''+cid+'\');"> Post a comment.</a>'); 
       document.write('<form method="POST" name="comment'+cid+'" ACTION="http://thecaverns.netfirms.com/cgi-bin/postcommentblog.pl">');
       document.write('<div class="entercomment">');
       document.write('<span id="name'+cid+'"> name: &nbsp </span>');
       document.write('<INPUT id="author'+cid+'" TYPE="text" value="" name="author">');
       document.write('</div>');
       document.write('<div class="entercomment">');
       document.write('<textarea id="text'+cid+'" rows="5" cols="45" value=""> </textarea>');
       document.write('</div>');
       document.write('<div class="entercomment">');
       document.write('<a id="sub'+cid+'" href="javascript:submitComment(\''+cid+'\')">submit</a>');
       document.write('   ');
       document.write('<a id="can'+cid+'" href="javascript:hideComment(\''+cid+'\')">cancel</a>');
       document.write('</div>');
       document.write('<INPUT TYPE="hidden" name="uniqueid" value="'+cid+'">');
       document.write('</form>');
       document.getElementById('name'+cid).style.display='none';
       document.getElementById('author'+cid).style.display='none';
       document.getElementById('text'+cid).style.display='none';
       document.getElementById('sub'+cid).style.display='none';
       document.getElementById('can'+cid).style.display='none';
    }
    
   function showCommentWindow(cid){
      document.getElementById('name'+cid).style.display='';
      document.getElementById('author'+cid).style.display='';
      document.getElementById('text'+cid).style.display='';
      document.getElementById('sub'+cid).style.display='';
      document.getElementById('can'+cid).style.display='';
   }

   function clearComment(cid){
      document.getElementById('author'+cid).value='';
      document.getElementById('text'+cid).value='';
   }

   function hideComment(cid){
      document.getElementById('name'+cid).style.display='none';
      document.getElementById('author'+cid).style.display='none';
      document.getElementById('text'+cid).style.display='none';
      document.getElementById('sub'+cid).style.display='none';
      document.getElementById('can'+cid).style.display='none';
   }
   
   function createXMLHttpRequest(){
     try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
     try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
     try { return new XMLHttpRequest(); } catch(e) {}
     alert("XMLHTTPRequest not supported");
     return null;
   }
   
   function submitComment(cid){
     var good;
     good = true;
     var author = document.getElementById('author'+cid);
     var comment = document.getElementById('text'+cid);
     if (comment.value == ""){
       alert("Please enter a comment.");
       good = false;
     }
     else if (
         (comment.value.indexOf('%') != -1) ||
         (comment.value.indexOf('~') != -1) ||
         (author.value.indexOf('%')  != -1) ||
         (author.value.indexOf('~') != -1)
         ){
       alert("Please remove any special characters from your comment.")
       good = false;
     }

     //var re=/<\S[^><]*>/g;
     if(good){
      //comment.value=comment.value.replace(re,"");
      //author.value=author.value.replace(re,"");
      //document.getElementById('comment'+cid).submit();
      
      var dt = new Date();
      //format datetime for input	
	   var hour, min, month, day, year, pm, datestr;
	   hour = dt.getHours();
	   min = dt.getMinutes();
	   month = dt.getMonth() + 1;
	   day = dt.getDate();
	   year = dt.getFullYear();
      if (hour > 12){
        hour = 24 - hour;
        hour = 12 - hour;
	   pm = true;
      }else{ pm = false;}
	if (min < 10){
        min = '0' + min;
      }
      if (pm == true){
	      datestr = month+'.'+day+'.'+year+'  '+hour+':'+min+' PM';
      }
      else{
	      datestr = month+'.'+day+'.'+year+'  '+hour+':'+min+' AM';
      }
      var xh = createXMLHttpRequest();

      xh.open("POST", "http://thecaverns.netfirms.com/cgi-bin/postcommentblog.pl", false);
      xh.send('nothing=x&uniqueid='+cid+'&datetime='+datestr+'&commenttext='+comment.value+'&author='+author.value);  
      
      clearComment(cid);
      hideComment(cid);
      
      window.location.reload(false);
     }
   }

   function loadComments(cid){
     // build the ajax request
     var xh = createXMLHttpRequest();
     xh.open("GET", 'http://thecaverns.netfirms.com/cgi-bin/getcommentblog.pl?uniqueid='+cid,false);
     xh.send(null);
     var serverResponse = xh.responseText;
     document.write(serverResponse);
   }

  function toggleComments(numComments){
     var commentRule = getCSSRule('div.comments');
     if (commentRule.style.display == 'none'){
       commentRule.style.display = '';
       document.getElementById('commentLabel').innerHTML = 'Hide Comments';
     }else{
       commentRule.style.display = 'none';
       document.getElementById('commentLabel').innerHTML = 'Show Comments ('+numComments+')';
     }
  }

  function getNumComments(cid){
    var xh = createXMLHttpRequest();
    xh.open("GET", 'http://thecaverns.netfirms.com/cgi-bin/getcommentblog.pl?uniqueid='+cid+'&action=count',false);
    xh.send(null);
    return xh.responseText;
  }

  // adapted from www.hunlock.com
  function getCSSRule(ruleName){
    ruleName = ruleName.toLowerCase();
    if (document.styleSheets){
      for (var i=0; i<document.styleSheets.length; i++){
        var styleSheet=document.styleSheets[i];
        var ii = 0;
        var cssRule=true;
        while (cssRule){
          if (styleSheet.cssRules){
            cssRule = styleSheet.cssRules[ii];
          }else{
            cssRule = styleSheet.rules[ii];
          }
          if (cssRule){
            if (cssRule.selectorText.toLowerCase()==ruleName){
              return cssRule;
            }
          }
          ii++;
        } // while
      } // for
    } // if
  } // function
