function toggleComment() {
  	var post_block = $('post_comment');
  	var top_block = $('add-comment-top');
  	var bottom_block = $('add-comment');

	if( top_block != null ){

		if ( top_block.style.display == "none" ) {
			top_block.appendChild(post_block);
		}
		else {
			bottom_block.appendChild(post_block);
		}
		foldToggle('add-comment-top');
  	} else {
  		alert('You must be signed in to view comments.');
  	}

}

function postComment(form_name) {

    topic = $('topic_id');
//    var dev = location.href.indexOf('www.mp3.com');
//    if(dev != -1){
//    	var target_url = '/forums/post_ajax.html';
//    }
//    else {
//        var target_url = '/mp3/www/forums/post_ajax.html';
//    }
    var dev = location.href.indexOf('www.mp3.com');
    var staging = location.href.indexOf('staging.internal');

    if(dev != -1 || staging != -1){
    	var target_url = '/forums/post_ajax.html';
    }
    else {
        var target_url = '/mp3/www/forums/post_ajax.html';
    }		

    foldToggle('post-comment-buttons', 100, getElHeight($('post-comment-buttons')));
    foldToggle('processing-comment', 100, getElHeight($('processing-comment')));

    // Because the doAjax method doesn't have optional params, I have to do it myself.  :(
    var form = $(form_name);
    if (supportsAjax()) {
        new ajax (target_url, {method: 'post', postBody: $F(form), onComplete: processPostCommentResults});
        return true;
    }
    else {
        form.action = target_url;
        form.method = 'POST';
        form.submit();
        return false;
    }
}

function processPostCommentResults(results) {

    // set the data array to be the response of the ajax
    var json_results = eval( '(' + results.responseText + ')' );

    data = json_results['data'];
    template = json_results['template'];

    var add_comment_div = $('add-comment');

    var msg_content = $('msg_content');

    var display_comment_div = $('display-comment');

    var display_div = $('post-comment');

    // if the data was posted
    if ( data['msg_posted'] ) {
        // build the dw tag to display
        if ( data['msg_posted_url'] ) {
            // some snazzy js to parse the string
            // get everything before the destURL=
            data['dw_redir'] = data['msg_posted_url'].substring(0, data['msg_posted_url'].indexOf('destURL=')+8);
        }
        // do this check here since the msg_posted_url may not actually contain a dw tag.
        if ( !data['dw_redir'] ) {
            data['dw_redir'] = "http://dw.com.com/redir?ltype=&siteid=6&edid=107&asId=&astId=&ctype=&cval=&ptid=6036&onid=47&useract=82&destURL=";
        }
        data['dw_redir'] = data['dw_redir'] + "http://img.gamespot.com/gamespot/b.gif";
        // set the gif
        var clrgif = document.createElement('img');
        clrgif.setAttribute('src', data['dw_redir']);
        document.body.appendChild(clrgif);

        display_comment_div.innerHTML=template;
        fadeIn(display_comment_div);

        var comment_count_div = $('comment_count');
        if (comment_count_div)
        	comment_count_div.innerHTML = data['topic']['comment_count'] + ' Comments';

        msg_content.value = "";

        foldToggle('add-comment', 500, getElHeight(add_comment_div));

    }
    else {
        var size_incr = 0;
        msg_content.value = data['msg']['content'];

    	foldToggle('processing-comment', 100, getElHeight($('processing-comment')));

        display_div.innerHTML=template;

    }

  	// little hackity hack to stop the click trapper from stopping submit/preview/2nd comment
  	DoubleClickTrapperCounter--;


}