﻿var xmlHttp = null;
var CONST_NOT_INITIALIZED = 0;
var CONST_SETUP = 1;
var CONST_SENT = 2;
var CONST_IN_PROCESS = 3;
var CONST_COMPLETE = 4;
var oUserRatings = new Object();


function GetXmlHttpObject()
{
  var xmlHttp = null;
  
  try
  {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  {
    // Internet Explorer
    try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      try
      {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {
        alert("Your browser does not support AJAX!");
        return false; 
      }
    }
  }
  
  xmlHttp.onreadystatechange = postStatusChanged;
  return xmlHttp
}

function sendComment(mediaId)
{
  var oComment = document.getElementById("comment");
  comment(mediaId,oComment.value);
  
    
  var oNewComment = document.getElementById("newComment");
  oNewComment.innerHTML = "<hr />" + oComment.value + oNewComment.innerHTML;
  oComment.value = "";
}

function comment(mediaId,commentText)
{
  if (commentText.length < 1)
  {
    return false;
  }

  xmlHttp = GetXmlHttpObject();
  if (!xmlHttp)
  {
    return false;
  }
 
  var params = "m=" + mediaId + "&c=" + commentText;
  xmlHttp.open("POST","comment.aspx",true);
  xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  xmlHttp.setRequestHeader("Content-length", params.length);
  xmlHttp.setRequestHeader("Connection","close");
  xmlHttp.send(params);
}

function postStatusChanged() 
{ 
  if (xmlHttp.readyState == CONST_COMPLETE)
  { 
    //alert(xmlHttp.responseText);
  }
}
