(function () {
   observe (window, "load", init);

   function $(element) {
		if (typeof element == "string")
			element = document.getElementById (element);
		return element;
   }
	
   function observe (target, event_name, listener) {
		if (typeof target == "string")
			target = document.getElementById (target);
		if (target.addEventListener)
			target.addEventListener (event_name, listener, false);
		else if (target.attachEvent)
			target.attachEvent ("on" + event_name, function() {listener.call (target, window.event);});
		else
			target["on" + event_name] = function (e) {listener.call (target, e || window.event);};
   }
	
   function $c (name, txt, atts) {
		element =  document.createElement (name);
		if (txt != null && txt.length > 0)
			element.appendChild (document.createTextNode (txt));
		if (atts != null) {
			for (key in atts)
				element.setAttribute (key, atts[key]);
		}
		return element;
   }
	
   function init (e) {
		area = $("new-comment-area");
		if (area == null) {
			window.memoNavi = function (page, views, defViews) {
				tmp = "&v=" + views;
				if (views == defViews)
					tmp = "";
				location = "?p=" + page + tmp;
			};
			return;
		}
		form = $c ("form", null, {"method": "post", "action": window.location.pathname});
		area.appendChild (form);
		namearea = $c ("div", null, {});
		namearea.appendChild ($c ("div", "Name: ", {"id": "new-comment-name"}));
		namearea.appendChild ($c ("input", null, {"type": "text", "name": "name", "size": "25"}));
		form.appendChild (namearea);
		bodyarea = $c ("div", null, {});
		bodyarea.appendChild ($c ("textarea", null, {"rows": "5", "cols": "30", "name": "body"}));
		form.appendChild (bodyarea);
		footerarea = $c ("div", null, {});
		footerarea.appendChild ($c ("input", null, {"type": "submit", "value": "Post"}));
		form.appendChild (footerarea);
   }
}) ();
