 
function fill_star(star_id)
{
   switch(star_id)
   {
      case "rate_0p5":
         $("#rate_0p5").attr("src","/images/left_star_full.gif");
      break;
      case "rate_1p0":
         $("#rate_0p5").attr("src","/images/left_star_full.gif");
         $("#rate_1p0").attr("src","/images/right_star_full.gif");
      break;
      case "rate_1p5":
         $("#rate_0p5").attr("src","/images/left_star_full.gif");
         $("#rate_1p0").attr("src","/images/right_star_full.gif");
         $("#rate_1p5").attr("src","/images/left_star_full.gif");
      break;
      case "rate_2p0":
         $("#rate_0p5").attr("src","/images/left_star_full.gif");
         $("#rate_1p0").attr("src","/images/right_star_full.gif");
         $("#rate_1p5").attr("src","/images/left_star_full.gif");
         $("#rate_2p0").attr("src","/images/right_star_full.gif");
      break;
      case "rate_2p5":
         $("#rate_0p5").attr("src","/images/left_star_full.gif");
         $("#rate_1p0").attr("src","/images/right_star_full.gif");
         $("#rate_1p5").attr("src","/images/left_star_full.gif");
         $("#rate_2p0").attr("src","/images/right_star_full.gif");
         $("#rate_2p5").attr("src","/images/left_star_full.gif");
      break;
      case "rate_3p0":
         $("#rate_0p5").attr("src","/images/left_star_full.gif");
         $("#rate_1p0").attr("src","/images/right_star_full.gif");
         $("#rate_1p5").attr("src","/images/left_star_full.gif");
         $("#rate_2p0").attr("src","/images/right_star_full.gif");
         $("#rate_2p5").attr("src","/images/left_star_full.gif");
         $("#rate_3p0").attr("src","/images/right_star_full.gif");
      break;
      case "rate_3p5":
         $("#rate_0p5").attr("src","/images/left_star_full.gif");
         $("#rate_1p0").attr("src","/images/right_star_full.gif");
         $("#rate_1p5").attr("src","/images/left_star_full.gif");
         $("#rate_2p0").attr("src","/images/right_star_full.gif");
         $("#rate_2p5").attr("src","/images/left_star_full.gif");
         $("#rate_3p0").attr("src","/images/right_star_full.gif");
         $("#rate_3p5").attr("src","/images/left_star_full.gif");
      break;
      case "rate_4p0":
         $("#rate_0p5").attr("src","/images/left_star_full.gif");
         $("#rate_1p0").attr("src","/images/right_star_full.gif");
         $("#rate_1p5").attr("src","/images/left_star_full.gif");
         $("#rate_2p0").attr("src","/images/right_star_full.gif");
         $("#rate_2p5").attr("src","/images/left_star_full.gif");
         $("#rate_3p0").attr("src","/images/right_star_full.gif");
         $("#rate_3p5").attr("src","/images/left_star_full.gif");
         $("#rate_4p0").attr("src","/images/right_star_full.gif");
      break;
      case "rate_4p5":
         $("#rate_0p5").attr("src","/images/left_star_full.gif");
         $("#rate_1p0").attr("src","/images/right_star_full.gif");
         $("#rate_1p5").attr("src","/images/left_star_full.gif");
         $("#rate_2p0").attr("src","/images/right_star_full.gif");
         $("#rate_2p5").attr("src","/images/left_star_full.gif");
         $("#rate_3p0").attr("src","/images/right_star_full.gif");
         $("#rate_3p5").attr("src","/images/left_star_full.gif");
         $("#rate_4p0").attr("src","/images/right_star_full.gif");
         $("#rate_4p5").attr("src","/images/left_star_full.gif");
      break;
      case "rate_5p0":
         $("#rate_0p5").attr("src","/images/left_star_full.gif");
         $("#rate_1p0").attr("src","/images/right_star_full.gif");
         $("#rate_1p5").attr("src","/images/left_star_full.gif");
         $("#rate_2p0").attr("src","/images/right_star_full.gif");
         $("#rate_2p5").attr("src","/images/left_star_full.gif");
         $("#rate_3p0").attr("src","/images/right_star_full.gif");
         $("#rate_3p5").attr("src","/images/left_star_full.gif");
         $("#rate_4p0").attr("src","/images/right_star_full.gif");
               $("#rate_4p5").attr("src","/images/left_star_full.gif");
         $("#rate_5p0").attr("src","/images/right_star_full.gif");
      break;
   }//end switch(star_id)
}//end function fill_star(star_id)
function empty_star()
{
   $("#rate_0p5").attr("src","/images/left_star_empty.gif");
   $("#rate_1p0").attr("src","/images/right_star_empty.gif");
   $("#rate_1p5").attr("src","/images/left_star_empty.gif");
   $("#rate_2p0").attr("src","/images/right_star_empty.gif");
   $("#rate_2p5").attr("src","/images/left_star_empty.gif");
   $("#rate_3p0").attr("src","/images/right_star_empty.gif");
   $("#rate_3p5").attr("src","/images/left_star_empty.gif");
   $("#rate_4p0").attr("src","/images/right_star_empty.gif");
   $("#rate_4p5").attr("src","/images/left_star_empty.gif");
   $("#rate_5p0").attr("src","/images/right_star_empty.gif");
}//end function fill_star(star_id)
function hide_error(error_div)
{
   $(error_div).fadeOut("slow");
}//end hide_error(error_div)

