function OnAddTagSuccess ( oResponse )
{
	var txtT = document.getElementById ( 'txtNewTag' );
	if ( txtT != null )
		txtT.value = '';

	var chkI = document.getElementById ( 'chkInternal' );
	if ( chkI != null )
		chkI.checked = false;

	ShowMessage ( 'Your tag has been added', 'Your tag has been added successfully.' );
}

function OnAddTagFailure ()
{
	ShowMessage ( 'Adding your tag failed', 'There was an error while adding your tag. ' +
		'As a result, your tag has not been added.' );
}

function OnTagButtonClick ( oEvent )
{
	if ( s_sMediaName != null )
	{
		var txtT = document.getElementById ( 'txtNewTag' );

		if ( txtT != null )
		{
			var sTag = txtT.value;

			if ( sTag.length > 0 )
			{
				var chkI = document.getElementById ( 'chkInternal' );
				var sInternal = 'false';

				if ( ( chkI != null ) && ( chkI.checked == true ) )
					sInternal = 'true';
				
				StartWSCall ( 'Services/TagWebService.asmx/Add',
					'sMediaName=' + s_sMediaName + '&sTag=' + escape ( sTag ) +
					'&bInternal=' + sInternal,
					OnAddTagSuccess, OnAddTagFailure );
			}
			else
				ShowMessage ( 'No tag to add', 'Please enter a tag first.' );
		}
	}
}

function OnTagInputKeyPress ( oEvent )
{
	if ( !OnTextBoxKeyPress ( oEvent ) )
		return ( false );

	oEvent = GetEvent ( oEvent );
	
	if ( GetKeyCodeFromEvent ( oEvent ) == 13 ) // enter
	{
		var btnB = document.getElementById ( 'btnAddTag' );

		if ( btnB != null )
			btnB.click ();

		return ( false );
	}

	return ( true );
}