// JavaScript Document
var Comment = {
	
	arrangeDown : function()
	{
		$('comment-arrange').setStyle({background: 'url(/images/mw/arrows_grey_down.gif) no-repeat right center;'});
		$('comment-arrange-or').setStyle({background: 'url(/images/mw/arrows_red_up.gif) no-repeat right center;'});
	},
	
	arrangeUp : function()
	{
		$('comment-arrange').setStyle({background: 'url(/images/mw/arrows_red_down.gif) no-repeat right center;'});
		$('comment-arrange-or').setStyle({background: 'url(/images/mw/arrows_grey_up.gif) no-repeat right center;'});
	},
	
	showComments : function()
	{
		$('comment-area').setStyle({display: 'block'});
		$('show_comment').href = 'javascript:Comment.hideComments();';
		$('show_comment').update('hide Comments');
	},
	
	hideComments : function()
	{
		$('comment-area').setStyle({display: 'none'});
		$('show_comment').href = 'javascript:Comment.showComments();';
		$('show_comment').update('show Comments');
	},
	
	addComment : function()
	{
		$('comment-new').setStyle({display: 'block'});
		$('add_comment').href = 'javascript:Comment.cancelComment();';
		$('add_comment').update('cancel Comment');
	},
	
	cancelComment : function()
	{
		$('comment-new').setStyle({display: 'none'});
		$('add_comment').href = 'javascript:Comment.addComment();';
		$('add_comment').update('add a Comment');
		$('comment-form').reset();
	},
	
	clearName : function(object)
	{
		if ($(object).getValue() == "Name")
			$(object).setValue("");
	},
	
	clearMail : function(object)
	{
		if ($(object).getValue() == "Email (will not be published)")
			$(object).setValue("");
	},
	
	clearTextArea : function(object)
	{
		if ($(object).getValue() == "Add your comment here")
			$(object).setValue("");
	},
	
	commentAlert : function(type, msg)
	{
		var html = '' + 
			'<div id="message-container">' +
				'<div id="message-title">' +
					'<div id="message-title-text">' + type + '</div>' +
					'<a href="javascript: preBox.hideMessage(document.body);" id="message-close"><img src="/images/mw/black_x.png" alt="Close" width="16" height="16" class="' + (( Prototype.Browser.IE ) ? 'float-right' : 'float-left') +'" /></a>' +
					'<div class="clear">&nbsp;</div>' +
				'</div>' +
				'<div id="message-content">' +
					'<div id="error-message">' + msg + '</div>' +
					'<div class="clear">&nbsp;</div>' +
				'</div>' +
				'<div id="login-go"><input name="Submit" type="submit" value="Submit" style="display: none;" /><a href="javascript: preBox.hideMessage(document.body);" tabindex="4">Go</a></div>' +
			'</div>';
			
		return html;
	},
	
	validateComment : function()
	{
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

		if( $('co_comment_su_name').getValue() == '' || $('co_comment_su_name').getValue() == 'Name' )
		{
			preBox.showMessage(document.body, Comment.commentAlert("Required field Error", "Please enter a name to go with this comment."));	
			return false;
		}
		if( $('co_comment_su_email').getValue() == '' || $('co_comment_su_email').getValue() == 'Email (will not be published)')
		{
			preBox.showMessage(document.body, Comment.commentAlert("Required field Error", "Please enter an email address to go with this comment."));
			return false;
		}
		if( !filter.test($('co_comment_su_email').getValue()) )
		{
			preBox.showMessage(document.body, Comment.commentAlert("Invalid Email Address", "Please enter a valid email address to go with this comment."));
			return false;
		}
		if( $('co_comment').getValue() == '' || $('co_comment').getValue() == 'Add your comment here' )
		{
			preBox.showMessage(document.body, Comment.commentAlert("Invalid Comment", "Please enter a comment."));
			return false;	
		}
		if( $('captcha').getValue() == '' )
		{
			preBox.showMessage(document.body, Comment.commentAlert("Invalid Verification", "Please enter the verification code which is displayed inside the picture."));
			return false;
		}
			
		$('comment-form').submit();
			
	}
	
}
