function format_comments(obj) {
   var div = document.getElementById('latest_comments');
   while( div.hasChildNodes() ) { div.removeChild( div.lastChild ); }
   var data = eval(obj);
   var voter = "";
   if (GetCookie('startribune_user_auth')) {
      voter = GetCookie('startribune_user_auth').replace(/\|.*/,"");
   }
/**
   var internal_anchor = document.createElement('a');
   internal_anchor.href = '#comments';
   div.appendChild(internal_anchor);
   var comment_count_par = document.createElement('h2');

   if (data.contest_label != "") {
      comment_count_par.appendChild(document.createTextNode(data.contest_label));
   }

   if (data.comment_count > 5) {
      if (data.contest_label == "") {
         comment_count_par.appendChild(document.createTextNode("Comment on this story"));
      }
      var comment_count_span = document.createElement('span');
      comment_count_span.appendChild(document.createTextNode("\u00a0\u00a0|\u00a0\u00a0"));
      var all_comments_url = document.createElement('a');
      all_comments_url.href = "http://ww2.startribune.com/user_comments/comments.php?d=asset_comments&asset_id=" + data.asset_id;
      if (data.section != "") {
         all_comments_url.href += "&section=" + data.section;
      }
      all_comments_url.appendChild(document.createTextNode("Read all " + data.comment_count + " comments"));
      comment_count_span.appendChild(all_comments_url);
      comment_count_par.appendChild(comment_count_span);
   }
   else if (data.comment_count > 0 && data.contest_label == "") {
      comment_count_par.appendChild(document.createTextNode("Comment on this story"));
   }
   else if (data.comment_count == 0 && data.contest_label == "") {
      comment_count_par.appendChild(document.createTextNode("Be the first one to post a comment"));
   }
   div.appendChild(comment_count_par);

   //if not logged in, another message with link to member center
   if (GetCookie('startribune_user_auth')) {
   }
   else {
      var not_logged_in_par = document.createElement('p');
      var register_url = document.createElement('a');
      register_url.href = "http://www.startribune.com/s?action=login&rurl=" + data.section + "/"
                           + data.asset_id + ".html";
      register_url.appendChild(document.createTextNode("Register or log in"));
      not_logged_in_par.appendChild(register_url);
      not_logged_in_par.appendChild(document.createTextNode(" to post and/or vote a comment"));
      div.appendChild(not_logged_in_par);
   }
*/

   for (var i=data.comments.length-1;i>=0;i--)
   {
      var comment_id_div = document.createElement('div');
      comment_id_div.id = "comment_" + data.comments[i].comment.id;
      comment_id_div.className = 'comment';
      if (data.comments[i].comment.title != "") {
         var comment_title_par = document.createElement('h3');
         comment_title_par.appendChild(document.createTextNode(data.comments[i].comment.title));
         comment_id_div.appendChild(comment_title_par);
      }
      var comment_par = document.createElement('p');
      if (data.comments[i].comment.body != "") {
         comment_par.appendChild(document.createTextNode(data.comments[i].comment.body));
      }
      comment_id_div.appendChild(comment_par);
      var post_details_div = document.createElement('div');
      post_details_div.className = 'postDetails';
      var comment_posted_by = document.createElement('span');
      comment_posted_by.className = 'postedBy';
      var create_dtime = data.comments[i].comment.create_dtime;
      var year = create_dtime.substring(0,4); 
      var month = create_dtime.substring(5,7); 
      var day = create_dtime.substring(8,10); 
      var hour = create_dtime.substring(11,13); 
      var minute = create_dtime.substring(14,16); 
      d = new Date(year, month-1, day, hour, minute);
      var create_datetime = d.formatDate("M j, y \\a\\t g:i a");
      comment_posted_by.appendChild(document.createTextNode("posted by "));
      var bold_posted_by = document.createElement('b');
      bold_posted_by.appendChild(document.createTextNode(data.comments[i].comment.user_name));
      comment_posted_by.appendChild(bold_posted_by);
      comment_posted_by.appendChild(document.createTextNode(" on " + create_datetime + "\u00a0|\u00a0"));
      var comment_abuse_report_span = document.createElement('span');
      comment_abuse_report_span.id = "comment_abuse_report_" + data.comments[i].comment.id;
      var comment_ar_form = create_abuse_report_form(data.comments[i].comment.id);
      comment_abuse_report_span.appendChild(comment_ar_form);
      comment_posted_by.appendChild(comment_abuse_report_span);
      post_details_div.appendChild(comment_posted_by);
      var comment_vote_span = document.createElement('div');
      comment_vote_span.id = "comment_vote_" + data.comments[i].comment.id;
      if (voter != "" && voter != data.comments[i].comment.user_name) {
         var comment_vote_form = create_vote_form(data.comments[i].comment.id, data.comments[i].comment.yes_vote_count, data.comments[i].comment.total_vote_count, data.comments[i].comment.user_name, 1);
      }
      else {
         var comment_vote_form = create_vote_form(data.comments[i].comment.id, data.comments[i].comment.yes_vote_count, data.comments[i].comment.total_vote_count, data.comments[i].comment.user_name, 0);
      }
      comment_vote_span.appendChild(comment_vote_form);
      post_details_div.appendChild(comment_vote_span);
      comment_id_div.appendChild(post_details_div);
      document.getElementById('latest_comments').appendChild(comment_id_div);
   }
/**
   if (data.comment_count > 5) {
      var read_all_par = document.createElement('p');
      read_all_par.className = 'readAllComments';
      var all_comments_bottom_url = document.createElement('a');
      all_comments_bottom_url.href = "http://ww2.startribune.com/user_comments/comments.php?d=asset_comments&asset_id=" + data.asset_id;
      if (data.section != "") {
         all_comments_bottom_url.href += "&section=" + data.section;
      }
      all_comments_bottom_url.appendChild(document.createTextNode("Read all " + data.comment_count + " comments"));
      read_all_par.appendChild(all_comments_bottom_url);
      document.getElementById('latest_comments').appendChild(read_all_par);
   }
*/
}

