function GetXmlHttpObject()
{
  if(window.XMLHttpRequest)
  {
      // Code for IE+7,Firefox,Chrome,Opera,Safari.
      return new XMLHttpRequest();
  }
  if(window.ActiveXObject)
  {
      // Code for IE5,IE6
      return new ActiveXObject("Microsoft.XMLHTTP");

  }
  return null;
}
//Replace Special Characters with equivalent code
function convert_special_chars(value)
{
  value=encodeURIComponent(value);
  return value;
}
// Function to Get Add Comments
function submit_comment()
{

  var comment=document.getElementById("comment_text").value;
  var name=document.getElementById("name").value;

  if(name=="")
  {
      name="anonymous";
  }
  if(comment=="")
  {
      alert("Please Insert Comment!!!");
      return;
  }
  alert("Thanks! Your comment will show up in a few minutes.");

  // Convert Special Characters
  comment=convert_special_chars(comment);

  var param  = "coupon_id="+comment_coupon_id;
      param += "&comment=" + comment;
      param += "&name=" + name;

  var xmlhttp=GetXmlHttpObject();
  if(xmlhttp==null)
  {
      alert("Your browser does not support XMLHTTP!");
      return;
  }

  xmlhttp.onreadystatechange=function()
  {
      if(xmlhttp.readyState==4)
      {
          document.getElementById("comment_text").value="";
          document.getElementById("name").value="";
          cancel_add_comment();
          window.location.reload(true);
      }
  };
  // Request URL
  var url="/add-comment.html";
      url=url+"?id="+Math.random();
      xmlhttp.open("POST",url,true);
      xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

  // Send Parameter with the Script
  xmlhttp.send(param);
}
