var offers={};
var user_name;
var web_root

function setup_comment(name,root)
{
 user_name=name;
 web_root=root;
}



function show_comment(id)
{
 var comments=document.getElementById("comments_"+id);
 var add_comment=document.getElementById("add_comment_"+id);
 var show_comment=document.getElementById("show_comment_"+id);
 if(comments.style.visibility == 'visible')
 {
  comments.style.visibility='hidden';
  comments.style.display='none';
  add_comment.className="hide";
  show_comment.className="click comment_icon show underline_hover"
  show_comment.title="Show Comments";
 }
 else
 {
  comments.style.visibility="visible";
  if(document.all)
  {
   comments.style.display='block';
  }
  else
  {
   comments.style.display='table-row';
  }
  add_comment.className="unhide";
  show_comment.className="click comment_icon close underline_hover"
  show_comment.title="Hide Comments";
 }
}

function add_comment(id)
{
 setup_post_comment(id,null);
 document.getElementById("page_overlay").className="show";
 document.getElementById("add_comment_container").className="show";

}


function close_comment()
{
 document.getElementById('page_overlay').className="";
 document.getElementById("add_comment_container").className="";
 return false;
}

function submit_post()
{
 var error=false;
 message=document.getElementById("add_comment_message").value;
 id=document.getElementById("add_comment_id").value;
 var vars={};
 vars.inp="page=add_offer_comment";
 vars.data="id="+id+"&comment="+escape(message);
 vars.completedFunction=setup_result;
 vars.completedVars={"success":0,"message":"","header":"","id":id};

 Request(web_root+"request.php","POST",vars);
 return false;
}

function setup_post_comment(id,vars)
{
 if(!vars)
 {
  vars={"comment":""}
 }
 var area=document.getElementById('add_comment_form');
 var html=Array();
 html.push("<div class=\"add_comment_main\">");
 html.push("<h3>Post Your Comment</h3>");
 html.push("<form onsubmit=\"return submit_post()\">");
 html.push("<input type=\"hidden\" value=\""+id+"\" id=\"add_comment_id\">");
 if(vars.message)
 {
  html.push("<p id=\"post_comment_result\" class=\"error\">"+vars.message+"</p>");
 }
 html.push("<table class=\"form\">");
 html.push("<tr><td class=\"description\">User:</td><td class=\"field\">"+user_name+"</td></tr>");
 html.push("<tr><td class=\"description\">Message:<span class=\"req\">*</span></td>");
 html.push("<td class=\"field\"><textarea id=\"add_comment_message\" class=\"text\">"+vars.comment+"</textarea></td></tr>");
 html.push("<tr><td class=\"description\"></td>");
 html.push("<td class=\"field\"><input type=\"image\" src=\""+web_root+"img/gui/submit.gif\" title=\"Submit\" alt=\"Submit\" class=\"click\"></td></tr>");
 html.push("</table>");
 html.push("</form>");
 html.push("</div>");
 area.innerHTML=html.join("");
}

function setup_result(vars)
{
 if(vars.success)
 {
  var area=document.getElementById('add_comment_form');
  var html=Array();
  html.push("<div class=\"add_comment_main\">");
  html.push("<h3>"+vars.header+"</h3>");
  html.push("<p>"+vars.message+"</p>");
  html.push("<form onsubmit=\"return close_comment()\">");
  html.push("<input type=\"image\" src=\""+web_root+"img/gui/close_button.gif\" title=\"Close\" alt=\"Close\" class=\"click\">");
  html.push("</form>");
  html.push("</div>");
  area.innerHTML=html.join("");
 }
 else
 {
  setup_post_comment(vars.id,vars);
 }
}