function show_error(err_string)
{
   $("#CMNT_ERR").html(err_string);
   $("#CMNT_ERR").fadeIn("slow");
}//end function show_error(err_string);
function rate(rating)
{
   var npod_id = $("#HDN_npod_id").text();
   var ip = $("#HDN_IP").text();
   //disable clicking
   var star_divs = new Array("RATE_0P5_DIV", "RATE_1P0_DIV", "RATE_1P5_DIV", "RATE_2P0_DIV", "RATE_2P5_DIV", "RATE_3P0_DIV", "RATE_3P5_DIV", "RATE_4P0_DIV", "RATE_4P5_DIV", "RATE_5P0_DIV");
   for(var i in star_divs)
   {
      star_div = document.getElementById(star_divs[i]);
      star_div.style.display='none';
   }//end for(var star_div in star_divs)
   
   //change "Rate:" to "Rating..."
   $("#VT_RATE").html("Rating <img src='/images/rating_stars/rating_loop.gif' alt'...'");

   //update database
   $.ajax
   ({
      type: "POST",
      url: "/include/php/insert_rating.php",
      data: "rating=" + rating + "&npod_id=" + npod_id + "&ip=" + ip,
      success: function(msg)
      {
         //alert(msg);
         $("#VT_DG").html(msg);
         //$("#VT_RATE").html("Avg Rating: " + rating_pic);
      },
      error: function(xmlreq, tstatus, errorthrown)
      {
         alert("Some Error!: " + xmlreq + " 2: " + tstatus + " 3: " + errorthrown);
      }
   });//end ajax
         
   //alert("date: " + page_date + " ip: " + ip);
}
function submit_comment()
{
   hide_error("#CMNT_ERR");
   var error = "";
   var user = escape($("#user").val());
   var location = escape($("#location").val());
   var comment = escape($("#comment").val());
   //alert("user: " + user + " loc: " + location + " comment: " + comment);

   //gray out and disable button
   $("#comment_btn").attr("disabled","disabled");
   if(user == 'Seth' && location == 'Eagle')
   {
      $("#comment_btn").attr("value","Mansteak Fan");
   }
   else
   {
      $("#comment_btn").attr("value","Posting...");
   }
   //if successfull, update the html.  If not, show the error.
   if(user.length == 0)
   {
      user = "Someone";
   }
   if(location.length == 0)
   {
      location = "Somewhere";
   }
   if(comment.length == 0)
   {
      error = "Enter a comment.";
      show_error(error);
      $("#comment_btn").attr("disabled","");
      $("#comment_btn").attr("value","Post");
      return false;
   }
   //get the date
   var page_date = $("#HDN_PAGE_DATE").text();
   var ltst_date = $("#HDN_CMNT_DATE").text();
   var ip = $("#HDN_IP").text();
   //Call php page to update database
   $.ajax
   ({
      type: "POST",
      url: "/include/php/insert_comment.php",
      data: "usr=" + user + "&loc=" + location + "&cmnt=" + comment + "&ltst_date=" + ltst_date + "&page_date=" + page_date + "&ip=" + ip,
      success: function(msg)
      {
         //alert("Success: " + msg );
         //add html from the form to this div
         $("#HDN_CMNT").html(msg);
         //change visibility to "show" for all div's of class "cmnt_hdn"
         $("#HDN_CMNT").css("visibility","visible");
         //enable the button again to allow more comments
         $("#comment_btn").attr("disabled","");
         $("#comment_btn").attr("value","Post");
         $("#comment").attr("value","");
         //If the user leaves the first comment AND the second comment without refreshing
         //they will see the 1st comment twice because the ltst_date value is empty.
         if(ltst_date == "")
         {
            $.ajax
            ({
               type: "POST",
               url: "/include/php/get_cmnt_date.php",
               data: "page_date=" + page_date,
               success: function(date)
               {
                  $("#HDN_CMNT_DATE").html(date);
               }
               //error: function(xmlrq, tsts, errthrown)
              // {
               //   alert("Some Error!: " + xmlrq + " 2: " + tsts + " 3: " + errthrown);
              // }
            });
         }
      },
      error: function(xmlreq, tstatus, errorthrown)
      {
         alert("Some Error!: " + xmlreq + " 2: " + tstatus + " 3: " + errorthrown);
      }
   });
}//end submit_comment()

function display_comment_page(page_num, npod_id)
{
   $("#ALL_COMMENTS").html("<img src='/images/rating_stars/rating_loop.gif' alt'...'></img>");
   $.ajax
   ({
      type: "POST",
      url: "/include/php/get_npod_cmnt_pages.php",
      data: "page=" + page_num + "&npod_id=" + npod_id,
      success: function(msg)
      {
         $("#ALL_COMMENTS").html(msg);
      },
      error: function(xmlreq, tstatus, errorthrown)
      {
         alert("Some Error!: " + xmlreq + " 2: " + tstatus + " 3: " + errorthrown);
      }
   });//end ajax
}//end function display_page(page_num)

function show_email()
{
   $("#HDN_EMAIL").fadeIn("medium");
}//end function email()

function send_email(npod_id)
{
   $("#HDN_EMAIL").fadeOut("medium");
   var senders_email = escape($("#senders_email").val());
   var to_email = escape($("#to_email").val());
   var email_message = escape($("#email_message").val());
   $.ajax
   ({
      type: "POST",
      url: "/include/php/email_npod.php",
      data: "npod_id=" + npod_id + "&senders_email=" + senders_email + "&to_email=" + to_email + "&email_message=" + email_message,
      success: function(msg)
      {
         alert("Email Sent");
      },
      error: function(xmlreq, tstatus, errorthrown)
      {
         alert("Some Error!: " + xmlreq + " 2: " + tstatus + " 3: " + errorthrown);
      }
   });//end ajax
}//end function send_email(npod_id)
