var labels	= {"ator_name": "Name", "ator_email": "Email", "ator_url": "Website", "_text": "Comment"};
var messages = {
	"ator_email": "Ah, go on, type in your email. I promise not to do anything bad with it.",
	"_text": "You might want to type an actual comment in the actual box, if you actually want to actually post it to my actual website."
};
function checkCommentData(form) {
	var str = "";
	for(s in labels) {
		n = 'comment' + s;
		e = form[n];
		v = e.value;
		str += n + ": " + v + "\n";
		if(n && n.match(/^comment/)) {
			n = n.replace(/^comment/, '');
			if(v.length == 0 && n != 'ator_url') {
				alert(messages[n] ? messages[n] : "Please fill in the '" + labels[n] + "' field.");
				e.focus();
				return false;
			}
			switch(n) {
				case "ator_name":
					break;
				case "ator_email":
					var regex = new RegExp("^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$");
					if(!regex.test(v)) {
						alert('That looks like a dodgy email address to me!');
						e.focus();
						return false;
					}
					break;
				case "ator_url":
					if(v && !v.match(/^http:\/\//)) {
						e.value = "http://" + v;
					}
					break;
				case "_text":
					break;
				default: break;
			}
		}
	}

	return true;
//	doFormSubmission(form);

//	return false;
}

/*
function doFormSubmission(form) {
	var url	= document.location.href.replace(/#.*$/, "");
	var query	= "entry_id=" + form.elements['entry_id'].value + "&";
	var data	= {"entry_id": form.elements['entry_id'].value};
	for(s in labels) {
		data['comment'+s] = form['comment'+s].value;
		query += "comment" + s + "=" + escape(form['comment' + s].value) + "&";
	}
	query += hex_md5(document.cookie.replace(/.*__utma=([0-9\.]+);.*$/, "$1")) + "=" + hex_md5(navigator.userAgent);
	var xml = new JKL.ParseXML( url, query );
	var response = xml.parse();
	alert(response.length);
	return false;
	if(response.CommentSaveResponse.Success) {
		data['comment_date'] = response.CommentSaveResponse.Success.CommentDate;
		clearForm(form);
		updateComments(data);
		return false;
	}
	if(response.CommentSaveResponse.Error) {
		alert("Fuck it, there was a problem trying to save your comment.\r\nAh well... I guess it's probably not *that* important, eh?");
		return false;
	}
	return false;
}

function clearForm(form) {
	for(s in labels) {
		form['comment' +s].value = "";
	}
}

function updateComments(data) {
	var c_div = document.getElementById("comments_div");
	var c_ul;
	if((c_ul = document.getElementById("comments_ul")) == null) {
		createStyledElement('h2', c_div, 'comment_header', null, 'Comments');
		c_ul = dce('ul', {'class': "comments", 'id': "comments_ul"});
		c_div.appendChild(c_ul);
	}
	var li	= document.createElement('li');
	var span = createStyledElement('span', li, 'comment_info', null, null);
	var name = document.createTextNode(data.commentator_name);
	if(data.commentator_url != "") {
		var a = document.createElement('a');
		a.setAttribute('href', data.commentator_url);
		a.appendChild(name);
		span.appendChild(a);
	}
	else {
		span.appendChild(name);
	}
	span.appendChild(document.createTextNode(makePosterInfo(data)));
	createStyledElement('blockquote', li, 'indented', null, data.comment_text);
	c_ul.appendChild(li);
}

function dce(name, attrs) {
    var element =   document.createElement(name);
    for(attr in attrs) {
        element.setAttribute(attr, attrs[attr]);
    }
    return element;
}

function createStyledElement(tag, parent, cls, css, txt) {
	var el = document.createElement(tag);
	if(cls) el.className = cls;
	if(css) for(var s in css) el.style[s]=css[s];
	if(txt) {
		if (txt.indexOf('<')!=-1) el.innerHTML=txt;
		else {
			el.appendChild(document.createTextNode(txt));
		}
	}
	if(parent) parent.appendChild(el);
	return el;
}

function makePosterInfo(data) {
	var info = " made the following comment at " + makeFriendlyDate(data.comment_date);
	return info;
}

function makeFriendlyDate(datestring) {
	var months          =   ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; 
	var days            =   ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
	var splits	=	datestring.split(' ');
	var date	=	splits[0].split('-');
	var time	=	splits[1].split(':');
	var dateObj =	new Date(date[0], date[1] - 1, date[2], time[0], time[1], time[2]);
	return days[dateObj.getDay()] + ", " + months[dateObj.getMonth()] + " " + dateObj.getDate() + ", " + (dateObj.getYear() + (dateObj.getYear() > 1900 ? 0 : 1900));
}
*/

