

/*
 * showComments()
 *
 * Näyttää reference_id:n mukaiseen kohteeseen 
 * lisätyt kommentit:
 *
 * @param	reference_id	Kommenttien kohteen id
 */

function showComments(reference_id)
{
	var comment_div_id = "#comment_div_" + reference_id;
	$(comment_div_id).show("slow");
}



/*
 * hideComments()
 *
 * Piilottaa reference_id:n mukaiseen kohteeseen
 * lisätyt kommentit.
 *
 * @param	reference_id	Kommenttien kohteen id
 */

function hideComments(reference_id)
{
	var comment_div_id = "#comment_div_" + reference_id;
	$(comment_div_id).hide("slow");
}



/*
 * addComment()
 *
 * Näyttää kommentin lisäyslomakkeen.
 *
 * @param	reference_id	Sen ilmentymän id, johon kommentin
 *							lisäyslomake kuuluu.
 */

function addComment(reference_id)
{
	// Show add comment form:
	var comment_form_id = '#add_comment_form_div_' + reference_id;
	$(comment_form_id ).show("slow");
	
	var referred_url_id = '#referred_url_' + reference_id;
	$(referred_url_id).val(String(document.location));
}



/*
 * saveComment
 *
 * Tarkistaan ja lähettää kommenttilomakkeen tiedot palvelimelle.
 */

function saveComment(reference_id)
{
	var state = true;
	
	
	/*
	 * Tarkistetaan, että nimi- ja kommentti-kentät
	 * eivät ole tyhjiä:
	 */
	
	if(isEmptyField('comment_sender_name_' + reference_id) || isEmptyField('comment_text_' + reference_id))
	{
		state = false;
		alert(getMessage('empty_field_error'));
	}
	
	
	/*
	 * Tarkistetaan, että varmistemerkit on annettu oikein:
	 */
	
	if(!isConfirmValid('comment_confirm_' + reference_id, 'TB3E'))
	{
		state = false;
		alert(getMessage('invalid_confirm_error'));
	}
	
	
	/*
	 * Lähetetään lomakkeen tiedot, jos kaikki kentät
	 * ovat olleet valideja:
	 */
	 
	if(state)
	{
		var id = "#add_comment_form_" + reference_id;
		$(id).submit();
	}
}
 


/*
 * cancelAddComment()
 *
 * Kommentin lisäyksen peruminen. Tyhjentää kaikki
 * syöttökentät lomakkeessa ja piilottaa
 * lomakkeen.
 *
 * @param	reference_id	Sen ilmentymän id, johon kommentin
 *							lisäyslomake kuuluu.
 */

function cancelAddComment(reference_id)
{
	// Hide add comment form:
	var comment_form_id = '#add_comment_form_div_' + reference_id;
	$(comment_form_id ).hide("slow");
	
	// Clear all fields:
	var id = '#comment_sender_name_' + reference_id;
	$(id).val("");
	
	id = '#comment_sender_email_' + reference_id;
	$(id).val("");
	
	id = '#comment_sender_www_' + reference_id;
	$(id).val("");
	
	id = '#comment_text_' + reference_id;
	$(id).val("");
}



/*
 * enableComment()
 *
 * Date		29.10.2009
 *
 * Kommentin asettaminen tilaan 'enabled', jolloin
 * se näytetään sivulla julkisesti. Piilottaa
 * hyväksymispainikkeen kommentin yhteydestä.
 *
 * @param	comment_id	Sallittavan kommentin id.
 */

function enableComment(comment_id)
{
	$.post(String(document.location) + "&Action=enable_comment", { comment_id: comment_id },
	  function(data){
	    
	    if(data == "enable_comment_ok")
	    {
		    var id = '#enableCommentBtn_' + comment_id;
		    $(id).css("display", "none");
	    }
	});
}



/*
 * removeComment()
 *
 * Date		29.10.2009
 *
 * Kommentin poistaminen tietokannasta.
 * 
 * @param	comment_id	Poistettavan kommentin id.
 */

function removeComment(comment_id)
{	
	var comment_div = '#comment_list_item_' + comment_id;
	$(comment_div).hide("slow");
	
	$.post(String(document.location) + "&Action=remove_comment", { comment_id: comment_id },
	  function(data){
	    
	    if(data != "remove_comment_ok")
	    {
		    alert(getMessage('remove_comment_error'));
	    }
	});
}