function format_votes(obj) {
   var data = eval(obj);
   var comment_vote_div = document.getElementById("comment_vote_" + data.id);
   while( comment_vote_div.hasChildNodes() ) { comment_vote_div.removeChild( comment_vote_div.lastChild ); }
   var comment_vote_form = create_vote_form(data.id, data.yes_vote_count, data.total_vote_count, data.user_name, 1);
   comment_vote_div.appendChild(comment_vote_form);
}

function create_vote_form(comment_id, yes_vote_count, total_vote_count, creator_name, allow_vote) {
   var comment_vote_form = document.createElement('form');
   comment_vote_form.className = "vote";
   if (allow_vote == 1 && total_vote_count > 0) {
      comment_vote_form.appendChild(document.createTextNode(yes_vote_count + " of " + total_vote_count + 
        " people liked this comment. Do you?\u00a0\u00a0"));
   }
   else if (total_vote_count > 0) {
      comment_vote_form.appendChild(document.createTextNode(yes_vote_count + " of " + total_vote_count + 
        " people liked this comment."));
   }
   else if (allow_vote == 1) {
      comment_vote_form.appendChild(document.createTextNode("Do you like this comment?\u00a0\u00a0")); 
   }
   if (allow_vote == 1) {
      var vote_yes_button = document.createElement("input");
      vote_yes_button.type = "button";
      vote_yes_button.name = "yes";
      vote_yes_button.id = "btn1";
      vote_yes_button.onclick = comment_vote;
      vote_yes_button.value = "Yes";
      vote_yes_button.comment_id = comment_id;
      vote_yes_button.comment_creator = creator_name;
      vote_yes_button.vote_ind = "yes";
      var vote_no_button = document.createElement("input");
      vote_no_button.type = "button";
      vote_no_button.name = "no";
      vote_no_button.id = "btn2";
      vote_no_button.onclick = comment_vote;
      vote_no_button.value = "No";
      vote_no_button.comment_id = comment_id;
      vote_no_button.comment_creator = creator_name;
      vote_no_button.vote_ind = "no";
      comment_vote_form.appendChild(vote_yes_button);
      comment_vote_form.appendChild(document.createTextNode("\u00a0\u00a0"));
      comment_vote_form.appendChild(vote_no_button);
   }
   return comment_vote_form;
}

