/* Mantis #12737
 * The YUI dialog for deleting a comment was removed/replaced because it was
 * not working very well on pages with a very large number of comments
 */
// define name spaces
BSD.namespace('BSD.community');

// define some class members
BSD.community.redirect_referer = '' ;
BSD.community.redirect_url = '' ;


// show/hide the options for "replace with" when appropriate
BSD.community.manage_divs = function()
{
	if (document.delete_form.delete_style[0].checked)
	{
		hide('delete_with_options');
	}
	// explicitly define the other case b/c we want nothing to be unhidden if the radio is not yet defined
	else if (document.delete_form.delete_style[1].checked)
	{
		show('delete_with_options');
	}	
}

// allow an admin to hide/show a deleted comment
BSD.community.toggle_deleted_comment = function( id)
{
	if (document.getElementById(id).style.display == 'none')
	{
		show( id) ;
	}
	else
	{
		hide( id) ;
	}
}

// User is doesn't want to delete the comment, return to the calling page
BSD.community.cancel_delete_comment = function( referer )
{
    location.href = referer;
}

BSD.community.validate_form = function() {
	if (( document.delete_form.delete_style[1].checked) && (document.delete_form.replace_with_text.value == ''))
	{
		alert("Please enter a 'replace with' message.");
		return false ;
	}
	else
	{
		return true ;
	}
};


BSD.community.submit_delete_form = function( url, referer ) 
{
    if (!BSD.community.validate_form()) 
        return false;
	// set the global
	this.redirect_url = url ;
	this.redirect_referer = referer ;

    // construct the url and then redirect us to the delete backend
    var action = ((document.delete_form.delete_style[0].checked) ? 'permanent' : 'replace') ;
    var query_param = '?action=' + action ;
    if ( action == 'replace')
    {
        query_param += '&del_child=' + ((document.delete_form.delete_child.checked) ? 1 : 0) + '&text=' + encodeURIComponent(document.delete_form.replace_with_text.value) ;
    }
//alert( this.redirect_url + query_param + '&referer=' + this.redirect_referer) ;
    location.href = this.redirect_url + query_param + '&referer=' + this.redirect_referer;
}

