if (document.layers)	// if Netscape
	document.captureEvents(Event.MOUSEMOVE);

document.onmousemove = setMouseXY;	// always call setMouseXY when mouse moves

var cursor = {x:0, y:0}

function setVisibility(str, value)
{
	var divRef;

	if (document.getElementById)
	{
		divRef = document.getElementById(str).style;
	}
	else if (document.layers)
	{
		divRef = document.layers[str];
	}
	else if (document.all)
	{
		divRef = document.all[str].style;
	}

	if (divRef) divRef.visibility = value;
}

function writeTime()
{
	var date = new Date();
	var hours = dec2bin(date.getHours());
	var minutes = dec2bin(date.getMinutes());
	var seconds = dec2bin(date.getSeconds());

	var the_time = hours + ":" + minutes + ":" + seconds;

	window.document.clock.clock_text.value = the_time;

	the_timeout = setTimeout('writeTime();', 950);
}

function dec2bin(dec)
{
	var bin;
	var pow;

	bin = "000000";
	pow = 32;

	i = 0;

	while (dec >= 1)
	{
		if (dec >= pow)
		{
			bin = bin.substring(0, i) + "1" +
				bin.substring(i + 1, bin.length);
			dec -= pow;
		}

		pow /= 2;
		++i;
	}

	return bin;
}

function showPCJr()
{
	var divRef;

	if (document.getElementById)
	{
		divRef = document.getElementById('pcjr').style;
	}
	else if (document.layers)
	{
		divRef = document.layers['pcjr'];
	}
	else if (document.all)
	{
		divRef = document.all['pcjr'].style;
	}

	if (divRef) {
		divRef.top = cursor.y - 250 + "px";
		divRef.visibility = 'visible';
	}
}

function setMouseXY(e) {
	if (!document.all) {
		cursor.x = e.pageX;
		cursor.y = e.pageY;
	}
	else {
		cursor.x = event.clientX
         + (document.body.scrollLeft || document.documentElement.scrollLeft)
         - document.documentElement.clientLeft;
		cursor.y = event.clientY
         + (document.body.scrollTop || document.documentElement.scrollTop)
         - document.documentElement.clientTop;
	}

	return true;
}

function empty(textField) {
  if (textField.value == null || textField.value.length == 0)
    return true;
  return false;
}

function getBlogUrl() {
  return "/blog/blog.php";
}

function getCommentParams() {
  return "";
}

function insertComment(response) {
  var commentText;
  if (response.responseText != "ERROR!")
    commentText = response.responseText;
  else
    commentText = "<div class='error'>There was an error with your entry</div>";
  new Insertion.Bottom("comments", commentText);
}

function getCommentParams() {
  var params =
    "entry=" + $F('entry')
    + "&name=" + $F('name')
    + "&email=" + $F('email')
    + "&website=" + $F('website')
    + "&comment=" + $F('comment');
  return params;
}

function addComment() {
  var url = getBlogUrl();
  var params = getCommentParams();
  var request = new Ajax.Request(
    url,  { method: 'post', parameters: params, onComplete: insertComment });
};
