function processCommand(oFormObject) {
    
    
	oOption = oFormObject.options[oFormObject.selectedIndex];
	
    if (!oOption)
		return;
	
	
	sCmd = oOption.label;
	sData = oOption.value;
	
	if (!sData) return;
	
	// are we running in a popup?
	bInPop = window.opener;
	
	switch(sCmd) {
		
		
		default:
			document.getElementById('user_cmd').value = sCmd;
			document.getElementById('user_cmd_data').value = sData;
			
			if (sCmd == "Delete Message"){
				if(!confirm("Are you sure you want to delete this message?"))
				{
					oFormObject.selectedIndex = 0;
					return;
				}
			}
			if (sCmd == "Delete This Topic"){
				if(!confirm("Are you sure you want to delete this ENTIRE topic?"))
				{
					oFormObject.selectedIndex = 0;
					return;
				}
				
			}
			
			if (sCmd == "Move This Topic"){
				openChooser("/forums/board_chooser.php");
				storedData = sData;
				return;
			}
			

			if (sCmd == "Ban This User"){
				if(!confirm("Are you sure you want to ban this user?"))
				{
					oFormObject.selectedIndex = 0;
					return;
				}
				iNumDays = prompt("How many days (-1 is indefinite)?", "7");
				if (iNumDays != null)
					document.getElementById('user_cmd_extra_data').value = iNumDays;
				else
				{
					oFormObject.selectedIndex = 0;
					return;
				}
			}
			
			if (sCmd == "Suspend This User"){
				iNumDays = prompt("How many days (-1 is indefinite, Moderators may only select 1-7 days)?", "7");
				if (iNumDays != null)
					document.getElementById('user_cmd_extra_data').value = iNumDays;
				else
				{
					oFormObject.selectedIndex = 0;
					return;
				}

			}
			
			if (sCmd == "View Edit History"){
				if (window.opener)
					document.forms['command'].target = "_blank";
			}
			
			if (sCmd == "Moderate"){
			
			     if(!confirm("This will automatically mark the message as abusive and take you to the moderation page. Are you sure?"))
			     {
				    oFormObject.selectedIndex = 0;
				    return;
			     }
			}
				
			
			document.forms['command'].submit();
			break;
	}
}

function openChooser(sURL) {
	
	iChooserWin=window.open(sURL, "gamespot_chooser", "width=200,height=250,scrollbars=no,resizable=no,titlebar=no");
	iChooserWin.focus();
	return iChooserWin;
}

function boardPicked(sTitle, iId) {
    
	// user has picked a dest board for moving a topic
	if (confirm("You have chosen to move the this topic and all of it's messages from this board to the '" + sTitle + "' board. Are you sure?")) {
        document.getElementById('user_cmd_extra_data').value = iId;	
	    document.forms['command'].submit();
	}
	else
		document.forms['command'].topic_options.selectedIndex = 0;
}

function forum_toggle_spoiler(id) {

    if ( document.getElementById('spoiler'+id).style.display == "block" ) {
        document.getElementById('spoiler'+id).style.display = "none";
    }
    else {
        document.getElementById('spoiler'+id).style.display = "block";
    }
}

function forum_show_all_spoilers() {
    var id = 0;
    // max 50 msgs per page
    while (id <= 50) { 
        id++;
        try {
            var my_display = document.getElementById('spoiler'+id).style.display;
            forum_toggle_spoiler(id);
        }
        catch(err) {
            // don't auto return.  with moderation sometimes the actual spoiler id doesn't match up right due to original and current
            // msg checks
//            return;
        }
    }
}

function thumb_comment( msg_id, thumb_val ) {
    var target_url = '/pages/ajax/thumb_comment.php';
	var data = "msg_id=" + msg_id + "&thumb_val=" + thumb_val;
    if (supportsAjax()) {
    	$('thumbs_msg_' + msg_id).setStyle('display', 'none');
    	dbug.log("calling %s?%s", target_url, data);
        new Ajax (target_url, {method: 'post', postBody: data, onComplete: processThumbResults}).request();
        return true;
    }

}

function processThumbResults( results ) {	
	var json = eval( '(' + results + ')' );
	dbug.log(json);
	if ( json['error_msg'] ) {
		$('thumbs_msg_' + json['msg_id']).innerHTML = json['error_msg'];
		$('thumbs_msg_' + json['msg_id']).setStyle('display', 'block');
	}
	else {
		$('thumbs_diff_' + json['msg_id']).innerHTML = json['thumbs']['thumbs_diff'] >= 0 ? '+' + json['thumbs']['thumbs_diff'] : json['thumbs']['thumbs_diff'];
        // do this check here since the msg_posted_url may not actually contain a dw tag.
        if ( !json['dw_redir'] ) {
            json['dw_redir'] = "http://dw.com.com/redir?ltype=&siteid=6&edid=107&asId=&astId=&ptid=6036&onid=47&useract=1&destURL=";
        }
        json['dw_redir'] = json['dw_redir'] + "http://img.gamespot.com/gamespot/b.gif";
        // set the gif
        var clrgif = document.createElement('img');
        clrgif.setAttribute('src', json['dw_redir']);
        document.body.appendChild(clrgif);
		
	}
}