function create_abuse_report_form(comment_id) {
   var comment_ar_form = document.createElement('form');
   var report_button = document.createElement("input");
   report_button.type = "button";
   report_button.name = "report";
   report_button.id = "btn1";
   report_button.className = "violation";
   report_button.value = "Flag comment";
   report_button.comment_id = comment_id;
   //report_button.onclick = report_abuse;
   report_button.onclick = display_flag_comment_confirmation;
   comment_ar_form.appendChild(report_button);
   return comment_ar_form;
}

function comment_vote(){
   voter = GetCookie('startribune_user_auth').replace(/\|.*/,"");
   if (voter == "") {
      alert("You must login to vote on a comment.");
   }
   else if (voter == this.comment_creator) {
      alert("You can not vote on comment written by you");
   }
   else {
      //var story_id = document.getElementById("story_id").value;
      var story = document.getElementById("story_id");
      var story_id = 0;
      if (story != null) {
         story_id = document.getElementById("story_id").value;
      }
      else {
         story_id = document.getElementById("content_id").value;
      }
      var section_id = document.getElementById("section_id").value;
      var script = document.createElement('script');
      script.setAttribute('src', 'http://ww2.startribune.com/user_comments/comments.php?d=vote&comment_id=' + this.comment_id + '&vote=' + this.vote_ind + '&section_id=' + section_id + '&story_id=' + story_id);
      script.setAttribute('id', 'jsonScript');
      script.setAttribute('type', 'text/javascript');
      document.getElementById('comment_vote_' + this.comment_id).appendChild(script);
   }
}

function report_abuse(){
   comment_id = this.comment_id;
   var div = document.getElementById('comment_abuse_report_' + comment_id);
   while( div.hasChildNodes() ) { div.removeChild( div.lastChild ); }
   var script = document.createElement('script');
   script.setAttribute('src', 'http://ww2.startribune.com/user_comments/comments.php?d=report_abuse&comment_id=' + comment_id);
   script.setAttribute('id', 'jsonScript');
   script.setAttribute('type', 'text/javascript');
   document.getElementById('comment_abuse_report_' + comment_id).appendChild(script);
}

function display_flag_comment_confirmation() {
   comment_id = this.comment_id;
   var ar_div = document.getElementById('comment_abuse_report_' + comment_id);
   while( ar_div.hasChildNodes() ) { ar_div.removeChild( ar_div.lastChild ); }
   var ar_span = document.createElement('span');
   ar_span.className = 'warning';
   var ar_form = document.createElement('form');
   ar_form.name = "ar_form_conf_" + comment_id;
   ar_form.method = "post";
   ar_form.appendChild(document.createTextNode("You have chosen to flag this comment as inappropriate or in violation of our "));
   var terms_url = document.createElement('a');
   terms_url.href = "http://www.startribune.com/help/11484216.html";
   terms_url.appendChild(document.createTextNode("terms of use."));
   ar_form.appendChild(terms_url);
   var report_par = document.createElement('p');
   var report_button = document.createElement("input");
   report_button.type = "button";
   report_button.name = "report";
   report_button.id = "btn1";
   //report_button.className = "violation";
   report_button.value = "Continue";
   report_button.comment_id = comment_id;
   report_button.onclick = report_abuse;
   report_par.appendChild(report_button);
   report_par.appendChild(document.createTextNode("\u00a0\u00a0"));
   var cancel_button = document.createElement('input');
   cancel_button.type = "button";
   cancel_button.id = "cancel";
   cancel_button.name = "cancel";
   cancel_button.value = "Cancel";
   cancel_button.comment_id = comment_id;
   cancel_button.onclick = cancel_abuse_report;
   report_par.appendChild(cancel_button);
   ar_form.appendChild(report_par);
   ar_span.appendChild(ar_form);
   //ar_div.appendChild(ar_form);
   ar_div.appendChild(ar_span);
}

