

function pagekeypress(evt)
{
	var code = getCharCode(evt);
	if (code ==13)
	{
		sendComment(document.getElementById('textPost').value);
	}
}
function sendComment(txt)
{
	sendText('http://www.reedmagic.com/commentSend.php?textToPost='+document.getElementById('textPost').value);
	document.getElementById('textPost').value = 'sent! thanks!';
	
}
function readyStateFour()
{
	if(xmlhttp.readyState==4)
	{
		//change(xmlhttp.responseText,'t1');
	}
}
function sendText(url)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=readyStateFour;

	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}


function timeSince(amonth, aday, ayear) {
  // stolen with permission from http://javascript.internet.com/time-date/days-since.html
  var toRet ='';
  var x = new Date();
  var dyear;
  var dmonth;
  var dday;
  var tyear = x.getFullYear();
  var tmonth = x.getMonth()+1;
  var tday = x.getDate();
  var y=1;
  var mm=1;
  var d=1;
  var a2=0;
  var a1=0;
  var f=28;

  if ((tyear/4)-parseInt(tyear/4)==0) {
    f=29;
  }

  m = new Array(31, f, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

  dyear = tyear-(ayear);

  dmonth = tmonth-amonth;
  if (dmonth<0) {
    dmonth = dmonth+12;
    dyear--;
  }

  dday = tday-aday;
  if (dday<0) {
    var ma = amonth+tmonth;
    if (ma>12) {ma = ma-12;}
    if (ma=0) {ma = ma+12;}
    dday = dday+m[ma];
    dmonth--;
  }

  if (dyear==0) {y=0}
  if (dmonth==0) {mm=0}
  if (dday==0) {d=0}
  if ((y==1) && (mm==1)) {a1=1}
  if ((y==1) && (d==1)) {a1=1}
  if ((mm==1) && (d==1)) {a2=1}
  if (y==1){
  toRet = toRet+ dyear+" years" ;}
    if ((a1==1) && (a2==0)) {toRet = toRet + " and ";}
    if ((a1==1) && (a2==1)) {toRet = toRet + ", ";}
    if (mm==1){
    toRet= toRet +dmonth+" months";
  }
  if (a2==1) {toRet = toRet+ ", and ";}
  if (d==1){
    toRet = toRet + dday+" days";
  }
  return toRet;
}
function getCharCode(evt){
	var charCode;
	evt = (evt) ? evt : (window.event) ? event : null;
	if (evt)
	{
	charCode = (evt.charCode) ? evt.charCode :((evt.keyCode) ? evt.keyCode :((evt.which) ? evt.which : 0));
	}
	return charCode;
}
