var xmlHttp

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)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

function showCommentForm(id) {
	var qs = document.location.search;
	args = qs.split("=");
	var el = document.getElementById('commentdiv');
	var formcode = "<legend>Add a Comment</legend>";
	formcode += "<form name='commentform' action='add_comment.py'>";
	formcode += "<input type='hidden' name='article_id' value='" +id +"' />";
	formcode += "<p class='label'>Your Name: &nbsp;<input type='text' name='author' tabindex=0>";
	formcode += "<p class='label'>Comment:</p>";
	formcode += "<textarea name='comment_text' cols=40 rows=10></textarea>";
	formcode += "<p class='submit'><input type='submit' value='Submit Comment' onClick='sendComment(this.form)' name='addclick'>";
	formcode += "</form>";

	el.innerHTML =  "<br />";
	el.innerHTML += "<fieldset>" +formcode +"</fieldset>";
	}

function sendComment(form) {
document.getElementById('commentList').innerHTML = "<p>Loading.......</p>"; 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var article_id = form.article_id.value;
var author = form.author.value;
var comment_text = form.comment_text.value;

var url="/insert_comment.py?article_id=" +article_id + "&author=" +author + "&comment_text=" +escape(comment_text) +"&addclick=Submit+Comment"; 
xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
	document.getElementById("commentList").innerHTML = xmlHttp.responseText;
        }
      }
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


function showQuoteScreen() {
	var formcode = "<fieldset><legend>Add quote.</legend>";
	formcode += "<form name='quoteform' action='add_quote.py'>";
	formcode += "<p class='label'>Name: &nbsp;<input name='author'>";
	formcode += "<p class='label'>Quote:</p>";
	formcode += "<textarea name='quote_text' cols=40 rows=10></textarea>";
	formcode += "<p class='submit'><input type='submit' value='Submit Quote' name='addclick'>";
	formcode += "</form></fieldset>";
	
	myRef = window.open('','mywin', 'left=50,top=200,width=750,height=500,toolbar=0,resizable=1');
	myRef.document.writeln('<p>Testing...</p>');
	myRef.document.write(formcode);
	myRef.document.quoteform.author.focus();
}


