//$Id: lists.js 1595 2007-03-21 15:32:15Z star000s $   
function show_top_responses(list_id, suffix) {
   url  = 'http://' + location.hostname + '/lists.php?d=top_responses&list_id=' + list_id + '&show=3';
   loadDoc(url, list_id + '_' + suffix);
}
function update_list(list_id, user_logged_in, current_url, div_id) {
   if (user_logged_in == 1) {
      var poststr = "d=add_resps&list_id=" + list_id +
         "&goto_page=" + encodeURIComponent( document.getElementById("goto_page").value ) +
         "&u_resp_1=" + encodeURIComponent( document.getElementById("u_resp_1").value ) +
         "&u_resp_2=" + encodeURIComponent( document.getElementById("u_resp_2").value ) +
         "&u_resp_3=" + encodeURIComponent( document.getElementById("u_resp_3").value ) +
         "&u_resp_4=" + encodeURIComponent( document.getElementById("u_resp_4").value ) +
         "&u_resp_5=" + encodeURIComponent( document.getElementById("u_resp_5").value ) +
         "&u_resp_6=" + encodeURIComponent( document.getElementById("u_resp_6").value ) +
         "&u_resp_7=" + encodeURIComponent( document.getElementById("u_resp_7").value ) +
         "&u_resp_8=" + encodeURIComponent( document.getElementById("u_resp_8").value ) +
         "&u_resp_9=" + encodeURIComponent( document.getElementById("u_resp_9").value ) +
         "&u_resp_10=" + encodeURIComponent( document.getElementById("u_resp_10").value );
//         makePOSTRequest('list_detail.php', poststr, 'list_and_edit');
      makePOSTRequest('list_detail.php', poststr, div_id);
   }
   else {
      location.href="http://" + location.hostname + "/user_admin.php?d=user_login&url=" + current_url;
   }
}
function clear_list(list_id, user_logged_in, current_url, div_id) {
   if (user_logged_in == 1) {
      var poststr = "d=clear_resps&list_id=" + list_id +
         "&goto_page=" + encodeURIComponent( document.getElementById("goto_page").value );
      //makePOSTRequest('list_detail.php', poststr, 'list_and_edit');
      makePOSTRequest('list_detail.php', poststr, div_id);
   }
   else {
      location.href="http://" + location.hostname + "/user_admin.php?d=user_login&url=" + current_url;
   }
}
function edit_your_responses(user_logged_in, current_url) {
   if (user_logged_in == 1) {
      show('user_responses');
   }
   else {
      location.href="http://" + location.hostname + "/user_admin.php?d=user_login&url=" + current_url;
   }
}
function delete_resps(list_id, user_logged_in, current_url) {
   if (user_logged_in == 1) {
      var poststr = "d=clear_resps&show=all&list_id=" + list_id +
         "&goto_page=" + encodeURIComponent( document.getElementById("goto_page").value );
      makePOSTRequest('list_detail.php', poststr, 'user_list_resps');
   }
   else {
      location.href="http://" + location.hostname + "/user_admin.php?d=user_login&url=" + current_url;
   }
}
function edit_list(list_id, goto_page) {
   url  = 'http://' + location.hostname + '/list_detail.php?d=edit_list&list_id=' + list_id + '&goto_page=' + goto_page;
   loadDoc(url, 'list_' + list_id);
}
function show_user_responses(list_id) {
   url  = 'http://' + location.hostname + '/list_detail.php?d=user_resp_by_list&list_id=' + list_id +
         "&goto_page=" + encodeURIComponent( document.getElementById("goto_page").value );
   loadDoc(url, 'list_' + list_id);
}
function clear_response(response_nbr) {
   document.getElementById("u_resp_" + response_nbr).value = "";
}
function move_response(response_nbr, up_or_down) {
   var current_response = document.getElementById("u_resp_" + response_nbr).value;
   var new_response = "";
   var new_response_nbr = 0;
   if (up_or_down == "up") {
      new_response_nbr = parseInt(response_nbr) - 1;
   }
   else if (up_or_down == "down") {
      new_response_nbr = parseInt(response_nbr) + 1;
   }
   new_response = document.getElementById("u_resp_" + new_response_nbr).value;
   document.getElementById("u_resp_" + response_nbr).value = new_response;
   document.getElementById("u_resp_" + new_response_nbr).value = current_response;
   return false;
}
function copy_response(response) {
   for (x=1; x<=10; x++) {
      var current_response = document.getElementById("u_resp_" + x).value;
      if (current_response == "") {
         document.getElementById("u_resp_" + x).value = response;
         return;
      }
   }
}
function show_responders(id) {
   url  = 'http://' + location.hostname + '/list_detail.php?d=responders&id=' + id;
   loadDoc(url, 'a_response_' + id);
}

function show_common_responses(show_option, id) {
   url = 'http://' + location.hostname + '/lists.php?d=top_responses&list_id=' + id + '&common=1';
   if (show_option == "past_year") {
      url += "&option=past_year";
   }
   loadDoc(url, 'list_top_responses');
}
