function clear_hand_search()
{
	document.getElementById('search_id').value = "";
	document.getElementById('search_origin').value = "";
	document.getElementById('search_game').selectedIndex = 0;
	document.getElementById('search_hand').selectedIndex = 0;
	document.getElementById('search_hand_better').checked = false;
	document.getElementById('search_site').selectedIndex = 0;
	document.getElementById('search_street').selectedIndex = 0;
	document.getElementById('search_street_later').checked = false;
	document.getElementById('search_structure').selectedIndex = 0;
	document.getElementById('search_outcome').selectedIndex = 0;
	document.getElementById('search_outcome_value').value = "";
	document.getElementById('search_limit').selectedIndex = 0;
	document.getElementById('search_position').selectedIndex = 0;
	document.getElementById('search_stakes').selectedIndex = 0;
	document.getElementById('search_players').selectedIndex = 0;
	document.getElementById('search_pot_size_min').value = "";
	document.getElementById('search_pot_size_max').value = "";
	document.getElementById('search_pot_size_bb').checked = false;
	document.getElementById('search_hole_cards').value = "";
}

function clear_session_search()
{
	document.getElementById('search_id').value = "";
	document.getElementById('search_origin').value = "";
	document.getElementById('search_game').selectedIndex = 0;
	document.getElementById('search_site').selectedIndex = 0;
	document.getElementById('search_structure').selectedIndex = 0;
	document.getElementById('search_outcome').selectedIndex = 0;
	document.getElementById('search_outcome_value').value = "";
	document.getElementById('search_limit').selectedIndex = 0;
	document.getElementById('search_position').selectedIndex = 0;
	document.getElementById('search_stakes').selectedIndex = 0;
	document.getElementById('search_players').selectedIndex = 0;
	document.getElementById('search_hands_min').value = "";
	document.getElementById('search_hands_max').value = "";
}

function confirm_delete(type, url)
{
	if (confirm("Are you sure you want to delete this " + type + "?"))
		document.location = url;
}

function confirm_delete_submit(type)
{
	return (confirm("Are you sure you want to delete this " + type + "?"));
}

function confirm_submit(message)
{
	return (confirm(message));
}

var channel_hand_id_submit = 0;

function showChannelSubmit(hand_id)
{
	channel_hand_id_submit = hand_id;
	document.getElementById('hand_id_span').innerHTML = channel_hand_id_submit;
	$("#channel_id_"+hand_id).live('click', function(e) {
		//$("#channel-mod-div").show();
		$("#channel-mod-div").animate({
		    width: "450px",
		    height: "380px",
		    opacity: 0.99,
		    marginLeft: "0px",
		    borderWidth: "2px"
		  }, 0 );
	    var relativeX = e.pageX - this.offsetLeft -580;
	    var relativeY = e.pageY - this.offsetTop -200;
	    $("#channel-mod-div").css('top', relativeY);
	    $("#channel-mod-div").css('left', relativeX);
	});
}

function hideme(obj_id)
{
	document.getElementById(obj_id).style.display = '';
	document.getElementById(obj_id).style.height = "1px";
	document.getElementById(obj_id).style.width = "1px";
	document.getElementById(obj_id).style.top = "1px";
	document.getElementById(obj_id).style.width = "1px";
	channel_hand_id_submit = 0;
}

function addToChannel()
{
	var comment = document.getElementById('channel_hand_comment').value.replace(/^\s+/, '');
	document.getElementById('channel_hand_comment').value = comment;
	if (comment == '')
	{
		document.getElementById('channel_hand_comment').focus();
		alert('You must enter a comment');
	}
	else
	{
		posturl_obj=new postURL('../AJAX/poker-tools-ajax.php', addToChannel_handler);
		posturl_obj.addpost("ADD_TO_CHANNEL", "ADD_TO_CHANNEL");
		posturl_obj.addpost("hand_id", channel_hand_id_submit);
		var channel_id = 0;
		obj_channel_form = document.getElementById('channel_form');
		if (obj_channel_form)
		{
			var channel_form_inputs = obj_channel_form.getElementsByTagName ('input');
			if (channel_form_inputs)
			{
				for (var i = 0; i < channel_form_inputs.length; ++i)
				{
			      if ((channel_form_inputs[i].type == 'radio') && (channel_form_inputs[i].name == 'channel_radio') && channel_form_inputs[i].checked)
			      {
			       	 channel_id = channel_form_inputs[i].value;
			       	 break;
			      }
			    }
			    posturl_obj.addpost("channel_id", channel_id);
			}
		}

		if (channel_id == 0)
		{
			alert('You must select a channel');
		}
		else
		{
			posturl_obj.addpost("comment", comment);
	    	posturl_obj.go();
		}
	}
}

function addToChannel_handler(data)
{
	var data_ary = data.split('||||');

	if (data_ary[0] == 1)
	{
		alert('You have successfully assigned hand id: '+data_ary[2]+' to your selected channel.');
		hideme('channel-mod-div');
		document.getElementById('channel_form').reset();
	}
	else
	{
		alert(data_ary[1]);
	}
}