function display_report_abuse_form(obj) {
   var data = eval(obj);
   var ar_div = document.getElementById('comment_abuse_report_' + data.comment_id);
   while( ar_div.hasChildNodes() ) { ar_div.removeChild( ar_div.lastChild ); }
   var ar_form = document.createElement('form');
   ar_form.name = "ar_form_" + data.comment_id;
   ar_form.method = "post";
   var hidden_comment_id = document.createElement('input');
   hidden_comment_id.type = "hidden";
   hidden_comment_id.id = "comment_id_" + data.comment_id;
   hidden_comment_id.name = "comment_id";
   hidden_comment_id.value = data.comment_id;
   ar_form.appendChild(hidden_comment_id);
   var ar_table = document.createElement('table');
   ar_table.setAttribute("cellPadding", "0");
   ar_table.setAttribute("cellSpacing", "0");
   ar_table.setAttribute("border", "0");
   var ar_row1 = document.createElement('tr');
   var ar_r1c1 = document.createElement('td');
   ar_r1c1.appendChild(document.createTextNode("Subject:"));
   //ar_form.appendChild(document.createTextNode("Violation:"));
   ar_row1.appendChild(ar_r1c1);
   var ar_r1c2 = document.createElement('td');
   ar_r1c2.className = 'topRow';
   var ar_category = document.createElement('select');
   ar_category.name = "abuse_category";
   ar_category.id = "abuse_category_" + data.comment_id;
   //create the first option that displays the select category message
   var ar_cat_option1 = document.createElement('option');
   ar_cat_option1.value = "0";
   ar_cat_option1.appendChild(document.createTextNode("-Select a reason for reporting this content-"));
   ar_category.appendChild(ar_cat_option1);
   for (var i=0;i<data.abuse_categories.length;i++)
   {
      var ar_cat_option = document.createElement('option');
      ar_cat_option.value = data.abuse_categories[i].category.id; 
      ar_cat_option.appendChild(document.createTextNode(data.abuse_categories[i].category.name));
      ar_category.appendChild(ar_cat_option);
   }
   ar_r1c2.appendChild(ar_category);
   //ar_form.appendChild(ar_category);
   ar_row1.appendChild(ar_r1c2);
   ar_table.appendChild(ar_row1);
   var ar_row2 = document.createElement('tr');
   var ar_r2c1 = document.createElement('td');
   ar_r2c1.setAttribute("valign", "top");
   ar_r2c1.appendChild(document.createTextNode("Additional comments:"));
   //ar_form.appendChild(document.createTextNode("Additional comments:"));
   ar_row2.appendChild(ar_r2c1);
   var ar_r2c2 = document.createElement('td');
   ar_r2c2.className = 'bottomRow';
   var ar_comments_text = document.createElement('textarea');
   ar_comments_text.id = "abuse_comments_text_" + data.comment_id;
   ar_comments_text.name = "abuse_comments_text";
   ar_comments_text.cols = 35;
   ar_comments_text.rows = 4;
   ar_r2c2.appendChild(ar_comments_text);
   ar_r2c2.appendChild(document.createElement('br'));
   var submit_button = document.createElement('input');
   submit_button.type = "button";
   submit_button.id = "submit";
   submit_button.name = "submit";
   submit_button.value = "Send";
   submit_button.comment_id = data.comment_id;
   submit_button.onclick = submit_abuse_report;
   if (BrowserDetect.browser == "Explorer") {
      submit_button.setAttribute('onclick', 'submit_abuse_report(' + data.comment_id + ');');
   }
   ar_r2c2.appendChild(submit_button);
   ar_r2c2.appendChild(document.createTextNode("\u00a0\u00a0"));
   var cancel_button = document.createElement('input');
   cancel_button.type = "button";
   cancel_button.id = "cancel";
   cancel_button.name = "cancel";
   cancel_button.value = "Cancel";
   cancel_button.comment_id = data.comment_id; 
   cancel_button.onclick = cancel_abuse_report;
   if (BrowserDetect.browser == "Explorer") {
      cancel_button.setAttribute('onclick', 'cancel_abuse_report(' + data.comment_id + ');');
   }
   ar_r2c2.appendChild(cancel_button);
   ar_row2.appendChild(ar_r2c2);
   ar_table.appendChild(ar_row2);
   ar_form.appendChild(ar_table);
   ar_div.appendChild(ar_form);

   if (BrowserDetect.browser == "Explorer") {
      ar_div.innerHTML = ar_div.innerHTML;
   }
}

