// 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_comment1').href = 'javascript:Comment.cancelComment();';
		$('add_comment1').update('Cancel Comment');
        $('add_comment2').href = 'javascript:Comment.cancelComment();';
		$('add_comment2').update('Cancel Comment');
	},
	
	cancelComment : function()
	{
		$('comment_new').setStyle({display: 'none'});
		$('add_comment1').href = 'javascript:Comment.addComment();';
		$('add_comment1').update('Add a Comment');
        $('add_comment2').href = 'javascript:Comment.addComment();';
		$('add_comment2').update('Add a Comment');
		$('comment_yform').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("");
	},
    
    clearCaptcha : function(object)
	{
		if ($(object).getValue() == "Please enter the text you see in the above image")
			$(object).setValue("");
	},
	
	commentAlert : function(type, msg, color)
	{ 
    
        var html = '<div id="dl-container" style="height:105px;background-image:url(http://us-cdn.creamermedia.co.za/template/polity/images/cbg.png)">' +
                        '<div id="menu-top-left">&nbsp;</div>' +
                        '<div id="menu-topdl-middle">' +
                            '<a href="javascript: preBox.hideMessage(document.body);" id="message-close" style="margin-top:-7px"><img src="http://us-cdn.creamermedia.co.za/template/polity/images/close_window_button.png" alt="Close" width="170" height="21" class="' + (( Prototype.Browser.IE ) ? 'float-right' : 'float-right') +'" /></a>' +
                        '</div>'+
                        '<div id="menu-top-right">&nbsp;</div>' +
                        '<div class="clear">&nbsp;</div>' +
                        '<div id="menu-content-dl">' + msg +  
                        '</div>' +
                        '<div id="menu-bottomdl-left">&nbsp;</div>' +
                        '<div id="menu-bottomdl-middle">&nbsp;</div>' +
                         '<div id="menu-bottomdl-right">&nbsp;</div>' 

                 '</div>';

		return html;
    
    
	},
	
	validateComment : function(color)
	{
		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.", color));	
			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.", color));
			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.", color));
			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.", color));
			return false;	
		}
		if( $('captcha').getValue() == '' )
		{
			preBox.showMessage(document.body, Comment.commentAlert("Invalid Verification", "Please enter the verification code which is displayed inside the picture.", color));
			return false;
		}
		
        preBox.showMessage(document.body, Comment.commentAlert("Success", "Thank you, your comment has been submitted and will appear as soon as it is approved.", color));
		$('comment_form').submit();
        return true;
        
	}
	
}