function comments_form_submit( form )
{
	var comment_post_ID = form.comment_post_ID.value;
	var comment_parent = form.comment_parent.value;
	var author = form.author.value;
	var email = form.email.value;
	var url = form.url.value;
	var comment = form.comment.value;
	
	var formDiv = '#comments_form_' + comment_post_ID;
	var commentDiv = '#comments_extra_' + comment_post_ID;
	var commentGravatar = '#comments_extra_' + comment_post_ID + '_gravatar';
	var commentInfName = '#comments_extra_' + comment_post_ID + '_inf_name';
	var commentComment = '#comments_extra_' + comment_post_ID + '_comment';
	
	var responseArrayFinal;
	
	
	// HIDE FORM
	$( formDiv ).fadeOut( 'slow' );
	
	
	// AJAX
	var ajax = ajaxInit();

	if( ajax )
	{
		ajax.open( "POST", globalURL + "wp-content/themes/talkability/ajax.comments.php?ACTION=gravar_comment&comment_post_ID=" + comment_post_ID + "&comment_parent=" + comment_parent + "&author=" + author + "&email=" + email + "&url=" + url + "&comment=" + comment, true );
		
		ajax.onreadystatechange = function()
		{
			if( ajax.readyState == 4 )
			{
				// RETURN
				responseArrayFinal = comments_split( ajax.responseText );
				
				
				// EXTRA COMMENT
				if( responseArrayFinal[ "return" ] == "SUCCESS" )
				{
					// COMMENT CONTENT
					$( commentGravatar ).html( responseArrayFinal[ "gravatar" ] );
					if( url == "" || url == "http://" )
						$( commentInfName ).text( author );
					else
						$( commentInfName ).html( "<a href='" + url + "' target='_blank'>" + author + "</a>" );
					$( commentComment ).text( comment );
					
					// SHOW COMMENT MOTION
					$( commentDiv ).css( "display", "block" );
					$( commentDiv ).fadeIn( 'slow' );
					
					// RETURN FUNCTION KEY PAGES
					keyStatus = true;
					
					
					// UPDATE NUMBER TOTAL
					if( $( "#post_comments_button_number_" + comment_post_ID ).text() != "" )
					{
						if( $( "#post_comments_button_number_" + comment_post_ID ).text() == "0" )
						{
							$( "#post_no_comments_display_" + comment_post_ID ).css( "display", "none" );
							$( "#post_comments_display_" + comment_post_ID ).css( "display", "block" );
							$( "#post_comments_button_number_" + comment_post_ID ).text( "1" );
						}
						else
						{
							var numberTotal = parseInt( $( "#post_comments_button_number_" + comment_post_ID ).text() );
							numberTotal++;
							$( "#post_comments_button_number_" + comment_post_ID ).text( numberTotal );
						}
					}
					
					
					// ANALYTICS
					analyticsEvent( 'comment', 'Submit' );
				}
				
				
				// HEADER
				//setTimeout( headerActualize, 2000 );
			}
		}

		ajax.send( null );
 	}
 	
 	
 	// Return
	return false;
}

function comments_split( responseText )
{
	var responseArray = responseText.split( "#" );
	var responseArrayFinal = new Array();

	for( var i in responseArray )
	{
		var itemArray = responseArray[ i ].split( "=>" );
		
		responseArrayFinal[ itemArray[ 0 ] ] = itemArray[ 1 ];
	}
	
	return responseArrayFinal;
}
	

function comments_validate( form )
{
	if(form.author.value=="" || form.author.value=="Nome*")
	{
		alert("Faltou o nome!");
		form.author.focus();
		return false;
	}
	
	
	if(form.email.value=="false" || form.email.value=="e-mail*")
	{
		alert("Faltou o e-mail!");
		form.email.focus();
		return false;
	}
	
	
	if(form.comment.value=="" || form.comment.value=="Comentário*")
	{
		alert("Faltou o comentário!");
		form.comment.focus();
		return false;
	}
	
	
	// SEND
	comments_form_submit( form );
	
	
	// Return
	return false;
}

function campo_label(campo, label)
{
	if(campo.value == '')
	{
		campo.value = label;
	}
	
	
	// FUNCTION KEY STATUS
	keyStatus = true;
}

function campo_focus()
{
	// FUNCTION KEY STATUS
	keyStatus = false;
}

function input_click_author(campo)
{
	if(campo.value == 'Nome*')
	{
		campo.value = '';
	}
}

function input_click_email(campo)
{
	if(campo.value == 'e-mail*')
	{
		campo.value = '';
	}
}

function input_click_site(campo)
{
	if(campo.value == "http://")
	{
		
	}
}

function textarea_click_comment(campo)
{
	if(campo.value == 'Comentário*')
	{
		campo.value = '';
	}
}