//function cancel_abuse_report(id) 
function cancel_abuse_report() {
   var ar_div = document.getElementById('comment_abuse_report_' + this.comment_id);
   comment_id = this.comment_id;
   while( ar_div.hasChildNodes() ) { ar_div.removeChild( ar_div.lastChild ); }
   var abuse_form = create_abuse_report_form(comment_id);
   ar_div.appendChild(abuse_form);
}

function submit_abuse_report(id) {
   if (BrowserDetect.browser == "Explorer") {
      var ar_div = document.getElementById('comment_abuse_report_' + id);
      var comment_id = document.getElementById("comment_id_" + id).value;
   }
   else {
      var ar_div = document.getElementById('comment_abuse_report_' + this.comment_id);
      var comment_id = document.getElementById("comment_id_" + this.comment_id).value;
   }
   var category_id = document.getElementById("abuse_category_" + comment_id);
   var abuse_comments = encodeURIComponent(document.getElementById("abuse_comments_text_" + comment_id).value);
   var category_id_ix = category_id.selectedIndex;
   var abuse_category = category_id.options[category_id_ix].value;
   if (abuse_category == "0" && !abuse_comments) {
      alert("Please choose a violation reason and/or comments");
      document.getElementById("abuse_category_" + comment_id).focus();
   }
   else { 
      while( ar_div.hasChildNodes() ) { ar_div.removeChild( ar_div.lastChild ); }
      var script = document.createElement('script');
      script.setAttribute('src', 'http://ww2.startribune.com/user_comments/comments.php?d=save_abuse_report&comment_id=' + comment_id + '&abuse_category=' + abuse_category + '&abuse_comments=' + abuse_comments);
      script.setAttribute('id', 'jsonScript');
      script.setAttribute('type', 'text/javascript');
      document.getElementById('comment_abuse_report_' + comment_id).appendChild(script);
   }
}

function display_report_saved_msg(obj) {
   var data = eval(obj);
   var ar_div = document.getElementById("comment_abuse_report_" + data.comment_id);
   while( ar_div.hasChildNodes() ) { ar_div.removeChild( ar_div.lastChild ); }
   var msg_font = document.createElement("font");
   msg_font.setAttribute("color", "red");
   msg_font.appendChild(document.createTextNode("Your violation report has been submitted"));
   ar_div.appendChild(msg_font);
}

function display_partial_comment(comment, nbr_of_words) {
   var word_array = comment.split(" ");
   var comment_word_length = word_array.length;
   var partial_comment = "";
   var word_count = 0;
   for (i=0; i < comment_word_length; i++) {
      partial_comment += word_array[i] + " ";
      word_count++;
      last_char = word_array[i].substring(word_array[i].length-1);
      if (word_count >= nbr_of_words && (last_char == "." || last_char == "?" || last_char == "!")) {
         break;
      }
   }
   return partial_comment;
}

