//------------------------------------------------------------------------------
// report_bad_site
// 
// id:   The id of the bad item to report.
// type: The type of the bad item to report.
//          "site":     Report a bad site.
//          "review":   Report a bad review.
//
//------------------------------------------------------------------------------

// Will choose the correct php script to call.
var report_type_php = new Array();
   report_type_php["site"] = "report_bad.php";
   report_type_php["review"] = "report_bad.php";

// Will choose the correct command to send.
var report_type_command = new Array();
   report_type_command["site"] = "report_site";
   report_type_command["review"] = "report_review";

var report_bad_request = null;

function report_bad( id, type )
{
   if ( report_bad_request == null )
   {
      report_bad_request = create_request();
   }

   if ( report_bad_request != null )
   {
      var parameters = ""; 
      
      // Fill parameter.
      parameters += "id=" + encodeURI( id );
      parameters += "&command=" + encodeURI( report_type_command[type] );

      report_bad_request.open('POST', report_type_php[type], true);              
      report_bad_request.onreadystatechange = report_bad_callback;
      report_bad_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      report_bad_request.setRequestHeader("Content-length", parameters.length);
      report_bad_request.setRequestHeader("Connection", "close");
      report_bad_request.send(parameters);
   }
   else
   {
      alert("Cannot create parameters list to report the " + type + "." );
   }
}

//------------------------------------------------------------------------------
// report_bad_callback
//------------------------------------------------------------------------------
function report_bad_callback()
{
   if (report_bad_request.readyState == 4) 
   {
      if (report_bad_request.status == 200)
      {
         alert("Thank you for your help keeping Mom On The Road grow securely.");
      }
      else 
      {
         alert("There was a problem retrieving the XML data:\n" + report_bad_request.statusText);
      }
   } 
}

