window.addEvent('domready', function() {
	if($('commentform')) {
		$('commentform').addEvent('submit', function(ent) {
	try {
		var error = '';
		var elfocus = '';
		if(this.author && this.author.value == '') {
			error += '<br />Please give your name';
			this.author.focus();
		}
		if(this.email && !(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(this.email.value))) {
			error += '<br />Please give a valid email address';
			this.email.focus();
		}
		
		if(this.comment.value == '' || this.comment.value == this.comment.title) {
			error += '<br />You forgot a message';
			this.comment.focus();
		}
		if(error != '')
			mcp_error(error);
		else {
			$('comment').setStyle('background', 'transparent url('+mcpoptions.throbber+') no-repeat 50% 50%');
			this.send({
				evalScripts : true,
				onFailure : function() {
					var errorMessage = this.transport.responseText.split('<body>')
						errorMessage = errorMessage[1].split('</body>')
					mcp_error(errorMessage[0]);
				}
			});
		}
		new Event(ent).stop();
		return false;
			} catch(e) {return true;}
	}.bind($('commentform')));
	new Element('input', {
		type : 'hidden',
		name : 'moojaxxed',
		value : 'true'
	}).injectInside($('commentform'));
	a = new Image(); a.src = mcpoptions.throbber;
	}
});

mcp_removeForm = function() {
	if(mcpoptions.killForm) {
		var hider = new Element('div').injectBefore($('commentform'));
		$('commentform').injectInside(hider);
		hider.setStyle('overflow','hidden');
		var winFx = new Fx.Styles(hider, {duration: 1800});
		winFx.start({
			opacity : [1,0],
			height : [hider.getStyle('height').toInt(), 0],
			'margin-bottom' : [0,hider.getStyle('height').toInt()]
		}).chain(function() {
			hider.remove();
		});
	} else
		$('comment').value = '';
};

mcp_ajaxDone = function() {	//remove all signs of ajax activity
	$('comment').setStyle('background', '');
};

mcp_error = function(errorMessage) {
	mcp_ajaxDone();
	var err = new Element('div', {'class': 'error' }).setHTML(errorMessage).injectAfter($('comment'));
	var errSlide = new Fx.Slide(err);
	errSlide.slideIn();
	var errFx = new Fx.Style(err, 'opacity', {duration:1000});
	errFx.start(0.1,0.9).chain(function(){
	errFx.start(0.9,0.1);
}).chain(function(){
	errFx.start(0.1,0.9);
}).chain(function() {
	errSlide.slideOut();
});
}