function format_error(obj) {
   var data = eval(obj);
   var div = document.getElementById(data.id);
   //while( div.hasChildNodes() ) { div.removeChild( div.lastChild ); }
   x = document.createElement('p');
   x.appendChild(document.createTextNode(data.error_message));
   //document.getElementById(data.id).appendChild(x);
   var sibling = document.getElementById(data.id).firstChild;
   document.getElementById(data.id).insertBefore(x, sibling);
}

function display_user_ban_message() {
   var div = document.getElementById('latest_comments');
   while( div.hasChildNodes() ) { div.removeChild( div.lastChild ); }
   var div_suspended = document.createElement('div');
   div_suspended.className = 'suspended';
   var user_ban_heading = document.createElement('h2');
   user_ban_heading.appendChild(document.createTextNode("Commenting privileges for this account have been suspended"));
   //var user_ban_par = document.createElement('p');
   div_suspended.appendChild(user_ban_heading);
   div_suspended.appendChild(document.createTextNode("The StarTribune.com terms of use regarding online conduct are designed to ensure that the site remains a forum for the free and open exchange of ideas in a climate of mutual respect. Any action by a user that infringes on another user's right to use and enjoy StarTribune.com is considered a violation of those terms. Based on a review of content you have contributed via the story comments interface on StarTribune.com, we have suspended your access to the commenting function."));
   var contact_par = document.createElement('p');
   contact_par.appendChild(document.createTextNode("If you feel this action was taken in error, please contact the site "));
   var contact_url = document.createElement('a');
   contact_url.href = "mailto: commentsadmin@startribune.com";
   contact_url.appendChild(document.createTextNode("comments administrator."));
   contact_par.appendChild(contact_url);
   div_suspended.appendChild(contact_par);
   document.getElementById('latest_comments').appendChild(div_suspended);
}

function add_comment() {
   //var script = document.createElement('script');
   var comment_title = encodeURIComponent(document.getElementById("comment_title").value);
   var comment_body = encodeURIComponent(document.getElementById("comment_body").value);
   var contest_url = document.getElementById("contest_url").value;
   if (!comment_body) {
      alert("Please enter a comment");
      document.getElementById("comment_body").focus();
   }
   else {
      var story = document.getElementById("story_id");
      var story_id = 0;
      if (story != null) {
         story_id = document.getElementById("story_id").value;
      }
      else {
         story_id = document.getElementById("content_id").value;
      }
      var section_id = document.getElementById("section_id").value;
      var content = document.getElementById("content_type");
      var content_type = "Article";
      if (content != null) {
         content_type = encodeURIComponent(document.getElementById("content_type").value);
      }
      if (contest_url != "") {
         location.href = 'http://ww2.startribune.com/user_comments/comments.php?d=add&title=' + comment_title + '&body=' + comment_body + '&content_id=' + story_id + '&section_id=' + section_id + '&contest_url=' + contest_url + '&content_type=' + content_type;
      }
      else {
         document.getElementById('comment_submit').disabled = true;
         //alert('http://ww2.startribune.com/user_comments/comments.php?d=add&title=' + comment_title + '&body=' + comment_body + '&content_id=' + story_id + '&section_id=' + section_id + '&content_type=' + content_type);
         location.href = 'http://ww2.startribune.com/user_comments/comments.php?d=add&title=' + comment_title + '&body=' + comment_body + '&content_id=' + story_id + '&section_id=' + section_id + '&content_type=' + content_type;
         //script.setAttribute('src', 'http://ww2.startribune.com/user_comments/comments.php?d=add&title=' + comment_title + '&body=' + comment_body + '&story_id=' + story_id + '&section_id=' + section_id + '&contest_url=' + contest_url);
         //script.setAttribute('id', 'jsonScript');
         //script.setAttribute('type', 'text/javascript');
         //document.getElementById('latest_comments').appendChild(script);
         //document.getElementById('comment_title').value = "";
         //document.getElementById('comment_body').value = "";
      }
   }
}

