var bolSbmt = false;

function joinList() {
	if(!bolSbmt) {
		bolSbmt = true;
		if(chckEmail(document.webform.ea.value)) {document.webform.submit();}
		else {alert('Please fill in a valid email address.'); bolSbmt = false;}
	}
}

function chckEmail(eml) {
	var intLen;
	var i; var j; var bolRet;
	
	intLen = eml.length;
	i = 0; j = 0; bolRet = false;
	
	while(i < intLen){ 
		if(j == 0) {if(eml.substr(i,1) == '@') {j = 1;}}
		if(j == 1) {if(eml.substr(i,1) == '.') {bolRet = true; break;}}
		i++;
	}
	
	return bolRet;
};
	$(document).ready(function() {
	
	//function to toggle the display of the comment form
	$('#commentForm .showComment').toggle(function() {
		$('#commentForm .formDiv').slideDown();
	},function() {
		$('#commentForm .formDiv').slideUp();
	});
		
		//click handler to submit comment
		$('#submit').click(function() {
			$('#commentForm .formDiv').slideUp();				
			
			//alert($('#comment_author_url').val());
			
			$.post(window.location,{
				action: 'submitComment', 
				name: $('#author').val(), 
				email: $('#email').val(), 
				post_id: $('#comment_post_ID').val(),
				url: $('#comment_author_url').val(),
				comment: $('#comment').val(),
					recaptcha_response: $('#recaptcha_response_field').val(),
					recaptcha_challenge: $('#recaptcha_challenge_field').val()			
				},function(resp) {
					if (resp == 'success') {										
						$('#commentForm h3').text('Your comment has been submitted. Thanks!').css('color','#494949'); 
						$('.showComment').remove();
						} else {
							$('#commentForm h3').text('Whoops, there was a problem. Please try again.').css('color','red');
							$('#commentForm .formDiv').slideDown();				
						}
				
			});
		})
	});
