// 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-inner').setStyle({display: 'block'});
		$('show_comment').href = 'javascript:Comment.hideComments();';
		$('show_comment').update('Hide Comments');
	},
	
	hideComments : function()
	{
		$('comment-area-inner').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>' +
					'<div class="clearDiv">&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" style="font-family:Georgia">x close</a></div>' +
			'</div>';
			
		return html;
	},
	
    reasonForm : function()
	{
		var html = '' + 
       			'<div id="message-container">' +
				'<div id="message-title">' +
					'<div id="message-title-text"></div>' +
					'<div class="clearDiv">&nbsp;</div>' +
				'</div>' +
				'<div id="message-content">' +
					'<div id="error-message"><iframe id="formIFrame" height="564" allowTransparency="true" frameborder="0" scrolling="no" style="width:300px;border:none;position:relative" src="http://www.genderlinks.org.za/forms/embed.php?id=5" title="Reason For Viewing This Article"><a href="http://www.genderlinks.org.za/forms/view.php?id=5" title="Reason For Viewing This Article">Reason For Viewing This Article</a></iframe></div>' +
					'<div class="clear">&nbsp;</div>' +
				'</div>' +
				'<div id="login-go" style="margin-top:-15px;position:relative;z-index:2;padding:5px"><input name="Submit" type="submit" value="Submit" style="display: none;" /><a href="javascript: preBox.hideMessage(document.body);" tabindex="4" style="font-family:Georgia;font-size:8pt">x close</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();
			
	}
	
}