function print_comment_form(story_id, section_id, contest_url, content_type) {
   document.write("<a name=\"post_comments\"></a>");
   if (GetCookie('startribune_user_auth')) {
      if (contest_url === undefined) {
         contest_url = "";
      }
      if (content_type === undefined) {
         content_type = "Article";
      }
      document.write("<div class=\"post\">");
      document.write("<h3>Post your comment:</h3>");
      document.write("<form name=\"comment_form\" action=\"#\" method=\"post\">");
      document.write("<input type=\"hidden\" id=\"content_id\" name=\"content_id\" value=\"" + story_id + "\" />");
      document.write("<input type=\"hidden\" id=\"section_id\" name=\"section_id\" value=\"" + section_id + "\" />");
      document.write("<input type=\"hidden\" id=\"contest_url\" name=\"contest_url\" value=\"" + contest_url + "\" />");
      document.write("<input type=\"hidden\" id=\"content_type\" name=\"content_type\" value=\"" + content_type + "\" />");
      document.write("<h4>Title <span>(Optional)</span></h4><input id=\"comment_title\" name=\"comment_title\" type=\"text\" size=\"45\" maxlength=\"255\" style=\"width:420px\" onFocus=\"cancelRefresh();\"/>");
      document.write("<h4> Your comments:</h4><textarea id=\"comment_body\" name=\"comment_body\" cols=\"40\" rows=\"8\" onFocus=\"cancelRefresh();\"></textarea>");
      document.write("<input id=\"comment_submit\" type=\"submit\" value=\"Post your comment\" onClick=\"add_comment();return false;\"/>");
      document.write("</form>");
      document.write("</div>");
   }
   else {
      //document.write("Please <a href=\"http://24hour.startribune.com/user_registration/membercenter/?goto=http://www.startribune.com" + section_id + "/" + story_id + ".html\">register or login</a> to post and/or vote a comment");
      document.write("<p><a href=\"http://www.startribune.com/s?action=login&rurl=" + section_id + "/" + story_id + ".html\">Register or log in</a> to comment and vote on others' comments.</p>");
   }
}

//not being used currently
function create_comment_form(story_id, section_id) {
   //var post_div = document.createElement('div');
   //post_div.className = 'post';
   var post_head = document.createElement('h3');
   post_head.appendChild(document.createTextNode("Post your comment:"));
   var comment_form = document.createElement('form');
   var input_story = document.createElement("input");
   input_story.type = "hidden";
   input_story.id = "story_id";
   input_story.value = story_id;
   comment_form.appendChild(input_story);
   var input_section = document.createElement("input");
   input_section.type = "hidden";
   input_section.id = "section_id";
   input_section.value = section_id;
   comment_form.appendChild(input_section);
   var title_head = document.createElement('h4');
   title_head.appendChild(document.createTextNode("Title "));
   var optional_span = document.createElement('span');
   optional_span.appendChild(document.createTextNode("Optional"));
   title_head.appendChild(optional_span);
   var input_title = document.createElement('input');
   input_title.id = "comment_title";
   input_title.name = "comment_title";
   input_title.type = "text";
   input_title.size = '45';
   input_title.maxLength = '255';
   comment_form.appendChild(input_title);
   var comments_head = document.createElement('h4');
   comments_head.appendChild(document.createTextNode("Your comments:"));
   comment_form.appendChild(comments_head);
   var comments_text = document.createElement('textarea');
   comments_text.id = "comment_body";
   comments_text.name = "comment_body";
   comments_text.cols = 40;
   comments_text.rows = 8;
   comment_form.appendChild(comments_text);

   var submit_button = document.createElement("input");
   submit_button.type = "submit";
   submit_button.name = "submit";
   submit_button.id = "comment_submit";
   submit_button.value = "Post your comment";
   submit_button.onclick = add_comment;
   comment_form.appendChild(submit_button);
   post_div.appendChild(comment_form);
   document.getElementById('comment_post').appendChild(post_head);
   document.getElementById('comment_post').appendChild(comment_form);
}


